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-2022 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 "surfaceMesh.H"
62 #include "polyMesh.H"
63 #include "coordinateSystems.H"
64 #include "interpolation.H"
65 
66 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
67 
68 namespace Foam
69 {
70 
71 // Forward declaration of friend functions and operators
72 
73 class sampledSurface;
74 
75 Ostream& operator<<(Ostream&, const sampledSurface&);
76 
77 
78 /*---------------------------------------------------------------------------*\
79  Class sampledSurface Declaration
80 \*---------------------------------------------------------------------------*/
81 
82 class sampledSurface
83 {
84  // Private Data
85 
86  //- Name of sample surface
87  word name_;
88 
89  //- Reference to mesh
90  const polyMesh& mesh_;
91 
92  //- Do we intend to interpolate the information?
93  const bool interpolate_;
94 
95 
96  // Demand-driven data
97 
98  //- Face area vectors
99  mutable vectorField* SfPtr_;
100 
101  //- Mag face area vectors
102  mutable scalarField* magSfPtr_;
103 
104  //- Face centres
105  mutable vectorField* CfPtr_;
106 
107  //- Total surface area
108  mutable scalar area_;
109 
110 
111  // Make geometric data
112 
113  //- Make Sf
114  void makeSf() const;
115 
116  //- Make magSf
117  void makeMagSf() const;
118 
119  //- Make Cf
120  void makeCf() const;
121 
122 
123  // Service methods
124 
125  //- Check field size matches surface size
126  template<class Type>
127  bool checkFieldSize(const Field<Type>&) const;
128 
129  //- Project field onto surface
130  template<class ReturnType, class Type>
131  void project
132  (
134  const Field<Type>&
135  ) const;
136 
137  //- Project field onto surface
138  template<class ReturnType, class Type>
139  void project
140  (
142  const tmp<Field<Type>>&
143  ) const;
144 
145  //- Project field onto surface
146  template<class ReturnType, class Type>
147  tmp<Field<ReturnType>> project(const tmp<Field<Type>>&) const;
148 
149 
150 protected:
151 
152  // Protected Member functions
153 
154  virtual void clearGeom() const;
155 
156 
157 public:
158 
159  //- Runtime type information
160  TypeName("sampledSurface");
161 
162 
163  //- Declare run-time constructor selection table
165  (
166  autoPtr,
168  word,
169  (
170  const word& name,
171  const polyMesh& mesh,
172  const dictionary& dict
173  ),
174  (name, mesh, dict)
175  );
176 
177 
178  // iNew helper class
179 
180  //- Class used for the PtrLists read-construction
181  class iNew
182  {
183  //- Reference to the volume mesh
184  const polyMesh& mesh_;
185 
186  public:
187 
188  iNew(const polyMesh& mesh)
189  :
190  mesh_(mesh)
191  {}
192 
194  {
195  word name(is);
196  dictionary dict(is);
197 
198  return sampledSurface::New(name, mesh_, dict);
199  }
200  };
201 
202 
203  // Constructors
204 
205  //- Construct from name, mesh
207  (
208  const word& name,
209  const polyMesh&,
210  const bool interpolate = false
211  );
212 
213  //- Construct from dictionary
215  (
216  const word& name,
217  const polyMesh&,
218  const dictionary&
219  );
220 
221  //- Clone
223  {
225  return autoPtr<sampledSurface>(nullptr);
226  }
227 
228 
229  // Selectors
230 
231  //- Return a reference to the selected surface
233  (
234  const word& name,
235  const polyMesh&,
236  const dictionary&
237  );
238 
239 
240  //- Destructor
241  virtual ~sampledSurface();
242 
243 
244  // Member Functions
245 
246  // Access
247 
248  //- Access to the underlying mesh
249  const polyMesh& mesh() const
250  {
251  return mesh_;
252  }
253 
254  //- Name of surface
255  const word& name() const
256  {
257  return name_;
258  }
259 
260  //- Interpolation requested for surface
261  bool interpolate() const
262  {
263  return interpolate_;
264  }
265 
266  //- Does the surface need an update?
267  virtual bool needsUpdate() const = 0;
268 
269  //- Return the list of fields required
270  virtual wordList fields() const
271  {
272  return wordList::null();
273  }
274 
275  //- Mark the surface as needing an update.
276  // May also free up unneeded data.
277  // Return false if surface was already marked as expired.
278  virtual bool expire() = 0;
279 
280  //- Update the surface as required.
281  // Do nothing (and return false) if no update was required
282  virtual bool update() = 0;
283 
284  //- Points of surface
285  virtual const pointField& points() const = 0;
286 
287  //- Faces of surface
288  virtual const faceList& faces() const = 0;
289 
290  //- Return face area vectors
291  virtual const vectorField& Sf() const;
292 
293  //- Return face area magnitudes
294  virtual const scalarField& magSf() const;
295 
296  //- Return face centres as vectorField
297  virtual const vectorField& Cf() const;
298 
299  //- The total surface area
300  scalar area() const;
301 
302  //- Integration of a field across the surface
303  template<class Type>
304  Type integrate(const Field<Type>&) const;
305 
306  //- Integration of a field across the surface
307  template<class Type>
308  Type integrate(const tmp<Field<Type>>&) const;
309 
310  //- Area-averaged value of a field across the surface
311  template<class Type>
312  Type average(const Field<Type>&) const;
313 
314  //- Area-averaged value of a field across the surface
315  template<class Type>
316  Type average(const tmp<Field<Type>>&) const;
317 
318  //- Project field onto surface
319  tmp<Field<scalar>> project(const Field<scalar>&) const;
320 
321  //- Project field onto surface
322  tmp<Field<scalar>> project(const Field<vector>&) const;
323 
324  //- Project field onto surface
325  tmp<Field<vector>> project(const Field<sphericalTensor>&) const;
326 
327  //- Project field onto surface
328  tmp<Field<vector>> project(const Field<symmTensor>&) const;
329 
330  //- Project field onto surface
331  tmp<Field<vector>> project(const Field<tensor>&) const;
332 
333  //- Sample field on surface
334  virtual tmp<scalarField> sample
335  (
336  const volScalarField&
337  ) const = 0;
338 
339  //- Sample field on surface
340  virtual tmp<vectorField> sample
341  (
342  const volVectorField&
343  ) const = 0;
344 
345  //- Sample field on surface
347  (
349  ) const = 0;
350 
351  //- Sample field on surface
353  (
354  const volSymmTensorField&
355  ) const = 0;
356 
357  //- Sample field on surface
358  virtual tmp<tensorField> sample
359  (
360  const volTensorField&
361  ) const = 0;
362 
363  //- Surface sample field on surface
364  virtual tmp<scalarField> sample
365  (
366  const surfaceScalarField&
367  ) const;
368 
369  //- Surface Sample field on surface
370  virtual tmp<vectorField> sample
371  (
372  const surfaceVectorField&
373  ) const;
374 
375  //- Surface sample field on surface
377  (
379  ) const;
380 
381  //- Surface sample field on surface
383  (
385  ) const;
386 
387  //- Surface sample field on surface
388  virtual tmp<tensorField> sample
389  (
390  const surfaceTensorField&
391  ) const;
392 
393  //- Interpolate field on surface
395  (
396  const interpolation<scalar>&
397  ) const = 0;
398 
399 
400  //- Interpolate field on surface
402  (
403  const interpolation<vector>&
404  ) const = 0;
405 
406  //- Interpolate field on surface
408  (
410  ) const = 0;
411 
412  //- Interpolate field on surface
414  (
416  ) const = 0;
417 
418  //- Interpolate field on surface
420  (
421  const interpolation<tensor>&
422  ) const = 0;
423 
424 
425  // Edit
426 
427  //- Rename
428  virtual void rename(const word& newName)
429  {
430  name_ = newName;
431  }
432 
433 
434  // Write
435 
436  //- Write
437  virtual void print(Ostream&) const;
438 
439  //- Ostream operator
440  friend Ostream& operator<<(Ostream&, const sampledSurface&);
441 };
442 
443 
444 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
445 
446 } // End namespace Foam
447 
448 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
449 
450 #ifdef NoRepository
451  #include "sampledSurfaceTemplates.C"
452 #endif
453 
454 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
455 
456 #endif
457 
458 // ************************************************************************* //
Generic GeometricField class.
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 keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Abstract base class for interpolation.
Definition: interpolation.H:55
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
Class used for the PtrLists read-construction.
iNew(const polyMesh &mesh)
autoPtr< sampledSurface > operator()(Istream &is) const
An abstract class for surfaces with sampling.
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 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.
Type average(const Field< Type > &) const
Area-averaged value of a field across the surface.
virtual tmp< scalarField > sample(const volScalarField &) const =0
Sample field on 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.
virtual bool expire()=0
Mark the surface as needing an update.
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.
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
#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.
dictionary dict
Basic run-time type information using word as the type's name. Used to enhance the standard RTTI to c...