sampledIsoSurface.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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 const pointScalarField* pointFieldPtr_;
98 
99  // And on subsetted mesh
100 
101  //- Cached submesh
102  mutable autoPtr<fvMeshSubset> subMeshPtr_;
103 
104  //- Cached volfield
105  mutable autoPtr<volScalarField> storedVolSubFieldPtr_;
106  mutable const volScalarField* volSubFieldPtr_;
107 
108  //- Cached pointfield
109  mutable autoPtr<pointScalarField> storedPointSubFieldPtr_;
110  mutable const pointScalarField* pointSubFieldPtr_;
111 
112 
113 
114  // Private Member Functions
115 
116  //- Get fields needed to recreate iso surface.
117  void getIsoFields() const;
118 
119  //- Create iso surface (if time has changed)
120  // Do nothing (and return false) if no update was needed
121  bool updateGeometry() const;
122 
123  //- Sample field on faces
124  template<class Type>
125  tmp<Field<Type>> sampleField
126  (
128  ) const;
129 
130 
131  template<class Type>
133  interpolateField(const interpolation<Type>&) const;
134 
135 
136 public:
137 
138  //- Runtime type information
139  TypeName("sampledIsoSurface");
140 
141 
142  // Constructors
143 
144  //- Construct from dictionary
146  (
147  const word& name,
148  const polyMesh& mesh,
149  const dictionary& dict
150  );
151 
152 
153  //- Destructor
154  virtual ~sampledIsoSurface();
155 
156 
157  // Member Functions
158 
159  //- Does the surface need an update?
160  virtual bool needsUpdate() const;
161 
162  //- Mark the surface as needing an update.
163  // May also free up unneeded data.
164  // Return false if surface was already marked as expired.
165  virtual bool expire();
166 
167  //- Update the surface as required.
168  // Do nothing (and return false) if no update was needed
169  virtual bool update();
170 
171 
172  //- Points of surface
173  virtual const pointField& points() const
174  {
175  return surface().points();
176  }
177 
178  //- Faces of surface
179  virtual const faceList& faces() const
180  {
181  if (facesPtr_.empty())
182  {
183  const triSurface& s = surface();
184 
185  facesPtr_.reset(new faceList(s.size()));
186 
187  forAll(s, i)
188  {
189  facesPtr_()[i] = s[i].triFaceFace();
190  }
191  }
192  return facesPtr_;
193  }
194 
196  const isoSurface& surface() const
197  {
198  return surfPtr_();
199  }
200 
201  //- Lookup or read isoField. Sets volFieldPtr_ and pointFieldPtr_.
202  void getIsoField();
203 
204 
205  //- Sample field on surface
206  virtual tmp<scalarField> sample
207  (
208  const volScalarField&
209  ) const;
210 
211  //- Sample field on surface
212  virtual tmp<vectorField> sample
213  (
214  const volVectorField&
215  ) const;
216 
217  //- Sample field on surface
219  (
221  ) const;
222 
223  //- Sample field on surface
225  (
226  const volSymmTensorField&
227  ) const;
228 
229  //- Sample field on surface
230  virtual tmp<tensorField> sample
231  (
232  const volTensorField&
233  ) const;
234 
235 
236  //- Interpolate field on surface
238  (
239  const interpolation<scalar>&
240  ) const;
241 
242  //- Interpolate field on surface
244  (
245  const interpolation<vector>&
246  ) const;
247 
248  //- Interpolate field on surface
250  (
252  ) const;
253 
254  //- Interpolate field on surface
256  (
258  ) const;
259 
260  //- Interpolate field on surface
262  (
263  const interpolation<tensor>&
264  ) const;
265 
266  //- Write
267  virtual void print(Ostream&) const;
268 };
269 
270 
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 
273 } // End namespace Foam
274 
275 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
276 
277 #ifdef NoRepository
279 #endif
280 
281 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
282 
283 #endif
284 
285 // ************************************************************************* //
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
TypeName("sampledIsoSurface")
Runtime type information.
void reset(T *=nullptr)
If object pointer already set, delete object and set to given.
Definition: autoPtrI.H:114
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.
const word & name() const
Name of surface.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
bool interpolate() const
Interpolation requested for surface.
virtual tmp< scalarField > sample(const volScalarField &) const
Sample field on surface.
List< face > faceList
Definition: faceListFwd.H:43
virtual ~sampledIsoSurface()
Destructor.
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
bool empty() const
Return true if the autoPtr is empty (ie, no pointer set)
Definition: autoPtrI.H:76
virtual bool update()
Update the surface as required.
virtual bool needsUpdate() const
Does the surface need an update?
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))
A class for handling words, derived from string.
Definition: word.H:59
virtual const faceList & faces() const
Faces of surface.
const Field< PointType > & points() const
Return reference to global points.
virtual const pointField & points() const
Points of surface.
virtual void print(Ostream &) const
Write.
const polyMesh & mesh() const
Access to the underlying mesh.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
const isoSurface & surface() const
Abstract base class for interpolation.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
virtual bool expire()
Mark the surface as needing an update.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
A surface formed by the iso value. After "Regularised Marching Tetrahedra: improved iso-surface extra...
Definition: isoSurface.H:83
sampledIsoSurface(const word &name, const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
A class for managing temporary objects.
Definition: PtrList.H:53
Triangulated surface description with patch information.
Definition: triSurface.H:66
Namespace for OpenFOAM.
void getIsoField()
Lookup or read isoField. Sets volFieldPtr_ and pointFieldPtr_.
A sampledSurface defined by a surface of iso value. Always triangulated. To be used in sampleSurfaces...