sampledSurface.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 
26 #include "sampledSurface.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
35 }
36 
37 
38 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
39 
40 void Foam::sampledSurface::makeSf() const
41 {
42  // It is an error to recalculate if the pointer is already set
43  if (SfPtr_)
44  {
46  << "face area vectors already exist"
47  << abort(FatalError);
48  }
49 
50  const faceList& theFaces = faces();
51  SfPtr_ = new vectorField(theFaces.size());
52 
53  vectorField& values = *SfPtr_;
54  forAll(theFaces, facei)
55  {
56  values[facei] = theFaces[facei].area(points());
57  }
58 }
59 
60 
61 void Foam::sampledSurface::makeMagSf() const
62 {
63  // It is an error to recalculate if the pointer is already set
64  if (magSfPtr_)
65  {
67  << "mag face areas already exist"
68  << abort(FatalError);
69  }
70 
71  const faceList& theFaces = faces();
72  magSfPtr_ = new scalarField(theFaces.size());
73 
74  scalarField& values = *magSfPtr_;
75  forAll(theFaces, facei)
76  {
77  values[facei] = theFaces[facei].mag(points());
78  }
79 }
80 
81 
82 void Foam::sampledSurface::makeCf() const
83 {
84  // It is an error to recalculate if the pointer is already set
85  if (CfPtr_)
86  {
88  << "face centres already exist"
89  << abort(FatalError);
90  }
91 
92  const faceList& theFaces = faces();
93  CfPtr_ = new vectorField(theFaces.size());
94 
95  vectorField& values = *CfPtr_;
96  forAll(theFaces, facei)
97  {
98  values[facei] = theFaces[facei].centre(points());
99  }
100 }
101 
102 
103 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
104 
106 {
107  deleteDemandDrivenData(SfPtr_);
108  deleteDemandDrivenData(magSfPtr_);
109  deleteDemandDrivenData(CfPtr_);
110  area_ = -1;
111 }
112 
113 
114 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
115 
117 (
118  const word& name,
119  const polyMesh& mesh,
120  const dictionary& dict
121 )
122 {
123  const word sampleType(dict.lookup("type"));
124 
125  if (debug)
126  {
127  Info<< indentOrNl << "Selecting sampledType " << sampleType << endl;
128  }
129 
130  wordConstructorTable::iterator cstrIter =
131  wordConstructorTablePtr_->find(sampleType);
132 
133  if (cstrIter == wordConstructorTablePtr_->end())
134  {
136  << "Unknown sample type "
137  << sampleType << nl << nl
138  << "Valid sample types : " << endl
139  << wordConstructorTablePtr_->sortedToc()
140  << exit(FatalError);
141  }
142 
143  return autoPtr<sampledSurface>(cstrIter()(name, mesh, dict));
144 }
145 
146 
147 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
148 
150 (
151  const word& name,
152  const polyMesh& mesh,
153  const bool interpolate
154 )
155 :
156  name_(name),
157  mesh_(mesh),
158  interpolate_(interpolate),
159  SfPtr_(nullptr),
160  magSfPtr_(nullptr),
161  CfPtr_(nullptr),
162  area_(-1)
163 {}
164 
165 
167 (
168  const word& name,
169  const polyMesh& mesh,
170  const dictionary& dict
171 )
172 :
173  name_(name),
174  mesh_(mesh),
175  interpolate_(dict.lookupOrDefault("interpolate", false)),
176  SfPtr_(nullptr),
177  magSfPtr_(nullptr),
178  CfPtr_(nullptr),
179  area_(-1)
180 {
181  dict.readIfPresent("name", name_);
182 }
183 
184 
185 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
186 
188 {
189  clearGeom();
190 }
191 
192 
193 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
194 
196 {
197  if (!SfPtr_)
198  {
199  makeSf();
200  }
201 
202  return *SfPtr_;
203 }
204 
205 
207 {
208  if (!magSfPtr_)
209  {
210  makeMagSf();
211  }
212 
213  return *magSfPtr_;
214 }
215 
216 
218 {
219  if (!CfPtr_)
220  {
221  makeCf();
222  }
223 
224  return *CfPtr_;
225 }
226 
227 
228 Foam::scalar Foam::sampledSurface::area() const
229 {
230  if (area_ < 0)
231  {
232  area_ = sum(magSf());
233  reduce(area_, sumOp<scalar>());
234  }
235 
236  return area_;
237 }
238 
239 
240 #define IMPLEMENT_SAMPLE(Type, nullArg) \
241  Foam::tmp<Foam::Field<Foam::Type>> \
242  Foam::sampledSurface::sample \
243  ( \
244  const SurfaceField<Type>& vField \
245  ) const \
246  { \
247  NotImplemented; \
248  return tmp<Field<Type>>(nullptr); \
249  }
251 #undef IMPLEMENT_SAMPLE
252 
253 
255 Foam::sampledSurface::project(const Field<scalar>& field) const
256 {
257  tmp<Field<scalar>> tRes(new Field<scalar>(faces().size()));
258  Field<scalar>& res = tRes.ref();
259 
260  forAll(faces(), facei)
261  {
262  res[facei] = field[facei];
263  }
264 
265  return tRes;
266 }
267 
268 
270 Foam::sampledSurface::project(const Field<vector>& field) const
271 {
272  tmp<Field<scalar>> tRes(new Field<scalar>(faces().size()));
273  project(tRes.ref(), field);
274  return tRes;
275 }
276 
277 
279 Foam::sampledSurface::project(const Field<sphericalTensor>& field) const
280 {
281  tmp<Field<vector>> tRes(new Field<vector>(faces().size()));
282  project(tRes.ref(), field);
283  return tRes;
284 }
285 
286 
288 Foam::sampledSurface::project(const Field<symmTensor>& field) const
289 {
290  tmp<Field<vector>> tRes(new Field<vector>(faces().size()));
291  project(tRes.ref(), field);
292  return tRes;
293 }
294 
295 
297 Foam::sampledSurface::project(const Field<tensor>& field) const
298 {
299  tmp<Field<vector>> tRes(new Field<vector>(faces().size()));
300  project(tRes.ref(), field);
301  return tRes;
302 }
303 
304 
306 {
307  os << type();
308 }
309 
310 
311 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
312 
314 {
315  s.print(os);
316  os.check("Ostream& operator<<(Ostream&, const sampledSurface&");
317  return os;
318 }
319 
320 
321 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Macros for easy insertion into run-time selection tables.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:108
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:669
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
An abstract class for surfaces with sampling.
virtual const faceList & faces() const =0
Faces of surface.
static autoPtr< sampledSurface > New(const word &name, const polyMesh &, const dictionary &)
Return a reference to the selected surface.
virtual void clearGeom() const
sampledSurface(const word &name, const polyMesh &, const bool interpolate=false)
Construct from name, mesh.
virtual const scalarField & magSf() const
Return face area magnitudes.
virtual ~sampledSurface()
Destructor.
virtual void print(Ostream &) const
Write.
virtual const vectorField & Cf() const
Return face centres as vectorField.
virtual const pointField & points() const =0
Points of surface.
scalar area() const
The total surface area.
virtual const vectorField & Sf() const
Return face area vectors.
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:197
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
const pointField & points
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), lagrangian::cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
static tmp< SurfaceField< Type > > interpolate(const VolField< Type > &tvf, const surfaceScalarField &faceFlux, Istream &schemeData)
Interpolate field onto faces using scheme given by Istream.
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
void deleteDemandDrivenData(DataType *&dataPtr)
errorManip< error > abort(error &err)
Definition: errorManip.H:131
FOR_ALL_FIELD_TYPES(makeDimensionedPointFieldFunctions)
messageStream Info
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
defineRunTimeSelectionTable(fvConstraint, dictionary)
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
Field< vector > vectorField
Specialisation of Field<T> for vector.
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
Ostream & indentOrNl(Ostream &os)
Indent stream or add newline if indent level == 0.
Definition: Ostream.H:250
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
error FatalError
List< face > faceList
Definition: faceListFwd.H:41
defineTypeNameAndDebug(atmosphericBoundaryLayer, 0)
static const char nl
Definition: Ostream.H:297
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
#define IMPLEMENT_SAMPLE(Type, nullArg)
dictionary dict