ensightOutputFunctions.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "ensightOutputFunctions.H"
00028
00029 #include "passiveParticle.H"
00030 #include "IOField.H"
00031 #include "volFields.H"
00032 #include "surfaceFields.H"
00033
00034 #include "OFstream.H"
00035 #include "IOmanip.H"
00036
00037 namespace Foam
00038 {
00039
00040
00041
00042 void ensightCaseEntry
00043 (
00044 OFstream& caseFile,
00045 const string& ensightType,
00046 const word& fieldName,
00047 const fileName& dataMask,
00048 const fileName& local,
00049 const label cloudNo,
00050 const label timeSet
00051 )
00052 {
00053 caseFile.setf(ios_base::left);
00054
00055 fileName dirName(dataMask);
00056 if (local.size())
00057 {
00058 dirName = dirName/local;
00059 }
00060
00061 if (cloudNo >= 0)
00062 {
00063 label ts = 1;
00064 if (timeSet > ts)
00065 {
00066 ts = timeSet;
00067 }
00068
00069
00070 caseFile
00071 << ensightType.c_str()
00072 << " per measured node: " << ts << " "
00073 << setw(15)
00074 << ("c" + Foam::name(cloudNo) + fieldName).c_str()
00075 << " "
00076 << (dirName/fieldName).c_str()
00077 << nl;
00078 }
00079 else
00080 {
00081 caseFile
00082 << ensightType.c_str()
00083 << " per element: "
00084 << setw(15) << fieldName
00085 << " "
00086 << (dirName/fieldName).c_str()
00087 << nl;
00088 }
00089 }
00090
00091
00092 void ensightParticlePositions
00093 (
00094 const polyMesh& mesh,
00095 const fileName& dataDir,
00096 const fileName& subDir,
00097 const word& cloudName,
00098 IOstream::streamFormat format
00099 )
00100 {
00101 Cloud<passiveParticle> parcels(mesh, cloudName, false);
00102
00103 fileName cloudDir = subDir/cloud::prefix/cloudName;
00104 fileName postFileName = cloudDir/"positions";
00105
00106
00107 mkDir(dataDir/cloudDir);
00108 ensightFile os(dataDir/postFileName, format);
00109
00110
00111 os.writeBinaryHeader();
00112 os.write(postFileName);
00113 os.newline();
00114 os.write("particle coordinates");
00115 os.newline();
00116 os.write(parcels.size(), 8);
00117 os.newline();
00118
00119
00120 if (format == IOstream::BINARY)
00121 {
00122 forAll (parcels, i)
00123 {
00124 os.write(i+1);
00125 }
00126
00127 forAllIter(Cloud<passiveParticle>, parcels, elmnt)
00128 {
00129 const vector& p = elmnt().position();
00130
00131 os.write(p.x());
00132 os.write(p.y());
00133 os.write(p.z());
00134 }
00135 }
00136 else
00137 {
00138 label nParcels = 0;
00139
00140 forAllIter(Cloud<passiveParticle>, parcels, elmnt)
00141 {
00142 const vector& p = elmnt().position();
00143
00144 os.write(++nParcels, 8);
00145 os.write(p.x());
00146 os.write(p.y());
00147 os.write(p.z());
00148 os.newline();
00149 }
00150 }
00151 }
00152
00153
00154
00155 template<class Type>
00156 void ensightLagrangianField
00157 (
00158 const IOobject& fieldObject,
00159 const fileName& dataDir,
00160 const fileName& subDir,
00161 const word& cloudName,
00162 IOstream::streamFormat format
00163 )
00164 {
00165 Info<< " " << fieldObject.name() << flush;
00166
00167 fileName cloudDir = subDir/cloud::prefix/cloudName;
00168 fileName postFileName = cloudDir/fieldObject.name();
00169
00170 string title =
00171 postFileName + " with " + pTraits<Type>::typeName + " values";
00172
00173 ensightFile os(dataDir/postFileName, format);
00174 os.write(title);
00175 os.newline();
00176
00177 IOField<Type> field(fieldObject);
00178
00179
00180 label count = 0;
00181
00182 forAll(field, i)
00183 {
00184 Type val = field[i];
00185
00186 if (mag(val) < 1.0e-90)
00187 {
00188 val = pTraits<Type>::zero;
00189 }
00190
00191 for (direction cmpt=0; cmpt < pTraits<Type>::nComponents; cmpt++)
00192 {
00193 os.write( component(val, cmpt) );
00194 }
00195
00196 count += pTraits<Type>::nComponents;
00197
00198 if (count % 6 == 0)
00199 {
00200 os.newline();
00201 }
00202 }
00203
00204
00205 if (count % 6)
00206 {
00207 os.newline();
00208 }
00209 }
00210
00211
00212
00213 template <class Type>
00214 void ensightVolField
00215 (
00216 const ensightParts& partsList,
00217 const IOobject& fieldObject,
00218 const fvMesh& mesh,
00219 const fileName& dataDir,
00220 const fileName& subDir,
00221 IOstream::streamFormat format
00222 )
00223 {
00224 Info<< " " << fieldObject.name() << flush;
00225
00226 fileName postFileName = subDir/fieldObject.name();
00227
00228 ensightFile os(dataDir/postFileName, format);
00229 os.write(postFileName);
00230 os.newline();
00231
00232
00233 partsList.writeField
00234 (
00235 os,
00236 GeometricField<Type, fvPatchField, volMesh>
00237 (
00238 fieldObject,
00239 mesh
00240 )
00241 );
00242 }
00243
00244
00245
00246 }
00247
00248
00249
Copyright © 2000-2009 OpenCFD Ltd