1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM 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 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
28 #include "volFields.H"
29 #include "dictionary.H"
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 defineTypeNameAndDebug(probes, 0);
40 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
42 void Foam::probes::findCells(const fvMesh& mesh)
44 if (cellList_.size() == 0)
46 cellList_.setSize(probeLocations_.size());
48 forAll(probeLocations_, probeI)
50 cellList_[probeI] = mesh.findCell(probeLocations_[probeI]);
52 if (debug && cellList_[probeI] != -1)
54 Pout<< "probes : found point " << probeLocations_[probeI]
55 << " in cell " << cellList_[probeI] << endl;
60 // Check if all probes have been found.
61 forAll(cellList_, probeI)
63 label cellI = cellList_[probeI];
65 // Check at least one processor with cell.
66 reduce(cellI, maxOp<label>());
70 if (Pstream::master())
72 WarningIn("probes::read()")
73 << "Did not find location " << probeLocations_[probeI]
74 << " in any cell. Skipping location." << endl;
79 // Make sure location not on two domains.
80 if (cellList_[probeI] != -1 && cellList_[probeI] != cellI)
82 WarningIn("probes::read()")
83 << "Location " << probeLocations_[probeI]
84 << " seems to be on multiple domains:"
85 << " cell " << cellList_[probeI]
86 << " on my domain " << Pstream::myProcNo()
87 << " and cell " << cellI << " on some other domain."
89 << "This might happen if the probe location is on"
90 << " a processor patch. Change the location slightly"
91 << " to prevent this." << endl;
99 bool Foam::probes::checkFieldTypes()
101 wordList fieldTypes(fieldNames_.size());
103 // check files for a particular time
106 forAll(fieldNames_, fieldI)
111 obr_.time().timeName(),
112 refCast<const polyMesh>(obr_),
120 fieldTypes[fieldI] = io.headerClassName();
124 fieldTypes[fieldI] = "(notFound)";
130 // check objectRegistry
131 forAll(fieldNames_, fieldI)
133 objectRegistry::const_iterator iter =
134 obr_.find(fieldNames_[fieldI]);
136 if (iter != obr_.end())
138 fieldTypes[fieldI] = iter()->type();
142 fieldTypes[fieldI] = "(notFound)";
150 // classify fieldTypes
151 nFields += countFields(scalarFields_, fieldTypes);
152 nFields += countFields(vectorFields_, fieldTypes);
153 nFields += countFields(sphericalTensorFields_, fieldTypes);
154 nFields += countFields(symmTensorFields_, fieldTypes);
155 nFields += countFields(tensorFields_, fieldTypes);
157 // concatenate all the lists into foundFields
158 wordList foundFields(nFields);
161 forAll(scalarFields_, i)
163 foundFields[fieldI++] = scalarFields_[i];
165 forAll(vectorFields_, i)
167 foundFields[fieldI++] = vectorFields_[i];
169 forAll(sphericalTensorFields_, i)
171 foundFields[fieldI++] = sphericalTensorFields_[i];
173 forAll(symmTensorFields_, i)
175 foundFields[fieldI++] = symmTensorFields_[i];
177 forAll(tensorFields_, i)
179 foundFields[fieldI++] = tensorFields_[i];
182 if (Pstream::master())
185 if (Pstream::parRun())
187 // Put in undecomposed case
188 // (Note: gives problems for distributed data running)
189 probeDir = obr_.time().path()/".."/name_/obr_.time().timeName();
193 probeDir = obr_.time().path()/name_/obr_.time().timeName();
196 // Close the file if any fields have been removed.
197 forAllIter(HashPtrTable<OFstream>, probeFilePtrs_, iter)
199 if (findIndex(foundFields, iter.key()) == -1)
203 Pout<< "close stream: " << iter()->name() << endl;
206 delete probeFilePtrs_.remove(iter);
210 // Open new files for new fields. Keep existing files.
212 probeFilePtrs_.resize(2*foundFields.size());
214 forAll(foundFields, fieldI)
216 const word& fldName = foundFields[fieldI];
218 // Check if added field. If so open a stream for it.
220 if (!probeFilePtrs_.found(fldName))
222 // Create directory if does not exist.
225 OFstream* sPtr = new OFstream(probeDir/fldName);
229 Pout<< "open stream: " << sPtr->name() << endl;
232 probeFilePtrs_.insert(fldName, sPtr);
234 unsigned int w = IOstream::defaultPrecision() + 7;
236 for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
238 *sPtr<< '#' << setw(IOstream::defaultPrecision() + 6)
239 << vector::componentNames[cmpt];
241 forAll(probeLocations_, probeI)
243 *sPtr<< ' ' << setw(w) << probeLocations_[probeI][cmpt];
248 *sPtr<< '#' << setw(IOstream::defaultPrecision() + 6)
255 Pout<< "Probing fields:" << foundFields << nl
256 << "Probing locations:" << probeLocations_ << nl
266 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
271 const objectRegistry& obr,
272 const dictionary& dict,
273 const bool loadFromFiles
278 loadFromFiles_(loadFromFiles),
283 sphericalTensorFields_(),
293 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
295 Foam::probes::~probes()
299 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
301 void Foam::probes::execute()
303 // Do nothing - only valid on write
307 void Foam::probes::write()
309 if (probeLocations_.size() && checkFieldTypes())
311 sampleAndWrite(scalarFields_);
312 sampleAndWrite(vectorFields_);
313 sampleAndWrite(sphericalTensorFields_);
314 sampleAndWrite(symmTensorFields_);
315 sampleAndWrite(tensorFields_);
320 void Foam::probes::read(const dictionary& dict)
322 dict.lookup("fields") >> fieldNames_;
323 dict.lookup("probeLocations") >> probeLocations_;
325 // Force all cell locations to be redetermined
327 findCells(refCast<const fvMesh>(obr_));
332 // ************************************************************************* //