Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
38namespace Foam
39{
42 (
45 word,
46 plane
47 );
48}
49
50
51// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
52
53Foam::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
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
96Foam::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!";
137 Info<< endl;
138 }
139 }
140}
141
142
144(
145 const word& name,
146 const polyMesh& mesh,
147 const dictionary& dict
148)
149:
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;
227
228 needsUpdate_ = false;
229 return true;
230}
231
232
234(
236) const
237{
238 return sampleOnFaces(sampler);
239}
240
241
243(
245) const
246{
247 return sampleOnFaces(sampler);
248}
249
250
252(
254) const
255{
256 return sampleOnFaces(sampler);
257}
258
259
261(
263) const
264{
265 return sampleOnFaces(sampler);
266}
267
268
270(
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
289 const interpolation<vector>& interpolator
290) const
291{
292 return sampleOnPoints(interpolator);
293}
294
296(
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
322void 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// ************************************************************************* //
if(maxValue - minValue< SMALL)
Macros for easy insertion into run-time selection tables.
#define addNamedToRunTimeSelectionTable(baseType, thisType, argNames, lookupName)
Add to construction table with 'lookupName' as the key.
if(patchID !=-1)
static const List< face > & null() noexcept
Definition List.H:138
virtual label triangulate()
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
bool empty() const noexcept
True if List is empty (ie, size() is zero).
Definition UList.H:701
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
A bounding box defined in terms of min/max extrema points.
Definition boundBox.H:71
Constructs cutting plane through a mesh.
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.
virtual void performCut(const primitiveMesh &mesh, const bool triangulate, bitSet &&cellIdLabels)
Cut mesh, restricted to a list of cells.
cuttingPlane(const plane &pln)
Construct from a plane description without any cutting.
const plane & planeDesc() const
The plane used.
static int debug
Debug information.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Abstract base class for volume field interpolation.
Geometric class that creates a 3D plane and can return the intersection point between a line and the ...
Definition plane.H:91
plane()
Construct zero-initialised.
Definition planeI.H:23
const point & origin() const noexcept
The plane base point.
Definition planeI.H:38
const vector & normal() const noexcept
The plane unit normal.
Definition planeI.H:32
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
A sampledSurface defined by a plane which cuts the mesh using the cuttingPlane alorithm....
virtual void print(Ostream &os, int level=0) const
Print information.
virtual tmp< scalarField > sample(const interpolation< scalar > &sampler) const
Sample volume field onto surface faces.
virtual const faceList & faces() const
Faces of surface.
virtual bool expire()
Mark the surface as needing an update.
virtual bool needsUpdate() const
Does the surface need an update?
virtual bool update()
Update the surface as required.
sampledPlane(const word &name, const polyMesh &mesh, const plane &planeDesc, const wordRes &zones=wordRes(), const bool triangulate=true)
Construct from components.
An abstract class for surfaces with sampling.
sampledSurface(const word &name, std::nullptr_t)
Construct null.
const word & name() const noexcept
Name of surface.
virtual void clearGeom() const
Additional cleanup when clearing the geometry.
const polyMesh & mesh() const noexcept
Access to the underlying mesh.
bool interpolate() const noexcept
Same as isPointData().
A class for managing temporary objects.
Definition tmp.H:75
A List of wordRe with additional matching capabilities.
Definition wordRes.H:56
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
auto & name
const pointField & points
#define DebugInfo
Report an information message using Foam::Info.
Namespace for handling debugging switches.
Definition debug.C:45
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition FlatOutput.H:217
vector point
Point is a vector.
Definition point.H:37
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Vector< scalar > vector
Definition vector.H:57
dictionary dict