sampledSets.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
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"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(sampledSets, 0);
39  bool sampledSets::verbose_ = false;
40 }
41 
42 
43 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
44 
46 (
47  PtrList<coordSet>& masterSampledSets,
48  labelListList& indexSets
49 )
50 {
51  // Combine sampleSets from processors. Sort by curveDist. Return
52  // ordering in indexSets.
53  // Note: only master results are valid
54 
55  masterSampledSets_.clear();
56  masterSampledSets_.setSize(size());
57  indexSets_.setSize(size());
58 
59  const PtrList<sampledSet>& sampledSets = *this;
60 
61  forAll(sampledSets, setI)
62  {
63  const sampledSet& samplePts = sampledSets[setI];
64 
65  // Collect data from all processors
66  List<List<point> > gatheredPts(Pstream::nProcs());
67  gatheredPts[Pstream::myProcNo()] = samplePts;
68  Pstream::gatherList(gatheredPts);
69 
70  List<labelList> gatheredSegments(Pstream::nProcs());
71  gatheredSegments[Pstream::myProcNo()] = samplePts.segments();
72  Pstream::gatherList(gatheredSegments);
73 
74  List<scalarList> gatheredDist(Pstream::nProcs());
75  gatheredDist[Pstream::myProcNo()] = samplePts.curveDist();
76  Pstream::gatherList(gatheredDist);
77 
78 
79  // Combine processor lists into one big list.
80  List<point> allPts
81  (
83  (
84  gatheredPts, accessOp<List<point> >()
85  )
86  );
87  labelList allSegments
88  (
89  ListListOps::combine<labelList>
90  (
91  gatheredSegments, accessOp<labelList>()
92  )
93  );
94  scalarList allCurveDist
95  (
96  ListListOps::combine<scalarList>
97  (
98  gatheredDist, accessOp<scalarList>()
99  )
100  );
101 
102 
103  if (Pstream::master() && allCurveDist.size() == 0)
104  {
106  << "Sample set " << samplePts.name()
107  << " has zero points." << endl;
108  }
109 
110  // Sort curveDist and use to fill masterSamplePts
111  SortableList<scalar> sortedDist(allCurveDist);
112  indexSets[setI] = sortedDist.indices();
113 
114  masterSampledSets.set
115  (
116  setI,
117  new coordSet
118  (
119  samplePts.name(),
120  samplePts.axis(),
121  List<point>(UIndirectList<point>(allPts, indexSets[setI])),
122  sortedDist
123  )
124  );
125  }
126 }
127 
128 
129 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
130 
132 (
133  const word& name,
134  const objectRegistry& obr,
135  const dictionary& dict,
136  const bool loadFromFiles
137 )
138 :
141  mesh_(refCast<const fvMesh>(obr)),
142  loadFromFiles_(loadFromFiles),
143  outputPath_(fileName::null),
144  searchEngine_(mesh_),
145  interpolationScheme_(word::null),
146  writeFormat_(word::null)
147 {
148  if (Pstream::parRun())
149  {
150  outputPath_ = mesh_.time().path()/".."/"postProcessing"/name_;
151  }
152  else
153  {
154  outputPath_ = mesh_.time().path()/"postProcessing"/name_;
155  }
156  if (mesh_.name() != fvMesh::defaultRegion)
157  {
158  outputPath_ = outputPath_/mesh_.name();
159  }
160 
161  read(dict);
162 }
163 
164 
165 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
166 
168 {}
169 
170 
171 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
172 
173 void Foam::sampledSets::verbose(const bool verbosity)
174 {
175  verbose_ = verbosity;
176 }
177 
178 
180 {
181  // Do nothing - only valid on write
182 }
183 
184 
186 {
187  // Do nothing - only valid on write
188 }
189 
190 
192 {
193  // Do nothing - only valid on write
194 }
195 
196 
198 {
199  if (size())
200  {
201  const label nFields = classifyFields();
202 
203  if (Pstream::master())
204  {
205  if (debug)
206  {
207  Pout<< "timeName = " << mesh_.time().timeName() << nl
208  << "scalarFields " << scalarFields_ << nl
209  << "vectorFields " << vectorFields_ << nl
210  << "sphTensorFields " << sphericalTensorFields_ << nl
211  << "symTensorFields " << symmTensorFields_ <<nl
212  << "tensorFields " << tensorFields_ <<nl;
213  }
214 
215  if (nFields)
216  {
217  if (debug)
218  {
219  Pout<< "Creating directory "
220  << outputPath_/mesh_.time().timeName()
221  << nl << endl;
222  }
223 
224  mkDir(outputPath_/mesh_.time().timeName());
225  }
226  }
227 
228  if (nFields)
229  {
230  sampleAndWrite(scalarFields_);
231  sampleAndWrite(vectorFields_);
232  sampleAndWrite(sphericalTensorFields_);
233  sampleAndWrite(symmTensorFields_);
234  sampleAndWrite(tensorFields_);
235  }
236  }
237 }
238 
239 
241 {
242  dict_ = dict;
243 
244  bool setsFound = dict_.found("sets");
245  if (setsFound)
246  {
247  dict_.lookup("fields") >> fieldSelection_;
248  clearFieldGroups();
249 
250  dict.lookup("interpolationScheme") >> interpolationScheme_;
251  dict.lookup("setFormat") >> writeFormat_;
252 
253  PtrList<sampledSet> newList
254  (
255  dict_.lookup("sets"),
256  sampledSet::iNew(mesh_, searchEngine_)
257  );
258  transfer(newList);
259  combineSampledSets(masterSampledSets_, indexSets_);
260 
261  if (this->size())
262  {
263  Info<< "Reading set description:" << nl;
264  forAll(*this, setI)
265  {
266  Info<< " " << operator[](setI).name() << nl;
267  }
268  Info<< endl;
269  }
270  }
271 
272  if (Pstream::master() && debug)
273  {
274  Pout<< "sample fields:" << fieldSelection_ << nl
275  << "sample sets:" << nl << "(" << nl;
276 
277  forAll(*this, setI)
278  {
279  Pout<< " " << operator[](setI) << endl;
280  }
281  Pout<< ")" << endl;
282  }
283 }
284 
285 
287 {
288  bool setsFound = dict_.found("sets");
289  if (setsFound)
290  {
291  searchEngine_.correct();
292 
293  PtrList<sampledSet> newList
294  (
295  dict_.lookup("sets"),
296  sampledSet::iNew(mesh_, searchEngine_)
297  );
298  transfer(newList);
299  combineSampledSets(masterSampledSets_, indexSets_);
300  }
301 }
302 
303 
305 {
306  correct();
307 }
308 
309 
311 {
312  correct();
313 }
314 
315 
317 {
318  if (state != polyMesh::UNCHANGED)
319  {
320  correct();
321  }
322 }
323 
324 
325 // ************************************************************************* //
Foam::sampledSet
Holds list of sampling points which is filled at construction time. Various implementations of this b...
Definition: sampledSet.H:64
Foam::sampledSets::~sampledSets
virtual ~sampledSets()
Destructor.
Definition: sampledSets.C:167
volFields.H
Foam::coordSet::name
const word & name() const
Definition: coordSet.H:111
Foam::sampledSets::readUpdate
virtual void readUpdate(const polyMesh::readUpdateState state)
Update for changes of mesh due to readUpdate.
Definition: sampledSets.C:316
Foam::sampledSets::updateMesh
virtual void updateMesh(const mapPolyMesh &)
Update for changes of mesh.
Definition: sampledSets.C:304
Foam::sampledSets::execute
virtual void execute()
Execute, currently does nothing.
Definition: sampledSets.C:179
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::functionObjectState
Base class for function objects, adding functionality to read/write state information (data required ...
Definition: functionObjectState.H:54
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::sampledSets
Set of sets to sample. Call sampledSets.write() to sample&write files.
Definition: sampledSets.H:60
Foam::sampledSets::end
virtual void end()
Execute at the final time-loop, currently does nothing.
Definition: sampledSets.C:185
Foam::sampledSets::read
virtual void read(const dictionary &)
Read the sampledSets.
Definition: sampledSets.C:240
ListListOps.H
Foam::read
bool read(const char *, int32_t &)
Definition: int32IO.C:87
Foam::sampledSets::verbose
void verbose(const bool verbosity=true)
Set verbosity level.
Definition: sampledSets.C:173
Foam::ListListOps::combine
AccessType combine(const List< T > &, AccessOp aop=accessOp< T >())
Combines sublists into one big list.
Definition: ListListOps.C:34
Foam::sampledSets::write
virtual void write()
Sample and write.
Definition: sampledSets.C:197
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::accessOp
Definition: ListListOps.H:98
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::coordSet::axis
word axis() const
Definition: coordSet.H:116
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::sampledSets::timeSet
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: sampledSets.C:191
sampledSets.H
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
SortableList.H
Foam::PtrList::set
bool set(const label) const
Is element set.
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::dictionary::found
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:304
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
correct
fvOptions correct(rho)
Foam::polyMesh::UNCHANGED
@ UNCHANGED
Definition: polyMesh.H:90
Foam::PtrList
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::coordSet::curveDist
const scalarList & curveDist() const
Cumulative distance.
Definition: coordSet.H:122
Foam::sampledSet::segments
const labelList & segments() const
Definition: sampledSet.H:258
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::SortableList
A list that is sorted upon construction or when explicitly requested with the sort() method.
Definition: List.H:65
Foam::sampledSets::combineSampledSets
void combineSampledSets(PtrList< coordSet > &masterSampledSets, labelListList &indexSets)
Combine points from all processors. Sort by curveDist and produce.
Definition: sampledSets.C:46
Foam::coordSet
Holds list of sampling positions.
Definition: coordSet.H:49
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::sampledSets::correct
void correct()
Correct for mesh changes.
Definition: sampledSets.C:286
Foam::UPstream::master
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:399
Foam::polyMesh::readUpdateState
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:88
volPointInterpolation.H
Foam::Pout
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
dictionary.H
Foam::sampledSets::movePoints
virtual void movePoints(const polyMesh &)
Update for mesh point-motion.
Definition: sampledSets.C:310
Foam::SortableList::indices
const labelList & indices() const
Return the list of sorted indices. Updated every sort.
Definition: SortableList.H:90
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
Foam::UIndirectList
A List with indirect addressing.
Definition: fvMatrix.H:106
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::mkDir
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:419
Foam::sampledSets::verbose_
static bool verbose_
Output verbosity.
Definition: sampledSets.H:152
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::sampledSet::iNew
Class used for the read-construction of.
Definition: sampledSet.H:173
Foam::sampledSets::sampledSets
sampledSets(const sampledSets &)
Disallow default bitwise copy construct and assignment.