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-2015 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  grpFunctionObjects
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 /*---------------------------------------------------------------------------*\
75  Class sampledSurface Declaration
76 \*---------------------------------------------------------------------------*/
77 
78 class sampledSurface
79 {
80  // Private data
81 
82  //- Name of sample surface
83  word name_;
84 
85  //- Reference to mesh
86  const polyMesh& mesh_;
87 
88  //- Do we intend to interpolate the information?
89  const bool interpolate_;
90 
91 
92  // Demand-driven data
93 
94  //- Face area vectors
95  mutable vectorField* SfPtr_;
96 
97  //- Mag face area vectors
98  mutable scalarField* magSfPtr_;
99 
100  //- Face centres
101  mutable vectorField* CfPtr_;
102 
103  //- Total surface area
104  mutable scalar area_;
105 
106 
107  // Make geometric data
108 
109  //- Make Sf
110  void makeSf() const;
111 
112  //- Make magSf
113  void makeMagSf() const;
114 
115  //- Make Cf
116  void makeCf() const;
117 
118 
119  // Service methods
120 
121  //- Check field size matches surface size
122  template<class Type>
123  bool checkFieldSize(const Field<Type>&) const;
124 
125  //- Project field onto surface
126  template<class ReturnType, class Type>
127  void project
128  (
130  const Field<Type>&
131  ) const;
132 
133  //- Project field onto surface
134  template<class ReturnType, class Type>
135  void project
136  (
138  const tmp<Field<Type> >&
139  ) const;
140 
141  //- Project field onto surface
142  template<class ReturnType, class Type>
143  tmp<Field<ReturnType> > project(const tmp<Field<Type> >&) const;
144 
145 
146 protected:
147 
148  // Protected Member functions
149 
150  virtual void clearGeom() const;
151 
152 
153 public:
154 
155  //- Runtime type information
156  TypeName("sampledSurface");
157 
158 
159  //- Declare run-time constructor selection table
161  (
162  autoPtr,
164  word,
165  (
166  const word& name,
167  const polyMesh& mesh,
168  const dictionary& dict
169  ),
170  (name, mesh, dict)
171  );
172 
173 
174  // iNew helper class
175 
176  //- Class used for the PtrLists read-construction
177  class iNew
178  {
179  //- Reference to the volume mesh
180  const polyMesh& mesh_;
181 
182  public:
183 
184  iNew(const polyMesh& mesh)
185  :
186  mesh_(mesh)
187  {}
188 
190  {
191  word name(is);
192  dictionary dict(is);
193 
195  }
196  };
197 
198 
199  // Constructors
200 
201  //- Construct from name, mesh
203  (
204  const word& name,
205  const polyMesh&,
206  const bool interpolate = false
207  );
208 
209  //- Construct from dictionary
211  (
212  const word& name,
213  const polyMesh&,
214  const dictionary&
215  );
216 
217  //- Clone
219  {
221  return autoPtr<sampledSurface>(NULL);
222  }
223 
224 
225  // Selectors
226 
227  //- Return a reference to the selected surface
229  (
230  const word& name,
231  const polyMesh&,
232  const dictionary&
233  );
234 
235 
236  //- Destructor
237  virtual ~sampledSurface();
238 
239 
240  // Member Functions
241 
242  // Access
243 
244  //- Access to the underlying mesh
245  const polyMesh& mesh() const
246  {
247  return mesh_;
248  }
249 
250  //- Name of surface
251  const word& name() const
252  {
253  return name_;
254  }
255 
256  //- Interpolation requested for surface
257  bool interpolate() const
258  {
259  return interpolate_;
260  }
261 
262  //- Does the surface need an update?
263  virtual bool needsUpdate() const = 0;
264 
265  //- Mark the surface as needing an update.
266  // May also free up unneeded data.
267  // Return false if surface was already marked as expired.
268  virtual bool expire() = 0;
269 
270  //- Update the surface as required.
271  // Do nothing (and return false) if no update was required
272  virtual bool update() = 0;
273 
274  //- Points of surface
275  virtual const pointField& points() const = 0;
276 
277  //- Faces of surface
278  virtual const faceList& faces() const = 0;
279 
280  //- Return face area vectors
281  virtual const vectorField& Sf() const;
282 
283  //- Return face area magnitudes
284  virtual const scalarField& magSf() const;
285 
286  //- Return face centres as vectorField
287  virtual const vectorField& Cf() const;
288 
289  //- The total surface area
290  scalar area() const;
291 
292  //- Integration of a field across the surface
293  template<class Type>
294  Type integrate(const Field<Type>&) const;
295 
296  //- Integration of a field across the surface
297  template<class Type>
298  Type integrate(const tmp<Field<Type> >&) const;
299 
300  //- Area-averaged value of a field across the surface
301  template<class Type>
302  Type average(const Field<Type>&) const;
303 
304  //- Area-averaged value of a field across the surface
305  template<class Type>
306  Type average(const tmp<Field<Type> >&) const;
307 
308  //- Project field onto surface
309  tmp<Field<scalar> > project(const Field<scalar>&) const;
310 
311  //- Project field onto surface
312  tmp<Field<scalar> > project(const Field<vector>&) const;
313 
314  //- Project field onto surface
316 
317  //- Project field onto surface
319 
320  //- Project field onto surface
321  tmp<Field<vector> > project(const Field<tensor>&) const;
322 
323  //- Interpolate from points to cell centre
324  template<class Type>
326  (
328  ) const;
329 
330  //- Sample field on surface
331  virtual tmp<scalarField> sample
332  (
333  const volScalarField&
334  ) const = 0;
335 
336  //- Sample field on surface
337  virtual tmp<vectorField> sample
338  (
339  const volVectorField&
340  ) const = 0;
341 
342  //- Sample field on surface
344  (
346  ) const = 0;
347 
348  //- Sample field on surface
350  (
351  const volSymmTensorField&
352  ) const = 0;
353 
354  //- Sample field on surface
355  virtual tmp<tensorField> sample
356  (
357  const volTensorField&
358  ) const = 0;
359 
360  //- Surface sample field on surface
361  virtual tmp<scalarField> sample
362  (
363  const surfaceScalarField&
364  ) const;
365 
366  //- Surface Sample field on surface
367  virtual tmp<vectorField> sample
368  (
369  const surfaceVectorField&
370  ) const;
371 
372  //- Surface sample field on surface
374  (
376  ) const;
377 
378  //- Surface sample field on surface
380  (
382  ) const;
383 
384  //- Surface sample field on surface
385  virtual tmp<tensorField> sample
386  (
387  const surfaceTensorField&
388  ) const;
389 
390  //- Interpolate field on surface
392  (
393  const interpolation<scalar>&
394  ) const = 0;
395 
396 
397  //- Interpolate field on surface
399  (
400  const interpolation<vector>&
401  ) const = 0;
402 
403  //- Interpolate field on surface
405  (
407  ) const = 0;
408 
409  //- Interpolate field on surface
411  (
413  ) const = 0;
414 
415  //- Interpolate field on surface
417  (
418  const interpolation<tensor>&
419  ) const = 0;
420 
421 
422  // Edit
423 
424  //- Rename
425  virtual void rename(const word& newName)
426  {
427  name_ = newName;
428  }
429 
430 
431  // Write
432 
433  //- Write
434  virtual void print(Ostream&) const;
435 
436  //- Ostream operator
437  friend Ostream& operator<<(Ostream&, const sampledSurface&);
438 };
439 
440 
441 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
442 
443 } // End namespace Foam
444 
445 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
446 
447 #ifdef NoRepository
448 # include "sampledSurfaceTemplates.C"
449 #endif
450 
451 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
452 
453 #endif
454 
455 // ************************************************************************* //
volFieldsFwd.H
Foam::sampledSurface::Sf
virtual const vectorField & Sf() const
Return face area vectors.
Definition: sampledSurface.C:195
Foam::sampledSurface::operator<<
friend Ostream & operator<<(Ostream &, const sampledSurface &)
Ostream operator.
Foam::sampledSurface::makeCf
void makeCf() const
Make Cf.
Definition: sampledSurface.C:93
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::sampledSurface::faces
virtual const faceList & faces() const =0
Faces of surface.
typeInfo.H
Foam::sampledSurface::pointAverage
tmp< GeometricField< Type, fvPatchField, volMesh > > pointAverage(const GeometricField< Type, pointPatchField, pointMesh > &pfld) const
Interpolate from points to cell centre.
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::sampledSurface::makeSf
void makeSf() const
Make Sf.
Definition: sampledSurface.C:51
Foam::sampledSurface::average
Type average(const Field< Type > &) const
Area-averaged value of a field across the surface.
Definition: sampledSurfaceTemplates.C:74
Foam::sampledSurface::sampledSurface
sampledSurface(const word &name, const polyMesh &, const bool interpolate=false)
Construct from name, mesh.
Definition: sampledSurface.C:150
Foam::sampledSurface::declareRunTimeSelectionTable
declareRunTimeSelectionTable(autoPtr, sampledSurface, word,(const word &name, const polyMesh &mesh, const dictionary &dict),(name, mesh, dict))
Declare run-time constructor selection table.
Foam::sampledSurface::sample
virtual tmp< scalarField > sample(const volScalarField &) const =0
Sample field on surface.
Foam::sampledSurface::New
static autoPtr< sampledSurface > New(const word &name, const polyMesh &, const dictionary &)
Return a reference to the selected surface.
Definition: sampledSurface.C:117
Foam::sampledSurface::area
scalar area() const
The total surface area.
Definition: sampledSurface.C:228
interpolation.H
Foam::sampledSurface::project
void project(Field< ReturnType > &, const Field< Type > &) const
Project field onto surface.
Definition: sampledSurfaceTemplates.C:108
faceList.H
polyMesh.H
Foam::sampledSurface::integrate
Type integrate(const Field< Type > &) const
Integration of a field across the surface.
Definition: sampledSurfaceTemplates.C:50
Foam::sampledSurface::name_
word name_
Name of sample surface.
Definition: sampledSurface.H:82
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::sampledSurface::expire
virtual bool expire()=0
Mark the surface as needing an update.
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:365
Foam::sampledSurface::points
virtual const pointField & points() const =0
Points of surface.
labelList.H
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::sampledSurface::rename
virtual void rename(const word &newName)
Rename.
Definition: sampledSurface.H:424
Foam::sampledSurface::iNew::operator()
autoPtr< sampledSurface > operator()(Istream &is) const
Definition: sampledSurface.H:188
Foam::sampledSurface::Cf
virtual const vectorField & Cf() const
Return face centres as vectorField.
Definition: sampledSurface.C:217
Foam::sampledSurface::clone
autoPtr< sampledSurface > clone() const
Clone.
Definition: sampledSurface.H:217
Foam::sampledSurface
An abstract class for surfaces with sampling.
Definition: sampledSurface.H:77
Foam::sampledSurface::magSf
virtual const scalarField & magSf() const
Return face area magnitudes.
Definition: sampledSurface.C:206
Foam::sampledSurface::print
virtual void print(Ostream &) const
Write.
Definition: sampledSurface.C:341
Foam::sampledSurface::interpolate_
const bool interpolate_
Do we intend to interpolate the information?
Definition: sampledSurface.H:88
Foam::sampledSurface::iNew::iNew
iNew(const polyMesh &mesh)
Definition: sampledSurface.H:183
Foam::interpolation< scalar >
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
surfaceMesh.H
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
pointField.H
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Foam::sampledSurface::TypeName
TypeName("sampledSurface")
Runtime type information.
Foam::sampledSurface::mesh_
const polyMesh & mesh_
Reference to mesh.
Definition: sampledSurface.H:85
Foam::sampledSurface::iNew::mesh_
const polyMesh & mesh_
Reference to the volume mesh.
Definition: sampledSurface.H:179
Foam::sampledSurface::SfPtr_
vectorField * SfPtr_
Face area vectors.
Definition: sampledSurface.H:94
runTimeSelectionTables.H
Macros to ease declaration of run-time selection tables.
Foam::sampledSurface::needsUpdate
virtual bool needsUpdate() const =0
Does the surface need an update?
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::sampledSurface::iNew
Class used for the PtrLists read-construction.
Definition: sampledSurface.H:176
Foam::sampledSurface::name
const word & name() const
Name of surface.
Definition: sampledSurface.H:250
Foam::sampledSurface::~sampledSurface
virtual ~sampledSurface()
Destructor.
Definition: sampledSurface.C:187
surfaceFieldsFwd.H
Foam::sampledSurface::clearGeom
virtual void clearGeom() const
Definition: sampledSurface.C:42
Foam::sampledSurface::checkFieldSize
bool checkFieldSize(const Field< Type > &) const
Check field size matches surface size.
Definition: sampledSurfaceTemplates.C:29
Foam::sampledSurface::mesh
const polyMesh & mesh() const
Access to the underlying mesh.
Definition: sampledSurface.H:244
Foam::sampledSurface::magSfPtr_
scalarField * magSfPtr_
Mag face area vectors.
Definition: sampledSurface.H:97
Foam::sampledSurface::update
virtual bool update()=0
Update the surface as required.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
word.H
Foam::sampledSurface::area_
scalar area_
Total surface area.
Definition: sampledSurface.H:103
sampledSurfaceTemplates.C
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::sampledSurface::interpolate
bool interpolate() const
Interpolation requested for surface.
Definition: sampledSurface.H:256
Foam::sampledSurface::CfPtr_
vectorField * CfPtr_
Face centres.
Definition: sampledSurface.H:100
coordinateSystems.H
Foam::sampledSurface::makeMagSf
void makeMagSf() const
Make magSf.
Definition: sampledSurface.C:72
autoPtr.H