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-2019 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.lookupOrDefault("bounds", boundBox::invertedBox)),
111  triangulate_(dict.lookupOrDefault("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  if (debug)
135  {
136  Info<< "plane " << name << " :"
137  << " origin:" << origin()
138  << " normal:" << normal()
139  << " defined within a local coordinateSystem" << endl;
140  }
141 
142  // Reassign the plane
143  pln = plane(orig, norm);
144  }
145 
146 
147  if (debug)
148  {
149  Info<< "plane " << name << " :"
150  << " origin:" << origin()
151  << " normal:" << normal();
152 
153  if (bounds_.valid())
154  {
155  Info<< " bounds:" << bounds_;
156  }
157 
158  if (!zoneNames_.empty())
159  {
160  Info<< " cellZones " << flatOutput(zoneNames_);
161 
162  if (-1 == mesh.cellZones().findIndex(zoneNames_))
163  {
164  Info<< " not found!";
165  }
166  }
167  Info<< endl;
168  }
169 }
170 
171 
172 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
173 
175 {
176  return needsUpdate_;
177 }
178 
179 
181 {
182  // Already marked as expired
183  if (needsUpdate_)
184  {
185  return false;
186  }
187 
189 
190  needsUpdate_ = true;
191  return true;
192 }
193 
194 
196 {
197  if (!needsUpdate_)
198  {
199  return false;
200  }
201 
203 
204  performCut(mesh(), triangulate_, cellSelection(true));
205 
206  if (debug)
207  {
208  print(Pout);
209  Pout<< endl;
210  }
211 
212  needsUpdate_ = false;
213  return true;
214 }
215 
216 
218 (
219  const interpolation<scalar>& sampler
220 ) const
221 {
222  return sampleOnFaces(sampler);
223 }
224 
225 
227 (
228  const interpolation<vector>& sampler
229 ) const
230 {
231  return sampleOnFaces(sampler);
232 }
233 
234 
236 (
237  const interpolation<sphericalTensor>& sampler
238 ) const
239 {
240  return sampleOnFaces(sampler);
241 }
242 
243 
245 (
246  const interpolation<symmTensor>& sampler
247 ) const
248 {
249  return sampleOnFaces(sampler);
250 }
251 
252 
254 (
255  const interpolation<tensor>& sampler
256 ) const
257 {
258  return sampleOnFaces(sampler);
259 }
260 
261 
263 (
264  const interpolation<scalar>& interpolator
265 ) const
266 {
267  return sampleOnPoints(interpolator);
268 }
269 
270 
272 (
273  const interpolation<vector>& interpolator
274 ) const
275 {
276  return sampleOnPoints(interpolator);
277 }
278 
280 (
281  const interpolation<sphericalTensor>& interpolator
282 ) const
283 {
284  return sampleOnPoints(interpolator);
285 }
286 
287 
289 (
290  const interpolation<symmTensor>& interpolator
291 ) const
292 {
293  return sampleOnPoints(interpolator);
294 }
295 
296 
298 (
299  const interpolation<tensor>& interpolator
300 ) const
301 {
302  return sampleOnPoints(interpolator);
303 }
304 
305 
307 {
308  os << "sampledPlane: " << name() << " :"
309  << " origin:" << plane::origin()
310  << " normal:" << plane::normal()
311  << " triangulate:" << triangulate_
312  << " faces:" << faces().size()
313  << " points:" << points().size();
314 }
315 
316 
317 // ************************************************************************* //
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:585
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:195
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:64
Foam::sampledPlane::expire
virtual bool expire()
Mark the surface as needing an update.
Definition: sampledPlane.C:180
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
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: dictionary.C:359
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::VectorSpace::size
static constexpr direction size()
Return the number of elements in the VectorSpace = Ncmpts.
Definition: VectorSpaceI.H:92
Foam::polyMesh::cellZones
const cellZoneMesh & cellZones() const
Return cell zone mesh.
Definition: polyMesh.H:483
Foam::sampledPlane::sample
virtual tmp< scalarField > sample(const interpolation< scalar > &sampler) const
Sample volume field onto surface faces.
Definition: sampledPlane.C:218
Foam::ZoneMesh::findIndex
label findIndex(const keyType &key) const
Return zone index for the first match, return -1 if not found.
Definition: ZoneMesh.C:449
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::dictionary::lookupOrDefault
T lookupOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionary.H:1241
Foam::Pout
prefixOSstream Pout
An Ostream wrapper for parallel output to std::cout.
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
sampledPlane.H
Foam::sampledPlane::needsUpdate
virtual bool needsUpdate() const
Does the surface need an update?
Definition: sampledPlane.C:174
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::coordinateSystem::globalVector
vector globalVector(const vector &local) const
From local to global (cartesian) vector components.
Definition: coordinateSystem.H:611
Foam::coordinateSystem::New
static autoPtr< coordinateSystem > New(word modelType, const objectRegistry &obr, const dictionary &dict)
Definition: coordinateSystemNew.C:82
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:314
Foam::sampledSurface
An abstract class for surfaces with sampling.
Definition: sampledSurface.H:120
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:121
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::plane::origin
const point & origin() const
The plane base point.
Definition: planeI.H:45
Foam::sampledPlane::print
virtual void print(Ostream &os) const
Print information.
Definition: sampledPlane.C:306
Foam::flatOutput
FlatOutput< Container > flatOutput(const Container &obj, label len=0)
Global flatOutput function.
Definition: FlatOutput.H:85
Foam::coordSystem::cartesian
A Cartesian coordinate system.
Definition: cartesianCS.H:69
Foam::Vector< scalar >
Foam::sampledSurface::name
const word & name() const
Name of surface.
Definition: sampledSurface.H:308
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:172
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:55
Foam::sampledSurface::mesh
const polyMesh & mesh() const
Access to the underlying mesh.
Definition: sampledSurface.H:302
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::sampledSurface::interpolate
bool interpolate() const
Interpolation to nodes requested for surface.
Definition: sampledSurface.H:326
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:417