FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/pointField.H>
53 #include <OpenFOAM/word.H>
54 #include <OpenFOAM/labelList.H>
55 #include <OpenFOAM/faceList.H>
56 #include <OpenFOAM/typeInfo.H>
58 #include <OpenFOAM/autoPtr.H>
60 #include <OpenFOAM/polyMesh.H>
63 
64 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
65 
66 namespace Foam
67 {
68 
69 /*---------------------------------------------------------------------------*\
70  Class sampledSurface Declaration
71 \*---------------------------------------------------------------------------*/
72 
74 {
75  // Private data
76 
77  //- Name of sample surface
78  word name_;
79 
80  //- Reference to mesh
81  const polyMesh& mesh_;
82 
83  //- Do we intend to interpolate the information?
84  bool interpolate_;
85 
86 
87  // Demand-driven data
88 
89  //- Face area vectors
90  mutable vectorField* SfPtr_;
91 
92  //- Mag face area vectors
93  mutable scalarField* magSfPtr_;
94 
95  //- Face centres
96  mutable vectorField* CfPtr_;
97 
98  //- Total surface area
99  mutable scalar area_;
100 
101  // Make geometric data
102 
103  //- Make Sf
104  void makeSf() const;
105 
106  //- Make magSf
107  void makeMagSf() const;
108 
109  //- Make Cf
110  void makeCf() const;
111 
112  // Service methods
113 
114  //- Check field size matches surface size
115  template<class Type>
116  bool checkFieldSize(const Field<Type>&) const;
117 
118  //- Project field onto surface
119  template<class ReturnType, class Type>
120  void project
121  (
123  const Field<Type>&
124  ) const;
125 
126  //- Project field onto surface
127  template<class ReturnType, class Type>
128  void project
129  (
131  const tmp<Field<Type> >&
132  ) const;
133 
134  //- Project field onto surface
135  template<class ReturnType, class Type>
136  tmp<Field<ReturnType> > project(const tmp<Field<Type> >&) const;
137 
138 protected:
139 
140  // Protected Member functions
141 
142  virtual void clearGeom() const;
143 
144 public:
145 
146  //- Runtime type information
147  TypeName("sampledSurface");
148 
149 
150  // Declare run-time constructor selection table
151 
153  (
154  autoPtr,
156  word,
157  (
158  const word& name,
159  const polyMesh& mesh,
160  const dictionary& dict
161  ),
162  (name, mesh, dict)
163  );
164 
165 
166  //- Class used for the PtrLists read-construction
167  class iNew
168  {
169  //- Reference to the volume mesh
170  const polyMesh& mesh_;
171 
172  public:
173 
174  iNew(const polyMesh& mesh)
175  :
176  mesh_(mesh)
177  {}
178 
180  {
181  word name(is);
182  dictionary dict(is);
183 
184  return sampledSurface::New(name, mesh_, dict);
185  }
186  };
187 
188 
189  // Constructors
190 
191  //- Construct from name, mesh
193  (
194  const word& name,
195  const polyMesh&
196  );
197 
198  //- Construct from dictionary
200  (
201  const word& name,
202  const polyMesh&,
203  const dictionary&
204  );
205 
206  //- Clone
208  {
209  notImplemented("autoPtr<sampledSurface> clone() const");
210  return autoPtr<sampledSurface>(NULL);
211  }
212 
213 
214  // Selectors
215 
216  //- Return a reference to the selected surface
218  (
219  const word& name,
220  const polyMesh&,
221  const dictionary&
222  );
223 
224 
225  // Destructor
226 
227  virtual ~sampledSurface();
228 
229 
230  // Member Functions
231 
232  // Access
233 
234  //- Access to the underlying mesh
235  const polyMesh& mesh() const
236  {
237  return mesh_;
238  }
239 
240  //- Name of surface
241  const word& name() const
242  {
243  return name_;
244  }
245 
246  //- interpolation requested for surface
247  bool interpolate() const
248  {
249  return interpolate_;
250  }
251 
252  //- Does the surface need an update?
253  virtual bool needsUpdate() const = 0;
254 
255  //- Mark the surface as needing an update.
256  // May also free up unneeded data.
257  // Return false if surface was already marked as expired.
258  virtual bool expire() = 0;
259 
260  //- Update the surface as required.
261  // Do nothing (and return false) if no update was required
262  virtual bool update() = 0;
263 
264 
265  //- Points of surface
266  virtual const pointField& points() const = 0;
267 
268  //- Faces of surface
269  virtual const faceList& faces() const = 0;
270 
271  //- Return face area vectors
272  virtual const vectorField& Sf() const;
273 
274  //- Return face area magnitudes
275  virtual const scalarField& magSf() const;
276 
277  //- Return face centres as vectorField
278  virtual const vectorField& Cf() const;
279 
280  //- The total surface area
281  scalar area() const;
282 
283  //- Integration of a field across the surface
284  template<class Type>
285  Type integrate(const Field<Type>&) const;
286 
287  //- Integration of a field across the surface
288  template<class Type>
289  Type integrate(const tmp<Field<Type> >&) const;
290 
291  //- Area-averaged value of a field across the surface
292  template<class Type>
293  Type average(const Field<Type>&) const;
294 
295  //- Area-averaged value of a field across the surface
296  template<class Type>
297  Type average(const tmp<Field<Type> >&) const;
298 
299  //- Project field onto surface
300  tmp<Field<scalar> > project(const Field<scalar>&) const;
301 
302  //- Project field onto surface
303  tmp<Field<scalar> > project(const Field<vector>&) const;
304 
305  //- Project field onto surface
306  tmp<Field<vector> > project(const Field<sphericalTensor>&) const;
307 
308  //- Project field onto surface
309  tmp<Field<vector> > project(const Field<symmTensor>&) const;
310 
311  //- Project field onto surface
312  tmp<Field<vector> > project(const Field<tensor>&) const;
313 
314  //- Sample field on surface
315  virtual tmp<scalarField> sample
316  (
317  const volScalarField&
318  ) const = 0;
319 
320  //- Sample field on surface
321  virtual tmp<vectorField> sample
322  (
323  const volVectorField&
324  ) const = 0;
325 
326  //- Sample field on surface
328  (
330  ) const = 0;
331 
332  //- Sample field on surface
334  (
335  const volSymmTensorField&
336  ) const = 0;
337 
338  //- Sample field on surface
339  virtual tmp<tensorField> sample
340  (
341  const volTensorField&
342  ) const = 0;
343 
344 
345  //- Interpolate field on surface
347  (
348  const interpolation<scalar>&
349  ) const = 0;
350 
351 
352  //- Interpolate field on surface
354  (
355  const interpolation<vector>&
356  ) const = 0;
357 
358  //- Interpolate field on surface
360  (
362  ) const = 0;
363 
364  //- Interpolate field on surface
366  (
368  ) const = 0;
369 
370  //- Interpolate field on surface
372  (
373  const interpolation<tensor>&
374  ) const = 0;
375 
376 
377  // Edit
378 
379  //- Rename
380  virtual void rename(const word& newName)
381  {
382  name_ = newName;
383  }
384 
385 
386  // Write
387 
388  //- Write
389  virtual void print(Ostream&) const;
390 
391 
392  // IOstream operators
393 
394  friend Ostream& operator<<(Ostream&, const sampledSurface&);
395 };
396 
397 
398 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
399 
400 } // End namespace Foam
401 
402 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
403 
404 #ifdef NoRepository
406 #endif
407 
408 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
409 
410 #endif
411 
412 // ************************ vim: set sw=4 sts=4 et: ************************ //