surfaceWriter.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-2012 OpenFOAM Foundation
9  Copyright (C) 2015-2019 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 Namespace
28  Foam::surfaceWriters
29 
30 Description
31  Namespace for surface writers
32 
33 Class
34  Foam::surfaceWriter
35 
36 Description
37  Base class for surface writers.
38 
39  The surfaceWriter interface is rather large since we need a writer that
40  can either be initially defined without a surface association
41  and have that added at a later stage, or be defined with a surface
42  association.
43 
44  \verbatim
45  formatOptions
46  {
47  someFormat // Eg, ensight, vtk, etc
48  {
49  verbose true;
50  }
51  }
52  \endverbatim
53 
54  Format options:
55  \table
56  Property | Description | Required | Default
57  verbose | Additional output verbosity | no | no
58  \endtable
59 
60 Note
61  For surface formats that require geometry in a separate file,
62  it is the responsibility of the implementation (not the caller)
63  to ensure that this occurs.
64 
65 SourceFiles
66  surfaceWriter.C
67  surfaceWriterI.H
68 
69 \*---------------------------------------------------------------------------*/
70 
71 #ifndef surfaceWriter_H
72 #define surfaceWriter_H
73 
74 #include <functional>
75 #include "typeInfo.H"
76 #include "autoPtr.H"
77 #include "tmp.H"
78 #include "Field.H"
79 #include "fileName.H"
80 #include "instant.H"
81 #include "mergedSurf.H"
82 #include "meshedSurfRef.H"
83 #include "InfoProxy.H"
84 #include "runTimeSelectionTables.H"
85 
86 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
87 
88 namespace Foam
89 {
90 
91 // Forward Declarations
92 class Time;
93 class surfaceWriter;
94 
95 Ostream& operator<<(Ostream& os, const InfoProxy<surfaceWriter>& ip);
96 
97 
98 /*---------------------------------------------------------------------------*\
99  Class surfaceWriter Declaration
100 \*---------------------------------------------------------------------------*/
101 
102 class surfaceWriter
103 {
104 protected:
105 
106  // Static Data Members
107 
108  //- Placeholder
109  static const meshedSurf::emptySurface emptySurface_;
110 
111 
112  // Protected Data
113 
114  //- Reference to a surface
115  std::reference_wrapper<const meshedSurf> surf_;
116 
117  //- Reference to raw surface components
119 
120  //- Use raw surface components instead of surface reference
121  bool useComponents_;
122 
123  //- The topology/surface is up-to-date?
124  mutable bool upToDate_;
125 
126  //- Track if geometry has been written since the last open
127  mutable bool wroteGeom_;
128 
129  //- Writing in parallel (via master)
130  bool parallel_;
131 
132  //- Insert additional time sub-directory in the output path
134 
135  //- Is point vs cell data
137 
138  //- Additional output verbosity
139  bool verbose_;
140 
141  //- The number of fields
143 
144  //- Dimension for merging
145  scalar mergeDim_;
146 
147  //- Merging information and the resulting merged surface (parallel)
149 
150  //- The current time value/name
152 
153  //- The full output directory and file (surface) name
155 
156 
157  // Protected Member Functions
158 
159  //- Verify that the outputPath_ has been set or FatalError
160  bool checkOpen() const;
161 
162  //- Merge surfaces if they are not already upToDate (parallel)
163  //- or simply mark the surface as being up-to-date
164  virtual bool merge() const;
165 
166  //- Merge surfaces (if not upToDate) and return merged or
167  //- the regular surface
168  const meshedSurf& surface() const;
169 
170 
171  //- Gather (merge) fields with renumbering and shrinking for point data
172  template<class Type>
174 
175 #undef declareSurfaceWriterMergeMethod
176 #define declareSurfaceWriterMergeMethod(Type) \
177  tmp<Field<Type>> mergeField(const Field<Type>& fld) const;
178 
185 
186  #undef declareSurfaceWriterMergeMethod
187 
188  //- Dummy templated write operation
189  template<class Type>
190  fileName writeTemplate
191  (
192  const word& fieldName,
193  const Field<Type>& localValues
194  )
195  {
196  if (!wroteGeom_)
197  {
198  return this->write();
199  }
201  }
202 
203 
204 public:
205 
206  // Public Data
207 
208  //- The default merge dimension (1e-8)
209  static scalar defaultMergeDim;
210 
211 
212  //- Runtime type information
213  TypeName("surfaceWriter");
214 
215 
216  // Declare run-time constructor selection table
218  (
219  autoPtr,
221  word,
222  (),
223  ()
224  );
225 
227  (
228  autoPtr,
230  wordDict,
231  (
232  const dictionary& writeOpts
233  ),
234  (writeOpts)
235  );
236 
237 
238  // Selectors
239 
240  //- True if New is likely to succeed for this writeType
241  static bool supportedType(const word& writeType);
242 
243  //- Return a reference to the selected surfaceWriter
244  static autoPtr<surfaceWriter> New(const word& writeType);
245 
246  //- Return a reference to the selected surfaceWriter
247  // Select with extra write option
249  (
250  const word& writeType,
251  const dictionary& writeOptions
252  );
253 
254 
255  // Constructors
256 
257  //- Construct null
258  surfaceWriter();
259 
260  //- Construct null with specified options
261  explicit surfaceWriter(const dictionary& options);
262 
263  //- Construct from components
264  explicit surfaceWriter
265  (
266  const meshedSurf& surf,
267  bool parallel = Pstream::parRun(),
268  const dictionary& options = dictionary()
269  );
270 
271  //- Construct from components
273  (
274  const pointField& points,
275  const faceList& faces,
276  bool parallel = Pstream::parRun(),
277  const dictionary& options = dictionary()
278  );
279 
280 
281  //- Destructor
282  virtual ~surfaceWriter();
283 
284 
285  // Member Functions
286 
287  // Capability
288 
289  //- The writer is enabled. If the writer is not enabled, it may be
290  //- possible for the caller to skip various preparatory operations.
291  // This method is primarily useful for the null writer
292  virtual bool enabled() const
293  {
294  return true;
295  }
296 
297  //- True if the surface format requires geometry in a separate file.
298  virtual bool separateGeometry() const
299  {
300  return false;
301  }
302 
303 
304  // Bookkeeping
305 
306  //- Does the writer need an update (eg, lagging behind surface changes)
307  virtual bool needsUpdate() const;
308 
309  //- Geometry or fields written since the last open?
310  virtual bool wroteData() const;
311 
312  //- Mark that surface changed and the writer will need an update,
313  //- and set nFields = 0.
314  // May also free up unneeded data.
315  // Return false if it was previously already expired.
316  virtual bool expire();
317 
318  //- Close any open output, remove association with a surface and
319  //- expire the writer. The parallel flag remains untouched.
320  virtual void clear();
321 
322 
323  // Surface association
324 
325  //- Change association with a surface, expire the writer
326  //- with defined parallel/serial treatment
327  virtual void setSurface
328  (
329  const meshedSurf& surf,
330  bool parallel
331  );
332 
333  //- Change association with a surface, expire the writer
334  //- with defined parallel/serial treatment
335  virtual void setSurface
336  (
337  const pointField& points,
338  const faceList& faces,
339  bool parallel
340  );
341 
342  //- Change association with a surface, expire the writer
343  //- with the current parallel/serial treatment
344  virtual void setSurface
345  (
346  const meshedSurf& surf
347  );
348 
349  //- Change association with a surface, expire the writer
350  //- with the current parallel/serial treatment
351  virtual void setSurface
352  (
353  const pointField& points,
354  const faceList& faces
355  );
356 
357 
358  // Queries, Access
359 
360  //- Writer is associated with a surface
361  bool hasSurface() const;
362 
363  //- The surface to write is empty if the global number of faces is zero
364  bool empty() const;
365 
366  //- The global number of faces for the associated surface
367  label size() const;
368 
369  //- The number of expected output fields.
370  // Currently only used by the legacy VTK format.
371  inline label nFields() const;
372 
373  //- The number of expected output fields.
374  // Currently only used by the legacy VTK format.
375  inline label& nFields();
376 
377  //- Are the field data to be treated as point data?
378  inline bool isPointData() const;
379 
380  //- Set handling of field data to face/point data.
381  inline bool& isPointData();
382 
383  //- Should a time directory be spliced into the output path?
384  inline bool useTimeDir() const;
385 
386  //- Change handling of spliced output path.
387  inline bool& useTimeDir();
388 
389  //- Get output verbosity
390  inline bool verbose() const;
391 
392  //- Set output verbosity
393  inline bool& verbose();
394 
395  //- The current value of the point merge dimension (metre)
396  inline scalar mergeDim() const;
397 
398  //- The current value of the point merge dimension (metre)
399  inline scalar& mergeDim();
400 
401 
402  // Time
403 
404  //- True if there is a known time
405  inline bool hasTime() const;
406 
407  //- The current time value/name
408  inline const word& timeName() const;
409 
410  //- The current time value/name
411  inline scalar timeValue() const;
412 
413 
414  //- Set the current time
415  void setTime(const instant& inst);
416 
417  //- Set current time from timeValue, auto generating the name
418  void setTime(scalar timeValue);
419 
420  //- Set current time from timeValue and timeName
421  void setTime(scalar timeValue, const word& timeName);
422 
423  //- Clear the current time
424  void unsetTime();
425 
426 
427  //- Begin a time-step
428  virtual void beginTime(const Time& t);
429 
430  //- Begin a time-step
431  virtual void beginTime(const instant& inst);
432 
433  //- End a time-step
434  virtual void endTime();
435 
436 
437  // Output
438 
439  //- Open for output on specified path, using existing surface
440  virtual void open(const fileName& outputPath);
441 
442  //- Open from components
443  virtual void open
444  (
445  const pointField& points,
446  const faceList& faces,
447  const fileName& outputPath,
448  bool parallel
449  );
450 
451  //- Open from components
452  virtual void open
453  (
454  const meshedSurf& surf,
455  const fileName& outputPath,
456  bool parallel
457  );
458 
459  //- Open from components, with the current parallel/serial treatment
460  virtual void open
461  (
462  const pointField& points,
463  const faceList& faces,
464  const fileName& outputPath
465  );
466 
467  //- Open from components, with the current parallel/serial treatment
468  virtual void open
469  (
470  const meshedSurf& surf,
471  const fileName& outputPath
472  );
473 
474  //- Finish output, performing any necessary cleanup
475  virtual void close();
476 
477 
478  // Write
479 
480  //- Write separate surface geometry to file.
481  virtual fileName write() = 0;
482 
483 
484 #undef declareSurfaceWriterWriteMethod
485 #define declareSurfaceWriterWriteMethod(Type) \
486  \
487  virtual fileName write \
488  ( \
489  const word& fieldName, \
490  const Field<Type>& values \
491  ) = 0
492 
499 
500 
501 #undef declareSurfaceWriterWriteMethod
502 #define declareSurfaceWriterWriteMethod(Type) \
503  \
504  \
505  virtual fileName write \
506  ( \
507  const word& fieldName, \
508  const Field<Type>& values \
509  ) // override
510 
511 
512  // Other IO
513 
514  //- Return info proxy.
515  virtual InfoProxy<surfaceWriter> info() const
516  {
517  return *this;
518  }
519 
520  //- Output info proxy
521  friend Ostream& operator<<
522  (
523  Ostream& os,
525  );
526 };
527 
528 
529 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
530 
531 } // End namespace Foam
532 
533 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
534 
535 #include "surfaceWriterI.H"
536 
537 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
538 
539 #endif
540 
541 // ************************************************************************* //
Foam::Tensor< scalar >
Foam::sphericalTensor
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars.
Definition: sphericalTensor.H:51
Foam::SymmTensor< scalar >
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::surfaceWriter::timeValue
scalar timeValue() const
The current time value/name.
Definition: surfaceWriterI.H:102
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::surfaceWriter::write
virtual fileName write()=0
Write separate surface geometry to file.
Foam::InfoProxy
A helper class for outputting values to Ostream.
Definition: InfoProxy.H:47
Foam::surfaceWriter
Base class for surface writers.
Definition: surfaceWriter.H:111
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::surfaceWriter::mergeDim
scalar mergeDim() const
The current value of the point merge dimension (metre)
Definition: surfaceWriterI.H:78
Foam::surfaceWriter::TypeName
TypeName("surfaceWriter")
Runtime type information.
typeInfo.H
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
InfoProxy.H
Foam::surfaceWriter::defaultMergeDim
static scalar defaultMergeDim
The default merge dimension (1e-8)
Definition: surfaceWriter.H:218
Foam::surfaceWriter::unsetTime
void unsetTime()
Clear the current time.
Definition: surfaceWriter.C:222
Foam::surfaceWriter::merge
virtual bool merge() const
Definition: surfaceWriter.C:443
Foam::surfaceWriter::setSurface
virtual void setSurface(const meshedSurf &surf, bool parallel)
Definition: surfaceWriter.C:324
Foam::tensor
Tensor< scalar > tensor
Tensor of scalars.
Definition: tensor.H:53
Foam::surfaceWriter::useTimeDir
bool useTimeDir() const
Should a time directory be spliced into the output path?
Definition: surfaceWriterI.H:54
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:414
Foam::surfaceWriter::setTime
void setTime(const instant &inst)
Set the current time.
Definition: surfaceWriter.C:203
Foam::surfaceWriter::clear
virtual void clear()
Definition: surfaceWriter.C:313
Foam::surfaceWriter::useComponents_
bool useComponents_
Use raw surface components instead of surface reference.
Definition: surfaceWriter.H:130
Foam::surfaceWriter::useTimeDir_
bool useTimeDir_
Insert additional time sub-directory in the output path.
Definition: surfaceWriter.H:142
Foam::surfaceWriter::surface
const meshedSurf & surface() const
Definition: surfaceWriter.C:469
Foam::meshedSurf
Abstract definition of a meshed surface defined by faces and points.
Definition: meshedSurf.H:49
Foam::surfaceWriter::hasTime
bool hasTime() const
True if there is a known time.
Definition: surfaceWriterI.H:90
instant.H
Foam::surfaceWriter::size
label size() const
The global number of faces for the associated surface.
Definition: surfaceWriter.C:417
mergedSurf.H
Foam::surfaceWriter::emptySurface_
static const meshedSurf::emptySurface emptySurface_
Placeholder.
Definition: surfaceWriter.H:118
Foam::meshedSurfRef
Implements a meshed surface by referencing existing faces and points.
Definition: meshedSurfRef.H:48
Foam::surfaceWriter::writeTemplate
fileName writeTemplate(const word &fieldName, const Field< Type > &localValues)
Dummy templated write operation.
Definition: surfaceWriter.H:200
Foam::surfaceWriter::timeName
const word & timeName() const
The current time value/name.
Definition: surfaceWriterI.H:96
Foam::surfaceWriter::empty
bool empty() const
The surface to write is empty if the global number of faces is zero.
Definition: surfaceWriter.C:404
Foam::surfaceWriter::isPointData
bool isPointData() const
Are the field data to be treated as point data?
Definition: surfaceWriterI.H:42
declareSurfaceWriterMergeMethod
#define declareSurfaceWriterMergeMethod(Type)
Definition: surfaceWriter.H:185
Foam::surfaceWriter::verbose
bool verbose() const
Get output verbosity.
Definition: surfaceWriterI.H:66
Foam::surfaceWriter::endTime
virtual void endTime()
End a time-step.
Definition: surfaceWriter.C:241
Foam::surfaceWriter::upToDate_
bool upToDate_
The topology/surface is up-to-date?
Definition: surfaceWriter.H:133
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::surfaceWriter::beginTime
virtual void beginTime(const Time &t)
Begin a time-step.
Definition: surfaceWriter.C:229
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::surfaceWriter::nFields_
label nFields_
The number of fields.
Definition: surfaceWriter.H:151
Foam::mergedSurf
Simple class to manage surface merging information.
Definition: mergedSurf.H:52
Foam::surfaceWriter::surf_
std::reference_wrapper< const meshedSurf > surf_
Reference to a surface.
Definition: surfaceWriter.H:124
meshedSurfRef.H
Field.H
fileName.H
Foam::surfaceWriter::parallel_
bool parallel_
Writing in parallel (via master)
Definition: surfaceWriter.H:139
Foam::surfaceWriter::mergeDim_
scalar mergeDim_
Dimension for merging.
Definition: surfaceWriter.H:154
Foam::surfaceWriter::checkOpen
bool checkOpen() const
Verify that the outputPath_ has been set or FatalError.
Definition: surfaceWriter.C:430
Foam::surfaceWriter::surfaceWriter
surfaceWriter()
Construct null.
Definition: surfaceWriter.C:137
Foam::surfaceWriter::needsUpdate
virtual bool needsUpdate() const
Does the writer need an update (eg, lagging behind surface changes)
Definition: surfaceWriter.C:371
Foam::symmTensor
SymmTensor< scalar > symmTensor
SymmTensor of scalars.
Definition: symmTensor.H:50
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
Foam::surfaceWriter::outputPath_
fileName outputPath_
The full output directory and file (surface) name.
Definition: surfaceWriter.H:163
Foam::surfaceWriter::wroteData
virtual bool wroteData() const
Geometry or fields written since the last open?
Definition: surfaceWriter.C:377
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::surfaceWriter::expire
virtual bool expire()
Definition: surfaceWriter.C:383
Foam::surfaceWriter::info
virtual InfoProxy< surfaceWriter > info() const
Return info proxy.
Definition: surfaceWriter.H:524
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::surfaceWriter::enabled
virtual bool enabled() const
Definition: surfaceWriter.H:301
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:51
Foam::surfaceWriter::isPointData_
bool isPointData_
Is point vs cell data.
Definition: surfaceWriter.H:145
Foam::SphericalTensor< scalar >
Foam::fileName::null
static const fileName null
An empty fileName.
Definition: fileName.H:97
Foam::surfaceWriter::separateGeometry
virtual bool separateGeometry() const
True if the surface format requires geometry in a separate file.
Definition: surfaceWriter.H:307
Foam::meshedSurf::emptySurface
A meshedSurf class with no faces, points or zoneId.
Definition: meshedSurf.H:89
Foam::surfaceWriter::declareRunTimeSelectionTable
declareRunTimeSelectionTable(autoPtr, surfaceWriter, word,(),())
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
tmp.H
Foam::surfaceWriter::currTime_
instant currTime_
The current time value/name.
Definition: surfaceWriter.H:160
runTimeSelectionTables.H
Macros to ease declaration of run-time selection tables.
Foam::surfaceWriter::New
static autoPtr< surfaceWriter > New(const word &writeType)
Return a reference to the selected surfaceWriter.
Definition: surfaceWriter.C:64
Foam::Vector< scalar >
Foam::List< face >
Foam::surfaceWriter::surfComp_
meshedSurfRef surfComp_
Reference to raw surface components.
Definition: surfaceWriter.H:127
surfaceWriterI.H
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::surfaceWriter::~surfaceWriter
virtual ~surfaceWriter()
Destructor.
Definition: surfaceWriter.C:195
Foam::surfaceWriter::hasSurface
bool hasSurface() const
Writer is associated with a surface.
Definition: surfaceWriter.C:398
Foam::surfaceWriter::nFields
label nFields() const
The number of expected output fields.
Definition: surfaceWriterI.H:30
Foam::instant
An instant of time. Contains the time value and name.
Definition: instant.H:52
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::surfaceWriter::wroteGeom_
bool wroteGeom_
Track if geometry has been written since the last open.
Definition: surfaceWriter.H:136
Foam::surfaceWriter::mergeFieldTemplate
tmp< Field< Type > > mergeFieldTemplate(const Field< Type > &fld) const
Gather (merge) fields with renumbering and shrinking for point data.
Foam::surfaceWriter::verbose_
bool verbose_
Additional output verbosity.
Definition: surfaceWriter.H:148
Foam::surfaceWriter::close
virtual void close()
Finish output, performing any necessary cleanup.
Definition: surfaceWriter.C:306
declareSurfaceWriterWriteMethod
#define declareSurfaceWriterWriteMethod(Type)
Definition: surfaceWriter.H:511
Foam::surfaceWriter::supportedType
static bool supportedType(const word &writeType)
True if New is likely to succeed for this writeType.
Definition: surfaceWriter.C:52
Foam::surfaceWriter::open
virtual void open(const fileName &outputPath)
Open for output on specified path, using existing surface.
Definition: surfaceWriter.C:247
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &)
Definition: boundaryPatch.C:102
Foam::surfaceWriter::merged_
mergedSurf merged_
Merging information and the resulting merged surface (parallel)
Definition: surfaceWriter.H:157
autoPtr.H