$treeview $search $mathjax
|
Palabos
Version 1.1
$projectbrief
|
$projectbrief
|
$searchbox |
00001 /* This file is part of the Palabos library. 00002 * 00003 * Copyright (C) 2011 FlowKit Sarl 00004 * Avenue de Chailly 23 00005 * 1012 Lausanne, Switzerland 00006 * E-mail contact: contact@flowkit.com 00007 * 00008 * The most recent release of Palabos can be downloaded at 00009 * <http://www.palabos.org/> 00010 * 00011 * The library Palabos is free software: you can redistribute it and/or 00012 * modify it under the terms of the GNU Affero General Public License as 00013 * published by the Free Software Foundation, either version 3 of the 00014 * License, or (at your option) any later version. 00015 * 00016 * The library is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Affero General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Affero General Public License 00022 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00023 */ 00024 00025 /* Main author : Etienne Vergnault 00026 */ 00027 00028 #ifndef VTK_STRUCTURED_DATA_OUTPUT_HH 00029 #define VTK_STRUCTURED_DATA_OUTPUT_HH 00030 00031 #include "core/globalDefs.h" 00032 #include "parallelism/mpiManager.h" 00033 #include "io/vtkStructuredDataOutput.h" 00034 #include "io/vtkDataOutput.hh" 00035 #include "io/serializerIO.h" 00036 00037 #include <iostream> 00038 #include <iomanip> 00039 #include <fstream> 00040 #include <sstream> 00041 00042 namespace plb { 00043 00045 00046 template<typename T> 00047 void VtkStructuredWriter3D::writeDataField(DataSerializer const* serializer, 00048 std::string const& name, plint nDim) 00049 { 00050 if (global::mpi().isMainProcessor()) { 00051 (*ostr) << "<DataArray type=\"" << VtkTypeNames<T>::getName() 00052 << "\" Name=\"" << name 00053 << "\" format=\"binary\" encoding=\"base64"; 00054 if (nDim>1) { 00055 (*ostr) << "\" NumberOfComponents=\"" << nDim; 00056 } 00057 (*ostr) << "\">\n"; 00058 } 00059 00060 // Undocumented requirement of the vtk xml file format: 00061 // in front of every binary blob, base64 or raw-binary, appended or not, 00062 // there is an UInt32 length indicator, giving the size of the binary blob in bytes; 00063 // when using base64 encoding, that length header must be encoded separately; 00064 // there must be no newline between the encoded length indicator and the encoded data block. 00065 // 00066 // Those properties are properly handled by the serializer2ostr function, if pluint plint is 00067 // equal to UInt32. If not, you are on your own. 00068 00069 bool enforceUint=true; // VTK uses "unsigned" to indicate the size of data, even on a 64-bit machine. 00070 serializerToBase64Stream(serializer, ostr, enforceUint); 00071 00072 if (global::mpi().isMainProcessor()) { 00073 (*ostr) << "\n</DataArray>\n"; 00074 } 00075 } 00076 00077 00079 00080 template<typename T> 00081 VtkStructuredImageOutput2D<T>::VtkStructuredImageOutput2D(std::string fName, T deltaX_) 00082 : fullName ( global::directories().getVtkOutDir() + fName+".vts" ), 00083 vtkOut( fullName ), deltaX(deltaX_), offset(T(),T()), headerWritten( false ) 00084 { } 00085 00086 template<typename T> 00087 VtkStructuredImageOutput2D<T>::VtkStructuredImageOutput2D(std::string fName, T deltaX_, Array<T,2> offset_) 00088 : fullName ( global::directories().getVtkOutDir() + fName+".vts" ), 00089 vtkOut( fullName ), 00090 deltaX(deltaX_), 00091 offset(offset_), 00092 headerWritten( false ) 00093 { } 00094 00095 template<typename T> 00096 VtkStructuredImageOutput2D<T>::~VtkStructuredImageOutput2D() { 00097 writeFooter(); 00098 } 00099 00100 template<typename T> 00101 void VtkStructuredImageOutput2D<T>::writeHeader(plint nx_, plint ny_) { 00102 if (headerWritten) { 00103 PLB_PRECONDITION(nx == nx_); 00104 PLB_PRECONDITION(ny == ny_); 00105 } 00106 else { 00107 nx = nx_; 00108 ny = ny_; 00109 vtkOut.writeHeader(Box3D(0,nx-1,0,ny-1,0,0)); 00110 vtkOut.startPiece(Box3D(0,nx-1,0,ny-1,0,0), Array<T,3>(offset[0],offset[1],T()), deltaX); 00111 headerWritten = true; 00112 } 00113 } 00114 00115 template<typename T> 00116 void VtkStructuredImageOutput2D<T>::writeFooter() { 00117 if (headerWritten) { 00118 vtkOut.endPiece(); 00119 vtkOut.writeFooter(); 00120 headerWritten = false; 00121 } 00122 } 00123 00124 template<typename T> 00125 template<typename TConv> 00126 void VtkStructuredImageOutput2D<T>::writeData( ScalarField2D<T> & scalarField, 00127 std::string scalarFieldName, TConv scalingFactor ) 00128 { 00129 writeHeader(scalarField.getNx(), scalarField.getNy()); 00130 std::auto_ptr<ScalarField2D<TConv> > transformedField = copyConvert<T,TConv>(scalarField); 00131 multiplyInPlace(*transformedField, scalingFactor); 00132 vtkOut.writeDataField<TConv> ( 00133 transformedField->getBlockSerializer(transformedField->getBoundingBox(), IndexOrdering::backward), 00134 scalarFieldName, 1 ); 00135 } 00136 00137 template<typename T> 00138 template<typename TConv> 00139 void VtkStructuredImageOutput2D<T>::writeData( MultiScalarField2D<T> & scalarField, 00140 std::string scalarFieldName, TConv scalingFactor ) 00141 { 00142 writeHeader(scalarField.getNx(), scalarField.getNy()); 00143 std::auto_ptr<MultiScalarField2D<TConv> > transformedField = copyConvert<T,TConv>(scalarField); 00144 multiplyInPlace(*transformedField, scalingFactor); 00145 vtkOut.writeDataField<TConv> ( 00146 transformedField->getBlockSerializer(transformedField->getBoundingBox(), IndexOrdering::backward), 00147 scalarFieldName, 1); 00148 } 00149 00150 template<typename T> 00151 template<plint n, typename TConv> 00152 void VtkStructuredImageOutput2D<T>::writeData( TensorField2D<T,n> & tensorField, 00153 std::string tensorFieldName, TConv scalingFactor ) 00154 { 00155 writeHeader(tensorField.getNx(), tensorField.getNy()); 00156 std::auto_ptr<TensorField2D<TConv,n> > transformedField = copyConvert<T,TConv,n>(tensorField); 00157 multiplyInPlace(*transformedField, scalingFactor); 00158 vtkOut.writeDataField<TConv> ( 00159 transformedField->getBlockSerializer(transformedField->getBoundingBox(), IndexOrdering::backward), 00160 tensorFieldName, n ); 00161 } 00162 00163 template<typename T> 00164 template<plint n, typename TConv> 00165 void VtkStructuredImageOutput2D<T>::writeData( MultiTensorField2D<T,n> & tensorField, 00166 std::string tensorFieldName, TConv scalingFactor ) 00167 { 00168 writeHeader(tensorField.getNx(), tensorField.getNy()); 00169 std::auto_ptr<MultiTensorField2D<TConv,n> > transformedField = copyConvert<T,TConv,n>(tensorField); 00170 multiplyInPlace(*transformedField, scalingFactor); 00171 vtkOut.writeDataField<TConv> ( 00172 transformedField->getBlockSerializer(transformedField->getBoundingBox(), IndexOrdering::backward), 00173 tensorFieldName, n); 00174 } 00175 00177 00178 template<typename T> 00179 VtkStructuredImageOutput3D<T>::VtkStructuredImageOutput3D(std::string fName, T deltaX_) 00180 : fullName ( global::directories().getVtkOutDir() + fName+".vts" ), 00181 vtkOut( fullName ), deltaX(deltaX_), offset(T(),T(),T()), headerWritten( false ) 00182 { } 00183 00184 template<typename T> 00185 VtkStructuredImageOutput3D<T>::VtkStructuredImageOutput3D(std::string fName, T deltaX_, Array<T,3> offset_) 00186 : fullName ( global::directories().getVtkOutDir() + fName+".vts" ), 00187 vtkOut( fullName ), deltaX(deltaX_), offset(offset_), headerWritten( false ) 00188 { } 00189 00190 template<typename T> 00191 VtkStructuredImageOutput3D<T>::~VtkStructuredImageOutput3D() { 00192 writeFooter(); 00193 } 00194 00195 template<typename T> 00196 void VtkStructuredImageOutput3D<T>::writeHeader(plint nx_, plint ny_, plint nz_) { 00197 if (headerWritten) { 00198 PLB_PRECONDITION(nx == nx_); 00199 PLB_PRECONDITION(ny == ny_); 00200 PLB_PRECONDITION(nz == nz_); 00201 } 00202 else { 00203 nx = nx_; 00204 ny = ny_; 00205 nz = nz_; 00206 vtkOut.writeHeader(Box3D(0,nx-1,0,ny-1,0,nz-1)); 00207 vtkOut.startPiece(Box3D(0,nx-1,0,ny-1,0,nz-1), offset, deltaX); 00208 headerWritten = true; 00209 } 00210 } 00211 00212 template<typename T> 00213 void VtkStructuredImageOutput3D<T>::writeFooter() { 00214 if (headerWritten) { 00215 vtkOut.endPiece(); 00216 vtkOut.writeFooter(); 00217 headerWritten = false; 00218 } 00219 } 00220 00221 template<typename T> 00222 template<typename TConv> 00223 void VtkStructuredImageOutput3D<T>::writeData( ScalarField3D<T> & scalarField, 00224 std::string scalarFieldName, TConv scalingFactor ) 00225 { 00226 writeHeader(scalarField.getNx(), scalarField.getNy(), scalarField.getNz()); 00227 std::auto_ptr<ScalarField3D<TConv> > transformedField = copyConvert<T,TConv>(scalarField); 00228 multiplyInPlace(*transformedField, scalingFactor); 00229 vtkOut.writeDataField<TConv> ( 00230 transformedField->getBlockSerializer(transformedField->getBoundingBox(), IndexOrdering::backward), 00231 scalarFieldName, 1 ); 00232 } 00233 00234 template<typename T> 00235 template<typename TConv> 00236 void VtkStructuredImageOutput3D<T>::writeData( MultiScalarField3D<T> & scalarField, 00237 std::string scalarFieldName, TConv scalingFactor ) 00238 { 00239 writeHeader(scalarField.getNx(), scalarField.getNy(), scalarField.getNz()); 00240 std::auto_ptr<MultiScalarField3D<TConv> > transformedField = copyConvert<T,TConv>(scalarField); 00241 multiplyInPlace(*transformedField, scalingFactor); 00242 vtkOut.writeDataField<TConv> ( 00243 transformedField->getBlockSerializer(transformedField->getBoundingBox(), IndexOrdering::backward), 00244 scalarFieldName, 1 ); 00245 } 00246 00247 template<typename T> 00248 template<plint n, typename TConv> 00249 void VtkStructuredImageOutput3D<T>::writeData( TensorField3D<T,n> & tensorField, 00250 std::string tensorFieldName, TConv scalingFactor ) 00251 { 00252 writeHeader(tensorField.getNx(), tensorField.getNy(), tensorField.getNz()); 00253 std::auto_ptr<TensorField3D<TConv,n> > transformedField = copyConvert<T,TConv,n>(tensorField); 00254 multiplyInPlace(*transformedField, scalingFactor); 00255 vtkOut.writeDataField<TConv> ( 00256 transformedField->getBlockSerializer(transformedField->getBoundingBox(), IndexOrdering::backward), 00257 tensorFieldName, n ); 00258 } 00259 00260 template<typename T> 00261 template<plint n, typename TConv> 00262 void VtkStructuredImageOutput3D<T>::writeData( MultiTensorField3D<T,n> & tensorField, 00263 std::string tensorFieldName, TConv scalingFactor ) 00264 { 00265 writeHeader(tensorField.getNx(), tensorField.getNy(), tensorField.getNz()); 00266 std::auto_ptr<MultiTensorField3D<TConv,n> > transformedField = copyConvert<T,TConv,n>(tensorField); 00267 multiplyInPlace(*transformedField, scalingFactor); 00268 vtkOut.writeDataField<TConv> ( 00269 transformedField->getBlockSerializer(transformedField->getBoundingBox(), IndexOrdering::backward), 00270 tensorFieldName, n ); 00271 } 00272 00273 00274 } // namespace plb 00275 00276 #endif // VTK_STRUCTURED_DATA_OUTPUT_HH 00277 00278
1.6.3
1.6.3