All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2019 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 initialization.
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  //- Mark the surface as needing an update.
270  // May also free up unneeded data.
271  // Return false if surface was already marked as expired.
272  virtual bool expire() = 0;
273 
274  //- Update the surface as required.
275  // Do nothing (and return false) if no update was required
276  virtual bool update() = 0;
277 
278  //- Points of surface
279  virtual const pointField& points() const = 0;
280 
281  //- Faces of surface
282  virtual const faceList& faces() const = 0;
283 
284  //- Return face area vectors
285  virtual const vectorField& Sf() const;
286 
287  //- Return face area magnitudes
288  virtual const scalarField& magSf() const;
289 
290  //- Return face centres as vectorField
291  virtual const vectorField& Cf() const;
292 
293  //- The total surface area
294  scalar area() const;
295 
296  //- Integration of a field across the surface
297  template<class Type>
298  Type integrate(const Field<Type>&) const;
299 
300  //- Integration of a field across the surface
301  template<class Type>
302  Type integrate(const tmp<Field<Type>>&) const;
303 
304  //- Area-averaged value of a field across the surface
305  template<class Type>
306  Type average(const Field<Type>&) const;
307 
308  //- Area-averaged value of a field across the surface
309  template<class Type>
310  Type average(const tmp<Field<Type>>&) const;
311 
312  //- Project field onto surface
313  tmp<Field<scalar>> project(const Field<scalar>&) const;
314 
315  //- Project field onto surface
316  tmp<Field<scalar>> project(const Field<vector>&) const;
317 
318  //- Project field onto surface
319  tmp<Field<vector>> project(const Field<sphericalTensor>&) const;
320 
321  //- Project field onto surface
322  tmp<Field<vector>> project(const Field<symmTensor>&) const;
323 
324  //- Project field onto surface
325  tmp<Field<vector>> project(const Field<tensor>&) const;
326 
327  //- Interpolate from points to cell centre
328  template<class Type>
330  (
332  ) const;
333 
334  //- Sample field on surface
335  virtual tmp<scalarField> sample
336  (
337  const volScalarField&
338  ) const = 0;
339 
340  //- Sample field on surface
341  virtual tmp<vectorField> sample
342  (
343  const volVectorField&
344  ) const = 0;
345 
346  //- Sample field on surface
348  (
350  ) const = 0;
351 
352  //- Sample field on surface
354  (
355  const volSymmTensorField&
356  ) const = 0;
357 
358  //- Sample field on surface
359  virtual tmp<tensorField> sample
360  (
361  const volTensorField&
362  ) const = 0;
363 
364  //- Surface sample field on surface
365  virtual tmp<scalarField> sample
366  (
367  const surfaceScalarField&
368  ) const;
369 
370  //- Surface Sample field on surface
371  virtual tmp<vectorField> sample
372  (
373  const surfaceVectorField&
374  ) const;
375 
376  //- Surface sample field on surface
378  (
380  ) const;
381 
382  //- Surface sample field on surface
384  (
386  ) const;
387 
388  //- Surface sample field on surface
389  virtual tmp<tensorField> sample
390  (
391  const surfaceTensorField&
392  ) const;
393 
394  //- Interpolate field on surface
396  (
397  const interpolation<scalar>&
398  ) const = 0;
399 
400 
401  //- Interpolate field on surface
403  (
404  const interpolation<vector>&
405  ) const = 0;
406 
407  //- Interpolate field on surface
409  (
411  ) const = 0;
412 
413  //- Interpolate field on surface
415  (
417  ) const = 0;
418 
419  //- Interpolate field on surface
421  (
422  const interpolation<tensor>&
423  ) const = 0;
424 
425 
426  // Edit
427 
428  //- Rename
429  virtual void rename(const word& newName)
430  {
431  name_ = newName;
432  }
433 
434 
435  // Write
436 
437  //- Write
438  virtual void print(Ostream&) const;
439 
440  //- Ostream operator
441  friend Ostream& operator<<(Ostream&, const sampledSurface&);
442 };
443 
444 
445 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
446 
447 } // End namespace Foam
448 
449 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
450 
451 #ifdef NoRepository
452  #include "sampledSurfaceTemplates.C"
453 #endif
454 
455 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
456 
457 #endif
458 
459 // ************************************************************************* //
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:158
An abstract class for surfaces with sampling.
autoPtr< sampledSurface > clone() const
Clone.
const word & name() const
Name of surface.
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.
Generic GeometricField class.
autoPtr< sampledSurface > operator()(Istream &is) const
virtual void print(Ostream &) const
Write.
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.
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:53
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:74
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:366
Class used for the PtrLists read-construction.
Namespace for OpenFOAM.
virtual tmp< scalarField > sample(const volScalarField &) const =0
Sample field on surface.