sampledPlane.C
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) 2017-2022 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 \*---------------------------------------------------------------------------*/
28 
29 #include "sampledPlane.H"
30 #include "dictionary.H"
31 #include "polyMesh.H"
32 #include "volFields.H"
33 #include "cartesianCS.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40  defineTypeNameAndDebug(sampledPlane, 0);
42  (
43  sampledSurface,
44  sampledPlane,
45  word,
46  plane
47  );
48 }
49 
50 
51 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
52 
53 Foam::plane Foam::sampledPlane::definePlane
54 (
55  const polyMesh& mesh,
56  const dictionary& dict
57 )
58 {
59  plane pln(dict);
60 
61  // Optional (cartesian) coordinate transform.
62  // - with registry to allow lookup from globally defined systems
63 
64  auto csysPtr = coordinateSystem::NewIfPresent(mesh, dict);
65 
66  if (!csysPtr)
67  {
68  csysPtr = coordinateSystem::NewIfPresent(dict, "transform");
69  }
70 
71  // Make plane relative to the Cartesian coordinate system
72  if (csysPtr)
73  {
74  coordSystem::cartesian cs(csysPtr());
75 
76  const point orig = cs.globalPosition(pln.origin());
77  const vector norm = cs.globalVector(pln.normal());
78 
79  DebugInfo
80  << "plane "
81  << " origin:" << pln.origin()
82  << " normal:" << pln.normal()
83  << " =>"
84  << " origin:" << orig
85  << " normal:" << norm
86  << endl;
87 
88  // Reassign the plane
89  pln = plane(orig, norm);
90  }
91 
92  return pln;
93 }
94 
95 
96 Foam::bitSet Foam::sampledPlane::cellSelection(const bool warn) const
97 {
99  (
100  mesh(),
101  bounds_,
102  zoneNames_,
103  name(),
104  warn
105  );
106 }
107 
108 
109 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
110 
112 (
113  const word& name,
114  const polyMesh& mesh,
115  const plane& planeDesc,
116  const wordRes& zones,
117  const bool triangulate
118 )
119 :
121  cuttingPlane(planeDesc),
122  zoneNames_(zones),
123  bounds_(),
124  triangulate_(triangulate),
125  needsUpdate_(true)
126 {
127  if (debug)
128  {
129  if (!zoneNames_.empty())
130  {
131  Info<< " cellZones " << flatOutput(zoneNames_);
132 
133  if (-1 == mesh.cellZones().findIndex(zoneNames_))
134  {
135  Info<< " not found!";
136  }
138  }
139  }
140 }
141 
142 
144 (
145  const word& name,
146  const polyMesh& mesh,
147  const dictionary& dict
148 )
149 :
150  sampledSurface(name, mesh, dict),
151  cuttingPlane(definePlane(mesh, dict)),
152  zoneNames_(),
153  bounds_(dict.getOrDefault("bounds", boundBox::null())),
154  triangulate_(dict.getOrDefault("triangulate", true)),
155  needsUpdate_(true)
156 {
157  if (!dict.readIfPresent("zones", zoneNames_) && dict.found("zone"))
158  {
159  zoneNames_.resize(1);
160  dict.readEntry("zone", zoneNames_.first());
161  }
162 
163  if (debug)
164  {
165  Info<< "plane " << name << " :"
166  << " origin:" << origin()
167  << " normal:" << normal();
168 
169  if (bounds_.good())
170  {
171  Info<< " bounds:" << bounds_;
172  }
173 
174  if (!zoneNames_.empty())
175  {
176  Info<< " cellZones " << flatOutput(zoneNames_);
177 
178  if (-1 == mesh.cellZones().findIndex(zoneNames_))
179  {
180  Info<< " not found!";
181  }
182  }
184  }
185 }
186 
187 
188 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
191 {
192  return needsUpdate_;
193 }
194 
195 
197 {
198  // Already marked as expired
199  if (needsUpdate_)
200  {
201  return false;
202  }
203 
205 
206  needsUpdate_ = true;
207  return true;
208 }
209 
210 
212 {
213  if (!needsUpdate_)
214  {
215  return false;
216  }
217 
219 
220  performCut(mesh(), triangulate_, cellSelection(true));
221 
222  if (debug)
223  {
224  print(Pout, debug);
225  Pout<< endl;
226  }
228  needsUpdate_ = false;
229  return true;
230 }
231 
232 
234 (
235  const interpolation<scalar>& sampler
236 ) const
237 {
238  return sampleOnFaces(sampler);
239 }
240 
241 
243 (
244  const interpolation<vector>& sampler
245 ) const
246 {
247  return sampleOnFaces(sampler);
248 }
249 
250 
252 (
253  const interpolation<sphericalTensor>& sampler
254 ) const
255 {
256  return sampleOnFaces(sampler);
257 }
258 
259 
261 (
262  const interpolation<symmTensor>& sampler
263 ) const
264 {
265  return sampleOnFaces(sampler);
266 }
267 
268 
270 (
271  const interpolation<tensor>& sampler
272 ) const
273 {
274  return sampleOnFaces(sampler);
275 }
276 
277 
279 (
280  const interpolation<scalar>& interpolator
281 ) const
282 {
283  return sampleOnPoints(interpolator);
284 }
285 
286 
288 (
289  const interpolation<vector>& interpolator
290 ) const
291 {
292  return sampleOnPoints(interpolator);
293 }
294 
296 (
297  const interpolation<sphericalTensor>& interpolator
298 ) const
299 {
300  return sampleOnPoints(interpolator);
301 }
302 
303 
305 (
306  const interpolation<symmTensor>& interpolator
307 ) const
308 {
309  return sampleOnPoints(interpolator);
310 }
311 
312 
314 (
315  const interpolation<tensor>& interpolator
316 ) const
317 {
318  return sampleOnPoints(interpolator);
319 }
320 
321 
322 void Foam::sampledPlane::print(Ostream& os, int level) const
323 {
324  os << "sampledPlane: " << name() << " :"
325  << " origin:" << plane::origin()
326  << " normal:" << plane::normal()
327  << " triangulate:" << triangulate_;
328 
329  if (level)
330  {
331  os << " faces:" << faces().size()
332  << " points:" << points().size();
333  }
334 }
335 
336 
337 // ************************************************************************* //
dictionary dict
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
bool interpolate() const noexcept
Same as isPointData()
virtual void print(Ostream &os, int level=0) const
Print information.
Definition: sampledPlane.C:315
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:160
const polyMesh & mesh() const noexcept
Access to the underlying mesh.
An abstract class for surfaces with sampling.
label findIndex(const wordRe &key) const
Zone index for the first match, return -1 if not found.
Definition: ZoneMesh.C:601
Ostream & print(Ostream &os, UIntType value, char off='0', char on='1')
Print 0/1 bits in the (unsigned) integral type.
Definition: BitOps.H:323
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Definition: UList.H:666
T & first()
Access first element of the list, position [0].
Definition: UList.H:853
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
virtual tmp< scalarField > sample(const interpolation< scalar > &sampler) const
Sample volume field onto surface faces.
Definition: sampledPlane.C:227
Geometric class that creates a 3D plane and can return the intersection point between a line and the ...
Definition: plane.H:90
virtual bool expire()
Mark the surface as needing an update.
Definition: sampledPlane.C:189
Macros for easy insertion into run-time selection tables.
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
const word & name() const noexcept
Name of surface.
virtual bool needsUpdate() const
Does the surface need an update?
Definition: sampledPlane.C:183
const point & origin() const noexcept
The plane base point.
Definition: planeI.H:38
Constructs cutting plane through a mesh.
Definition: cuttingPlane.H:54
dynamicFvMesh & mesh
virtual void clearGeom() const
Additional cleanup when clearing the geometry.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
const pointField & points
A class for handling words, derived from Foam::string.
Definition: word.H:63
sampledPlane(const word &name, const polyMesh &mesh, const plane &planeDesc, const wordRes &zones=wordRes(), const bool triangulate=true)
Construct from components.
Definition: sampledPlane.C:105
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:53
virtual bool update()
Update the surface as required.
Definition: sampledPlane.C:204
Vector< scalar > vector
Definition: vector.H:57
#define DebugInfo
Report an information message using Foam::Info.
plane()
Construct zero-initialised.
Definition: planeI.H:23
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
static int debug
Debug information.
int debug
Static debugging option.
OBJstream os(runTime.globalPath()/outputName)
defineTypeNameAndDebug(combustionModel, 0)
vector point
Point is a vector.
Definition: point.H:37
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:59
bool good() const
Bounding box is non-inverted.
Definition: boundBoxI.H:156
const cellZoneMesh & cellZones() const noexcept
Return cell zone mesh.
Definition: polyMesh.H:678
messageStream Info
Information stream (stdout output on master, null elsewhere)
bitSet cellSelection(const polyMesh &mesh, const boundBox &userBounds, const wordRes &zoneNames, const word callerName, const bool warn) const
Define cell selection from bounding-box and zones.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
A class for managing temporary objects.
Definition: HashPtrTable.H:50
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
const vector & normal() const noexcept
The plane unit normal.
Definition: planeI.H:32
Namespace for OpenFOAM.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:225