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-2021 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:
188  iNew(const polyMesh& mesh)
189  :
190  mesh_(mesh)
191  {}
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  //- Interpolate from points to cell centre
334  template<class Type>
336  (
338  ) const;
339 
340  //- Sample field on surface
341  virtual tmp<scalarField> sample
342  (
343  const volScalarField&
344  ) const = 0;
345 
346  //- Sample field on surface
347  virtual tmp<vectorField> sample
348  (
349  const volVectorField&
350  ) const = 0;
351 
352  //- Sample field on surface
354  (
356  ) const = 0;
357 
358  //- Sample field on surface
360  (
361  const volSymmTensorField&
362  ) const = 0;
363 
364  //- Sample field on surface
365  virtual tmp<tensorField> sample
366  (
367  const volTensorField&
368  ) const = 0;
369 
370  //- Surface sample field on surface
371  virtual tmp<scalarField> sample
372  (
373  const surfaceScalarField&
374  ) const;
375 
376  //- Surface Sample field on surface
377  virtual tmp<vectorField> sample
378  (
379  const surfaceVectorField&
380  ) const;
381 
382  //- Surface sample field on surface
384  (
386  ) const;
387 
388  //- Surface sample field on surface
390  (
392  ) const;
393 
394  //- Surface sample field on surface
395  virtual tmp<tensorField> sample
396  (
397  const surfaceTensorField&
398  ) const;
399 
400  //- Interpolate field on surface
402  (
403  const interpolation<scalar>&
404  ) const = 0;
405 
406 
407  //- Interpolate field on surface
409  (
410  const interpolation<vector>&
411  ) const = 0;
412 
413  //- Interpolate field on surface
415  (
417  ) const = 0;
418 
419  //- Interpolate field on surface
421  (
423  ) const = 0;
424 
425  //- Interpolate field on surface
427  (
428  const interpolation<tensor>&
429  ) const = 0;
430 
431 
432  // Edit
433 
434  //- Rename
435  virtual void rename(const word& newName)
436  {
437  name_ = newName;
438  }
439 
440 
441  // Write
442 
443  //- Write
444  virtual void print(Ostream&) const;
445 
446  //- Ostream operator
447  friend Ostream& operator<<(Ostream&, const sampledSurface&);
448 };
449 
450 
451 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
452 
453 } // End namespace Foam
454 
455 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
456 
457 #ifdef NoRepository
458  #include "sampledSurfaceTemplates.C"
459 #endif
460 
461 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
462 
463 #endif
464 
465 // ************************************************************************* //
dictionary dict
Type integrate(const Field< Type > &) const
Integration of a field across the surface.
virtual ~sampledSurface()
Destructor.
TypeName("sampledSurface")
Runtime type information.
virtual bool expire()=0
Mark the surface as needing an update.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
An abstract class for surfaces with sampling.
autoPtr< sampledSurface > clone() const
Clone.
const word & name() const
Name of surface.
virtual wordList fields() const
Return the list of fields required.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
bool interpolate() const
Interpolation requested for surface.
autoPtr< sampledSurface > operator()(Istream &is) const
virtual void print(Ostream &) const
Write.
static const List< T > & null()
Return a null List.
Definition: ListI.H:118
friend Ostream & operator<<(Ostream &, const sampledSurface &)
Ostream operator.
virtual const faceList & faces() const =0
Faces of surface.
virtual bool needsUpdate() const =0
Does the surface need an update?
virtual void clearGeom() const
tmp< GeometricField< Type, fvPatchField, volMesh > > pointAverage(const GeometricField< Type, pointPatchField, pointMesh > &pfld) const
Interpolate from points to cell centre.
A class for handling words, derived from string.
Definition: word.H:59
Type average(const Field< Type > &) const
Area-averaged value of a field across the surface.
declareRunTimeSelectionTable(autoPtr, sampledSurface, word,(const word &name, const polyMesh &mesh, const dictionary &dict),(name, mesh, dict))
Declare run-time constructor selection table.
sampledSurface(const word &name, const polyMesh &, const bool interpolate=false)
Construct from name, mesh.
virtual tmp< scalarField > sample(const volScalarField &) const =0
Sample field on surface.
scalar area() const
The total surface area.
static autoPtr< sampledSurface > New(const word &name, const polyMesh &, const dictionary &)
Return a reference to the selected surface.
const polyMesh & mesh() const
Access to the underlying mesh.
virtual bool update()=0
Update the surface as required.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
virtual const vectorField & Sf() const
Return face area vectors.
iNew(const polyMesh &mesh)
virtual const vectorField & Cf() const
Return face centres as vectorField.
virtual const scalarField & magSf() const
Return face area magnitudes.
virtual const pointField & points() const =0
Points of surface.
Ostream & operator<<(Ostream &, const ensightPart &)
virtual void rename(const word &newName)
Rename.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
Macros to ease declaration of run-time selection tables.
A class for managing temporary objects.
Definition: PtrList.H:53
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:353
Class used for the PtrLists read-construction.
Namespace for OpenFOAM.