1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
27 #include "volFields.H"
28 #include "dictionary.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 defineTypeNameAndDebug(probes, 0);
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41 void Foam::probes::findCells(const fvMesh& mesh)
43 if (cellList_.empty())
45 Info<< "Searching for probe point locations" << endl;
47 cellList_.setSize(probeLocations_.size());
49 forAll(probeLocations_, probeI)
51 cellList_[probeI] = mesh.findCell(probeLocations_[probeI]);
53 if (debug && cellList_[probeI] != -1)
55 Pout<< "probes : found point " << probeLocations_[probeI]
56 << " in cell " << cellList_[probeI] << endl;
61 // Check if all probes have been found.
62 forAll(cellList_, probeI)
64 label cellI = cellList_[probeI];
66 // Check at least one processor with cell.
67 reduce(cellI, maxOp<label>());
71 if (Pstream::master())
73 WarningIn("probes::read()")
74 << "Did not find location " << probeLocations_[probeI]
75 << " in any cell. Skipping location." << endl;
80 // Make sure location not on two domains.
81 if (cellList_[probeI] != -1 && cellList_[probeI] != cellI)
83 WarningIn("probes::read()")
84 << "Location " << probeLocations_[probeI]
85 << " seems to be on multiple domains:"
86 << " cell " << cellList_[probeI]
87 << " on my domain " << Pstream::myProcNo()
88 << " and cell " << cellI << " on some other domain."
90 << "This might happen if the probe location is on"
91 << " a processor patch. Change the location slightly"
92 << " to prevent this." << endl;
100 bool Foam::probes::checkFieldTypes()
102 wordList fieldTypes(fieldNames_.size());
104 // check files for a particular time
107 forAll(fieldNames_, fieldI)
112 obr_.time().timeName(),
113 refCast<const polyMesh>(obr_),
121 fieldTypes[fieldI] = io.headerClassName();
125 fieldTypes[fieldI] = "(notFound)";
131 // check objectRegistry
132 forAll(fieldNames_, fieldI)
134 objectRegistry::const_iterator iter =
135 obr_.find(fieldNames_[fieldI]);
137 if (iter != obr_.end())
139 fieldTypes[fieldI] = iter()->type();
143 fieldTypes[fieldI] = "(notFound)";
151 // classify fieldTypes
152 nFields += countFields(scalarFields_, fieldTypes);
153 nFields += countFields(vectorFields_, fieldTypes);
154 nFields += countFields(sphericalTensorFields_, fieldTypes);
155 nFields += countFields(symmTensorFields_, fieldTypes);
156 nFields += countFields(tensorFields_, fieldTypes);
158 // concatenate all the lists into foundFields
159 wordList foundFields(nFields);
162 forAll(scalarFields_, i)
164 foundFields[fieldI++] = scalarFields_[i];
166 forAll(vectorFields_, i)
168 foundFields[fieldI++] = vectorFields_[i];
170 forAll(sphericalTensorFields_, i)
172 foundFields[fieldI++] = sphericalTensorFields_[i];
174 forAll(symmTensorFields_, i)
176 foundFields[fieldI++] = symmTensorFields_[i];
178 forAll(tensorFields_, i)
180 foundFields[fieldI++] = tensorFields_[i];
183 if (Pstream::master())
187 fileName probeSubDir = name_;
189 if (obr_.name() != polyMesh::defaultRegion)
191 probeSubDir = probeSubDir/obr_.name();
193 probeSubDir = probeSubDir/obr_.time().timeName();
195 if (Pstream::parRun())
197 // Put in undecomposed case
198 // (Note: gives problems for distributed data running)
199 probeDir = obr_.time().path()/".."/probeSubDir;
203 probeDir = obr_.time().path()/probeSubDir;
206 // Close the file if any fields have been removed.
207 forAllIter(HashPtrTable<OFstream>, probeFilePtrs_, iter)
209 if (findIndex(foundFields, iter.key()) == -1)
213 Pout<< "close stream: " << iter()->name() << endl;
216 delete probeFilePtrs_.remove(iter);
220 // Open new files for new fields. Keep existing files.
222 probeFilePtrs_.resize(2*foundFields.size());
224 forAll(foundFields, fieldI)
226 const word& fldName = foundFields[fieldI];
228 // Check if added field. If so open a stream for it.
230 if (!probeFilePtrs_.found(fldName))
232 // Create directory if does not exist.
235 OFstream* sPtr = new OFstream(probeDir/fldName);
239 Pout<< "open stream: " << sPtr->name() << endl;
242 probeFilePtrs_.insert(fldName, sPtr);
244 unsigned int w = IOstream::defaultPrecision() + 7;
246 for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
248 *sPtr<< '#' << setw(IOstream::defaultPrecision() + 6)
249 << vector::componentNames[cmpt];
251 forAll(probeLocations_, probeI)
253 *sPtr<< ' ' << setw(w) << probeLocations_[probeI][cmpt];
258 *sPtr<< '#' << setw(IOstream::defaultPrecision() + 6)
265 Pout<< "Probing fields:" << foundFields << nl
266 << "Probing locations:" << probeLocations_ << nl
276 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
281 const objectRegistry& obr,
282 const dictionary& dict,
283 const bool loadFromFiles
288 loadFromFiles_(loadFromFiles),
293 sphericalTensorFields_(),
303 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
305 Foam::probes::~probes()
309 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
311 void Foam::probes::execute()
316 void Foam::probes::end()
318 // Do nothing - only valid on write
322 void Foam::probes::write()
324 // Check if the mesh is changing and if so, resample
325 const fvMesh& mesh = refCast<const fvMesh>(obr_);
327 if (mesh.moving() || mesh.changing())
333 if (probeLocations_.size() && checkFieldTypes())
335 sampleAndWrite(scalarFields_);
336 sampleAndWrite(vectorFields_);
337 sampleAndWrite(sphericalTensorFields_);
338 sampleAndWrite(symmTensorFields_);
339 sampleAndWrite(tensorFields_);
344 void Foam::probes::read(const dictionary& dict)
346 dict.lookup("fields") >> fieldNames_;
347 dict.lookup("probeLocations") >> probeLocations_;
349 // Force all cell locations to be redetermined
351 findCells(refCast<const fvMesh>(obr_));
356 // ************************************************************************* //