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-2021 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  offsets | Offsets of the origin in the normal direction | no | (0)
59  isoMethod | Iso-algorithm (cell/topo/point) | no | topo
60  bounds | limit with bounding box | no |
61  zone | limit to cell zone (name or regex) | no |
62  zones | limit to cell zones (names, regexs) | no |
63  exposedPatchName | name for zone subset | optional |
64  regularise | Face simplification (enum or bool) | no | true
65  mergeTol | tolerance for merging points | no | 1e-6
66  \endtable
67 
68 Note
69  The keyword \c zones has priority over \c zone.
70 
71 SeeAlso
72  Foam::plane
73 
74 SourceFiles
75  sampledCuttingPlane.C
76 
77 \*---------------------------------------------------------------------------*/
78 
79 #ifndef sampledCuttingPlane_H
80 #define sampledCuttingPlane_H
81 
82 #include "sampledSurface.H"
83 #include "plane.H"
84 #include "fvMeshSubset.H"
85 #include "isoSurfaceBase.H"
86 
87 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
88 
89 namespace Foam
90 {
91 
92 /*---------------------------------------------------------------------------*\
93  Class sampledCuttingPlane Declaration
94 \*---------------------------------------------------------------------------*/
95 
96 class sampledCuttingPlane
97 :
98  public sampledSurface
99 {
100  // Private Data
101 
102  //- Plane
103  const plane plane_;
104 
105  //- The offsets to the plane - defaults to (0).
106  List<scalar> offsets_;
107 
108  //- Parameters (filtering etc) for iso-surface
109  isoSurfaceParams isoParams_;
110 
111  //- Whether to recalculate cell values as average of point values
112  bool average_;
113 
114  //- Use simple sub-meshing in algorithm itself
115  bool simpleSubMesh_;
116 
117  //- The zone or zones in which cutting is to occur
118  wordRes zoneNames_;
119 
120  //- For zones: patch to put exposed faces into
121  mutable word exposedPatchName_;
122 
123  //- Track if the surface needs an update
124  mutable bool needsUpdate_;
125 
126 
127  // Sampling geometry. Directly stored or via an iso-surface (ALGO_POINT)
128 
129  //- The extracted surface (direct storage)
130  mutable meshedSurface surface_;
131 
132  //- For every face the original cell in mesh (direct storage)
133  mutable labelList meshCells_;
134 
135  //- Constructed iso-surface (ALGO_POINT), for interpolators
136  autoPtr<isoSurfaceBase> isoSurfacePtr_;
137 
138 
139  // Mesh Subsetting
140 
141  //- Cached subMesh for (pre-)subset of cell zones
142  mutable autoPtr<fvMeshSubset> subMeshPtr_;
143 
144  //- Cached ignore cells for (post-)subset of cell zones
145  mutable autoPtr<bitSet> ignoreCellsPtr_;
146 
147 
148  // Fields
149 
150  //- Distance to cell centres
151  autoPtr<volScalarField> cellDistancePtr_;
152 
153  //- Distance to points
154  scalarField pointDistance_;
155 
156 
157  // Private Member Functions
158 
159  //- Check and warn if bounding box does not intersect mesh or plane
160  void checkBoundsIntersection
161  (
162  const plane& pln,
163  const boundBox& meshBb
164  ) const;
165 
166  //- Fill cellDistance, pointDistance fields for the specified plane
167  void setDistanceFields(const plane& pln);
168 
169  //- Collect iso-surfaces into a single surface (No point merging)
170  void combineSurfaces(PtrList<isoSurfaceBase>& isoSurfPtrs);
171 
172  //- Create iso surface
173  void createGeometry();
174 
175  //- Sample volume field onto surface faces
176  template<class Type>
177  tmp<Field<Type>> sampleOnFaces
178  (
179  const interpolation<Type>& sampler
180  ) const;
181 
182  //- Interpolate volume field onto surface points
183  template<class Type>
184  tmp<Field<Type>> sampleOnPoints
185  (
186  const interpolation<Type>& interpolator
187  ) const;
188 
189  //- Use isoSurfacePtr_ for point interpolation
190  template<class Type>
191  tmp<Field<Type>> sampleOnIsoSurfacePoints
192  (
193  const interpolation<Type>& interpolator
194  ) const;
195 
196 
197 protected:
198 
199  // Protected Member Functions
200 
201  //- Is currently backed by an isoSurfacePtr_
202  bool hasIsoSurface() const
203  {
204  return bool(isoSurfacePtr_);
205  }
206 
207 public:
208 
209  //- Runtime type information
210  TypeName("sampledCuttingPlane");
211 
212 
213  // Constructors
214 
215  //- Construct from dictionary
217  (
218  const word& name,
219  const polyMesh& mesh,
220  const dictionary& dict
221  );
222 
223 
224  //- Destructor
225  virtual ~sampledCuttingPlane() = default;
226 
227 
228  // Member Functions
229 
230  //- Does the surface need an update?
231  virtual bool needsUpdate() const;
232 
233  //- Mark the surface as needing an update.
234  // May also free up unneeded data.
235  // Return false if surface was already marked as expired.
236  virtual bool expire();
237 
238  //- Update the surface as required.
239  // Do nothing (and return false) if no update was needed
240  virtual bool update();
241 
242  //- The current surface geometry
243  const meshedSurface& surface() const
244  {
245  if (isoSurfacePtr_)
246  {
247  return *isoSurfacePtr_;
248  }
249  return surface_;
250  }
251 
252  //- For each face, the original cell in mesh
253  const labelList& meshCells() const
254  {
255  if (isoSurfacePtr_)
256  {
257  return isoSurfacePtr_->meshCells();
258  }
259  return meshCells_;
260  }
261 
262  //- Points of surface
263  virtual const pointField& points() const
264  {
265  return surface().points();
266  }
267 
268  //- Faces of surface
269  virtual const faceList& faces() const
270  {
271  return surface().surfFaces();
272  }
273 
274  //- Per-face zone/region information
275  virtual const labelList& zoneIds() const
276  {
277  return labelList::null();
278  }
279 
280  //- Face area magnitudes
281  virtual const vectorField& Sf() const
282  {
283  return surface().Sf();
284  }
285 
286  //- Face area magnitudes
287  virtual const scalarField& magSf() const
288  {
289  return surface().magSf();
290  }
291 
292  //- Face centres
293  virtual const vectorField& Cf() const
294  {
295  return surface().Cf();
296  }
297 
298 
299  // Sample
300 
301  //- Sample volume field onto surface faces
302  virtual tmp<scalarField> sample
303  (
304  const interpolation<scalar>& sampler
305  ) const;
306 
307  //- Sample volume field onto surface faces
308  virtual tmp<vectorField> sample
309  (
310  const interpolation<vector>& sampler
311  ) const;
312 
313  //- Sample volume field onto surface faces
315  (
316  const interpolation<sphericalTensor>& sampler
317  ) const;
318 
319  //- Sample volume field onto surface faces
321  (
322  const interpolation<symmTensor>& sampler
323  ) const;
324 
325  //- Sample volume field onto surface faces
326  virtual tmp<tensorField> sample
327  (
328  const interpolation<tensor>& sampler
329  ) const;
330 
331 
332  // Interpolate
333 
334  //- Interpolate volume field onto surface points
336  (
337  const interpolation<scalar>& interpolator
338  ) const;
339 
340  //- Interpolate volume field onto surface points
342  (
343  const interpolation<vector>& interpolator
344  ) const;
345 
346  //- Interpolate volume field onto surface points
348  (
349  const interpolation<sphericalTensor>& interpolator
350  ) const;
351 
352  //- Interpolate volume field onto surface points
354  (
355  const interpolation<symmTensor>& interpolator
356  ) const;
357 
358  //- Interpolate volume field onto surface points
360  (
361  const interpolation<tensor>& interpolator
362  ) const;
363 
364 
365  // Output
366 
367  //- Print information
368  virtual void print(Ostream& os, int level=0) const;
369 };
370 
371 
372 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
373 
374 } // End namespace Foam
375 
376 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
377 
378 #ifdef NoRepository
380 #endif
381 
382 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
383 
384 #endif
385 
386 // ************************************************************************* //
Foam::sampledCuttingPlane::points
virtual const pointField & points() const
Points of surface.
Definition: sampledCuttingPlane.H:317
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
Foam::sampledCuttingPlane::surface
const meshedSurface & surface() const
The current surface geometry.
Definition: sampledCuttingPlane.H:297
Foam::List::null
static const List< T > & null()
Return a null List.
Definition: ListI.H:109
Foam::sampledCuttingPlane::hasIsoSurface
bool hasIsoSurface() const
Is currently backed by an isoSurfacePtr_.
Definition: sampledCuttingPlane.H:256
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::sampledCuttingPlane::TypeName
TypeName("sampledCuttingPlane")
Runtime type information.
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::sampledCuttingPlane
A sampledSurface defined by a plane using an iso-surface algorithm to cut the mesh.
Definition: sampledCuttingPlane.H:150
sampledCuttingPlaneTemplates.C
fvMeshSubset.H
Foam::MeshedSurface::Sf
const vectorField & Sf() const
Face area vectors (normals)
Definition: MeshedSurface.H:435
Foam::MeshedSurface::surfFaces
const List< Face > & surfFaces() const
Return const access to the faces.
Definition: MeshedSurface.H:413
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
isoSurfaceBase.H
Foam::sampledCuttingPlane::print
virtual void print(Ostream &os, int level=0) const
Print information.
Definition: sampledCuttingPlane.C:749
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:597
Foam::MeshedSurface::magSf
const scalarField & magSf() const
Face area magnitudes.
Definition: MeshedSurface.H:441
Foam::sampledSurface::interpolate
bool interpolate() const noexcept
Same as isPointData()
Definition: sampledSurface.H:598
Foam::sampledCuttingPlane::zoneIds
virtual const labelList & zoneIds() const
Per-face zone/region information.
Definition: sampledCuttingPlane.H:329
Foam::Field< scalar >
plane.H
sampledSurface.H
Foam::sampledCuttingPlane::update
virtual bool update()
Update the surface as required.
Definition: sampledCuttingPlane.C:629
Foam::sampledSurface
An abstract class for surfaces with sampling.
Definition: sampledSurface.H:121
Foam::sampledCuttingPlane::Cf
virtual const vectorField & Cf() const
Face centres.
Definition: sampledCuttingPlane.H:347
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:59
Foam::interpolation
Abstract base class for interpolation.
Definition: mappedPatchFieldBase.H:96
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:123
Foam::isoSurfaceParams
Preferences for controlling iso-surface algorithms.
Definition: isoSurfaceParams.H:107
os
OBJstream os(runTime.globalPath()/outputName)
Foam::sampledCuttingPlane::Sf
virtual const vectorField & Sf() const
Face area magnitudes.
Definition: sampledCuttingPlane.H:335
Foam::sampledSurface::name
const word & name() const noexcept
Name of surface.
Definition: sampledSurface.H:322
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:307
Foam::sampledCuttingPlane::sampledCuttingPlane
sampledCuttingPlane(const word &name, const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
Definition: sampledCuttingPlane.C:508
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::faceList
List< face > faceList
A List of faces.
Definition: faceListFwd.H:47
Foam::List< scalar >
Foam::sampledSurface::mesh
const polyMesh & mesh() const noexcept
Access to the underlying mesh.
Definition: sampledSurface.H:316
Foam::sampledCuttingPlane::magSf
virtual const scalarField & magSf() const
Face area magnitudes.
Definition: sampledCuttingPlane.H:341
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:323
bool
bool
Definition: EEqn.H:20
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:447
Foam::sampledCuttingPlane::sample
virtual tmp< scalarField > sample(const interpolation< scalar > &sampler) const
Sample volume field onto surface faces.
Definition: sampledCuttingPlane.C:651
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::MeshedSurface< face >
Foam::sampledCuttingPlane::expire
virtual bool expire()
Mark the surface as needing an update.
Definition: sampledCuttingPlane.C:603