sampledIsoSurface.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "sampledIsoSurface.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 namespace sampledSurfaces
34 {
35  defineTypeNameAndDebug(isoSurface, 0);
36  addToRunTimeSelectionTable(sampledSurface, isoSurface, word);
37 }
38 }
39 
40 
41 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
42 
43 bool Foam::sampledSurfaces::isoSurface::updateGeometry() const
44 {
45  const fvMesh& fvm = static_cast<const fvMesh&>(mesh());
46 
47  // no update needed
48  if (fvm.time().timeIndex() == prevTimeIndex_)
49  {
50  return false;
51  }
52 
53  prevTimeIndex_ = fvm.time().timeIndex();
54 
55  // Clear derived data
57 
58  // Optionally read volScalarField
59  autoPtr<volScalarField> readFieldPtr_;
60 
61  // 1. see if field in database
62  // 2. see if field can be read
63  const volScalarField* cellFldPtr = nullptr;
64  if (fvm.foundObject<volScalarField>(isoField_))
65  {
66  if (debug)
67  {
68  InfoInFunction << "Lookup " << isoField_ << endl;
69  }
70 
71  cellFldPtr = &fvm.lookupObject<volScalarField>(isoField_);
72  }
73  else
74  {
75  // Bit of a hack. Read field and store.
76 
77  if (debug)
78  {
80  << "Reading " << isoField_
81  << " from time " <<fvm.time().timeName()
82  << endl;
83  }
84 
85  readFieldPtr_.reset
86  (
87  new volScalarField
88  (
89  IOobject
90  (
91  isoField_,
92  fvm.time().timeName(),
93  fvm,
96  false
97  ),
98  fvm
99  )
100  );
101 
102  cellFldPtr = readFieldPtr_.operator->();
103  }
104  const volScalarField& cellFld = *cellFldPtr;
105 
106  tmp<pointScalarField> pointFld
107  (
109  );
110 
111  PtrList<Foam::isoSurface> isos(isoVals_.size());
112  forAll(isos, isoi)
113  {
114  isos.set
115  (
116  isoi,
117  new Foam::isoSurface
118  (
119  fvm,
120  cellFld.primitiveField(),
121  pointFld().primitiveField(),
122  isoVals_[isoi],
123  filter_
124  )
125  );
126  }
127 
128  if (isos.size() == 1)
129  {
130  // Straight transfer
131  const_cast<isoSurface&>
132  (
133  *this
135  meshCells_ = isos[0].meshCells();
136  }
137  else
138  {
139  label nFaces = 0;
140  label nPoints = 0;
141  forAll(isos, isoi)
142  {
143  nFaces += isos[isoi].size();
144  nPoints += isos[isoi].points().size();
145  }
146 
147  faceList allFaces(nFaces);
148  labelList allMeshCells(nFaces);
149  pointField allPoints(nPoints);
150 
151  nFaces = 0;
152  nPoints = 0;
153  forAll(isos, isoi)
154  {
155  Foam::isoSurface& iso = isos[isoi];
156 
157  SubList<face> subAll(allFaces, iso.size(), nFaces);
158  subAll = iso;
159  // Offset point indices
160  if (nPoints > 0)
161  {
162  forAll(subAll, i)
163  {
164  face& f = subAll[i];
165  forAll(f, fp)
166  {
167  f[fp] += nPoints;
168  }
169  }
170  }
171  SubList<label>(allMeshCells, iso.size(), nFaces) = iso.meshCells();
172  nFaces += iso.size();
173 
174  const pointField& pts = iso.points();
175  SubList<point>(allPoints, pts.size(), nPoints) = pts;
176  nPoints += pts.size();
177 
178  // Clear out asap
179  isos.set(isoi, nullptr);
180  }
181 
182  if (nFaces != allFaces.size() || nPoints != allPoints.size())
183  {
184  FatalErrorInFunction << "nFaces:" << nFaces
185  << " nPoints:" << nPoints << exit(FatalError);
186  }
187 
188 
189  surfZoneList allZones(1);
190  allZones[0] = surfZone
191  (
192  "allFaces",
193  allFaces.size(), // size
194  0, // start
195  0 // index
196  );
197 
198  // Transfer
199  const_cast<isoSurface&>
200  (
201  *this
203  (
204  move(allPoints),
205  move(allFaces),
206  move(allZones)
207  );
208  meshCells_.transfer(allMeshCells);
209  }
210  if (debug)
211  {
212  Pout<< "sampledSurfaces::isoSurface::updateGeometry() : "
213  "constructed iso:"
214  << nl
215  << " filtering : "
216  << Foam::isoSurface::filterTypeNames_[filter_] << nl
217  << " isoField : " << isoField_ << nl;
218  if (isoVals_.size() == 1)
219  {
220  Pout<< " isoValue : " << isoVals_[0] << nl;
221  }
222  else
223  {
224  Pout<< " isoValues : " << isoVals_ << nl;
225  }
226  Pout<< " points : " << points().size() << nl
227  << " faces : " << faces().size() << nl
228  << " cut cells : " << meshCells_.size() << endl;
229  }
230 
231  return true;
232 }
233 
234 
235 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
236 
238 (
239  const word& name,
240  const polyMesh& mesh,
241  const dictionary& dict
242 )
243 :
244  sampledSurface(name, mesh, dict),
245  isoField_(dict.lookup("isoField")),
246  isoVals_
247  (
248  dict.found("isoValues")
249  ? scalarField(dict.lookup("isoValues"))
250  : scalarField(1, dict.lookup<scalar>("isoValue"))
251  ),
252  filter_
253  (
254  dict.found("filtering")
255  ? Foam::isoSurface::filterTypeNames_.read(dict.lookup("filtering"))
257  ),
258  zoneKey_(keyType::null),
259  prevTimeIndex_(-1),
260  meshCells_(0)
261 {}
262 
263 
264 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
265 
267 {}
268 
269 
270 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
271 
273 {
274  const fvMesh& fvm = static_cast<const fvMesh&>(mesh());
275 
276  return fvm.time().timeIndex() != prevTimeIndex_;
277 }
278 
279 
281 {
282  // Clear derived data
285 
286  // already marked as expired
287  if (prevTimeIndex_ == -1)
288  {
289  return false;
290  }
291 
292  // force update
293  prevTimeIndex_ = -1;
294  return true;
295 }
296 
297 
299 {
300  return updateGeometry();
301 }
302 
303 
306 (
307  const volScalarField& vField
308 ) const
309 {
310  return sampleField(vField);
311 }
312 
313 
316 (
317  const volVectorField& vField
318 ) const
319 {
320  return sampleField(vField);
321 }
322 
323 
326 (
327  const volSphericalTensorField& vField
328 ) const
329 {
330  return sampleField(vField);
331 }
332 
333 
336 (
337  const volSymmTensorField& vField
338 ) const
339 {
340  return sampleField(vField);
341 }
342 
343 
346 (
347  const volTensorField& vField
348 ) const
349 {
350  return sampleField(vField);
351 }
352 
353 
356 (
357  const interpolation<scalar>& interpolator
358 ) const
359 {
360  return interpolateField(interpolator);
361 }
362 
363 
366 (
367  const interpolation<vector>& interpolator
368 ) const
369 {
370  return interpolateField(interpolator);
371 }
372 
375 (
376  const interpolation<sphericalTensor>& interpolator
377 ) const
378 {
379  return interpolateField(interpolator);
380 }
381 
382 
385 (
386  const interpolation<symmTensor>& interpolator
387 ) const
388 {
389  return interpolateField(interpolator);
390 }
391 
392 
395 (
396  const interpolation<tensor>& interpolator
397 ) const
398 {
399  return interpolateField(interpolator);
400 }
401 
402 
404 {
405  os << "isoSurface: " << name() << " :"
406  << " field:" << isoField_;
407  if (isoVals_.size() == 1)
408  {
409  os << " value:" << isoVals_[0];
410  }
411  else
412  {
413  os << " values:" << isoVals_;
414  }
415  os << " faces:" << faces().size()
416  << " points:" << points().size();
417 }
418 
419 
420 // ************************************************************************* //
virtual tmp< scalarField > sample(const volScalarField &) const
Sample field on surface.
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:667
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
const word & name() const
Return the name of this functionObject.
virtual void print(Ostream &) const
Write.
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
An abstract class for surfaces with sampling.
defineTypeNameAndDebug(distanceSurface, 0)
bool interpolate(const vector &p1, const vector &p2, const vector &o, vector &n, scalar l)
Definition: curveTools.C:75
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
bool interpolate() const
Interpolation requested for surface.
List< face > faceList
Definition: faceListFwd.H:43
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
virtual bool needsUpdate() const
Does the surface need an update?
void transfer(MeshedSurface< face > &)
Transfer the contents of the argument and annul the argument.
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:239
isoSurface(const word &name, const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
const labelList & meshCells() const
For every face original cell in mesh.
Definition: isoSurface.H:236
virtual bool expire()
Mark the surface as needing an update.
Macros for easy insertion into run-time selection tables.
static const volPointInterpolation & New(const fvMesh &mesh)
Definition: MeshObject.C:44
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
dynamicFvMesh & mesh
virtual void clearGeom() const
const pointField & points
A class for handling words, derived from string.
Definition: word.H:59
label nPoints
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
static const NamedEnum< filterType, 3 > filterTypeNames_
Definition: isoSurface.H:73
const Field< PointType > & points() const
Return reference to global points.
List< label > labelList
A List of labels.
Definition: labelList.H:56
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
virtual void reset(pointField &&points, List< face > &&faces, surfZoneList &&zones)
Reset primitive data (points, faces and zones)
static const char nl
Definition: Ostream.H:260
labelList f(nPoints)
addToRunTimeSelectionTable(sampledSurface, distanceSurface, word)
List< surfZone > surfZoneList
Definition: surfZoneList.H:45
label timeIndex() const
Return current time index.
Definition: TimeStateI.H:35
label size() const
The surface size is the number of faces.
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
tmp< pointField > allPoints(const Triangulation &t)
Extract all points in vertex-index order.
Enum read(Istream &) const
Read a word from Istream and return the corresponding.
Definition: NamedEnum.C:61
virtual bool update()
Update the surface as required.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Marching tet iso surface algorithm with optional filtering to keep only points originating from mesh ...
Definition: isoSurface.H:57
A class for managing temporary objects.
Definition: PtrList.H:53
static const keyType null
An empty keyType.
Definition: keyType.H:92
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:812
#define InfoInFunction
Report an information message using Foam::Info.