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-2020 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 bool Foam::sampledSets::verbose(const bool on)
154 {
155  bool old(verbose_);
156  verbose_ = on;
157  return old;
158 }
159 
160 
162 {
163  return true;
164 }
165 
166 
168 {
169  if (size())
170  {
171  const label nFields = classifyFields();
172 
173  if (Pstream::master())
174  {
175  if (debug)
176  {
177  Pout<< "timeName = " << mesh_.time().timeName() << nl
178  << "scalarFields " << scalarFields_ << nl
179  << "vectorFields " << vectorFields_ << nl
180  << "sphTensorFields " << sphericalTensorFields_ << nl
181  << "symTensorFields " << symmTensorFields_ <<nl
182  << "tensorFields " << tensorFields_ <<nl;
183  }
184 
185  if (nFields)
186  {
187  if (debug)
188  {
189  Pout<< "Creating directory "
190  << outputPath_/mesh_.time().timeName()
191  << nl << endl;
192  }
193 
194  mkDir(outputPath_/mesh_.time().timeName());
195  }
196  else
197  {
198  Info<< "No fields to sample" << endl;
199  }
200  }
201 
202  if (nFields)
203  {
204  sampleAndWrite(scalarFields_);
205  sampleAndWrite(vectorFields_);
206  sampleAndWrite(sphericalTensorFields_);
207  sampleAndWrite(symmTensorFields_);
208  sampleAndWrite(tensorFields_);
209  }
210  }
211 
212  return true;
213 }
214 
215 
217 {
218  dict_ = dict;
219 
220  if (dict_.found("sets"))
221  {
222  dict_.readEntry("fields", fieldSelection_);
223  clearFieldGroups();
224 
225  dict.readEntry("interpolationScheme", interpolationScheme_);
226  dict.readEntry("setFormat", writeFormat_);
227 
228  PtrList<sampledSet> newList
229  (
230  dict_.lookup("sets"),
231  sampledSet::iNew(mesh_, searchEngine_)
232  );
233  transfer(newList);
234  combineSampledSets(masterSampledSets_, indexSets_);
235 
236  if (this->size())
237  {
238  Info<< "Reading set description:" << nl;
239  forAll(*this, setI)
240  {
241  Info<< " " << operator[](setI).name() << nl;
242  }
243  Info<< endl;
244  }
245  }
246 
247  if (Pstream::master() && debug)
248  {
249  Pout<< "sample fields:" << fieldSelection_ << nl
250  << "sample sets:" << nl << "(" << nl;
251 
252  forAll(*this, setI)
253  {
254  Pout<< " " << operator[](setI) << endl;
255  }
256  Pout<< ")" << endl;
257  }
258 
259  return true;
260 }
261 
262 
264 {
265  if (dict_.found("sets"))
266  {
267  searchEngine_.correct();
268 
269  PtrList<sampledSet> newList
270  (
271  dict_.lookup("sets"),
272  sampledSet::iNew(mesh_, searchEngine_)
273  );
274  transfer(newList);
275  combineSampledSets(masterSampledSets_, indexSets_);
276  }
277 }
278 
279 
281 {
282  if (&mpm.mesh() == &mesh_)
283  {
284  correct();
285  }
286 }
287 
288 
290 {
291  if (&mesh == &mesh_)
292  {
293  correct();
294  }
295 }
296 
297 
299 {
300  if (state != polyMesh::UNCHANGED)
301  {
302  correct();
303  }
304 }
305 
306 
307 // ************************************************************************* //
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:71
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:298
Foam::sampledSets::updateMesh
virtual void updateMesh(const mapPolyMesh &)
Update for changes of mesh.
Definition: sampledSets.C:280
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:318
mapPolyMesh.H
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::UPstream::master
static bool master(const label communicator=worldComm)
Am I the master process.
Definition: UPstream.H:458
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::sampledSets::write
virtual bool write()
Sample and write.
Definition: sampledSets.C:167
Foam::Pout
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
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:296
sampledSets.H
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
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::sampledSets::verbose
bool verbose(const bool on)
Enable/disable verbose output.
Definition: sampledSets.C:153
Foam::polyMesh::UNCHANGED
Definition: polyMesh.H:92
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:352
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:263
Foam::fileName::null
static const fileName null
An empty fileName.
Definition: fileName.H:97
Foam::polyMesh::readUpdateState
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:90
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:161
Foam::nl
constexpr char nl
Definition: Ostream.H:385
dictionary.H
Foam::sampledSets::movePoints
virtual void movePoints(const polyMesh &)
Update for mesh point-motion.
Definition: sampledSets.C:289
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:325
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:161
Foam::functionObjects::regionFunctionObject
Specialization of Foam::functionObject for a region and providing a reference to the region Foam::obj...
Definition: regionFunctionObject.H:90
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:363
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:216