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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2015-2018 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "sampledSets.H"
30 #include "dictionary.H"
31 #include "Time.H"
32 #include "volFields.H"
33 #include "volPointInterpolation.H"
34 #include "mapPolyMesh.H"
36 
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41  defineTypeNameAndDebug(sampledSets, 0);
42 
44  (
45  functionObject,
46  sampledSets,
47  dictionary
48  );
49 }
50 
51 bool Foam::sampledSets::verbose_ = false;
52 
53 
54 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
55 
56 void Foam::sampledSets::combineSampledSets
57 (
58  PtrList<coordSet>& masterSampledSets,
59  labelListList& indexSets
60 )
61 {
62  // Combine sampleSets from processors. Sort by curveDist. Return
63  // ordering in indexSets.
64  // Note: only master results are valid
65 
66  masterSampledSets_.clear();
67  masterSampledSets_.setSize(size());
68  indexSets_.setSize(size());
69 
70  const PtrList<sampledSet>& sampledSets = *this;
71 
72  forAll(sampledSets, setI)
73  {
74  labelList segments;
75  masterSampledSets.set
76  (
77  setI,
78  sampledSets[setI].gather(indexSets[setI], segments)
79  );
80  }
81 }
82 
83 
84 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
85 
86 Foam::sampledSets::sampledSets
87 (
88  const word& name,
89  const Time& runTime,
90  const dictionary& dict
91 )
92 :
95  mesh_(refCast<const fvMesh>(obr_)),
96  loadFromFiles_(false),
97  outputPath_(fileName::null),
98  searchEngine_(mesh_),
99  interpolationScheme_(word::null),
100  writeFormat_(word::null)
101 {
102  outputPath_ =
103  (
104  mesh_.time().globalPath()/functionObject::outputPrefix/name
105  );
106 
107  if (mesh_.name() != fvMesh::defaultRegion)
108  {
109  outputPath_ = outputPath_/mesh_.name();
110  }
111 
112  outputPath_.clean(); // Remove unneeded ".."
113 
114  read(dict);
115 }
116 
117 
118 Foam::sampledSets::sampledSets
119 (
120  const word& name,
121  const objectRegistry& obr,
122  const dictionary& dict,
123  const bool loadFromFiles
124 )
125 :
128  mesh_(refCast<const fvMesh>(obr)),
129  loadFromFiles_(loadFromFiles),
130  outputPath_(fileName::null),
131  searchEngine_(mesh_),
132  interpolationScheme_(word::null),
133  writeFormat_(word::null)
134 {
135  outputPath_ =
136  (
137  mesh_.time().globalPath()/functionObject::outputPrefix/name
138  );
139 
140  if (mesh_.name() != fvMesh::defaultRegion)
141  {
142  outputPath_ = outputPath_/mesh_.name();
143  }
144 
145  outputPath_.clean(); // Remove unneeded ".."
146 
147  read(dict);
148 }
149 
150 
151 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
152 
153 void Foam::sampledSets::verbose(const bool verbosity)
154 {
155  verbose_ = verbosity;
156 }
157 
158 
160 {
161  return true;
162 }
163 
164 
166 {
167  if (size())
168  {
169  const label nFields = classifyFields();
170 
171  if (Pstream::master())
172  {
173  if (debug)
174  {
175  Pout<< "timeName = " << mesh_.time().timeName() << nl
176  << "scalarFields " << scalarFields_ << nl
177  << "vectorFields " << vectorFields_ << nl
178  << "sphTensorFields " << sphericalTensorFields_ << nl
179  << "symTensorFields " << symmTensorFields_ <<nl
180  << "tensorFields " << tensorFields_ <<nl;
181  }
182 
183  if (nFields)
184  {
185  if (debug)
186  {
187  Pout<< "Creating directory "
188  << outputPath_/mesh_.time().timeName()
189  << nl << endl;
190  }
191 
192  mkDir(outputPath_/mesh_.time().timeName());
193  }
194  else
195  {
196  Info<< "No fields to sample" << endl;
197  }
198  }
199 
200  if (nFields)
201  {
202  sampleAndWrite(scalarFields_);
203  sampleAndWrite(vectorFields_);
204  sampleAndWrite(sphericalTensorFields_);
205  sampleAndWrite(symmTensorFields_);
206  sampleAndWrite(tensorFields_);
207  }
208  }
209 
210  return true;
211 }
212 
213 
215 {
216  dict_ = dict;
217 
218  if (dict_.found("sets"))
219  {
220  dict_.readEntry("fields", fieldSelection_);
221  clearFieldGroups();
222 
223  dict.readEntry("interpolationScheme", interpolationScheme_);
224  dict.readEntry("setFormat", writeFormat_);
225 
226  PtrList<sampledSet> newList
227  (
228  dict_.lookup("sets"),
229  sampledSet::iNew(mesh_, searchEngine_)
230  );
231  transfer(newList);
232  combineSampledSets(masterSampledSets_, indexSets_);
233 
234  if (this->size())
235  {
236  Info<< "Reading set description:" << nl;
237  forAll(*this, setI)
238  {
239  Info<< " " << operator[](setI).name() << nl;
240  }
241  Info<< endl;
242  }
243  }
244 
245  if (Pstream::master() && debug)
246  {
247  Pout<< "sample fields:" << fieldSelection_ << nl
248  << "sample sets:" << nl << "(" << nl;
249 
250  forAll(*this, setI)
251  {
252  Pout<< " " << operator[](setI) << endl;
253  }
254  Pout<< ")" << endl;
255  }
256 
257  return true;
258 }
259 
260 
262 {
263  if (dict_.found("sets"))
264  {
265  searchEngine_.correct();
266 
267  PtrList<sampledSet> newList
268  (
269  dict_.lookup("sets"),
270  sampledSet::iNew(mesh_, searchEngine_)
271  );
272  transfer(newList);
273  combineSampledSets(masterSampledSets_, indexSets_);
274  }
275 }
276 
277 
279 {
280  if (&mpm.mesh() == &mesh_)
281  {
282  correct();
283  }
284 }
285 
286 
288 {
289  if (&mesh == &mesh_)
290  {
291  correct();
292  }
293 }
294 
295 
297 {
298  if (state != polyMesh::UNCHANGED)
299  {
300  correct();
301  }
302 }
303 
304 
305 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:74
volFields.H
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::sampledSets::readUpdate
virtual void readUpdate(const polyMesh::readUpdateState state)
Update for changes of mesh due to readUpdate.
Definition: sampledSets.C:296
Foam::sampledSets::updateMesh
virtual void updateMesh(const mapPolyMesh &)
Update for changes of mesh.
Definition: sampledSets.C:278
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::polyMesh::defaultRegion
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:312
Foam::sampledSets::verbose
void verbose(const bool verbosity=true)
Set verbosity level.
Definition: sampledSets.C:153
mapPolyMesh.H
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::sampledSets::write
virtual bool write()
Sample and write.
Definition: sampledSets.C:165
Foam::Pout
prefixOSstream Pout
An Ostream wrapper for parallel output to std::cout.
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
sampledSets.H
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
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:62
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
correct
fvOptions correct(rho)
Foam::polyMesh::UNCHANGED
Definition: polyMesh.H:93
Foam::dictionary::readEntry
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Definition: dictionaryTemplates.C:314
Foam::PtrList< sampledSet >
Foam::functionObject::outputPrefix
static word outputPrefix
Directory prefix.
Definition: functionObject.H:259
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::sampledSets::correct
void correct()
Correct for mesh changes.
Definition: sampledSets.C:261
Foam::fileName::null
static const fileName null
An empty fileName.
Definition: fileName.H:97
Foam::UPstream::master
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:438
Foam::polyMesh::readUpdateState
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:91
volPointInterpolation.H
Time.H
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
Foam::sampledSets::execute
virtual bool execute()
Execute, currently does nothing.
Definition: sampledSets.C:159
Foam::nl
constexpr char nl
Definition: Ostream.H:372
dictionary.H
Foam::sampledSets::movePoints
virtual void movePoints(const polyMesh &)
Update for mesh point-motion.
Definition: sampledSets.C:287
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
Foam::List::set
std::enable_if< std::is_same< bool, TypeT >::value, bool >::type set(const label i, bool val=true)
A bitSet::set() method for a list of bool.
Definition: List.H:320
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:160
Foam::functionObjects::regionFunctionObject
Specialization of Foam::functionObject for a region and providing a reference to the region Foam::obj...
Definition: regionFunctionObject.H:87
Foam::List::setSize
void setSize(const label newSize)
Alias for resize(const label)
Definition: ListI.H:146
Foam::mapPolyMesh::mesh
const polyMesh & mesh() const
Return polyMesh.
Definition: mapPolyMesh.H:362
Foam::mkDir
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
Definition: MSwindows.C:507
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::sampledSet::iNew
Class used for the read-construction of.
Definition: sampledSet.H:204
Foam::sampledSets::read
virtual bool read(const dictionary &)
Read the sampledSets.
Definition: sampledSets.C:214