distanceSurface.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::distanceSurface
26 
27 Description
28  A sampledSurface defined by a distance to a surface.
29 
30  Uses either isoSurfaceCell or isoSurface.
31 
32 SourceFiles
33  distanceSurface.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef distanceSurface_H
38 #define distanceSurface_H
39 
40 #include "sampledSurface.H"
41 #include "searchableSurface.H"
42 #include "isoSurfaceCell.H"
43 #include "isoSurface.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class distanceSurface Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 class distanceSurface
55 :
56  public sampledSurface
57 {
58  // Private data
59 
60  //- Surface
61  const autoPtr<searchableSurface> surfPtr_;
62 
63  //- Distance value
64  const scalar distance_;
65 
66  //- Signed distance
67  const bool signed_;
68 
69  //- Whether to use isoSurfaceCell or isoSurface
70  const bool cell_;
71 
72  //- Whether to coarsen
73  const Switch regularise_;
74 
75  //- Whether to recalculate cell values as average of point values
76  const Switch average_;
77 
78  //- If restricted to zones, name of this zone or a regular expression
79  keyType zoneKey_;
80 
81  //- Track if the surface needs an update
82  mutable bool needsUpdate_;
83 
84 
85  //- Distance to cell centres
86  autoPtr<volScalarField> cellDistancePtr_;
87 
88  //- Distance to points
89  scalarField pointDistance_;
90 
91  //- Constructed iso surface
92  autoPtr<isoSurfaceCell> isoSurfCellPtr_;
93 
94  //- Constructed iso surface
95  autoPtr<isoSurface> isoSurfPtr_;
96 
97  //- Triangles converted to faceList
98  mutable autoPtr<faceList> facesPtr_;
99 
100 
101  // Private Member Functions
102 
103  //- Create iso surface
104  void createGeometry();
105 
106  //- Sample field on faces
107  template<class Type>
108  tmp<Field<Type>> sampleField
109  (
111  ) const;
112 
113 
114  template<class Type>
116  interpolateField(const interpolation<Type>&) const;
117 
118 
119 public:
120 
121  //- Runtime type information
122  TypeName("distanceSurface");
123 
124 
125  // Constructors
126 
127  //- Construct from dictionary
129  (
130  const word& name,
131  const polyMesh& mesh,
132  const dictionary& dict
133  );
134 
135  //- Construct from components
137  (
138  const word& name,
139  const polyMesh& mesh,
140  const bool interpolate,
141  const word& surfaceType,
142  const word& surfaceName,
143  const scalar distance,
144  const bool signedDistance,
145  const bool cell,
146  const Switch regularise,
147  const Switch average
148  );
149 
150 
151  //- Destructor
152  virtual ~distanceSurface();
153 
154 
155  // Member Functions
156 
157  //- Does the surface need an update?
158  virtual bool needsUpdate() const;
159 
160  //- Mark the surface as needing an update.
161  // May also free up unneeded data.
162  // Return false if surface was already marked as expired.
163  virtual bool expire();
164 
165  //- Update the surface as required.
166  // Do nothing (and return false) if no update was needed
167  virtual bool update();
168 
169  //- Points of surface
170  virtual const pointField& points() const
171  {
172  return surface().points();
173  }
174 
175  //- Faces of surface
176  virtual const faceList& faces() const
177  {
178  if (facesPtr_.empty())
179  {
180  const triSurface& s = surface();
181 
182  facesPtr_.reset(new faceList(s.size()));
183 
184  forAll(s, i)
185  {
186  facesPtr_()[i] = s[i].triFaceFace();
187  }
188  }
189  return facesPtr_;
190  }
192  const triSurface& surface() const
193  {
194  if (cell_)
195  {
196  return isoSurfCellPtr_();
197  }
198  else
199  {
200  return isoSurfPtr_();
201  }
202  }
203 
204  //- Sample field on surface
205  virtual tmp<scalarField> sample
206  (
207  const volScalarField&
208  ) const;
209 
210  //- Sample field on surface
211  virtual tmp<vectorField> sample
212  (
213  const volVectorField&
214  ) const;
215 
216  //- Sample field on surface
218  (
220  ) const;
221 
222  //- Sample field on surface
224  (
225  const volSymmTensorField&
226  ) const;
227 
228  //- Sample field on surface
229  virtual tmp<tensorField> sample
230  (
231  const volTensorField&
232  ) const;
233 
234 
235  //- Interpolate field on surface
237  (
238  const interpolation<scalar>&
239  ) const;
240 
241  //- Interpolate field on surface
243  (
244  const interpolation<vector>&
245  ) const;
246 
247  //- Interpolate field on surface
249  (
251  ) const;
252 
253  //- Interpolate field on surface
255  (
257  ) const;
258 
259  //- Interpolate field on surface
261  (
262  const interpolation<tensor>&
263  ) const;
264 
265  //- Write
266  virtual void print(Ostream&) const;
267 };
268 
269 
270 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
271 
272 } // End namespace Foam
273 
274 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
275 
276 #ifdef NoRepository
277  #include "distanceSurfaceTemplates.C"
278 #endif
279 
280 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
281 
282 #endif
283 
284 // ************************************************************************* //
A class for handling keywords in dictionaries.
Definition: keyType.H:64
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
void reset(T *=nullptr)
If object pointer already set, delete object and set to given.
Definition: autoPtrI.H:114
TypeName("distanceSurface")
Runtime type information.
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.
virtual const pointField & points() const
Points of surface.
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.
List< face > faceList
Definition: faceListFwd.H:43
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
scalar distance(const vector &p1, const vector &p2)
Definition: curveTools.C:12
Generic GeometricField class.
virtual ~distanceSurface()
Destructor.
virtual bool update()
Update the surface as required.
bool empty() const
Return true if the autoPtr is empty (ie, no pointer set)
Definition: autoPtrI.H:76
virtual void print(Ostream &) const
Write.
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
Type average(const Field< Type > &) const
Area-averaged value of a field across the surface.
const Field< PointType > & points() const
Return reference to global points.
const polyMesh & mesh() const
Access to the underlying mesh.
distanceSurface(const word &name, const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
virtual bool expire()
Mark the surface as needing an update.
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
virtual bool needsUpdate() const
Does the surface need an update?
Abstract base class for interpolation.
A sampledSurface defined by a distance to a surface.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
const triSurface & surface() const
A class for managing temporary objects.
Definition: PtrList.H:53
Triangulated surface description with patch information.
Definition: triSurface.H:66
virtual const faceList & faces() const
Faces of surface.
Namespace for OpenFOAM.
virtual tmp< scalarField > sample(const volScalarField &) const
Sample field on surface.