1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2010 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
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 \*---------------------------------------------------------------------------*/
26 #include "sampledSets.H"
27 #include "dictionary.H"
29 #include "volFields.H"
30 #include "ListListOps.H"
31 #include "SortableList.H"
32 #include "volPointInterpolation.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 defineTypeNameAndDebug(sampledSets, 0);
41 bool Foam::sampledSets::verbose_ = false;
44 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 bool Foam::sampledSets::checkFieldTypes()
48 wordList fieldTypes(fieldNames_.size());
50 // check files for a particular time
53 forAll(fieldNames_, fieldi)
58 mesh_.time().timeName(),
67 fieldTypes[fieldi] = io.headerClassName();
71 fieldTypes[fieldi] = "(notFound)";
77 // check objectRegistry
78 forAll(fieldNames_, fieldi)
80 objectRegistry::const_iterator iter =
81 mesh_.find(fieldNames_[fieldi]);
83 if (iter != mesh_.objectRegistry::end())
85 fieldTypes[fieldi] = iter()->type();
89 fieldTypes[fieldi] = "(notFound)";
97 // classify fieldTypes
98 nFields += grep(scalarFields_, fieldTypes);
99 nFields += grep(vectorFields_, fieldTypes);
100 nFields += grep(sphericalTensorFields_, fieldTypes);
101 nFields += grep(symmTensorFields_, fieldTypes);
102 nFields += grep(tensorFields_, fieldTypes);
104 if (Pstream::master())
108 Pout<< "timeName = " << mesh_.time().timeName() << nl
109 << "scalarFields " << scalarFields_ << nl
110 << "vectorFields " << vectorFields_ << nl
111 << "sphTensorFields " << sphericalTensorFields_ << nl
112 << "symTensorFields " << symmTensorFields_ <<nl
113 << "tensorFields " << tensorFields_ <<nl;
120 Pout<< "Creating directory "
121 << outputPath_/mesh_.time().timeName()
125 mkDir(outputPath_/mesh_.time().timeName());
133 void Foam::sampledSets::combineSampledSets
135 PtrList<coordSet>& masterSampledSets,
136 labelListList& indexSets
139 // Combine sampleSets from processors. Sort by curveDist. Return
140 // ordering in indexSets.
141 // Note: only master results are valid
143 masterSampledSets_.clear();
144 masterSampledSets_.setSize(size());
145 indexSets_.setSize(size());
147 const PtrList<sampledSet>& sampledSets = *this;
149 forAll(sampledSets, seti)
151 const sampledSet& samplePts = sampledSets[seti];
153 // Collect data from all processors
154 List<List<point> > gatheredPts(Pstream::nProcs());
155 gatheredPts[Pstream::myProcNo()] = samplePts;
156 Pstream::gatherList(gatheredPts);
158 List<labelList> gatheredSegments(Pstream::nProcs());
159 gatheredSegments[Pstream::myProcNo()] = samplePts.segments();
160 Pstream::gatherList(gatheredSegments);
162 List<scalarList> gatheredDist(Pstream::nProcs());
163 gatheredDist[Pstream::myProcNo()] = samplePts.curveDist();
164 Pstream::gatherList(gatheredDist);
167 // Combine processor lists into one big list.
170 ListListOps::combine<List<point> >
172 gatheredPts, accessOp<List<point> >()
175 labelList allSegments
177 ListListOps::combine<labelList>
179 gatheredSegments, accessOp<labelList>()
182 scalarList allCurveDist
184 ListListOps::combine<scalarList>
186 gatheredDist, accessOp<scalarList>()
191 if (Pstream::master() && allCurveDist.size() == 0)
193 WarningIn("sampledSets::combineSampledSets(..)")
194 << "Sample set " << samplePts.name()
195 << " has zero points." << endl;
198 // Sort curveDist and use to fill masterSamplePts
199 SortableList<scalar> sortedDist(allCurveDist);
200 indexSets[seti] = sortedDist.indices();
202 // Get reference point (note: only master has all points)
207 refPt = samplePts.getRefPoint(allPts);
211 refPt = vector::zero;
215 masterSampledSets.set
222 UIndirectList<point>(allPts, indexSets[seti]),
230 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
232 Foam::sampledSets::sampledSets
235 const objectRegistry& obr,
236 const dictionary& dict,
237 const bool loadFromFiles
240 PtrList<sampledSet>(),
242 mesh_(refCast<const fvMesh>(obr)),
243 loadFromFiles_(loadFromFiles),
244 outputPath_(fileName::null),
245 searchEngine_(mesh_, true),
247 interpolationScheme_(word::null),
248 writeFormat_(word::null)
250 if (Pstream::parRun())
252 outputPath_ = mesh_.time().path()/".."/name_;
256 outputPath_ = mesh_.time().path()/name_;
258 if (mesh_.name() != fvMesh::defaultRegion)
260 outputPath_ = outputPath_/mesh_.name();
267 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
269 Foam::sampledSets::~sampledSets()
273 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
275 void Foam::sampledSets::verbose(const bool verbosity)
277 verbose_ = verbosity;
281 void Foam::sampledSets::execute()
283 // Do nothing - only valid on write
287 void Foam::sampledSets::end()
289 // Do nothing - only valid on write
293 void Foam::sampledSets::write()
295 if (size() && checkFieldTypes())
297 sampleAndWrite(scalarFields_);
298 sampleAndWrite(vectorFields_);
299 sampleAndWrite(sphericalTensorFields_);
300 sampleAndWrite(symmTensorFields_);
301 sampleAndWrite(tensorFields_);
306 void Foam::sampledSets::read(const dictionary& dict)
310 fieldNames_ = wordList(dict_.lookup("fields"));
312 interpolationScheme_ = "cell";
313 dict_.readIfPresent("interpolationScheme", interpolationScheme_);
315 dict_.lookup("setFormat") >> writeFormat_;
317 scalarFields_.clear();
318 vectorFields_.clear();
319 sphericalTensorFields_.clear();
320 symmTensorFields_.clear();
321 tensorFields_.clear();
323 PtrList<sampledSet> newList
325 dict_.lookup("sets"),
326 sampledSet::iNew(mesh_, searchEngine_)
329 combineSampledSets(masterSampledSets_, indexSets_);
331 if (Pstream::master() && debug)
333 Pout<< "sample fields:" << fieldNames_ << nl
334 << "sample sets:" << nl << "(" << nl;
338 Pout << " " << operator[](si) << endl;
345 void Foam::sampledSets::correct()
347 // reset interpolation
348 pointMesh::Delete(mesh_);
349 volPointInterpolation::Delete(mesh_);
351 searchEngine_.correct();
353 PtrList<sampledSet> newList
355 dict_.lookup("sets"),
356 sampledSet::iNew(mesh_, searchEngine_)
359 combineSampledSets(masterSampledSets_, indexSets_);
363 void Foam::sampledSets::updateMesh(const mapPolyMesh&)
369 void Foam::sampledSets::movePoints(const pointField&)
375 void Foam::sampledSets::readUpdate(const polyMesh::readUpdateState state)
377 if (state != polyMesh::UNCHANGED)
384 // ************************************************************************* //