sampledThresholdCellFaces.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) 2018-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 
30 #include "thresholdCellFaces.H"
31 #include "dictionary.H"
32 #include "volFields.H"
33 #include "volPointInterpolation.H"
35 #include "fvMesh.H"
36 
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41  defineTypeNameAndDebug(sampledThresholdCellFaces, 0);
43  (
44  sampledSurface,
45  sampledThresholdCellFaces,
46  word,
47  thresholdCellFaces
48  );
49 }
50 
51 
52 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
53 
54 bool Foam::sampledThresholdCellFaces::updateGeometry() const
55 {
56  const fvMesh& fvm = static_cast<const fvMesh&>(mesh());
57 
58  // no update needed
59  if (fvm.time().timeIndex() == prevTimeIndex_)
60  {
61  return false;
62  }
63 
64  prevTimeIndex_ = fvm.time().timeIndex();
65 
66  // Use volField from database, or try to read it in
67 
68  const auto* cellFldPtr = fvm.findObject<volScalarField>(fieldName_);
69 
70  if (debug)
71  {
72  if (cellFldPtr)
73  {
74  InfoInFunction << "Lookup " << fieldName_ << endl;
75  }
76  else
77  {
79  << "Reading " << fieldName_
80  << " from time " << fvm.time().timeName()
81  << endl;
82  }
83  }
84 
85  // For holding the volScalarField read in.
86  autoPtr<volScalarField> fieldReadPtr;
87 
88  if (!cellFldPtr)
89  {
90  // Bit of a hack. Read field and store.
91 
92  fieldReadPtr = autoPtr<volScalarField>::New
93  (
94  IOobject
95  (
96  fieldName_,
97  fvm.time().timeName(),
98  fvm,
101  false
102  ),
103  fvm
104  );
105  }
106 
107  const volScalarField& cellFld =
108  (fieldReadPtr ? *fieldReadPtr : *cellFldPtr);
109 
110  Mesh& mySurface = const_cast<sampledThresholdCellFaces&>(*this);
111 
112  thresholdCellFaces surf
113  (
114  fvm,
115  cellFld.primitiveField(),
116  lowerThreshold_,
117  upperThreshold_,
118  triangulate_
119  );
120 
121  mySurface.transfer(static_cast<Mesh&>(surf));
122  meshCells_.transfer(surf.meshCells());
123 
124  // Clear derived data
126 
127  if (debug)
128  {
129  Pout<< "sampledThresholdCellFaces::updateGeometry() : constructed"
130  << nl
131  << " field : " << fieldName_ << nl
132  << " lowerLimit : " << lowerThreshold_ << nl
133  << " upperLimit : " << upperThreshold_ << nl
134  << " point : " << points().size() << nl
135  << " faces : " << faces().size() << nl
136  << " cut cells : " << meshCells_.size() << endl;
137  }
138 
139  return true;
140 }
141 
142 
143 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
144 
146 (
147  const word& name,
148  const polyMesh& mesh,
149  const dictionary& dict
150 )
151 :
153  fieldName_(dict.get<word>("field")),
154  lowerThreshold_(dict.getOrDefault<scalar>("lowerLimit", -VGREAT)),
155  upperThreshold_(dict.getOrDefault<scalar>("upperLimit", VGREAT)),
156  triangulate_(dict.getOrDefault("triangulate", false)),
157  prevTimeIndex_(-1),
158  meshCells_()
159 {
160  if (!dict.found("lowerLimit") && !dict.found("upperLimit"))
161  {
163  << "require at least one of 'lowerLimit' or 'upperLimit'" << endl
164  << abort(FatalError);
165  }
166 }
167 
168 
169 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
170 
172 {
173  const fvMesh& fvm = static_cast<const fvMesh&>(mesh());
174 
175  return fvm.time().timeIndex() != prevTimeIndex_;
176 }
177 
178 
180 {
181  // already marked as expired
182  if (prevTimeIndex_ == -1)
183  {
184  return false;
185  }
186 
187  // force update
188  prevTimeIndex_ = -1;
189  return true;
190 }
191 
192 
194 {
195  return updateGeometry();
196 }
197 
198 
200 (
201  const interpolation<scalar>& sampler
202 ) const
203 {
204  return sampleOnFaces(sampler);
205 }
206 
207 
209 (
210  const interpolation<vector>& sampler
211 ) const
212 {
213  return sampleOnFaces(sampler);
214 }
215 
216 
218 (
219  const interpolation<sphericalTensor>& sampler
220 ) const
221 {
222  return sampleOnFaces(sampler);
223 }
224 
225 
227 (
228  const interpolation<symmTensor>& sampler
229 ) const
230 {
231  return sampleOnFaces(sampler);
232 }
233 
234 
236 (
237  const interpolation<tensor>& sampler
238 ) const
239 {
240  return sampleOnFaces(sampler);
241 }
242 
243 
245 (
246  const interpolation<scalar>& interpolator
247 ) const
248 {
249  return sampleOnPoints(interpolator);
250 }
251 
252 
254 (
255  const interpolation<vector>& interpolator
256 ) const
257 {
258  return sampleOnPoints(interpolator);
259 }
260 
263 (
264  const interpolation<sphericalTensor>& interpolator
265 ) const
266 {
267  return sampleOnPoints(interpolator);
268 }
269 
270 
272 (
273  const interpolation<symmTensor>& interpolator
274 ) const
275 {
276  return sampleOnPoints(interpolator);
277 }
278 
279 
281 (
282  const interpolation<tensor>& interpolator
283 ) const
284 {
285  return sampleOnPoints(interpolator);
286 }
287 
288 
290 {
291  os << "sampledThresholdCellFaces: " << name() << " :"
292  << " field:" << fieldName_
293  << " lowerLimit:" << lowerThreshold_
294  << " upperLimit:" << upperThreshold_;
295 
296  // Possibly no geom yet...
297  // if (level)
298  // {
299  // os << " faces:" << faces().size()
300  // << " points:" << points().size();
301  // }
302 }
303 
304 
305 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
Foam::autoPtr::New
static autoPtr< T > New(Args &&... args)
Construct autoPtr of T with forwarding arguments.
volFields.H
InfoInFunction
#define InfoInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:350
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
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::sampledThresholdCellFaces::print
virtual void print(Ostream &os, int level=0) const
Print information.
Definition: sampledThresholdCellFaces.C:289
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:107
Foam::Pout
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Foam::sampledThresholdCellFaces::sampledThresholdCellFaces
sampledThresholdCellFaces(const word &name, const polyMesh &, const dictionary &)
Construct from dictionary.
Definition: sampledThresholdCellFaces.C:146
Foam::sampledThresholdCellFaces::needsUpdate
virtual bool needsUpdate() const
Does the surface need an update?
Definition: sampledThresholdCellFaces.C:171
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::sampledThresholdCellFaces::update
virtual bool update()
Update the surface as required.
Definition: sampledThresholdCellFaces.C:193
Foam::sampledThresholdCellFaces::sample
virtual tmp< scalarField > sample(const interpolation< scalar > &sampler) const
Sample volume field onto surface faces.
Definition: sampledThresholdCellFaces.C:200
Foam::TimeState::timeIndex
label timeIndex() const noexcept
Return current time index.
Definition: TimeStateI.H:37
Foam::sampledThresholdCellFaces::expire
virtual bool expire()
Mark the surface as needing an update.
Definition: sampledThresholdCellFaces.C:179
Foam::sampledSurface::interpolate
bool interpolate() const noexcept
Same as isPointData()
Definition: sampledSurface.H:598
Foam::List::transfer
void transfer(List< T > &list)
Definition: List.C:456
Foam::addNamedToRunTimeSelectionTable
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
Foam::sampledSurface
An abstract class for surfaces with sampling.
Definition: sampledSurface.H:121
Foam::volScalarField
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
thresholdCellFaces.H
Foam::interpolation< scalar >
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
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::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
volPointInterpolation.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::sampledSurface::mesh
const polyMesh & mesh() const noexcept
Access to the underlying mesh.
Definition: sampledSurface.H:316
dictionary.H
Foam::sampledSurface::clearGeom
virtual void clearGeom() const
Additional cleanup when clearing the geometry.
Definition: sampledSurface.C:53
Foam::sampledThresholdCellFaces::faces
virtual const faceList & faces() const
Faces of surface.
Definition: sampledThresholdCellFaces.H:211
sampledThresholdCellFaces.H
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:280
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::sampledThresholdCellFaces::points
virtual const pointField & points() const
Points of surface.
Definition: sampledThresholdCellFaces.H:205
Foam::IOobject::MUST_READ
Definition: IOobject.H:185