sampledThresholdCellFaces.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-2026 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 
27 #include "thresholdCellFaces.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace sampledSurfaces
35 {
38 }
39 }
40 
41 
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 
44 bool Foam::sampledSurfaces::thresholdCellFaces::updateGeometry() const
45 {
46  const fvMesh& fvm = static_cast<const fvMesh&>(mesh());
47 
48  // no update needed
49  if (fvm.time().timeIndex() == prevTimeIndex_)
50  {
51  return false;
52  }
53 
54  prevTimeIndex_ = fvm.time().timeIndex();
55 
56  // Optionally read volScalarField
57  autoPtr<volScalarField> readFieldPtr_;
58 
59  // 1. see if field in database
60  // 2. see if field can be read
61  const volScalarField* cellFldPtr = nullptr;
62  if (fvm.foundObject<volScalarField>(fieldName_))
63  {
64  if (debug)
65  {
66  InfoInFunction<< "Lookup " << fieldName_ << endl;
67  }
68 
69  cellFldPtr = &fvm.lookupObject<volScalarField>(fieldName_);
70  }
71  else
72  {
73  // Bit of a hack. Read field and store.
74 
75  if (debug)
76  {
78  << "Reading " << fieldName_
79  << " from time " << fvm.time().name()
80  << endl;
81  }
82 
83  readFieldPtr_.reset
84  (
85  new volScalarField
86  (
87  IOobject
88  (
89  fieldName_,
90  fvm.time().name(),
91  fvm,
94  false
95  ),
96  fvm
97  )
98  );
99 
100  cellFldPtr = readFieldPtr_.operator->();
101  }
102  const volScalarField& cellFld = *cellFldPtr;
103 
104 
106  (
107  fvm,
108  cellFld.primitiveField(),
109  lowerThreshold_,
110  upperThreshold_,
111  triangulate_
112  );
113 
114  const_cast<thresholdCellFaces&>
115  (
116  *this
118  meshCells_.transfer(surf.meshCells());
119 
120  // clear derived data
122 
123  if (debug)
124  {
125  Pout<< "thresholdCellFaces::updateGeometry() : constructed"
126  << nl
127  << " field : " << fieldName_ << nl
128  << " lowerLimit : " << lowerThreshold_ << nl
129  << " upperLimit : " << upperThreshold_ << nl
130  << " point : " << points().size() << nl
131  << " faces : " << faces().size() << nl
132  << " cut cells : " << meshCells_.size() << endl;
133  }
134 
135  return true;
136 }
137 
138 
139 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
140 
142 (
143  const word& name,
144  const polyMesh& mesh,
145  const dictionary& dict
146 )
147 :
149  fieldName_(dict.lookup("field")),
150  lowerThreshold_(dict.lookupOrDefault<scalar>("lowerLimit", -vGreat)),
151  upperThreshold_(dict.lookupOrDefault<scalar>("upperLimit", vGreat)),
152  triangulate_(dict.lookupOrDefault("triangulate", false)),
153  prevTimeIndex_(-1),
154  meshCells_(0)
155 {
156  if (!dict.found("lowerLimit") && !dict.found("upperLimit"))
157  {
159  << "require at least one of 'lowerLimit' or 'upperLimit'" << endl
160  << abort(FatalError);
161  }
162 }
163 
164 
165 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
166 
168 {}
169 
170 
171 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
172 
174 {
175  return wordList(fieldName_);
176 }
177 
178 
180 {
181  const fvMesh& fvm = static_cast<const fvMesh&>(mesh());
182 
183  return fvm.time().timeIndex() != prevTimeIndex_;
184 }
185 
186 
188 {
189  return updateGeometry();
190 }
191 
192 
193 #define IMPLEMENT_SAMPLE(Type, nullArg) \
194  Foam::tmp<Foam::Field<Foam::Type>> \
195  Foam::sampledSurfaces::thresholdCellFaces::sample \
196  ( \
197  const VolField<Type>& vField \
198  ) const \
199  { \
200  return sampleField(vField); \
201  }
203 #undef IMPLEMENT_SAMPLE
204 
205 
206 #define IMPLEMENT_INTERPOLATE(Type, nullArg) \
207  Foam::tmp<Foam::Field<Foam::Type>> \
208  Foam::sampledSurfaces::thresholdCellFaces::interpolate \
209  ( \
210  const interpolation<Type>& interpolator \
211  ) const \
212  { \
213  return interpolateField(interpolator); \
214  }
216 #undef IMPLEMENT_INTERPOLATE
217 
218 
220 {
221  prevTimeIndex_ = -1;
222 }
223 
224 
226 (
227  const polyTopoChangeMap&
228 )
229 {
230  prevTimeIndex_ = -1;
231 }
232 
233 
235 (
236  const polyMeshMap& map
237 )
238 {
239  prevTimeIndex_ = -1;
240 }
241 
242 
244 (
245  const polyDistributionMap& map
246 )
247 {
248  prevTimeIndex_ = -1;
249 }
250 
251 
253 {
254  os << "thresholdCellFaces: " << name() << " :"
255  << " field:" << fieldName_
256  << " lowerLimit:" << lowerThreshold_
257  << " upperLimit:" << upperThreshold_;
258  //<< " faces:" << faces().size() // possibly no geom yet
259  //<< " points:" << points().size();
260 }
261 
262 
263 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
void transfer(MeshedSurface< face > &)
Transfer the contents of the argument and annul the argument.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
label timeIndex() const
Return current time index.
Definition: TimeStateI.H:28
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:98
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:433
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
An abstract class for surfaces with sampling.
virtual void clearGeom() const
const polyMesh & mesh() const
Access to the underlying mesh.
A sampledSurface defined by the cell faces corresponding to a threshold value.
thresholdCellFaces(const word &name, const polyMesh &, const dictionary &)
Construct from dictionary.
virtual wordList fields() const
Return the list of fields required.
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
virtual void movePoints()
Update for mesh point-motion.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
virtual bool needsUpdate() const
Does the surface need an update?
virtual bool update()
Update the surface as required.
virtual void print(Ostream &) const
Write.
virtual const faceList & faces() const
Faces of surface.
virtual const pointField & points() const
Points of surface.
Selects the mesh cell faces specified by a threshold value. Non-triangulated by default.
A class for handling words, derived from string.
Definition: word.H:63
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
#define InfoInFunction
Report an information message using Foam::Info.
defineTypeNameAndDebug(cutPlane, 0)
addToRunTimeSelectionTable(sampledSurface, cutPlane, word)
const unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
Definition: units.C:346
Namespace for OpenFOAM.
List< word > wordList
A List of words.
Definition: fileName.H:54
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
errorManip< error > abort(error &err)
Definition: errorManip.H:131
FOR_ALL_FIELD_TYPES(makeDimensionedPointFieldFunctions)
VolField< scalar > volScalarField
Definition: volFieldsFwd.H:62
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
error FatalError
static const char nl
Definition: Ostream.H:297
#define IMPLEMENT_INTERPOLATE(Type, nullArg)
#define IMPLEMENT_SAMPLE(Type, nullArg)
dictionary dict