ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / sampling / sampledSet / sampledSets / sampledSets.C
blobf2bbced7a51ade9c32a7c9fbd48ec6fe33136242
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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"
28 #include "Time.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)
59     {
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.
77         List<point> allPts
78         (
79             ListListOps::combine<List<point> >
80             (
81                 gatheredPts, accessOp<List<point> >()
82             )
83         );
84         labelList allSegments
85         (
86             ListListOps::combine<labelList>
87             (
88                 gatheredSegments, accessOp<labelList>()
89             )
90         );
91         scalarList allCurveDist
92         (
93             ListListOps::combine<scalarList>
94             (
95                 gatheredDist, accessOp<scalarList>()
96             )
97         );
100         if (Pstream::master() && allCurveDist.size() == 0)
101         {
102             WarningIn("sampledSets::combineSampledSets(..)")
103                 << "Sample set " << samplePts.name()
104                 << " has zero points." << endl;
105         }
107         // Sort curveDist and use to fill masterSamplePts
108         SortableList<scalar> sortedDist(allCurveDist);
109         indexSets[setI] = sortedDist.indices();
111         masterSampledSets.set
112         (
113             setI,
114             new coordSet
115             (
116                 samplePts.name(),
117                 samplePts.axis(),
118                 List<point>(UIndirectList<point>(allPts, indexSets[setI])),
119                 allCurveDist
120             )
121         );
122     }
126 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
128 Foam::sampledSets::sampledSets
130     const word& name,
131     const objectRegistry& obr,
132     const dictionary& dict,
133     const bool loadFromFiles
136     PtrList<sampledSet>(),
137     name_(name),
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())
146     {
147         outputPath_ = mesh_.time().path()/".."/name_;
148     }
149     else
150     {
151         outputPath_ = mesh_.time().path()/name_;
152     }
153     if (mesh_.name() != fvMesh::defaultRegion)
154     {
155         outputPath_ = outputPath_/mesh_.name();
156     }
158     read(dict);
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()
190     if (size())
191     {
192         const label nFields = classifyFields();
194         if (Pstream::master())
195         {
196             if (debug)
197             {
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;
204             }
206             if (nFields)
207             {
208                 if (debug)
209                 {
210                     Pout<< "Creating directory "
211                         << outputPath_/mesh_.time().timeName()
212                             << nl << endl;
213                 }
215                 mkDir(outputPath_/mesh_.time().timeName());
216             }
217         }
219         if (nFields)
220         {
221             sampleAndWrite(scalarFields_);
222             sampleAndWrite(vectorFields_);
223             sampleAndWrite(sphericalTensorFields_);
224             sampleAndWrite(symmTensorFields_);
225             sampleAndWrite(tensorFields_);
226         }
227     }
231 void Foam::sampledSets::read(const dictionary& dict)
233     dict_ = dict;
235     bool setsFound = dict_.found("sets");
236     if (setsFound)
237     {
238         dict_.lookup("fields") >> fieldSelection_;
239         clearFieldGroups();
241         dict.lookup("interpolationScheme") >> interpolationScheme_;
242         dict.lookup("setFormat") >> writeFormat_;
244         PtrList<sampledSet> newList
245         (
246             dict_.lookup("sets"),
247             sampledSet::iNew(mesh_, searchEngine_)
248         );
249         transfer(newList);
250         combineSampledSets(masterSampledSets_, indexSets_);
252         if (this->size())
253         {
254             Info<< "Reading set description:" << nl;
255             forAll(*this, setI)
256             {
257                 Info<< "    " << operator[](setI).name() << nl;
258             }
259             Info<< endl;
260         }
261     }
263     if (Pstream::master() && debug)
264     {
265         Pout<< "sample fields:" << fieldSelection_ << nl
266             << "sample sets:" << nl << "(" << nl;
268         forAll(*this, setI)
269         {
270             Pout<< "  " << operator[](setI) << endl;
271         }
272         Pout<< ")" << endl;
273     }
277 void Foam::sampledSets::correct()
279     bool setsFound = dict_.found("sets");
280     if (setsFound)
281     {
282         // reset interpolation
283         pointMesh::Delete(mesh_);
284         volPointInterpolation::Delete(mesh_);
286         searchEngine_.correct();
288         PtrList<sampledSet> newList
289         (
290             dict_.lookup("sets"),
291             sampledSet::iNew(mesh_, searchEngine_)
292         );
293         transfer(newList);
294         combineSampledSets(masterSampledSets_, indexSets_);
295     }
299 void Foam::sampledSets::updateMesh(const mapPolyMesh&)
301     correct();
305 void Foam::sampledSets::movePoints(const pointField&)
307     correct();
311 void Foam::sampledSets::readUpdate(const polyMesh::readUpdateState state)
313     if (state != polyMesh::UNCHANGED)
314     {
315         correct();
316     }
320 // ************************************************************************* //