sampledIsoSurface.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::sampledIsoSurface
26 
27 Description
28  A sampledSurface defined by a surface of iso value. Always triangulated.
29  To be used in sampleSurfaces / functionObjects. Recalculates iso surface
30  only if time changes.
31 
32 SourceFiles
33  sampledIsoSurface.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef sampledIsoSurface_H
38 #define sampledIsoSurface_H
39 
40 #include "isoSurface.H"
41 #include "sampledSurface.H"
42 #include "ZoneIDs.H"
43 #include "fvMeshSubset.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class sampledIsoSurface Declaration
52 \*---------------------------------------------------------------------------*/
53 
55 :
56  public sampledSurface
57 {
58  // Private data
59 
60  //- Field to get isoSurface of
61  const word isoField_;
62 
63  //- Iso value
64  const scalar isoVal_;
65 
66  //- Merge tolerance
67  const scalar mergeTol_;
68 
69  //- Whether to coarse
70  const Switch regularise_;
71 
72  //- Whether to recalculate cell values as average of point values
73  const Switch average_;
74 
75  //- Zone name/index (if restricted to zones)
76  mutable cellZoneID zoneID_;
77 
78  //- For zones: patch to put exposed faces into
79  mutable word exposedPatchName_;
80 
81  mutable autoPtr<isoSurface> surfPtr_;
82 
83  //- Triangles converted to faceList
84  mutable autoPtr<faceList> facesPtr_;
85 
86 
87  // Recreated for every isoSurface
88 
89  //- Time at last call, also track if surface needs an update
90  mutable label prevTimeIndex_;
91 
92  //- Cached volfield
93  mutable autoPtr<volScalarField> storedVolFieldPtr_;
94  mutable const volScalarField* volFieldPtr_;
95 
96  //- Cached pointfield
97  mutable autoPtr<pointScalarField> storedPointFieldPtr_;
98  mutable const pointScalarField* pointFieldPtr_;
99 
100  // And on subsetted mesh
101 
102  //- Cached submesh
103  mutable autoPtr<fvMeshSubset> subMeshPtr_;
104 
105  //- Cached volfield
106  mutable autoPtr<volScalarField> storedVolSubFieldPtr_;
107  mutable const volScalarField* volSubFieldPtr_;
108 
109  //- Cached pointfield
110  mutable autoPtr<pointScalarField> storedPointSubFieldPtr_;
111  mutable const pointScalarField* pointSubFieldPtr_;
112 
113 
114 
115  // Private Member Functions
116 
117  //- Get fields needed to recreate iso surface.
118  void getIsoFields() const;
119 
120  //- Create iso surface (if time has changed)
121  // Do nothing (and return false) if no update was needed
122  bool updateGeometry() const;
123 
124  //- Sample field on faces
125  template<class Type>
126  tmp<Field<Type> > sampleField
127  (
129  ) const;
130 
131 
132  template<class Type>
134  interpolateField(const interpolation<Type>&) const;
135 
136 
137 public:
138 
139  //- Runtime type information
140  TypeName("sampledIsoSurface");
141 
142 
143  // Constructors
144 
145  //- Construct from dictionary
147  (
148  const word& name,
149  const polyMesh& mesh,
150  const dictionary& dict
151  );
152 
153 
154  //- Destructor
155  virtual ~sampledIsoSurface();
156 
157 
158  // Member Functions
159 
160  //- Does the surface need an update?
161  virtual bool needsUpdate() const;
162 
163  //- Mark the surface as needing an update.
164  // May also free up unneeded data.
165  // Return false if surface was already marked as expired.
166  virtual bool expire();
167 
168  //- Update the surface as required.
169  // Do nothing (and return false) if no update was needed
170  virtual bool update();
171 
172 
173  //- Points of surface
174  virtual const pointField& points() const
175  {
176  return surface().points();
177  }
178 
179  //- Faces of surface
180  virtual const faceList& faces() const
181  {
182  if (facesPtr_.empty())
183  {
184  const triSurface& s = surface();
185 
186  facesPtr_.reset(new faceList(s.size()));
187 
188  forAll(s, i)
189  {
190  facesPtr_()[i] = s[i].triFaceFace();
191  }
192  }
193  return facesPtr_;
194  }
195 
197  const isoSurface& surface() const
198  {
199  return surfPtr_();
200  }
201 
202  //- Lookup or read isoField. Sets volFieldPtr_ and pointFieldPtr_.
203  void getIsoField();
204 
205 
206  //- Sample field on surface
207  virtual tmp<scalarField> sample
208  (
209  const volScalarField&
210  ) const;
211 
212  //- Sample field on surface
213  virtual tmp<vectorField> sample
214  (
215  const volVectorField&
216  ) const;
217 
218  //- Sample field on surface
220  (
222  ) const;
223 
224  //- Sample field on surface
226  (
227  const volSymmTensorField&
228  ) const;
229 
230  //- Sample field on surface
231  virtual tmp<tensorField> sample
232  (
233  const volTensorField&
234  ) const;
235 
236 
237  //- Interpolate field on surface
239  (
240  const interpolation<scalar>&
241  ) const;
242 
243  //- Interpolate field on surface
245  (
246  const interpolation<vector>&
247  ) const;
248 
249  //- Interpolate field on surface
251  (
253  ) const;
254 
255  //- Interpolate field on surface
257  (
259  ) const;
260 
261  //- Interpolate field on surface
263  (
264  const interpolation<tensor>&
265  ) const;
266 
267  //- Write
268  virtual void print(Ostream&) const;
269 };
270 
271 
272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
273 
274 } // End namespace Foam
275 
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
277 
278 #ifdef NoRepository
280 #endif
281 
282 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
283 
284 #endif
285 
286 // ************************************************************************* //
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject( name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE ))
An abstract class for surfaces with sampling.
void reset(T *=0)
If object pointer already set, delete object and set to given.
Definition: autoPtrI.H:114
bool empty() const
Return true if the autoPtr is empty (ie, no pointer set).
Definition: autoPtrI.H:76
const isoSurface & surface() const
Triangulated surface description with patch information.
Definition: triSurface.H:57
virtual bool update()
Update the surface as required.
A class for handling words, derived from string.
Definition: word.H:59
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
virtual ~sampledIsoSurface()
Destructor.
const word & name() const
Name of surface.
Abstract base class for interpolation.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
const polyMesh & mesh() const
Access to the underlying mesh.
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none.
Definition: Switch.H:60
List< face > faceList
Definition: faceListFwd.H:43
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Namespace for OpenFOAM.
sampledIsoSurface(const word &name, const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
dictionary dict
#define forAll(list, i)
Definition: UList.H:421
A sampledSurface defined by a surface of iso value. Always triangulated. To be used in sampleSurfaces...
TypeName("sampledIsoSurface")
Runtime type information.
A surface formed by the iso value. After "Regularised Marching Tetrahedra: improved iso-surface extra...
Definition: isoSurface.H:83
bool interpolate() const
Interpolation requested for surface.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
virtual const faceList & faces() const
Faces of surface.
virtual bool needsUpdate() const
Does the surface need an update?
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
void getIsoField()
Lookup or read isoField. Sets volFieldPtr_ and pointFieldPtr_.
virtual void print(Ostream &) const
Write.
virtual tmp< scalarField > sample(const volScalarField &) const
Sample field on surface.
virtual const pointField & points() const
Points of surface.
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
const Field< PointType > & points() const
Return reference to global points.
virtual bool expire()
Mark the surface as needing an update.