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 bool adjust = false;
62 const dictionary* dictptr = nullptr;
63 coordSystem::cartesian cs;
64
65 if (dict.found(coordinateSystem::typeName_(), keyType::LITERAL))
66 {
67 // Create with registry to allow lookup from globally defined
68 // coordinate systems?
69
70 auto csPtr =
71 coordinateSystem::New(mesh, dict, coordinateSystem::typeName_());
72
73 if (csPtr)
74 {
75 adjust = true;
76 cs = csPtr();
77 }
78 }
79 else if
80 (
81 (dictptr = dict.findDict("transform", keyType::LITERAL)) != nullptr
82 )
83 {
84 adjust = true;
85 cs = coordSystem::cartesian(*dictptr);
86 }
87
88
89 // Make plane relative to the Cartesian coordinate system
90 if (adjust)
91 {
92 const point orig = cs.globalPosition(pln.origin());
93 const vector norm = cs.globalVector(pln.normal());
94
96 << "plane "
97 << " origin:" << pln.origin()
98 << " normal:" << pln.normal()
99 << " =>"
100 << " origin:" << orig
101 << " normal:" << norm
102 << endl;
103
104 // Reassign the plane
105 pln = plane(orig, norm);
106 }
107
108 return pln;
109}
110
111
113{
115 (
116 mesh(),
117 bounds_,
118 zoneNames_,
119 name(),
120 warn
121 );
122}
123
124
125// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
126
128(
129 const word& name,
130 const polyMesh& mesh,
131 const plane& planeDesc,
132 const wordRes& zones,
133 const bool triangulate
134)
135:
137 cuttingPlane(planeDesc),
138 zoneNames_(zones),
139 bounds_(),
140 triangulate_(triangulate),
141 needsUpdate_(true)
142{
143 if (debug)
144 {
145 if (!zoneNames_.empty())
146 {
147 Info<< " cellZones " << flatOutput(zoneNames_);
148
149 if (-1 == mesh.cellZones().findIndex(zoneNames_))
150 {
151 Info<< " not found!";
152 }
153 Info<< endl;
154 }
155 }
156}
157
158
160(
161 const word& name,
162 const polyMesh& mesh,
163 const dictionary& dict
164)
165:
167 cuttingPlane(definePlane(mesh, dict)),
168 zoneNames_(),
169 bounds_(dict.getOrDefault("bounds", boundBox::invertedBox)),
170 triangulate_(dict.getOrDefault("triangulate", true)),
171 needsUpdate_(true)
172{
173 if (!dict.readIfPresent("zones", zoneNames_) && dict.found("zone"))
174 {
175 zoneNames_.resize(1);
176 dict.readEntry("zone", zoneNames_.first());
177 }
178
179 if (debug)
180 {
181 Info<< "plane " << name << " :"
182 << " origin:" << origin()
183 << " normal:" << normal();
184
185 if (bounds_.valid())
186 {
187 Info<< " bounds:" << bounds_;
188 }
189
190 if (!zoneNames_.empty())
191 {
192 Info<< " cellZones " << flatOutput(zoneNames_);
193
194 if (-1 == mesh.cellZones().findIndex(zoneNames_))
195 {
196 Info<< " not found!";
197 }
198 }
199 Info<< endl;
200 }
201}
202
203
204// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
205
207{
208 return needsUpdate_;
209}
210
211
213{
214 // Already marked as expired
215 if (needsUpdate_)
216 {
217 return false;
218 }
219
221
222 needsUpdate_ = true;
223 return true;
224}
225
226
228{
229 if (!needsUpdate_)
230 {
231 return false;
232 }
233
235
236 performCut(mesh(), triangulate_, cellSelection(true));
237
238 if (debug)
239 {
240 print(Pout, debug);
241 Pout<< endl;
242 }
243
244 needsUpdate_ = false;
245 return true;
246}
247
248
250(
251 const interpolation<scalar>& sampler
252) const
253{
254 return sampleOnFaces(sampler);
255}
256
257
259(
260 const interpolation<vector>& sampler
261) const
262{
263 return sampleOnFaces(sampler);
264}
265
266
268(
269 const interpolation<sphericalTensor>& sampler
270) const
271{
272 return sampleOnFaces(sampler);
273}
274
275
277(
278 const interpolation<symmTensor>& sampler
279) const
280{
281 return sampleOnFaces(sampler);
282}
283
284
286(
287 const interpolation<tensor>& sampler
288) const
289{
290 return sampleOnFaces(sampler);
291}
292
293
295(
296 const interpolation<scalar>& interpolator
297) const
298{
299 return sampleOnPoints(interpolator);
300}
301
302
304(
305 const interpolation<vector>& interpolator
306) const
307{
308 return sampleOnPoints(interpolator);
309}
310
312(
313 const interpolation<sphericalTensor>& interpolator
314) const
315{
316 return sampleOnPoints(interpolator);
317}
318
319
321(
322 const interpolation<symmTensor>& interpolator
323) const
324{
325 return sampleOnPoints(interpolator);
326}
327
328
330(
331 const interpolation<tensor>& interpolator
332) const
333{
334 return sampleOnPoints(interpolator);
335}
336
337
338void Foam::sampledPlane::print(Ostream& os, int level) const
339{
340 os << "sampledPlane: " << name() << " :"
341 << " origin:" << plane::origin()
342 << " normal:" << plane::normal()
343 << " triangulate:" << triangulate_;
344
345 if (level)
346 {
347 os << " faces:" << faces().size()
348 << " points:" << points().size();
349 }
350}
351
352
353// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addNamedToRunTimeSelectionTable(baseType, thisType, argNames, lookupName)
Add to construction table with 'lookupName' as the key.
Minimal example by using system/controlDict.functions:
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
T & first()
Return the first element of the list.
Definition: UListI.H:202
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
Definition: UListI.H:427
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
label findIndex(const wordRe &key) const
Zone index for the first match, return -1 if not found.
Definition: ZoneMesh.C:497
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:66
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:64
bool valid() const
Bounding box is non-inverted.
Definition: boundBoxI.H:76
Constructs cutting plane through a mesh.
Definition: cuttingPlane.H:62
static int debug
Debug information.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX)
Find and return a sub-dictionary pointer if present.
Definition: dictionaryI.H:127
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
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Abstract base class for volume field interpolation.
Definition: interpolation.H:60
@ LITERAL
String literal.
Definition: keyType.H:81
scalar print()
Print to screen.
Geometric class that creates a 3D plane and can return the intersection point between a line and the ...
Definition: plane.H:95
plane()
Construct zero-initialised.
Definition: planeI.H:30
const point & origin() const noexcept
The plane base point.
Definition: planeI.H:45
const vector & normal() const noexcept
The plane unit normal.
Definition: planeI.H:39
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
const cellZoneMesh & cellZones() const noexcept
Return cell zone mesh.
Definition: polyMesh.H:504
A sampledSurface defined by a plane which cuts the mesh using the cuttingPlane alorithm....
Definition: sampledPlane.H:140
virtual bool expire()
Mark the surface as needing an update.
Definition: sampledPlane.C:212
virtual bool needsUpdate() const
Does the surface need an update?
Definition: sampledPlane.C:206
virtual bool update()
Update the surface as required.
Definition: sampledPlane.C:227
An abstract class for surfaces with sampling.
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:65
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
const pointField & points
#define DebugInfo
Report an information message using Foam::Info.
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
vector point
Point is a vector.
Definition: point.H:43
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:215
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
dictionary dict