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:
184  iNew(const polyMesh& mesh)
185  :
186  mesh_(mesh)
187  {}
190  {
191  word name(is);
192  dictionary dict(is);
193 
194  return sampledSurface::New(name, mesh_, dict);
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  {
220  notImplemented("autoPtr<sampledSurface> clone() const");
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
315  tmp<Field<vector> > project(const Field<sphericalTensor>&) const;
316 
317  //- Project field onto surface
318  tmp<Field<vector> > project(const Field<symmTensor>&) const;
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 // ************************************************************************* //
virtual tmp< scalarField > sample(const volScalarField &) const =0
Sample field on surface.
virtual const vectorField & Cf() const
Return face centres as vectorField.
iNew(const polyMesh &mesh)
An abstract class for surfaces with sampling.
Macros to ease declaration of run-time selection tables.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A class for handling words, derived from string.
Definition: word.H:59
Type integrate(const Field< Type > &) const
Integration of a field across the surface.
const word & name() const
Name of surface.
friend Ostream & operator<<(Ostream &, const sampledSurface &)
Ostream operator.
autoPtr< sampledSurface > operator()(Istream &is) const
const polyMesh & mesh() const
Access to the underlying mesh.
sampledSurface(const word &name, const polyMesh &, const bool interpolate=false)
Construct from name, mesh.
virtual const scalarField & magSf() const
Return face area magnitudes.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Type average(const Field< Type > &) const
Area-averaged value of a field across the surface.
Namespace for OpenFOAM.
virtual void rename(const word &newName)
Rename.
virtual bool needsUpdate() const =0
Does the surface need an update?
dictionary dict
virtual const vectorField & Sf() const
Return face area vectors.
virtual bool expire()=0
Mark the surface as needing an update.
virtual void clearGeom() const
virtual bool update()=0
Update the surface as required.
autoPtr< sampledSurface > clone() const
Clone.
scalar area() const
The total surface area.
bool interpolate() const
Interpolation requested for surface.
Generic GeometricField class.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
static autoPtr< sampledSurface > New(const word &name, const polyMesh &, const dictionary &)
Return a reference to the selected surface.
declareRunTimeSelectionTable(autoPtr, sampledSurface, word,( const word &name, const polyMesh &mesh, const dictionary &dict ),(name, mesh, dict))
Declare run-time constructor selection table.
virtual void print(Ostream &) const
Write.
Class used for the PtrLists read-construction.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
TypeName("sampledSurface")
Runtime type information.
virtual const pointField & points() const =0
Points of surface.
virtual const faceList & faces() const =0
Faces of surface.
tmp< GeometricField< Type, fvPatchField, volMesh > > pointAverage(const GeometricField< Type, pointPatchField, pointMesh > &pfld) const
Interpolate from points to cell centre.
#define notImplemented(functionName)
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:356
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
A class for managing temporary objects.
Definition: PtrList.H:118
virtual ~sampledSurface()
Destructor.