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-2013 OpenFOAM Foundation
6  \\/ M anipulation |
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 
45 void Foam::sampledSets::combineSampledSets
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  (
82  ListListOps::combine<List<point> >
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  {
105  WarningIn("sampledSets::combineSampledSets(..)")
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  allCurveDist
123  )
124  );
125  }
126 }
127 
128 
129 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
130 
131 Foam::sampledSets::sampledSets
132 (
133  const word& name,
134  const objectRegistry& obr,
135  const dictionary& dict,
136  const bool loadFromFiles
137 )
138 :
140  name_(name),
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 // ************************************************************************* //
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:380
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: sampledSets.C:191
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:306
virtual ~sampledSets()
Destructor.
Definition: sampledSets.C:167
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Gather data but keep individual values separate.
Info<< "Predicted p max-min : "<< max(p).value()<< " "<< min(p).value()<< endl;rho==max(psi *p+alphal *rhol0+((alphav *psiv+alphal *psil)-psi)*pSat, rhoMin);#1"/home/dm2/henry/OpenFOAM/OpenFOAM-3.0.x/applications/solvers/multiphase/cavitatingFoam/alphavPsi.H"1{alphav=max(min((rho-rholSat)/(rhovSat-rholSat), scalar(1)), scalar(0));alphal=1.0-alphav;Info<< "max-min alphav: "<< max(alphav).value()<< " "<< min(alphav).value()<< endl;psiModel-> correct()
Definition: pEqn.H:74
A class for handling words, derived from string.
Definition: word.H:59
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
messageStream Info
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Namespace for OpenFOAM.
AccessType combine(const List< T > &, AccessOp aop=accessOp< T >())
Combines sublists into one big list.
Definition: ListListOps.C:34
dictionary dict
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:386
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
virtual void execute()
Execute, currently does nothing.
Definition: sampledSets.C:179
#define WarningIn(functionName)
Report a warning using Foam::Warning.
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:88
#define forAll(list, i)
Definition: UList.H:421
virtual void readUpdate(const polyMesh::readUpdateState state)
Update for changes of mesh due to readUpdate.
Definition: sampledSets.C:316
Class used for the read-construction of.
Definition: sampledSet.H:173
static const fileName null
An empty fileName.
Definition: fileName.H:97
void correct()
Correct for mesh changes.
Definition: sampledSets.C:286
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:50
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:404
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:306
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
virtual void updateMesh(const mapPolyMesh &)
Update for changes of mesh.
Definition: sampledSets.C:304
Registry of regIOobjects.
List< label > labelList
A List of labels.
Definition: labelList.H:56
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:398
bool read(const char *, int32_t &)
Definition: int32IO.C:87
virtual void read(const dictionary &)
Read the sampledSets.
Definition: sampledSets.C:240
void verbose(const bool verbosity=true)
Set verbosity level.
Definition: sampledSets.C:173
virtual void write()
Sample and write.
Definition: sampledSets.C:197
virtual void end()
Execute at the final time-loop, currently does nothing.
Definition: sampledSets.C:185
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:420
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
static const word null
An empty word.
Definition: word.H:77
virtual void movePoints(const polyMesh &)
Update for mesh point-motion.
Definition: sampledSets.C:310
defineTypeNameAndDebug(combustionModel, 0)
prefixOSstream Pout(cout,"Pout")
Definition: IOstreams.H:53