distanceSurface.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::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
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  //- Optional bounding box to trim triangles against
79  const boundBox bounds_;
80 
81  //- If restricted to zones, name of this zone or a regular expression
83 
84  //- Track if the surface needs an update
85  mutable bool needsUpdate_;
86 
87 
88  //- Distance to cell centres
90 
91  //- Distance to points
93 
94  //- Constructed iso surface
96 
97  //- Constructed iso surface
99 
100  //- Triangles converted to faceList
102 
103 
104  // Private Member Functions
105 
106  //- Create iso surface
107  void createGeometry();
108 
109  //- Sample field on faces
110  template<class Type>
112  (
114  ) const;
115 
116 
117  template<class Type>
120 
121 
122 public:
123 
124  //- Runtime type information
125  TypeName("distanceSurface");
126 
127 
128  // Constructors
129 
130  //- Construct from dictionary
132  (
133  const word& name,
134  const polyMesh& mesh,
135  const dictionary& dict
136  );
137 
138  //- Construct from components
140  (
141  const word& name,
142  const polyMesh& mesh,
143  const bool interpolate,
144  const word& surfaceType,
145  const word& surfaceName,
146  const scalar distance,
147  const bool signedDistance,
148  const bool cell,
149  const Switch regularise,
150  const Switch average,
151  const boundBox& bounds = boundBox::greatBox
152  );
153 
154 
155  //- Destructor
156  virtual ~distanceSurface();
157 
158 
159  // Member Functions
160 
161  //- Does the surface need an update?
162  virtual bool needsUpdate() const;
163 
164  //- Mark the surface as needing an update.
165  // May also free up unneeded data.
166  // Return false if surface was already marked as expired.
167  virtual bool expire();
168 
169  //- Update the surface as required.
170  // Do nothing (and return false) if no update was needed
171  virtual bool update();
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 
196  const triSurface& surface() const
197  {
198  if (cell_)
199  {
200  return isoSurfCellPtr_();
201  }
202  else
203  {
204  return isoSurfPtr_();
205  }
206  }
207 
208  //- Sample field on surface
209  virtual tmp<scalarField> sample
210  (
211  const volScalarField&
212  ) const;
213 
214  //- Sample field on surface
215  virtual tmp<vectorField> sample
216  (
217  const volVectorField&
218  ) const;
219 
220  //- Sample field on surface
222  (
224  ) const;
225 
226  //- Sample field on surface
228  (
229  const volSymmTensorField&
230  ) const;
231 
232  //- Sample field on surface
233  virtual tmp<tensorField> sample
234  (
235  const volTensorField&
236  ) const;
237 
238 
239  //- Interpolate field on surface
241  (
242  const interpolation<scalar>&
243  ) const;
244 
245  //- Interpolate field on surface
247  (
248  const interpolation<vector>&
249  ) const;
250 
251  //- Interpolate field on surface
253  (
255  ) const;
256 
257  //- Interpolate field on surface
259  (
261  ) const;
262 
263  //- Interpolate field on surface
265  (
266  const interpolation<tensor>&
267  ) const;
268 
269  //- Write
270  virtual void print(Ostream&) const;
271 };
272 
273 
274 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
275 
276 } // End namespace Foam
277 
278 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
279 
280 #ifdef NoRepository
281 # include "distanceSurfaceTemplates.C"
282 #endif
283 
284 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
285 
286 #endif
287 
288 // ************************************************************************* //
Foam::Switch
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:60
Foam::distanceSurface::distance_
const scalar distance_
Distance value.
Definition: distanceSurface.H:63
Foam::PrimitivePatch::points
const Field< PointType > & points() const
Return reference to global points.
Definition: PrimitivePatchTemplate.H:282
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
searchableSurface.H
Foam::distanceSurface::isoSurfCellPtr_
autoPtr< isoSurfaceCell > isoSurfCellPtr_
Constructed iso surface.
Definition: distanceSurface.H:94
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::distanceSurface::surface
const triSurface & surface() const
Definition: distanceSurface.H:195
Foam::sampledSurface::average
Type average(const Field< Type > &) const
Area-averaged value of a field across the surface.
Definition: sampledSurfaceTemplates.C:74
isoSurfaceCell.H
Foam::distanceSurface::update
virtual bool update()
Update the surface as required.
Definition: distanceSurface.C:440
Foam::distanceSurface::average_
const Switch average_
Whether to recalculate cell values as average of point values.
Definition: distanceSurface.H:75
distanceSurfaceTemplates.C
Foam::distanceSurface::regularise_
const Switch regularise_
Whether to coarsen.
Definition: distanceSurface.H:72
Foam::distanceSurface::facesPtr_
autoPtr< faceList > facesPtr_
Triangles converted to faceList.
Definition: distanceSurface.H:100
Foam::distanceSurface::points
virtual const pointField & points() const
Points of surface.
Definition: distanceSurface.H:173
Foam::distanceSurface::signed_
const bool signed_
Signed distance.
Definition: distanceSurface.H:66
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::distanceSurface::interpolateField
tmp< Field< Type > > interpolateField(const interpolation< Type > &) const
Foam::distanceSurface::cellDistancePtr_
autoPtr< volScalarField > cellDistancePtr_
Distance to cell centres.
Definition: distanceSurface.H:88
Foam::distanceSurface::needsUpdate_
bool needsUpdate_
Track if the surface needs an update.
Definition: distanceSurface.H:84
Foam::distanceSurface::distanceSurface
distanceSurface(const word &name, const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
Definition: distanceSurface.C:306
Foam::distanceSurface::cell_
const bool cell_
Whether to use isoSurfaceCell or isoSurface.
Definition: distanceSurface.H:69
Foam::distanceSurface
A sampledSurface defined by a distance to a surface.
Definition: distanceSurface.H:53
Foam::distanceSurface::expire
virtual bool expire()
Mark the surface as needing an update.
Definition: distanceSurface.C:414
Foam::keyType
A class for handling keywords in dictionaries.
Definition: keyType.H:56
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::triSurface
Triangulated surface description with patch information.
Definition: triSurface.H:57
sampledSurface.H
Foam::distanceSurface::~distanceSurface
virtual ~distanceSurface()
Destructor.
Definition: distanceSurface.C:402
Foam::sampledSurface
An abstract class for surfaces with sampling.
Definition: sampledSurface.H:77
Foam::interpolation< Type >
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::distanceSurface::isoSurfPtr_
autoPtr< isoSurface > isoSurfPtr_
Constructed iso surface.
Definition: distanceSurface.H:97
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::distanceSurface::needsUpdate
virtual bool needsUpdate() const
Does the surface need an update?
Definition: distanceSurface.C:408
s
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))
Foam::distanceSurface::print
virtual void print(Ostream &) const
Write.
Definition: distanceSurface.C:550
Foam::distance
scalar distance(const vector &p1, const vector &p2)
Definition: curveTools.C:12
Foam::distanceSurface::faces
virtual const faceList & faces() const
Faces of surface.
Definition: distanceSurface.H:179
isoSurface.H
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Foam::distanceSurface::sampleField
tmp< Field< Type > > sampleField(const GeometricField< Type, fvPatchField, volMesh > &vField) const
Sample field on faces.
Foam::distanceSurface::surfPtr_
const autoPtr< searchableSurface > surfPtr_
Surface.
Definition: distanceSurface.H:60
Foam::boundBox::greatBox
static const boundBox greatBox
A very large boundBox: min/max == -/+ VGREAT.
Definition: boundBox.H:76
Foam::distanceSurface::sample
virtual tmp< scalarField > sample(const volScalarField &) const
Sample field on surface.
Definition: distanceSurface.C:462
Foam::faceList
List< face > faceList
Definition: faceListFwd.H:43
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::sampledSurface::name
const word & name() const
Name of surface.
Definition: sampledSurface.H:250
Foam::boundBox
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:55
Foam::distanceSurface::createGeometry
void createGeometry()
Create iso surface.
Definition: distanceSurface.C:44
Foam::sampledSurface::mesh
const polyMesh & mesh() const
Access to the underlying mesh.
Definition: sampledSurface.H:244
Foam::distanceSurface::TypeName
TypeName("distanceSurface")
Runtime type information.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::distanceSurface::pointDistance_
scalarField pointDistance_
Distance to points.
Definition: distanceSurface.H:91
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::sampledSurface::interpolate
bool interpolate() const
Interpolation requested for surface.
Definition: sampledSurface.H:256
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
Foam::distanceSurface::bounds_
const boundBox bounds_
Optional bounding box to trim triangles against.
Definition: distanceSurface.H:78
Foam::distanceSurface::zoneKey_
keyType zoneKey_
If restricted to zones, name of this zone or a regular expression.
Definition: distanceSurface.H:81