sampledSurface.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 | Copyright (C) 2011-2016 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 Group
28  grpUtilitiesFunctionObjects
29 
30 Description
31  An abstract class for surfaces with sampling.
32 
33  The constructors for the derived classes should generally start in a
34  'expired' condition (ie, needsUpdate() == true) and rely on a
35  subsequent call to the update() method to complete the initialization.
36  Delaying the final construction as late as possible allows the
37  construction of surfaces that may depend on intermediate calculation
38  results (eg, iso-surfaces) and also avoids the unnecessary
39  reconstruction of surfaces between sampling intervals.
40 
41  It is the responsibility of the caller to ensure that the surface
42  update() is called before the surface is used. The update() method
43  implementation should do nothing when the surface is already
44  up-to-date.
45 
46 SourceFiles
47  sampledSurface.C
48  sampledSurfaceTemplates.C
49 
50 \*---------------------------------------------------------------------------*/
51 
52 #ifndef sampledSurface_H
53 #define sampledSurface_H
54 
55 #include "pointField.H"
56 #include "word.H"
57 #include "labelList.H"
58 #include "faceList.H"
59 #include "typeInfo.H"
60 #include "runTimeSelectionTables.H"
61 #include "autoPtr.H"
62 #include "volFieldsFwd.H"
63 #include "surfaceFieldsFwd.H"
64 #include "surfaceMesh.H"
65 #include "polyMesh.H"
66 #include "coordinateSystems.H"
67 #include "interpolation.H"
68 
69 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
70 
71 namespace Foam
72 {
73 
74 // Forward declaration of friend functions and operators
75 
76 class sampledSurface;
77 
78 Ostream& operator<<(Ostream&, const sampledSurface&);
79 
80 
81 /*---------------------------------------------------------------------------*\
82  Class sampledSurface Declaration
83 \*---------------------------------------------------------------------------*/
84 
85 class sampledSurface
86 {
87  // Private data
88 
89  //- Name of sample surface
90  word name_;
91 
92  //- Reference to mesh
93  const polyMesh& mesh_;
94 
95  //- Do we intend to interpolate the information?
96  const bool interpolate_;
97 
98 
99  // Demand-driven data
100 
101  //- Face area vectors
102  mutable vectorField* SfPtr_;
103 
104  //- Mag face area vectors
105  mutable scalarField* magSfPtr_;
106 
107  //- Face centres
108  mutable vectorField* CfPtr_;
109 
110  //- Total surface area
111  mutable scalar area_;
112 
113 
114  // Make geometric data
115 
116  //- Make Sf
117  void makeSf() const;
118 
119  //- Make magSf
120  void makeMagSf() const;
121 
122  //- Make Cf
123  void makeCf() const;
124 
125 
126  // Service methods
127 
128  //- Check field size matches surface size
129  template<class Type>
130  bool checkFieldSize(const Field<Type>&) const;
131 
132  //- Project field onto surface
133  template<class ReturnType, class Type>
134  void project
135  (
137  const Field<Type>&
138  ) const;
139 
140  //- Project field onto surface
141  template<class ReturnType, class Type>
142  void project
143  (
145  const tmp<Field<Type>>&
146  ) const;
147 
148  //- Project field onto surface
149  template<class ReturnType, class Type>
150  tmp<Field<ReturnType>> project(const tmp<Field<Type>>&) const;
151 
152 
153 protected:
154 
155  // Protected Member functions
156 
157  virtual void clearGeom() const;
158 
159 
160 public:
161 
162  //- Runtime type information
163  TypeName("sampledSurface");
164 
165 
166  //- Declare run-time constructor selection table
168  (
169  autoPtr,
171  word,
172  (
173  const word& name,
174  const polyMesh& mesh,
175  const dictionary& dict
176  ),
177  (name, mesh, dict)
178  );
179 
180 
181  // iNew helper class
182 
183  //- Class used for the PtrLists read-construction
184  class iNew
185  {
186  //- Reference to the volume mesh
187  const polyMesh& mesh_;
188 
189  public:
191  iNew(const polyMesh& mesh)
192  :
193  mesh_(mesh)
194  {}
197  {
198  word name(is);
199  dictionary dict(is);
200 
201  return sampledSurface::New(name, mesh_, dict);
202  }
203  };
204 
205 
206  // Constructors
207 
208  //- Construct from name, mesh
210  (
211  const word& name,
212  const polyMesh&,
213  const bool interpolate = false
214  );
215 
216  //- Construct from dictionary
218  (
219  const word& name,
220  const polyMesh&,
221  const dictionary&
222  );
223 
224  //- Clone
226  {
228  return autoPtr<sampledSurface>(NULL);
229  }
230 
231 
232  // Selectors
233 
234  //- Return a reference to the selected surface
236  (
237  const word& name,
238  const polyMesh&,
239  const dictionary&
240  );
241 
242 
243  //- Destructor
244  virtual ~sampledSurface();
245 
246 
247  // Member Functions
248 
249  // Access
250 
251  //- Access to the underlying mesh
252  const polyMesh& mesh() const
253  {
254  return mesh_;
255  }
256 
257  //- Name of surface
258  const word& name() const
259  {
260  return name_;
261  }
262 
263  //- Interpolation requested for surface
264  bool interpolate() const
265  {
266  return interpolate_;
267  }
268 
269  //- Does the surface need an update?
270  virtual bool needsUpdate() const = 0;
271 
272  //- Mark the surface as needing an update.
273  // May also free up unneeded data.
274  // Return false if surface was already marked as expired.
275  virtual bool expire() = 0;
276 
277  //- Update the surface as required.
278  // Do nothing (and return false) if no update was required
279  virtual bool update() = 0;
280 
281  //- Points of surface
282  virtual const pointField& points() const = 0;
283 
284  //- Faces of surface
285  virtual const faceList& faces() const = 0;
286 
287  //- Return face area vectors
288  virtual const vectorField& Sf() const;
289 
290  //- Return face area magnitudes
291  virtual const scalarField& magSf() const;
292 
293  //- Return face centres as vectorField
294  virtual const vectorField& Cf() const;
295 
296  //- The total surface area
297  scalar area() const;
298 
299  //- Integration of a field across the surface
300  template<class Type>
301  Type integrate(const Field<Type>&) const;
302 
303  //- Integration of a field across the surface
304  template<class Type>
305  Type integrate(const tmp<Field<Type>>&) const;
306 
307  //- Area-averaged value of a field across the surface
308  template<class Type>
309  Type average(const Field<Type>&) const;
310 
311  //- Area-averaged value of a field across the surface
312  template<class Type>
313  Type average(const tmp<Field<Type>>&) const;
314 
315  //- Project field onto surface
316  tmp<Field<scalar>> project(const Field<scalar>&) const;
317 
318  //- Project field onto surface
319  tmp<Field<scalar>> project(const Field<vector>&) const;
320 
321  //- Project field onto surface
322  tmp<Field<vector>> project(const Field<sphericalTensor>&) const;
323 
324  //- Project field onto surface
325  tmp<Field<vector>> project(const Field<symmTensor>&) const;
326 
327  //- Project field onto surface
328  tmp<Field<vector>> project(const Field<tensor>&) const;
329 
330  //- Interpolate from points to cell centre
331  template<class Type>
333  (
335  ) const;
336 
337  //- Sample field on surface
338  virtual tmp<scalarField> sample
339  (
340  const volScalarField&
341  ) const = 0;
342 
343  //- Sample field on surface
344  virtual tmp<vectorField> sample
345  (
346  const volVectorField&
347  ) const = 0;
348 
349  //- Sample field on surface
351  (
353  ) const = 0;
354 
355  //- Sample field on surface
357  (
358  const volSymmTensorField&
359  ) const = 0;
360 
361  //- Sample field on surface
362  virtual tmp<tensorField> sample
363  (
364  const volTensorField&
365  ) const = 0;
366 
367  //- Surface sample field on surface
368  virtual tmp<scalarField> sample
369  (
370  const surfaceScalarField&
371  ) const;
372 
373  //- Surface Sample field on surface
374  virtual tmp<vectorField> sample
375  (
376  const surfaceVectorField&
377  ) const;
378 
379  //- Surface sample field on surface
381  (
383  ) const;
384 
385  //- Surface sample field on surface
387  (
389  ) const;
390 
391  //- Surface sample field on surface
392  virtual tmp<tensorField> sample
393  (
394  const surfaceTensorField&
395  ) const;
396 
397  //- Interpolate field on surface
399  (
400  const interpolation<scalar>&
401  ) const = 0;
402 
403 
404  //- Interpolate field on surface
406  (
407  const interpolation<vector>&
408  ) const = 0;
409 
410  //- Interpolate field on surface
412  (
414  ) const = 0;
415 
416  //- Interpolate field on surface
418  (
420  ) const = 0;
421 
422  //- Interpolate field on surface
424  (
425  const interpolation<tensor>&
426  ) const = 0;
427 
428 
429  // Edit
430 
431  //- Rename
432  virtual void rename(const word& newName)
433  {
434  name_ = newName;
435  }
436 
437 
438  // Write
439 
440  //- Write
441  virtual void print(Ostream&) const;
442 
443  //- Ostream operator
444  friend Ostream& operator<<(Ostream&, const sampledSurface&);
445 };
446 
447 
448 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
449 
450 } // End namespace Foam
451 
452 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
453 
454 #ifdef NoRepository
455  #include "sampledSurfaceTemplates.C"
456 #endif
457 
458 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
459 
460 #endif
461 
462 // ************************************************************************* //
scalar area() const
The total surface area.
autoPtr< sampledSurface > operator()(Istream &is) const
Type average(const Field< Type > &) const
Area-averaged value of a field across the surface.
dictionary dict
virtual void clearGeom() const
virtual ~sampledSurface()
Destructor.
autoPtr< sampledSurface > clone() const
Clone.
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:137
An abstract class for surfaces with sampling.
tmp< GeometricField< Type, fvPatchField, volMesh > > pointAverage(const GeometricField< Type, pointPatchField, pointMesh > &pfld) const
Interpolate from points to cell centre.
Type integrate(const Field< Type > &) const
Integration of a field across the surface.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Generic GeometricField class.
friend Ostream & operator<<(Ostream &, const sampledSurface &)
Ostream operator.
virtual void print(Ostream &) const
Write.
virtual const faceList & faces() const =0
Faces of surface.
virtual bool needsUpdate() const =0
Does the surface need an update?
const polyMesh & mesh() const
Access to the underlying mesh.
A class for handling words, derived from string.
Definition: word.H:59
declareRunTimeSelectionTable(autoPtr, sampledSurface, word,(const word &name, const polyMesh &mesh, const dictionary &dict),(name, mesh, dict))
Declare run-time constructor selection table.
const word & name() const
Name of surface.
sampledSurface(const word &name, const polyMesh &, const bool interpolate=false)
Construct from name, mesh.
virtual const vectorField & Cf() const
Return face centres as vectorField.
static autoPtr< sampledSurface > New(const word &name, const polyMesh &, const dictionary &)
Return a reference to the selected surface.
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 scalarField & magSf() const
Return face area magnitudes.
bool interpolate() const
Interpolation requested for surface.
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:53
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:54
#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.