sampledSurfaces.H
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-2016 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 Class
28  Foam::sampledSurfaces
29 
30 Description
31  Set of surfaces to sample.
32 
33  The write() method is used to sample and write files.
34 
35  Example of function object specification:
36 
37  \verbatim
38  surfaces
39  {
40  type surfaces;
41  libs (sampling);
42 
43  // Write at same frequency as fields
44  writeControl outputTime;
45  writeInterval 1;
46 
47  // Fields to be sampled
48  fields (p U);
49 
50  // Scheme to obtain face centre value
51  sampleScheme cell;
52 
53  // Scheme to obtain node values
54  // (only used if interpolate=true for the surfaces below)
55  interpolationScheme cell;
56 
57  // Optional: registry storage
58  store true
59 
60  // Output surface format
61  surfaceFormat vtk;
62 
63  formatOptions
64  {
65  vtk
66  {
67  precision 10;
68  }
69  }
70 
71  surfaces
72  {
73  f0surf
74  {
75  type meshedSurface;
76  surface f0surf.obj;
77  source cells;
78 
79  // Optional: keep original regions
80  keepIds true;
81 
82  // Optional: generate values on points instead of faces
83  interpolate true;
84 
85  // Optional: alternative output type
86  surfaceFormat ensight;
87 
88  // Optional: registry storage
89  store true
90  }
91  }
92  }
93  \endverbatim
94 
95  Entries:
96  \table
97  Property | Description | Required | Default
98  type | Type-name: surfaces | yes |
99  surfaces | Dictionary or list of sample surfaces | expected |
100  fields | word/regex list of fields to sample | yes |
101  sampleScheme | scheme to obtain face centre value | no | cell
102  interpolationScheme | scheme to obtain node values | no | cellPoint
103  surfaceFormat | output surface format | yes |
104  formatOptions | dictionary of format options | no |
105  sampleOnExecute | Sample (store) on execution as well | no | false
106  store | Store surface/fields on registry | no | false
107  \endtable
108 
109  Additional per-surface entries:
110  \table
111  Property | Description | Required | Default
112  store | Store surface/fields on registry | no |
113  surfaceFormat | output surface format | no |
114  formatOptions | dictionary of format options | no |
115  surfMeshStore | Store surface/fields as surfMesh (transitional) | no |
116  \endtable
117 
118 Note
119  The interpolationScheme is only used if interpolate=true is used by any
120  of the surfaces.
121 
122 SourceFiles
123  sampledSurfaces.C
124 
125 \*---------------------------------------------------------------------------*/
126 
127 #ifndef sampledSurfaces_H
128 #define sampledSurfaces_H
129 
130 #include "fvMeshFunctionObject.H"
131 #include "sampledSurface.H"
132 #include "surfaceWriter.H"
133 #include "volFieldsFwd.H"
134 #include "surfaceFieldsFwd.H"
135 #include "IOobjectList.H"
136 
137 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
138 
139 namespace Foam
140 {
141 
142 // Forward Declarations
143 class polySurface;
144 
145 /*---------------------------------------------------------------------------*\
146  Class sampledSurfaces Declaration
147 \*---------------------------------------------------------------------------*/
148 
149 class sampledSurfaces
150 :
151  public functionObjects::fvMeshFunctionObject,
152  public PtrList<sampledSurface>
153 {
154  // Static Data Members
155 
156  //- Tolerance for merging points (fraction of mesh bounding box)
157  static scalar mergeTol_;
158 
159  //- Local control for sampling actions
160  enum sampleActionType : unsigned
161  {
162  ACTION_NONE = 0,
163  ACTION_WRITE = 0x1,
164  ACTION_STORE = 0x2,
165  ACTION_SURF_MESH = 0x4,
166  ACTION_ALL = 0xF
167  };
168 
169 
170  // Private Data
171 
172  //- Load fields from files (not from objectRegistry)
173  const bool loadFromFiles_;
174 
175  //- Output verbosity
176  bool verbose_;
177 
178  //- Perform sample/store actions on execute as well
179  bool onExecute_;
180 
181  //- Output path
182  fileName outputPath_;
183 
184 
185  // Read from dictionary
186 
187  //- Names of fields to sample
188  wordRes fieldSelection_;
189 
190  //- Interpolation/sample scheme to obtain face values
191  word sampleFaceScheme_;
192 
193  //- Interpolation/sample scheme to obtain node values
194  word sampleNodeScheme_;
195 
196 
197  // Output control
198 
199  //- Surface writers (one per surface)
200  PtrList<surfaceWriter> writers_;
201 
202  //- Per-surface selection of store/write actions
203  List<unsigned> actions_;
204 
205  //- Cached values of the global number of faces per-surface
206  labelList nFaces_;
207 
208 
209  // Private Member Functions
210 
211  //- Return the surfaces
212  const PtrList<sampledSurface>& surfaces() const
213  {
214  return *this;
215  }
216 
217  //- Return the surfaces
218  PtrList<sampledSurface>& surfaces()
219  {
220  return *this;
221  }
222 
223  //- A new surfaceWriter, with per-surface formatOptions
224  static autoPtr<surfaceWriter> newWriter
225  (
226  word writeType,
227  const dictionary& formatOptions,
228  const dictionary& surfDict
229  );
230 
231 
232  //- Perform sampling action with store/write
233  bool performAction(unsigned request);
234 
235  //- Count selected/sampled fields per surface
236  void countFields();
237 
238  //- Write sampled fieldName on surface and on outputDir path
239  template<class Type>
240  void writeSurface
241  (
243  const Field<Type>& values,
244  const word& fieldName
245  );
246 
247  //- Sample and store/write a specific volume field
248  template<class Type>
249  void performAction
250  (
252  unsigned request
253  );
254 
255  //- Sample and store/write a specific surface field
256  template<class Type>
257  void performAction
258  (
260  unsigned request
261  );
262 
263  //- Sample and write all applicable sampled fields
264  template<class GeoField>
265  void performAction
266  (
267  const IOobjectList& objects,
268  unsigned request
269  );
270 
271 
272  //- Get surface from registry if available.
273  // \return surface or nullptr
274  polySurface* getRegistrySurface(const sampledSurface& s) const;
275 
276  //- Put surface onto registry, when enabled.
277  // \return surface or nullptr it surface should not be stored
278  polySurface* storeRegistrySurface(const sampledSurface& s);
279 
280  //- Remove surface from registry.
281  // \return True if surface existed and was removed
282  bool removeRegistrySurface(const sampledSurface& s);
283 
284  //- Store sampled field onto surface registry if it exists
285  template<class Type, class GeoMeshType>
286  bool storeRegistryField
287  (
288  const sampledSurface& s,
289  const word& fieldName,
290  const dimensionSet& dims,
292  );
293 
294  //- Test surfaces for condition
295  template<class Container, class Predicate>
296  static bool testAny(const Container& items, const Predicate& pred);
297 
298  //- Do any surfaces need an update?
299  virtual bool needsUpdate() const;
300 
301  //- Mark the surfaces as needing an update.
302  // Return false if all surfaces were already marked as expired.
303  // Optionally force expire, even if a surface has been marked as
304  // invariant.
305  virtual bool expire(const bool force=false);
306 
307  //- Update the surfaces as required.
308  // Return false if no surfaces required an update.
309  virtual bool update();
310 
311  //- No copy construct
312  sampledSurfaces(const sampledSurfaces&) = delete;
313 
314  //- No copy assignment
315  void operator=(const sampledSurfaces&) = delete;
316 
317 
318 public:
319 
320  //- Runtime type information
321  TypeName("surfaces");
322 
323 
324  // Constructors
325 
326  //- Construct from Time and dictionary
328  (
329  const word& name,
330  const Time& runTime,
331  const dictionary& dict
332  );
333 
334  //- Construct for given objectRegistry and dictionary
335  // allow the possibility to load fields from files
337  (
338  const word& name,
339  const objectRegistry& obr,
340  const dictionary& dict,
341  const bool loadFromFiles = false
342  );
343 
344 
345  //- Destructor
346  virtual ~sampledSurfaces() = default;
347 
348 
349  // Member Functions
350 
351  //- Enable/disable verbose output
352  // \return old value
353  bool verbose(const bool on);
354 
355  //- Read the sampledSurfaces dictionary
356  virtual bool read(const dictionary& dict);
357 
358  //- Sample and store if the sampleOnExecute is enabled.
359  virtual bool execute();
360 
361  //- Sample and write
362  virtual bool write();
363 
364  //- Update for changes of mesh - expires the surfaces
365  virtual void updateMesh(const mapPolyMesh& mpm);
366 
367  //- Update for mesh point-motion - expires the surfaces
368  virtual void movePoints(const polyMesh& mesh);
369 
370  //- Update for changes of mesh due to readUpdate - expires the surfaces
371  virtual void readUpdate(const polyMesh::readUpdateState state);
372 
373  //- Get merge tolerance
374  static scalar mergeTol();
375 
376  //- Set merge tolerance and return old value
377  static scalar mergeTol(const scalar tol);
378 };
379 
380 
381 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
382 
383 } // End namespace Foam
384 
385 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
386 
387 #ifdef NoRepository
388  #include "sampledSurfacesTemplates.C"
389 #endif
390 
391 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
392 
393 #endif
394 
395 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::sampledSurfaces::TypeName
TypeName("surfaces")
Runtime type information.
volFieldsFwd.H
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:65
Foam::surfaceWriter
Base class for surface writers.
Definition: surfaceWriter.H:114
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
s
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.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))
Definition: gmvOutputSpray.H:25
fvMeshFunctionObject.H
Foam::sampledSurfaces::readUpdate
virtual void readUpdate(const polyMesh::readUpdateState state)
Update for changes of mesh due to readUpdate - expires the surfaces.
Definition: sampledSurfaces.C:683
Foam::HashTableOps::values
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:149
sampledSurfacesTemplates.C
Foam::sampledSurfaces::read
virtual bool read(const dictionary &dict)
Read the sampledSurfaces dictionary.
Definition: sampledSurfaces.C:281
IOobjectList.H
Foam::sampledSurfaces::updateMesh
virtual void updateMesh(const mapPolyMesh &mpm)
Update for changes of mesh - expires the surfaces.
Definition: sampledSurfaces.C:663
Foam::dimensionSet
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Definition: dimensionSet.H:108
surfaceWriter.H
Foam::sampledSurfaces::mergeTol
static scalar mergeTol()
Get merge tolerance.
Definition: sampledSurfaces.C:764
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
formatOptions
const dictionary formatOptions
Definition: createFields.H:26
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::sampledSurfaces::verbose
bool verbose(const bool on)
Enable/disable verbose output.
Definition: sampledSurfaces.C:273
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::sampledSurfaces
Set of surfaces to sample.
Definition: sampledSurfaces.H:223
Foam::polySurface
A surface mesh consisting of general polygon faces and capable of holding fields.
Definition: polySurface.H:67
Foam::sampledSurfaces::execute
virtual bool execute()
Sample and store if the sampleOnExecute is enabled.
Definition: sampledSurfaces.C:646
Foam::Field
Generic templated field type.
Definition: Field.H:63
sampledSurface.H
Foam::sampledSurface
An abstract class for surfaces with sampling.
Definition: sampledSurface.H:121
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:59
fld
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputLagrangian.H:23
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:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::writer
Base class for graphics format writing. Entry points are.
Definition: writer.H:81
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:55
Foam::polyMesh::readUpdateState
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:90
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::functionObject::name
const word & name() const noexcept
Return the name of this functionObject.
Definition: functionObject.C:143
Foam::List< unsigned >
Foam::functionObjects::regionFunctionObject::obr
virtual const objectRegistry & obr() const
The region or sub-region registry being used.
Definition: regionFunctionObject.C:47
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
surfaceFieldsFwd.H
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:161
Foam::sampledSurfaces::write
virtual bool write()
Sample and write.
Definition: sampledSurfaces.C:657
Foam::GeometricField< Type, fvPatchField, volMesh >
Foam::sampledSurfaces::~sampledSurfaces
virtual ~sampledSurfaces()=default
Destructor.
Foam::sampledSurfaces::movePoints
virtual void movePoints(const polyMesh &mesh)
Update for mesh point-motion - expires the surfaces.
Definition: sampledSurfaces.C:674