1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
27 #include "volFields.H"
28 #include "dictionary.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 defineTypeNameAndDebug(Foam::probes, 0);
37 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
39 void Foam::probes::findElements(const fvMesh& mesh)
42 elementList_.setSize(size());
46 const vector& location = operator[](probeI);
48 elementList_[probeI] = mesh.findCell(location);
50 if (debug && elementList_[probeI] != -1)
52 Pout<< "probes : found point " << location
53 << " in cell " << elementList_[probeI] << endl;
58 // Check if all probes have been found.
59 forAll(elementList_, probeI)
61 const vector& location = operator[](probeI);
62 label cellI = elementList_[probeI];
64 // Check at least one processor with cell.
65 reduce(cellI, maxOp<label>());
69 if (Pstream::master())
71 WarningIn("probes::read()")
72 << "Did not find location " << location
73 << " in any cell. Skipping location." << endl;
78 // Make sure location not on two domains.
79 if (elementList_[probeI] != -1 && elementList_[probeI] != cellI)
81 WarningIn("probes::read()")
82 << "Location " << location
83 << " seems to be on multiple domains:"
84 << " cell " << elementList_[probeI]
85 << " on my domain " << Pstream::myProcNo()
86 << " and cell " << cellI << " on some other domain."
88 << "This might happen if the probe location is on"
89 << " a processor patch. Change the location slightly"
90 << " to prevent this." << endl;
97 Foam::label Foam::probes::prepare()
99 const label nFields = classifyFields();
101 // adjust file streams
102 if (Pstream::master())
104 wordHashSet currentFields;
106 currentFields.insert(scalarFields_);
107 currentFields.insert(vectorFields_);
108 currentFields.insert(sphericalTensorFields_);
109 currentFields.insert(symmTensorFields_);
110 currentFields.insert(tensorFields_);
114 Info<< "Probing fields:" << currentFields << nl
115 << "Probing locations:" << *this << nl
121 fileName probeSubDir = name_;
123 if (mesh_.name() != polyMesh::defaultRegion)
125 probeSubDir = probeSubDir/mesh_.name();
127 probeSubDir = probeSubDir/mesh_.time().timeName();
129 if (Pstream::parRun())
131 // Put in undecomposed case
132 // (Note: gives problems for distributed data running)
133 probeDir = mesh_.time().path()/".."/probeSubDir;
137 probeDir = mesh_.time().path()/probeSubDir;
140 // ignore known fields, close streams for fields that no longer exist
141 forAllIter(HashPtrTable<OFstream>, probeFilePtrs_, iter)
143 if (!currentFields.erase(iter.key()))
147 Info<< "close probe stream: " << iter()->name() << endl;
150 delete probeFilePtrs_.remove(iter);
154 // currentFields now just has the new fields - open streams for them
155 forAllConstIter(wordHashSet, currentFields, iter)
157 const word& fieldName = iter.key();
159 // Create directory if does not exist.
162 OFstream* sPtr = new OFstream(probeDir/fieldName);
166 Info<< "open probe stream: " << sPtr->name() << endl;
169 probeFilePtrs_.insert(fieldName, sPtr);
171 unsigned int w = IOstream::defaultPrecision() + 7;
173 for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
175 *sPtr<< '#' << setw(IOstream::defaultPrecision() + 6)
176 << vector::componentNames[cmpt];
178 forAll(*this, probeI)
180 *sPtr<< ' ' << setw(w) << operator[](probeI)[cmpt];
185 *sPtr<< '#' << setw(IOstream::defaultPrecision() + 6)
194 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
199 const objectRegistry& obr,
200 const dictionary& dict,
201 const bool loadFromFiles
206 mesh_(refCast<const fvMesh>(obr)),
207 loadFromFiles_(loadFromFiles)
213 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
215 Foam::probes::~probes()
219 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
221 void Foam::probes::execute()
223 // Do nothing - only valid on write
227 void Foam::probes::end()
229 // Do nothing - only valid on write
233 void Foam::probes::write()
235 if (size() && prepare())
237 sampleAndWrite(scalarFields_);
238 sampleAndWrite(vectorFields_);
239 sampleAndWrite(sphericalTensorFields_);
240 sampleAndWrite(symmTensorFields_);
241 sampleAndWrite(tensorFields_);
246 void Foam::probes::read(const dictionary& dict)
248 dict.lookup("probeLocations") >> *this;
249 dict.lookup("fields") >> fieldSelection_;
251 // redetermined all cell locations
257 // ************************************************************************* //