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 \*---------------------------------------------------------------------------*/
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 * * * * * * * * * * * * * //
36 defineTypeNameAndDebug(Foam::sampledSets, 0);
37 bool Foam::sampledSets::verbose_ = false;
40 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
42 void Foam::sampledSets::combineSampledSets
44 PtrList<coordSet>& masterSampledSets,
45 labelListList& indexSets
48 // Combine sampleSets from processors. Sort by curveDist. Return
49 // ordering in indexSets.
50 // Note: only master results are valid
52 masterSampledSets_.clear();
53 masterSampledSets_.setSize(size());
54 indexSets_.setSize(size());
56 const PtrList<sampledSet>& sampledSets = *this;
58 forAll(sampledSets, setI)
60 const sampledSet& samplePts = sampledSets[setI];
62 // Collect data from all processors
63 List<List<point> > gatheredPts(Pstream::nProcs());
64 gatheredPts[Pstream::myProcNo()] = samplePts;
65 Pstream::gatherList(gatheredPts);
67 List<labelList> gatheredSegments(Pstream::nProcs());
68 gatheredSegments[Pstream::myProcNo()] = samplePts.segments();
69 Pstream::gatherList(gatheredSegments);
71 List<scalarList> gatheredDist(Pstream::nProcs());
72 gatheredDist[Pstream::myProcNo()] = samplePts.curveDist();
73 Pstream::gatherList(gatheredDist);
76 // Combine processor lists into one big list.
79 ListListOps::combine<List<point> >
81 gatheredPts, accessOp<List<point> >()
86 ListListOps::combine<labelList>
88 gatheredSegments, accessOp<labelList>()
91 scalarList allCurveDist
93 ListListOps::combine<scalarList>
95 gatheredDist, accessOp<scalarList>()
100 if (Pstream::master() && allCurveDist.size() == 0)
102 WarningIn("sampledSets::combineSampledSets(..)")
103 << "Sample set " << samplePts.name()
104 << " has zero points." << endl;
107 // Sort curveDist and use to fill masterSamplePts
108 SortableList<scalar> sortedDist(allCurveDist);
109 indexSets[setI] = sortedDist.indices();
111 masterSampledSets.set
118 List<point>(UIndirectList<point>(allPts, indexSets[setI])),
126 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
128 Foam::sampledSets::sampledSets
131 const objectRegistry& obr,
132 const dictionary& dict,
133 const bool loadFromFiles
136 PtrList<sampledSet>(),
138 mesh_(refCast<const fvMesh>(obr)),
139 loadFromFiles_(loadFromFiles),
140 outputPath_(fileName::null),
141 searchEngine_(mesh_, true),
142 interpolationScheme_(word::null),
143 writeFormat_(word::null)
145 if (Pstream::parRun())
147 outputPath_ = mesh_.time().path()/".."/name_;
151 outputPath_ = mesh_.time().path()/name_;
153 if (mesh_.name() != fvMesh::defaultRegion)
155 outputPath_ = outputPath_/mesh_.name();
162 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
164 Foam::sampledSets::~sampledSets()
168 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
170 void Foam::sampledSets::verbose(const bool verbosity)
172 verbose_ = verbosity;
176 void Foam::sampledSets::execute()
178 // Do nothing - only valid on write
182 void Foam::sampledSets::end()
184 // Do nothing - only valid on write
188 void Foam::sampledSets::write()
192 const label nFields = classifyFields();
194 if (Pstream::master())
198 Pout<< "timeName = " << mesh_.time().timeName() << nl
199 << "scalarFields " << scalarFields_ << nl
200 << "vectorFields " << vectorFields_ << nl
201 << "sphTensorFields " << sphericalTensorFields_ << nl
202 << "symTensorFields " << symmTensorFields_ <<nl
203 << "tensorFields " << tensorFields_ <<nl;
210 Pout<< "Creating directory "
211 << outputPath_/mesh_.time().timeName()
215 mkDir(outputPath_/mesh_.time().timeName());
221 sampleAndWrite(scalarFields_);
222 sampleAndWrite(vectorFields_);
223 sampleAndWrite(sphericalTensorFields_);
224 sampleAndWrite(symmTensorFields_);
225 sampleAndWrite(tensorFields_);
231 void Foam::sampledSets::read(const dictionary& dict)
235 bool setsFound = dict_.found("sets");
238 dict_.lookup("fields") >> fieldSelection_;
241 dict.lookup("interpolationScheme") >> interpolationScheme_;
242 dict.lookup("setFormat") >> writeFormat_;
244 PtrList<sampledSet> newList
246 dict_.lookup("sets"),
247 sampledSet::iNew(mesh_, searchEngine_)
250 combineSampledSets(masterSampledSets_, indexSets_);
254 Info<< "Reading set description:" << nl;
257 Info<< " " << operator[](setI).name() << nl;
263 if (Pstream::master() && debug)
265 Pout<< "sample fields:" << fieldSelection_ << nl
266 << "sample sets:" << nl << "(" << nl;
270 Pout<< " " << operator[](setI) << endl;
277 void Foam::sampledSets::correct()
279 bool setsFound = dict_.found("sets");
282 // reset interpolation
283 pointMesh::Delete(mesh_);
284 volPointInterpolation::Delete(mesh_);
286 searchEngine_.correct();
288 PtrList<sampledSet> newList
290 dict_.lookup("sets"),
291 sampledSet::iNew(mesh_, searchEngine_)
294 combineSampledSets(masterSampledSets_, indexSets_);
299 void Foam::sampledSets::updateMesh(const mapPolyMesh&)
305 void Foam::sampledSets::movePoints(const pointField&)
311 void Foam::sampledSets::readUpdate(const polyMesh::readUpdateState state)
313 if (state != polyMesh::UNCHANGED)
320 // ************************************************************************* //