sampledCuttingPlane.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::sampledCuttingPlane
29 
30 Description
31  A sampledSurface defined by a plane using an iso-surface algorithm
32  to \a cut the mesh.
33 
34  This is often embedded as part of a sampled surfaces function object.
35 
36 Usage
37  Example of function object partial specification:
38  \verbatim
39  surfaces
40  (
41  surface1
42  {
43  type cuttingPlane;
44  planeType pointAndNormal;
45  pointAndNormalDict
46  {
47  ...
48  }
49  }
50  );
51  \endverbatim
52 
53  Where the sub-entries comprise:
54  \table
55  Property | Description | Required | Default
56  type | cuttingPlane | yes |
57  planeType | plane description (pointAndNormal etc) | yes |
58  mergeTol | tolerance for merging points | no | 1e-6
59  isoAlgorithm | (cell/topo/point) | no | point
60  regularise | point snapping (bool or enum) | no | true
61  bounds | limit with bounding box | no |
62  zone | limit to cell zone (name or regex) | no |
63  zones | limit to cell zones (names, regexs) | no |
64  exposedPatchName | name for zone subset | partly |
65  \endtable
66 
67 Note
68  The keyword \c zones has priority over \c zone.
69 
70 SeeAlso
71  Foam::plane
72 
73 SourceFiles
74  sampledCuttingPlane.C
75 
76 \*---------------------------------------------------------------------------*/
77 
78 #ifndef sampledCuttingPlane_H
79 #define sampledCuttingPlane_H
80 
81 #include "sampledSurface.H"
82 #include "plane.H"
83 #include "fvMeshSubset.H"
84 #include "isoSurface.H"
85 #include "isoSurfaceCell.H"
86 #include "isoSurfaceTopo.H"
87 
88 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
89 
90 namespace Foam
91 {
92 
93 /*---------------------------------------------------------------------------*\
94  Class sampledCuttingPlane Declaration
95 \*---------------------------------------------------------------------------*/
96 
97 class sampledCuttingPlane
98 :
99  public sampledSurface
100 {
101  // Private data
102 
103  //- Plane
104  const plane plane_;
105 
106  //- Optional bounding box to trim triangles against
107  const boundBox bounds_;
108 
109  //- Merge tolerance
110  const scalar mergeTol_;
111 
112  //- The iso-surface algorithm type
113  const isoSurfaceBase::algorithmType isoAlgo_;
114 
115  //- Filtering for iso-surface triangles
116  const isoSurfaceBase::filterType filter_;
117 
118  //- Whether to recalculate cell values as average of point values
119  const bool average_;
120 
121  //- The zone or zones in which cutting is to occur
122  wordRes zoneNames_;
123 
124  //- For zones: patch to put exposed faces into
125  mutable word exposedPatchName_;
126 
127  //- Track if the surface needs an update
128  mutable bool needsUpdate_;
129 
130 
131  //- Mesh subset (optional: only used with zones)
132  autoPtr<fvMeshSubset> subMeshPtr_;
133 
134  //- Distance to cell centres
135  autoPtr<volScalarField> cellDistancePtr_;
136 
137  //- Distance to points
138  scalarField pointDistance_;
139 
140  //- Constructed iso surface (ALGO_POINT)
141  autoPtr<isoSurface> isoSurfPtr_;
142 
143  //- Constructed iso surface (ALGO_CELL)
144  autoPtr<isoSurfaceCell> isoSurfCellPtr_;
145 
146  //- Constructed iso surface (ALGO_TOPO)
147  autoPtr<isoSurfaceTopo> isoSurfTopoPtr_;
148 
149 
150  // Private Member Functions
151 
152  //- Check and warn if bounding box does not intersect mesh or plane
153  void checkBoundsIntersection
154  (
155  const plane& pln,
156  const boundBox& meshBb
157  ) const;
158 
159  //- Create iso surface
160  void createGeometry();
161 
162  //- Sample volume field onto surface faces
163  template<class Type>
164  tmp<Field<Type>> sampleOnFaces
165  (
166  const interpolation<Type>& sampler
167  ) const;
168 
169  //- Interpolate volume field onto surface points
170  template<class Type>
171  tmp<Field<Type>> sampleOnPoints
172  (
173  const interpolation<Type>& interpolator
174  ) const;
175 
176  //- Interpolates cCoords,pCoords.
177  template<class Type>
178  tmp<Field<Type>> isoSurfaceInterpolate
179  (
181  const Field<Type>& pCoords
182  ) const;
183 
184 public:
185 
186  //- Runtime type information
187  TypeName("sampledCuttingPlane");
188 
189 
190  // Constructors
191 
192  //- Construct from dictionary
194  (
195  const word& name,
196  const polyMesh& mesh,
197  const dictionary& dict
198  );
199 
200 
201  //- Destructor
202  virtual ~sampledCuttingPlane() = default;
203 
204 
205  // Member Functions
206 
207  //- Does the surface need an update?
208  virtual bool needsUpdate() const;
209 
210  //- Mark the surface as needing an update.
211  // May also free up unneeded data.
212  // Return false if surface was already marked as expired.
213  virtual bool expire();
214 
215  //- Update the surface as required.
216  // Do nothing (and return false) if no update was needed
217  virtual bool update();
218 
219  //- Points of surface
220  virtual const pointField& points() const
221  {
222  return surface().points();
223  }
224 
225  //- Faces of surface
226  virtual const faceList& faces() const
227  {
228  return surface().surfFaces();
229  }
230 
231  //- Per-face zone/region information
232  virtual const labelList& zoneIds() const
233  {
234  return labelList::null();
235  }
236 
237  //- Face area magnitudes
238  virtual const vectorField& Sf() const
239  {
240  return surface().Sf();
241  }
242 
243  //- Face area magnitudes
244  virtual const scalarField& magSf() const
245  {
246  return surface().magSf();
247  }
248 
249  //- Face centres
250  virtual const vectorField& Cf() const
251  {
252  return surface().Cf();
253  }
254 
255 
256  //- The underlying surface
257  const meshedSurface& surface() const
258  {
259  if (isoSurfCellPtr_)
260  {
261  return *isoSurfCellPtr_;
262  }
263  else if (isoSurfTopoPtr_)
264  {
265  return *isoSurfTopoPtr_;
266  }
267  return *isoSurfPtr_;
268  }
269 
270  //- The underlying surface
272  {
273  if (isoSurfCellPtr_)
274  {
275  return *isoSurfCellPtr_;
276  }
277  else if (isoSurfTopoPtr_)
278  {
279  return *isoSurfTopoPtr_;
280  }
281  return *isoSurfPtr_;
282  }
283 
284  //- For each face, the original cell in mesh
285  const labelList& meshCells() const
286  {
287  if (isoSurfCellPtr_)
288  {
289  return isoSurfCellPtr_->meshCells();
290  }
291  else if (isoSurfTopoPtr_)
292  {
293  return isoSurfTopoPtr_->meshCells();
294  }
295  return isoSurfPtr_->meshCells();
296  }
297 
298  //- For each face, the original cell in mesh
300  {
301  if (isoSurfCellPtr_)
302  {
303  return isoSurfCellPtr_->meshCells();
304  }
305  else if (isoSurfTopoPtr_)
306  {
307  return isoSurfTopoPtr_->meshCells();
308  }
309  return isoSurfPtr_->meshCells();
310  }
311 
312 
313  // Sample
314 
315  //- Sample volume field onto surface faces
316  virtual tmp<scalarField> sample
317  (
318  const interpolation<scalar>& sampler
319  ) const;
320 
321  //- Sample volume field onto surface faces
322  virtual tmp<vectorField> sample
323  (
324  const interpolation<vector>& sampler
325  ) const;
326 
327  //- Sample volume field onto surface faces
329  (
330  const interpolation<sphericalTensor>& sampler
331  ) const;
332 
333  //- Sample volume field onto surface faces
335  (
336  const interpolation<symmTensor>& sampler
337  ) const;
338 
339  //- Sample volume field onto surface faces
340  virtual tmp<tensorField> sample
341  (
342  const interpolation<tensor>& sampler
343  ) const;
344 
345 
346  // Interpolate
347 
348  //- Interpolate volume field onto surface points
350  (
351  const interpolation<scalar>& interpolator
352  ) const;
353 
354  //- Interpolate volume field onto surface points
356  (
357  const interpolation<vector>& interpolator
358  ) const;
359 
360  //- Interpolate volume field onto surface points
362  (
363  const interpolation<sphericalTensor>& interpolator
364  ) const;
365 
366  //- Interpolate volume field onto surface points
368  (
369  const interpolation<symmTensor>& interpolator
370  ) const;
371 
372  //- Interpolate volume field onto surface points
374  (
375  const interpolation<tensor>& interpolator
376  ) const;
377 
378 
379  // Output
380 
381  //- Print information
382  virtual void print(Ostream& os) const;
383 };
384 
385 
386 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
387 
388 } // End namespace Foam
389 
390 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
391 
392 #ifdef NoRepository
394 #endif
395 
396 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
397 
398 #endif
399 
400 // ************************************************************************* //
Foam::sampledCuttingPlane::points
virtual const pointField & points() const
Points of surface.
Definition: sampledCuttingPlane.H:269
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:74
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
Foam::sampledCuttingPlane::surface
const meshedSurface & surface() const
The underlying surface.
Definition: sampledCuttingPlane.H:306
Foam::List< label >::null
static const List< label > & null()
Return a null List.
Definition: ListI.H:108
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
isoSurfaceTopo.H
Foam::sampledCuttingPlane::TypeName
TypeName("sampledCuttingPlane")
Runtime type information.
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::sampledCuttingPlane
A sampledSurface defined by a plane using an iso-surface algorithm to cut the mesh.
Definition: sampledCuttingPlane.H:146
isoSurfaceCell.H
sampledCuttingPlaneTemplates.C
fvMeshSubset.H
Foam::MeshedSurface::Sf
const vectorField & Sf() const
Face area vectors (normals)
Definition: MeshedSurface.H:376
Foam::MeshedSurface::surfFaces
const List< Face > & surfFaces() const
Return const access to the faces.
Definition: MeshedSurface.H:362
Foam::sampledCuttingPlane::surface
meshedSurface & surface()
The underlying surface.
Definition: sampledCuttingPlane.H:320
meshBb
List< treeBoundBox > meshBb(1, treeBoundBox(boundBox(coarseMesh.points(), false)).extend(rndGen, 1e-3))
Foam::sampledCuttingPlane::~sampledCuttingPlane
virtual ~sampledCuttingPlane()=default
Destructor.
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::sampledCuttingPlane::print
virtual void print(Ostream &os) const
Print information.
Definition: sampledCuttingPlane.C:572
Foam::vectorField
Field< vector > vectorField
Specialisation of Field<T> for vector.
Definition: primitiveFieldsFwd.H:54
Foam::plane
Geometric class that creates a 3D plane and can return the intersection point between a line and the ...
Definition: plane.H:89
Foam::sampledCuttingPlane::needsUpdate
virtual bool needsUpdate() const
Does the surface need an update?
Definition: sampledCuttingPlane.C:424
Foam::isoSurfaceBase::algorithmType
algorithmType
The algorithm types.
Definition: isoSurfaceBase.H:78
Foam::MeshedSurface::magSf
const scalarField & magSf() const
Face area magnitudes.
Definition: MeshedSurface.H:382
Foam::sampledCuttingPlane::zoneIds
virtual const labelList & zoneIds() const
Per-face zone/region information.
Definition: sampledCuttingPlane.H:281
Foam::Field< scalar >
plane.H
sampledSurface.H
Foam::sampledCuttingPlane::update
virtual bool update()
Update the surface as required.
Definition: sampledCuttingPlane.C:452
Foam::sampledSurface
An abstract class for surfaces with sampling.
Definition: sampledSurface.H:120
Foam::sampledCuttingPlane::Cf
virtual const vectorField & Cf() const
Face centres.
Definition: sampledCuttingPlane.H:299
Foam::interpolation
Abstract base class for interpolation.
Definition: mappedPatchFieldBase.H:95
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::sampledCuttingPlane::Sf
virtual const vectorField & Sf() const
Face area magnitudes.
Definition: sampledCuttingPlane.H:287
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::sampledCuttingPlane::meshCells
const labelList & meshCells() const
For each face, the original cell in mesh.
Definition: sampledCuttingPlane.H:334
Foam::sampledCuttingPlane::sampledCuttingPlane
sampledCuttingPlane(const word &name, const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
Definition: sampledCuttingPlane.C:358
isoSurface.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::meshedSurface
MeshedSurface< face > meshedSurface
Definition: MeshedSurfacesFwd.H:41
Foam::List< face >
Foam::sampledSurface::name
const word & name() const
Name of surface.
Definition: sampledSurface.H:308
Foam::sampledCuttingPlane::meshCells
labelList & meshCells()
For each face, the original cell in mesh.
Definition: sampledCuttingPlane.H:348
Foam::sampledCuttingPlane::magSf
virtual const scalarField & magSf() const
Face area magnitudes.
Definition: sampledCuttingPlane.H:293
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Foam::sampledCuttingPlane::faces
virtual const faceList & faces() const
Faces of surface.
Definition: sampledCuttingPlane.H:275
Foam::boundBox
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
Foam::MeshedSurface::Cf
const vectorField & Cf() const
Face centres.
Definition: MeshedSurface.H:388
Foam::sampledSurface::mesh
const polyMesh & mesh() const
Access to the underlying mesh.
Definition: sampledSurface.H:302
Foam::sampledCuttingPlane::sample
virtual tmp< scalarField > sample(const interpolation< scalar > &sampler) const
Sample volume field onto surface faces.
Definition: sampledCuttingPlane.C:474
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::GeometricField< Type, fvPatchField, volMesh >
Foam::MeshedSurface< face >
Foam::sampledCuttingPlane::expire
virtual bool expire()
Mark the surface as needing an update.
Definition: sampledCuttingPlane.C:430
Foam::sampledSurface::interpolate
bool interpolate() const
Interpolation to nodes requested for surface.
Definition: sampledSurface.H:326
Foam::isoSurfaceBase::filterType
filterType
The filtering (regularization) to apply.
Definition: isoSurfaceBase.H:87