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-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 \*---------------------------------------------------------------------------*/
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::bitSet Foam::sampledPlane::cellSelection(const bool warn) const
54 {
56  (
57  mesh(),
58  bounds_,
59  zoneNames_,
60  name(),
61  warn
62  );
63 }
64 
65 
66 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
67 
69 (
70  const word& name,
71  const polyMesh& mesh,
72  const plane& planeDesc,
73  const wordRes& zones,
74  const bool triangulate
75 )
76 :
78  cuttingPlane(planeDesc),
79  zoneNames_(zones),
80  bounds_(),
81  triangulate_(triangulate),
82  needsUpdate_(true)
83 {
84  if (debug)
85  {
86  if (!zoneNames_.empty())
87  {
88  Info<< " cellZones " << flatOutput(zoneNames_);
89 
90  if (-1 == mesh.cellZones().findIndex(zoneNames_))
91  {
92  Info<< " not found!";
93  }
94  Info<< endl;
95  }
96  }
97 }
98 
99 
101 (
102  const word& name,
103  const polyMesh& mesh,
104  const dictionary& dict
105 )
106 :
109  zoneNames_(),
110  bounds_(dict.getOrDefault("bounds", boundBox::invertedBox)),
111  triangulate_(dict.getOrDefault("triangulate", true)),
112  needsUpdate_(true)
113 {
114  if (!dict.readIfPresent("zones", zoneNames_) && dict.found("zone"))
115  {
116  zoneNames_.resize(1);
117  dict.readEntry("zone", zoneNames_.first());
118  }
119 
120 
121  // Make plane relative to the coordinateSystem (Cartesian)
122  // allow lookup from global coordinate systems
123  if (dict.found(coordinateSystem::typeName_()))
124  {
126  (
127  coordinateSystem::New(mesh, dict, coordinateSystem::typeName_())
128  );
129  plane& pln = planeDesc();
130 
131  const point orig = cs.globalPosition(pln.origin());
132  const vector norm = cs.globalVector(pln.normal());
133 
134  DebugInfo
135  << "plane " << name << " :"
136  << " origin:" << origin()
137  << " normal:" << normal()
138  << " defined within a local coordinateSystem" << endl;
139 
140  // Reassign the plane
141  pln = plane(orig, norm);
142  }
143 
144 
145  if (debug)
146  {
147  Info<< "plane " << name << " :"
148  << " origin:" << origin()
149  << " normal:" << normal();
150 
151  if (bounds_.valid())
152  {
153  Info<< " bounds:" << bounds_;
154  }
155 
156  if (!zoneNames_.empty())
157  {
158  Info<< " cellZones " << flatOutput(zoneNames_);
159 
160  if (-1 == mesh.cellZones().findIndex(zoneNames_))
161  {
162  Info<< " not found!";
163  }
164  }
165  Info<< endl;
166  }
167 }
168 
169 
170 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
171 
173 {
174  return needsUpdate_;
175 }
176 
177 
179 {
180  // Already marked as expired
181  if (needsUpdate_)
182  {
183  return false;
184  }
185 
187 
188  needsUpdate_ = true;
189  return true;
190 }
191 
192 
194 {
195  if (!needsUpdate_)
196  {
197  return false;
198  }
199 
201 
202  performCut(mesh(), triangulate_, cellSelection(true));
203 
204  if (debug)
205  {
206  print(Pout, debug);
207  Pout<< endl;
208  }
209 
210  needsUpdate_ = false;
211  return true;
212 }
213 
214 
216 (
217  const interpolation<scalar>& sampler
218 ) const
219 {
220  return sampleOnFaces(sampler);
221 }
222 
223 
225 (
226  const interpolation<vector>& sampler
227 ) const
228 {
229  return sampleOnFaces(sampler);
230 }
231 
232 
234 (
235  const interpolation<sphericalTensor>& sampler
236 ) const
237 {
238  return sampleOnFaces(sampler);
239 }
240 
241 
243 (
244  const interpolation<symmTensor>& sampler
245 ) const
246 {
247  return sampleOnFaces(sampler);
248 }
249 
250 
252 (
253  const interpolation<tensor>& sampler
254 ) const
255 {
256  return sampleOnFaces(sampler);
257 }
258 
259 
261 (
262  const interpolation<scalar>& interpolator
263 ) const
264 {
265  return sampleOnPoints(interpolator);
266 }
267 
268 
270 (
271  const interpolation<vector>& interpolator
272 ) const
273 {
274  return sampleOnPoints(interpolator);
275 }
276 
278 (
279  const interpolation<sphericalTensor>& interpolator
280 ) const
281 {
282  return sampleOnPoints(interpolator);
283 }
284 
285 
287 (
288  const interpolation<symmTensor>& interpolator
289 ) const
290 {
291  return sampleOnPoints(interpolator);
292 }
293 
294 
296 (
297  const interpolation<tensor>& interpolator
298 ) const
299 {
300  return sampleOnPoints(interpolator);
301 }
302 
303 
304 void Foam::sampledPlane::print(Ostream& os, int level) const
305 {
306  os << "sampledPlane: " << name() << " :"
307  << " origin:" << plane::origin()
308  << " normal:" << plane::normal()
309  << " triangulate:" << triangulate_;
310 
311  if (level)
312  {
313  os << " faces:" << faces().size()
314  << " points:" << points().size();
315  }
316 }
317 
318 
319 // ************************************************************************* //
Foam::sampledPlane::sampledPlane
sampledPlane(const word &name, const polyMesh &mesh, const plane &planeDesc, const wordRes &zones=wordRes(), const bool triangulate=true)
Construct from components.
Definition: sampledPlane.C:69
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::coordinateSystem::globalPosition
point globalPosition(const point &local) const
From local coordinate position to global (cartesian) position.
Definition: coordinateSystem.H:595
volFields.H
Foam::plane::normal
const vector & normal() const
The plane unit normal.
Definition: planeI.H:39
Foam::sampledPlane::update
virtual bool update()
Update the surface as required.
Definition: sampledPlane.C:193
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::ZoneMesh::findIndex
label findIndex(const wordRe &key) const
Zone index for the first match, return -1 if not found.
Definition: ZoneMesh.C:491
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
Foam::sampledPlane::expire
virtual bool expire()
Mark the surface as needing an update.
Definition: sampledPlane.C:178
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::dictionary::found
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
Definition: dictionaryI.H:87
Foam::cuttingPlane
Constructs cutting plane through a mesh.
Definition: cuttingPlane.H:58
Foam::boundBox::invertedBox
static const boundBox invertedBox
A large inverted boundBox: min/max == +/- ROOTVGREAT.
Definition: boundBox.H:86
Foam::sampledPlane::sample
virtual tmp< scalarField > sample(const interpolation< scalar > &sampler) const
Sample volume field onto surface faces.
Definition: sampledPlane.C:216
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::Pout
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
cartesianCS.H
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
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::sampledPlane::print
virtual void print(Ostream &os, int level=0) const
Print information.
Definition: sampledPlane.C:304
sampledPlane.H
Foam::sampledSurface::interpolate
bool interpolate() const noexcept
Same as isPointData()
Definition: sampledSurface.H:598
Foam::sampledPlane::needsUpdate
virtual bool needsUpdate() const
Does the surface need an update?
Definition: sampledPlane.C:172
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::polyMesh::cellZones
const cellZoneMesh & cellZones() const noexcept
Return cell zone mesh.
Definition: polyMesh.H:492
Foam::coordinateSystem::globalVector
vector globalVector(const vector &local) const
From local to global (cartesian) vector components.
Definition: coordinateSystem.H:621
Foam::coordinateSystem::New
static autoPtr< coordinateSystem > New(word modelType, const objectRegistry &obr, const dictionary &dict)
Definition: coordinateSystemNew.C:84
Foam::addNamedToRunTimeSelectionTable
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
Foam::dictionary::readEntry
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Definition: dictionaryTemplates.C:302
Foam::sampledSurface
An abstract class for surfaces with sampling.
Definition: sampledSurface.H:121
Foam::interpolation< scalar >
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
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::sampledSurface::name
const word & name() const noexcept
Name of surface.
Definition: sampledSurface.H:322
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::flatOutput
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:216
Foam::plane::origin
const point & origin() const
The plane base point.
Definition: planeI.H:45
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition: messageStream.H:382
Foam::coordSystem::cartesian
A Cartesian coordinate system.
Definition: cartesianCS.H:69
Foam::Vector< scalar >
Foam::sampledSurface::mesh
const polyMesh & mesh() const noexcept
Access to the underlying mesh.
Definition: sampledSurface.H:316
Foam::BitOps::print
Ostream & print(Ostream &os, UIntType value, char off='0', char on='1')
Print 0/1 bits in the (unsigned) integral type.
Definition: BitOps.H:199
points
const pointField & points
Definition: gmvOutputHeader.H:1
dictionary.H
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Foam::sampledSurface::clearGeom
virtual void clearGeom() const
Additional cleanup when clearing the geometry.
Definition: sampledSurface.C:53
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::dictionary::getOrDefault
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:148
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::cuttingPlane::cellSelection
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.
Definition: cuttingPlaneSelection.C:67
Foam::dictionary::readIfPresent
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:405