probes.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 "probes.H"
00028 #include "volFields.H"
00029 #include "dictionary.H"
00030 #include "Time.H"
00031 #include "IOmanip.H"
00032
00033
00034
00035 namespace Foam
00036 {
00037 defineTypeNameAndDebug(probes, 0);
00038 }
00039
00040
00041
00042 void Foam::probes::findCells(const fvMesh& mesh)
00043 {
00044 if (cellList_.empty())
00045 {
00046 cellList_.setSize(probeLocations_.size());
00047
00048 forAll(probeLocations_, probeI)
00049 {
00050 cellList_[probeI] = mesh.findCell(probeLocations_[probeI]);
00051
00052 if (debug && cellList_[probeI] != -1)
00053 {
00054 Pout<< "probes : found point " << probeLocations_[probeI]
00055 << " in cell " << cellList_[probeI] << endl;
00056 }
00057 }
00058
00059
00060
00061 forAll(cellList_, probeI)
00062 {
00063 label cellI = cellList_[probeI];
00064
00065
00066 reduce(cellI, maxOp<label>());
00067
00068 if (cellI == -1)
00069 {
00070 if (Pstream::master())
00071 {
00072 WarningIn("probes::read()")
00073 << "Did not find location " << probeLocations_[probeI]
00074 << " in any cell. Skipping location." << endl;
00075 }
00076 }
00077 else
00078 {
00079
00080 if (cellList_[probeI] != -1 && cellList_[probeI] != cellI)
00081 {
00082 WarningIn("probes::read()")
00083 << "Location " << probeLocations_[probeI]
00084 << " seems to be on multiple domains:"
00085 << " cell " << cellList_[probeI]
00086 << " on my domain " << Pstream::myProcNo()
00087 << " and cell " << cellI << " on some other domain."
00088 << endl
00089 << "This might happen if the probe location is on"
00090 << " a processor patch. Change the location slightly"
00091 << " to prevent this." << endl;
00092 }
00093 }
00094 }
00095 }
00096 }
00097
00098
00099 bool Foam::probes::checkFieldTypes()
00100 {
00101 wordList fieldTypes(fieldNames_.size());
00102
00103
00104 if (loadFromFiles_)
00105 {
00106 forAll(fieldNames_, fieldI)
00107 {
00108 IOobject io
00109 (
00110 fieldNames_[fieldI],
00111 obr_.time().timeName(),
00112 refCast<const polyMesh>(obr_),
00113 IOobject::MUST_READ,
00114 IOobject::NO_WRITE,
00115 false
00116 );
00117
00118 if (io.headerOk())
00119 {
00120 fieldTypes[fieldI] = io.headerClassName();
00121 }
00122 else
00123 {
00124 fieldTypes[fieldI] = "(notFound)";
00125 }
00126 }
00127 }
00128 else
00129 {
00130
00131 forAll(fieldNames_, fieldI)
00132 {
00133 objectRegistry::const_iterator iter =
00134 obr_.find(fieldNames_[fieldI]);
00135
00136 if (iter != obr_.end())
00137 {
00138 fieldTypes[fieldI] = iter()->type();
00139 }
00140 else
00141 {
00142 fieldTypes[fieldI] = "(notFound)";
00143 }
00144 }
00145 }
00146
00147
00148 label nFields = 0;
00149
00150
00151 nFields += countFields(scalarFields_, fieldTypes);
00152 nFields += countFields(vectorFields_, fieldTypes);
00153 nFields += countFields(sphericalTensorFields_, fieldTypes);
00154 nFields += countFields(symmTensorFields_, fieldTypes);
00155 nFields += countFields(tensorFields_, fieldTypes);
00156
00157
00158 wordList foundFields(nFields);
00159
00160 label fieldI = 0;
00161 forAll(scalarFields_, i)
00162 {
00163 foundFields[fieldI++] = scalarFields_[i];
00164 }
00165 forAll(vectorFields_, i)
00166 {
00167 foundFields[fieldI++] = vectorFields_[i];
00168 }
00169 forAll(sphericalTensorFields_, i)
00170 {
00171 foundFields[fieldI++] = sphericalTensorFields_[i];
00172 }
00173 forAll(symmTensorFields_, i)
00174 {
00175 foundFields[fieldI++] = symmTensorFields_[i];
00176 }
00177 forAll(tensorFields_, i)
00178 {
00179 foundFields[fieldI++] = tensorFields_[i];
00180 }
00181
00182 if (Pstream::master())
00183 {
00184 fileName probeDir;
00185
00186 fileName probeSubDir = name_;
00187
00188 if (obr_.name() != polyMesh::defaultRegion)
00189 {
00190 probeSubDir = probeSubDir/obr_.name();
00191 }
00192 probeSubDir = probeSubDir/obr_.time().timeName();
00193
00194 if (Pstream::parRun())
00195 {
00196
00197
00198 probeDir = obr_.time().path()/".."/probeSubDir;
00199 }
00200 else
00201 {
00202 probeDir = obr_.time().path()/probeSubDir;
00203 }
00204
00205
00206 forAllIter(HashPtrTable<OFstream>, probeFilePtrs_, iter)
00207 {
00208 if (findIndex(foundFields, iter.key()) == -1)
00209 {
00210 if (debug)
00211 {
00212 Pout<< "close stream: " << iter()->name() << endl;
00213 }
00214
00215 delete probeFilePtrs_.remove(iter);
00216 }
00217 }
00218
00219
00220
00221 probeFilePtrs_.resize(2*foundFields.size());
00222
00223 forAll(foundFields, fieldI)
00224 {
00225 const word& fldName = foundFields[fieldI];
00226
00227
00228
00229 if (!probeFilePtrs_.found(fldName))
00230 {
00231
00232 mkDir(probeDir);
00233
00234 OFstream* sPtr = new OFstream(probeDir/fldName);
00235
00236 if (debug)
00237 {
00238 Pout<< "open stream: " << sPtr->name() << endl;
00239 }
00240
00241 probeFilePtrs_.insert(fldName, sPtr);
00242
00243 unsigned int w = IOstream::defaultPrecision() + 7;
00244
00245 for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
00246 {
00247 *sPtr<< '#' << setw(IOstream::defaultPrecision() + 6)
00248 << vector::componentNames[cmpt];
00249
00250 forAll(probeLocations_, probeI)
00251 {
00252 *sPtr<< ' ' << setw(w) << probeLocations_[probeI][cmpt];
00253 }
00254 *sPtr << endl;
00255 }
00256
00257 *sPtr<< '#' << setw(IOstream::defaultPrecision() + 6)
00258 << "Time" << endl;
00259 }
00260 }
00261
00262 if (debug)
00263 {
00264 Pout<< "Probing fields:" << foundFields << nl
00265 << "Probing locations:" << probeLocations_ << nl
00266 << endl;
00267 }
00268 }
00269
00270
00271 return nFields > 0;
00272 }
00273
00274
00275
00276
00277 Foam::probes::probes
00278 (
00279 const word& name,
00280 const objectRegistry& obr,
00281 const dictionary& dict,
00282 const bool loadFromFiles
00283 )
00284 :
00285 name_(name),
00286 obr_(obr),
00287 loadFromFiles_(loadFromFiles),
00288 fieldNames_(0),
00289 probeLocations_(0),
00290 scalarFields_(),
00291 vectorFields_(),
00292 sphericalTensorFields_(),
00293 symmTensorFields_(),
00294 tensorFields_(),
00295 cellList_(0),
00296 probeFilePtrs_(0)
00297 {
00298 read(dict);
00299 }
00300
00301
00302
00303
00304 Foam::probes::~probes()
00305 {}
00306
00307
00308
00309
00310 void Foam::probes::execute()
00311 {
00312
00313 }
00314
00315
00316 void Foam::probes::end()
00317 {
00318
00319 }
00320
00321
00322 void Foam::probes::write()
00323 {
00324 if (probeLocations_.size() && checkFieldTypes())
00325 {
00326 sampleAndWrite(scalarFields_);
00327 sampleAndWrite(vectorFields_);
00328 sampleAndWrite(sphericalTensorFields_);
00329 sampleAndWrite(symmTensorFields_);
00330 sampleAndWrite(tensorFields_);
00331 }
00332 }
00333
00334
00335 void Foam::probes::read(const dictionary& dict)
00336 {
00337 dict.lookup("fields") >> fieldNames_;
00338 dict.lookup("probeLocations") >> probeLocations_;
00339
00340
00341 cellList_.clear();
00342 findCells(refCast<const fvMesh>(obr_));
00343 checkFieldTypes();
00344 }
00345
00346
00347
Copyright © 2000-2009 OpenCFD Ltd