sampledSurfaces.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-2014 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 "sampledSurfaces.H"
27 #include "volFields.H"
28 #include "dictionary.H"
29 #include "Time.H"
30 #include "IOmanip.H"
31 #include "volPointInterpolation.H"
32 #include "PatchTools.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(sampledSurfaces, 0);
39 }
40 
42 Foam::scalar Foam::sampledSurfaces::mergeTol_ = 1e-10;
43 
44 
45 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 
48 {
49  // Write to time directory under outputPath_
50  // Skip surface without faces (eg, a failed cut-plane)
51 
52  const fileName outputDir = outputPath_/obr_.time().timeName();
53 
54  forAll(*this, surfI)
55  {
56  const sampledSurface& s = operator[](surfI);
57 
58  if (Pstream::parRun())
59  {
60  if (Pstream::master() && mergeList_[surfI].faces.size())
61  {
62  formatter_->write
63  (
64  outputDir,
65  s.name(),
66  mergeList_[surfI].points,
67  mergeList_[surfI].faces
68  );
69  }
70  }
71  else if (s.faces().size())
72  {
73  formatter_->write
74  (
75  outputDir,
76  s.name(),
77  s.points(),
78  s.faces()
79  );
80  }
81  }
82 }
83 
84 
85 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
86 
88 (
89  const word& name,
90  const objectRegistry& obr,
91  const dictionary& dict,
92  const bool loadFromFiles
93 )
94 :
97  obr_(obr),
98  loadFromFiles_(loadFromFiles),
99  outputPath_(fileName::null),
100  fieldSelection_(),
101  interpolationScheme_(word::null),
102  mergeList_(),
103  formatter_(NULL)
104 {
105  // Only active if a fvMesh is available
106  if (setActive<fvMesh>())
107  {
108  read(dict);
109  }
110 
111  if (Pstream::parRun())
112  {
113  outputPath_ = obr_.time().path()/".."/"postProcessing"/name_;
114  }
115  else
116  {
117  outputPath_ = obr_.time().path()/"postProcessing"/name_;
118  }
119 
120  read(dict);
121 }
122 
123 
124 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
125 
127 {}
128 
129 
130 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
131 
132 void Foam::sampledSurfaces::verbose(const bool verbosity)
133 {
134  verbose_ = verbosity;
135 }
136 
137 
139 {
140  // Do nothing - only valid on write
141 }
142 
143 
145 {
146  // Do nothing - only valid on write
147 }
148 
149 
151 {
152  // Do nothing - only valid on write
153 }
154 
155 
157 {
158  if (size())
159  {
160  // Finalize surfaces, merge points etc.
161  update();
162 
163  const label nFields = classifyFields();
164 
165  // write geometry first if required,
166  // or when no fields would otherwise be written
167  if (nFields == 0 || formatter_->separateGeometry())
168  {
169  writeGeometry();
170  }
171 
172  const IOobjectList objects(obr_, obr_.time().timeName());
173 
174  sampleAndWrite<volScalarField>(objects);
175  sampleAndWrite<volVectorField>(objects);
176  sampleAndWrite<volSphericalTensorField>(objects);
177  sampleAndWrite<volSymmTensorField>(objects);
178  sampleAndWrite<volTensorField>(objects);
179 
180  sampleAndWrite<surfaceScalarField>(objects);
181  sampleAndWrite<surfaceVectorField>(objects);
182  sampleAndWrite<surfaceSphericalTensorField>(objects);
183  sampleAndWrite<surfaceSymmTensorField>(objects);
184  sampleAndWrite<surfaceTensorField>(objects);
185  }
186 }
187 
188 
190 {
191  bool surfacesFound = dict.found("surfaces");
192 
193  if (surfacesFound)
194  {
195  dict.lookup("fields") >> fieldSelection_;
196 
197  dict.lookup("interpolationScheme") >> interpolationScheme_;
198  const word writeType(dict.lookup("surfaceFormat"));
199 
200  // Define the surface formatter
201  // Optionally defined extra controls for the output formats
202  formatter_ = surfaceWriter::New
203  (
204  writeType,
205  dict.subOrEmptyDict("formatOptions").subOrEmptyDict(writeType)
206  );
207 
208  const fvMesh& mesh = refCast<const fvMesh>(obr_);
209 
211  (
212  dict.lookup("surfaces"),
214  );
215  transfer(newList);
216 
217  if (Pstream::parRun())
218  {
219  mergeList_.setSize(size());
220  }
221 
222  // Ensure all surfaces and merge information are expired
223  expire();
224 
225  if (this->size())
226  {
227  Info<< "Reading surface description:" << nl;
228  forAll(*this, surfI)
229  {
230  Info<< " " << operator[](surfI).name() << nl;
231  }
232  Info<< endl;
233  }
234  }
235 
236  if (Pstream::master() && debug)
237  {
238  Pout<< "sample fields:" << fieldSelection_ << nl
239  << "sample surfaces:" << nl << "(" << nl;
240 
241  forAll(*this, surfI)
242  {
243  Pout<< " " << operator[](surfI) << endl;
244  }
245  Pout<< ")" << endl;
246  }
247 }
248 
249 
251 {
252  expire();
253 
254  // pointMesh and interpolation will have been reset in mesh.update
255 }
256 
257 
259 {
260  expire();
261 }
262 
263 
265 {
266  if (state != polyMesh::UNCHANGED)
267  {
268  expire();
269  }
270 }
271 
272 
274 {
275  forAll(*this, surfI)
276  {
277  if (operator[](surfI).needsUpdate())
278  {
279  return true;
280  }
281  }
282 
283  return false;
284 }
285 
286 
288 {
289  bool justExpired = false;
290 
291  forAll(*this, surfI)
292  {
293  if (operator[](surfI).expire())
294  {
295  justExpired = true;
296  }
297 
298  // Clear merge information
299  if (Pstream::parRun())
300  {
301  mergeList_[surfI].clear();
302  }
303  }
304 
305  // true if any surfaces just expired
306  return justExpired;
307 }
308 
309 
311 {
312  bool updated = false;
313 
314  if (!needsUpdate())
315  {
316  return updated;
317  }
318 
319  // Serial: quick and easy, no merging required
320  if (!Pstream::parRun())
321  {
322  forAll(*this, surfI)
323  {
324  Info << "current model name is :" << operator[](surfI).name()<<endl;
325  if (operator[](surfI).update())
326  {
327  updated = true;
328  }
329  }
330 
331  return updated;
332  }
333 
334  const fvMesh& mesh = refCast<const fvMesh>(obr_);
335 
336  // Dimension as fraction of mesh bounding box
337  scalar mergeDim = mergeTol_*mesh.bounds().mag();
338 
339  if (Pstream::master() && debug)
340  {
341  Pout<< nl << "Merging all points within "
342  << mergeDim << " metre" << endl;
343  }
344 
345  forAll(*this, surfI)
346  {
347  Info << "current model name is :" << operator[](surfI).name()<<endl;
348  sampledSurface& s = operator[](surfI);
349 
350  if (s.update())
351  {
352  updated = true;
353  }
354  else
355  {
356  continue;
357  }
358 
360  (
361  mergeDim,
363  (
364  SubList<face>(s.faces(), s.faces().size()),
365  s.points()
366  ),
367  mergeList_[surfI].points,
368  mergeList_[surfI].faces,
369  mergeList_[surfI].pointsMap
370  );
371  }
372 
373  return updated;
374 }
375 
376 
378 {
379  return mergeTol_;
380 }
381 
382 
383 Foam::scalar Foam::sampledSurfaces::mergeTol(const scalar tol)
384 {
385  scalar oldTol = mergeTol_;
386  mergeTol_ = tol;
387  return oldTol;
388 }
389 
390 
391 // ************************************************************************* //
Foam::sampledSurfaces::outputPath_
fileName outputPath_
Output path.
Definition: sampledSurfaces.H:103
volFields.H
Foam::sampledSurfaces::formatter_
autoPtr< surfaceWriter > formatter_
Surface formatter.
Definition: sampledSurfaces.H:124
Foam::boundBox::mag
scalar mag() const
The magnitude of the bounding box span.
Definition: boundBoxI.H:90
Foam::PrimitivePatch::points
const Field< PointType > & points() const
Return reference to global points.
Definition: PrimitivePatchTemplate.H:282
Foam::sampledSurfaces::mergeTol_
static scalar mergeTol_
Tolerance for merging points (fraction of mesh bounding box)
Definition: sampledSurfaces.H:91
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::functionObjectState
Base class for function objects, adding functionality to read/write state information (data required ...
Definition: functionObjectState.H:54
Foam::sampledSurfaces::readUpdate
virtual void readUpdate(const polyMesh::readUpdateState state)
Update for changes of mesh due to readUpdate - expires the surfaces.
Definition: sampledSurfaces.C:264
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::sampledSurfaces::~sampledSurfaces
virtual ~sampledSurfaces()
Destructor.
Definition: sampledSurfaces.C:126
Foam::sampledSurfaces::obr_
const objectRegistry & obr_
Const reference to database.
Definition: sampledSurfaces.H:97
Foam::sampledSurfaces::needsUpdate
virtual bool needsUpdate() const
Does any of the surfaces need an update?
Definition: sampledSurfaces.C:273
Foam::read
bool read(const char *, int32_t &)
Definition: int32IO.C:87
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:53
Foam::sampledSurfaces::mergeList_
List< mergeInfo > mergeList_
Information for merging surfaces.
Definition: sampledSurfaces.H:118
Foam::objectRegistry::time
const Time & time() const
Return time.
Definition: objectRegistry.H:117
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:377
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::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::sampledSurfaces::mergeTol
static scalar mergeTol()
Get merge tolerance.
Definition: sampledSurfaces.C:377
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::sampledSurfaces::update
virtual bool update()
Update the surfaces as required and merge surface points (parallel).
Definition: sampledSurfaces.C:310
Foam::sampledSurfaces::sampledSurfaces
sampledSurfaces(const sampledSurfaces &)
Disallow default bitwise copy construct and assignment.
sampledSurfaces.H
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::sampledSurfaces::verbose
void verbose(const bool verbosity=true)
Set verbosity level.
Definition: sampledSurfaces.C:132
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
IOmanip.H
Istream and Ostream manipulators taking arguments.
Foam::polyMesh::UNCHANGED
@ UNCHANGED
Definition: polyMesh.H:90
Foam::PtrList< sampledSurface >::operator[]
const T & operator[](const label) const
Return element const reference.
Foam::sampledSurface
An abstract class for surfaces with sampling.
Definition: sampledSurface.H:77
Foam::sampledSurfaces::writeGeometry
void writeGeometry() const
Write geometry only.
Definition: sampledSurfaces.C:47
Foam::PtrList< sampledSurface >
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
s
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:50
Foam::fileName::null
static const fileName null
An empty fileName.
Definition: fileName.H:97
Foam::sampledSurfaces::execute
virtual void execute()
Execute, currently does nothing.
Definition: sampledSurfaces.C:138
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::polyMesh::bounds
const boundBox & bounds() const
Return mesh bounding box.
Definition: polyMesh.H:427
Foam::sampledSurfaces::read
virtual void read(const dictionary &)
Read the sampledSurfaces dictionary.
Definition: sampledSurfaces.C:189
Foam::Pout
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
Foam::surfaceWriter::New
static autoPtr< surfaceWriter > New(const word &writeType)
Return a reference to the selected surfaceWriter.
Definition: surfaceWriter.C:55
Foam::Time::timeName
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:741
Foam::sampledSurfaces::verbose_
static bool verbose_
Output verbosity.
Definition: sampledSurfaces.H:88
Foam::sampledSurface::iNew
Class used for the PtrLists read-construction.
Definition: sampledSurface.H:176
Foam::sampledSurfaces::movePoints
virtual void movePoints(const polyMesh &)
Update for mesh point-motion - expires the surfaces.
Definition: sampledSurfaces.C:258
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: doubleFloat.H:94
Foam::dictionary::subOrEmptyDict
dictionary subOrEmptyDict(const word &, const bool mustRead=false) const
Find and return a sub-dictionary as a copy, or.
Definition: dictionary.C:666
dictionary.H
Foam::sampledSurfaces::write
virtual void write()
Sample and write.
Definition: sampledSurfaces.C:156
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
Foam::sampledSurfaces::end
virtual void end()
Execute at the final time-loop, currently does nothing.
Definition: sampledSurfaces.C:144
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
Foam::sampledSurfaces::timeSet
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: sampledSurfaces.C:150
Foam::PatchTools::gatherAndMerge
static void gatherAndMerge(const scalar mergeDist, const PrimitivePatch< Face, FaceList, PointField, PointType > &p, Field< PointType > &mergedPoints, List< Face > &mergedFaces, labelList &pointMergeMap)
Gather points and faces onto master and merge into single patch.
Definition: PatchToolsGatherAndMerge.C:43
Foam::sampledSurfaces::updateMesh
virtual void updateMesh(const mapPolyMesh &)
Update for changes of mesh - expires the surfaces.
Definition: sampledSurfaces.C:250
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::sampledSurfaces::expire
virtual bool expire()
Mark the surfaces as needing an update.
Definition: sampledSurfaces.C:287
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatchTemplate.H:88