sampledSurface.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2026 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 Class
25  Foam::sampledSurface
26 
27 Description
28  An abstract class for surfaces with sampling.
29 
30  The constructors for the derived classes should generally start in a
31  'expired' condition (ie, needsUpdate() == true) and rely on a
32  subsequent call to the update() method to complete the initialisation.
33  Delaying the final construction as late as possible allows the
34  construction of surfaces that may depend on intermediate calculation
35  results (eg, iso-surfaces) and also avoids the unnecessary
36  reconstruction of surfaces between sampling intervals.
37 
38  It is the responsibility of the caller to ensure that the surface
39  update() is called before the surface is used. The update() method
40  implementation should do nothing when the surface is already
41  up-to-date.
42 
43 SourceFiles
44  sampledSurface.C
45  sampledSurfaceTemplates.C
46 
47 \*---------------------------------------------------------------------------*/
48 
49 #ifndef sampledSurface_H
50 #define sampledSurface_H
51 
52 #include "pointField.H"
53 #include "word.H"
54 #include "labelList.H"
55 #include "faceList.H"
56 #include "typeInfo.H"
57 #include "runTimeSelectionTables.H"
58 #include "autoPtr.H"
59 #include "volFieldsFwd.H"
60 #include "surfaceFieldsFwd.H"
61 #include "polyMesh.H"
62 #include "coordinateSystems.H"
63 #include "interpolation.H"
64 
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
66 
67 namespace Foam
68 {
69 
70 // Forward declaration of friend functions and operators
71 
72 class sampledSurface;
73 
74 Ostream& operator<<(Ostream&, const sampledSurface&);
75 
76 
77 /*---------------------------------------------------------------------------*\
78  Class sampledSurface Declaration
79 \*---------------------------------------------------------------------------*/
80 
81 class sampledSurface
82 {
83  // Private Data
84 
85  //- Name of sample surface
86  word name_;
87 
88  //- Reference to mesh
89  const polyMesh& mesh_;
90 
91  //- Do we intend to interpolate the information?
92  const bool interpolate_;
93 
94 
95  // Demand-driven data
96 
97  //- Face area vectors
98  mutable vectorField* SfPtr_;
99 
100  //- Mag face area vectors
101  mutable scalarField* magSfPtr_;
102 
103  //- Face centres
104  mutable vectorField* CfPtr_;
105 
106  //- Total surface area
107  mutable scalar area_;
108 
109 
110  // Make geometric data
111 
112  //- Make Sf
113  void makeSf() const;
114 
115  //- Make magSf
116  void makeMagSf() const;
117 
118  //- Make Cf
119  void makeCf() const;
120 
121 
122  // Service methods
123 
124  //- Check field size matches surface size
125  template<class Type>
126  bool checkFieldSize(const Field<Type>&) const;
127 
128  //- Project field onto surface
129  template<class ReturnType, class Type>
130  void project
131  (
133  const Field<Type>&
134  ) const;
135 
136  //- Project field onto surface
137  template<class ReturnType, class Type>
138  void project
139  (
141  const tmp<Field<Type>>&
142  ) const;
143 
144  //- Project field onto surface
145  template<class ReturnType, class Type>
146  tmp<Field<ReturnType>> project(const tmp<Field<Type>>&) const;
147 
148 
149 protected:
150 
151  // Protected Member functions
152 
153  virtual void clearGeom() const;
154 
155 
156 public:
157 
158  //- Runtime type information
159  TypeName("sampledSurface");
160 
161 
162  //- Declare run-time constructor selection table
164  (
165  autoPtr,
167  word,
168  (
169  const word& name,
170  const polyMesh& mesh,
171  const dictionary& dict
172  ),
173  (name, mesh, dict)
174  );
175 
176 
177  // iNew helper class
178 
179  //- Class used for the PtrLists read-construction
180  class iNew
181  {
182  //- Reference to the volume mesh
183  const polyMesh& mesh_;
184 
185  public:
186 
187  iNew(const polyMesh& mesh)
188  :
189  mesh_(mesh)
190  {}
191 
193  {
194  word name(is);
195  dictionary dict(is);
196 
197  return sampledSurface::New(name, mesh_, dict);
198  }
199  };
200 
201 
202  // Constructors
203 
204  //- Construct from name, mesh
206  (
207  const word& name,
208  const polyMesh&,
209  const bool interpolate = false
210  );
211 
212  //- Construct from dictionary
214  (
215  const word& name,
216  const polyMesh&,
217  const dictionary&
218  );
219 
220  //- Clone
222  {
224  return autoPtr<sampledSurface>(nullptr);
225  }
226 
227 
228  // Selectors
229 
230  //- Return a reference to the selected surface
232  (
233  const word& name,
234  const polyMesh&,
235  const dictionary&
236  );
237 
238 
239  //- Destructor
240  virtual ~sampledSurface();
241 
242 
243  // Member Functions
244 
245  //- Access to the underlying mesh
246  const polyMesh& mesh() const
247  {
248  return mesh_;
249  }
250 
251  //- Name of surface
252  const word& name() const
253  {
254  return name_;
255  }
256 
257  //- Interpolation requested for surface
258  bool interpolate() const
259  {
260  return interpolate_;
261  }
262 
263  //- Does the surface need an update?
264  virtual bool needsUpdate() const = 0;
265 
266  //- Return the list of fields required
267  virtual wordList fields() const
268  {
269  return wordList::null();
270  }
271 
272  //- Update the surface as required.
273  // Do nothing (and return false) if no update was required
274  virtual bool update() = 0;
275 
276  //- Points of surface
277  virtual const pointField& points() const = 0;
278 
279  //- Faces of surface
280  virtual const faceList& faces() const = 0;
281 
282  //- Return face area vectors
283  virtual const vectorField& Sf() const;
284 
285  //- Return face area magnitudes
286  virtual const scalarField& magSf() const;
287 
288  //- Return face centres as vectorField
289  virtual const vectorField& Cf() const;
290 
291  //- The total surface area
292  scalar area() const;
293 
294  //- Integration of a field across the surface
295  template<class Type>
296  Type integrate(const Field<Type>&) const;
297 
298  //- Integration of a field across the surface
299  template<class Type>
300  Type integrate(const tmp<Field<Type>>&) const;
301 
302  //- Area-averaged value of a field across the surface
303  template<class Type>
304  Type average(const Field<Type>&) const;
305 
306  //- Project field onto surface
307  tmp<Field<scalar>> project(const Field<scalar>&) const;
308 
309  //- Project field onto surface
310  tmp<Field<scalar>> project(const Field<vector>&) const;
311 
312  //- Project field onto surface
313  tmp<Field<vector>> project(const Field<sphericalTensor>&) const;
314 
315  //- Project field onto surface
316  tmp<Field<vector>> project(const Field<symmTensor>&) const;
317 
318  //- Project field onto surface
319  tmp<Field<vector>> project(const Field<tensor>&) const;
320 
321  //- Area-averaged value of a field across the surface
322  template<class Type>
323  Type average(const tmp<Field<Type>>&) const;
324 
325  //- Sample field on the surface's faces
326  #define DEFINE_SAMPLE(Type, nullArg) \
327  virtual tmp<Field<Type>> sample \
328  ( \
329  const VolField<Type>& \
330  ) const = 0; \
331  \
332  virtual tmp<Field<Type>> sample \
333  ( \
334  const SurfaceField<Type>& \
335  ) const;
337  #undef DEFINE_SAMPLE
338 
339  //- Interpolate field to the surface's points
340  #define DEFINE_INTERPOLATE(Type, nullArg) \
341  virtual tmp<Field<Type>> interpolate \
342  ( \
343  const interpolation<Type>& \
344  ) const = 0;
346  #undef DEFINE_INTERPOLATE
347 
348 
349  // Mesh Change
350 
351  //- Update for mesh point-motion
352  virtual void movePoints() = 0;
353 
354  //- Update topology using the given map
355  virtual void topoChange(const polyTopoChangeMap&) = 0;
356 
357  //- Update from another mesh using the given map
358  virtual void mapMesh(const polyMeshMap&) = 0;
359 
360  //- Redistribute or update using the given distribution map
361  virtual void distribute(const polyDistributionMap&) = 0;
362 
363 
364  // Edit
365 
366  //- Rename
367  virtual void rename(const word& newName)
368  {
369  name_ = newName;
370  }
371 
372 
373  // Write
374 
375  //- Write
376  virtual void print(Ostream&) const;
377 
378  //- Ostream operator
379  friend Ostream& operator<<(Ostream&, const sampledSurface&);
380 };
381 
382 
383 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
384 
385 } // End namespace Foam
386 
387 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
388 
389 #ifdef NoRepository
390  #include "sampledSurfaceTemplates.C"
391 #endif
392 
393 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
394 
395 #endif
396 
397 // ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
static const List< word > & null()
Return a null List.
Definition: ListI.H:118
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Class used for the PtrLists read-construction.
iNew(const polyMesh &mesh)
autoPtr< sampledSurface > operator()(Istream &is) const
An abstract class for surfaces with sampling.
virtual void mapMesh(const polyMeshMap &)=0
Update from another mesh using the given map.
declareRunTimeSelectionTable(autoPtr, sampledSurface, word,(const word &name, const polyMesh &mesh, const dictionary &dict),(name, mesh, dict))
Declare run-time constructor selection table.
virtual bool needsUpdate() const =0
Does the surface need an update?
virtual void movePoints()=0
Update for mesh point-motion.
virtual void distribute(const polyDistributionMap &)=0
Redistribute or update using the given distribution map.
virtual wordList fields() const
Return the list of fields required.
friend Ostream & operator<<(Ostream &, const sampledSurface &)
Ostream operator.
autoPtr< sampledSurface > clone() const
Clone.
virtual const faceList & faces() const =0
Faces of surface.
static autoPtr< sampledSurface > New(const word &name, const polyMesh &, const dictionary &)
Return a reference to the selected surface.
FOR_ALL_FIELD_TYPES(DEFINE_SAMPLE)
Type average(const Field< Type > &) const
Area-averaged value of a field across the surface.
virtual bool update()=0
Update the surface as required.
virtual void clearGeom() const
sampledSurface(const word &name, const polyMesh &, const bool interpolate=false)
Construct from name, mesh.
virtual const scalarField & magSf() const
Return face area magnitudes.
virtual ~sampledSurface()
Destructor.
virtual void print(Ostream &) const
Write.
virtual void rename(const word &newName)
Rename.
bool interpolate() const
Interpolation requested for surface.
const word & name() const
Name of surface.
virtual const vectorField & Cf() const
Return face centres as vectorField.
virtual const pointField & points() const =0
Points of surface.
scalar area() const
The total surface area.
const polyMesh & mesh() const
Access to the underlying mesh.
TypeName("sampledSurface")
Runtime type information.
virtual const vectorField & Sf() const
Return face area vectors.
Type integrate(const Field< Type > &) const
Integration of a field across the surface.
virtual void topoChange(const polyTopoChangeMap &)=0
Update topology using the given map.
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:63
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:381
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
Macros to ease declaration of run-time selection tables.
#define DEFINE_SAMPLE(Type, nullArg)
Sample field on the surface's faces.
#define DEFINE_INTERPOLATE(Type, nullArg)
Interpolate field to the surface's points.
dictionary dict
Basic run-time type information using word as the type's name. Used to enhance the standard RTTI to c...