sampledSurface.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 | Copyright (C) 2011-2015 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"
27 #include "polyMesh.H"
28 #include "demandDrivenData.H"
29 
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(sampledSurface, 0);
36  defineRunTimeSelectionTable(sampledSurface, word);
37 }
38 
39 
40 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41 
43 {
47  area_ = -1;
48 }
49 
50 
52 {
53  // It is an error to recalculate if the pointer is already set
54  if (SfPtr_)
55  {
57  << "face area vectors already exist"
58  << abort(FatalError);
59  }
60 
61  const faceList& theFaces = faces();
62  SfPtr_ = new vectorField(theFaces.size());
63 
64  vectorField& values = *SfPtr_;
65  forAll(theFaces, faceI)
66  {
67  values[faceI] = theFaces[faceI].normal(points());
68  }
69 }
70 
71 
73 {
74  // It is an error to recalculate if the pointer is already set
75  if (magSfPtr_)
76  {
78  << "mag face areas already exist"
79  << abort(FatalError);
80  }
81 
82  const faceList& theFaces = faces();
83  magSfPtr_ = new scalarField(theFaces.size());
84 
85  scalarField& values = *magSfPtr_;
86  forAll(theFaces, faceI)
87  {
88  values[faceI] = theFaces[faceI].mag(points());
89  }
90 }
91 
92 
94 {
95  // It is an error to recalculate if the pointer is already set
96  if (CfPtr_)
97  {
99  << "face centres already exist"
100  << abort(FatalError);
101  }
102 
103  const faceList& theFaces = faces();
104  CfPtr_ = new vectorField(theFaces.size());
105 
106  vectorField& values = *CfPtr_;
107  forAll(theFaces, faceI)
108  {
109  values[faceI] = theFaces[faceI].centre(points());
110  }
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<< "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_(NULL),
160  magSfPtr_(NULL),
161  CfPtr_(NULL),
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_(NULL),
177  magSfPtr_(NULL),
178  CfPtr_(NULL),
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 
241 (
242  const surfaceScalarField& sField
243 ) const
244 {
246  return tmp<scalarField>(NULL);
247 }
248 
249 
251 (
252  const surfaceVectorField& sField
253 ) const
254 {
256  return tmp<vectorField>(NULL);
257 }
258 
259 
261 (
262  const surfaceSphericalTensorField& sField
263 ) const
264 {
266  return tmp<sphericalTensorField>(NULL);
267 }
268 
269 
271 (
272  const surfaceSymmTensorField& sField
273 ) const
274 {
276  return tmp<symmTensorField>(NULL);
277 }
278 
279 
281 (
282  const surfaceTensorField& sField
283 ) const
284 {
286  return tmp<tensorField>(NULL);
287 }
288 
289 
292 {
293  tmp<Field<scalar> > tRes(new Field<scalar>(faces().size()));
294  Field<scalar>& res = tRes();
295 
296  forAll(faces(), faceI)
297  {
298  res[faceI] = field[faceI];
299  }
300 
301  return tRes;
302 }
303 
304 
307 {
308  tmp<Field<scalar> > tRes(new Field<scalar>(faces().size()));
309  project(tRes(), field);
310  return tRes;
311 }
312 
313 
316 {
317  tmp<Field<vector> > tRes(new Field<vector>(faces().size()));
318  project(tRes(), field);
319  return tRes;
320 }
321 
322 
325 {
326  tmp<Field<vector> > tRes(new Field<vector>(faces().size()));
327  project(tRes(), field);
328  return tRes;
329 }
330 
331 
334 {
335  tmp<Field<vector> > tRes(new Field<vector>(faces().size()));
336  project(tRes(), field);
337  return tRes;
338 }
339 
340 
342 {
343  os << type();
344 }
345 
346 
347 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
348 
350 {
351  s.print(os);
352  os.check("Ostream& operator<<(Ostream&, const sampledSurface&");
353  return os;
354 }
355 
356 
357 // ************************************************************************* //
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:48
Foam::sampledSurface::Sf
virtual const vectorField & Sf() const
Return face area vectors.
Definition: sampledSurface.C:195
Foam::sampledSurface::makeCf
void makeCf() const
Make Cf.
Definition: sampledSurface.C:93
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::sampledSurface::makeSf
void makeSf() const
Make Sf.
Definition: sampledSurface.C:51
Foam::dictionary::readIfPresent
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
Definition: dictionaryTemplates.C:94
Foam::sampledSurface::sampledSurface
sampledSurface(const word &name, const polyMesh &, const bool interpolate=false)
Construct from name, mesh.
Definition: sampledSurface.C:150
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::defineRunTimeSelectionTable
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
Foam::surfaceTensorField
GeometricField< tensor, fvsPatchField, surfaceMesh > surfaceTensorField
Definition: surfaceFieldsFwd.H:60
Foam::sampledSurface::sample
virtual tmp< scalarField > sample(const volScalarField &) const =0
Sample field on surface.
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::sampledSurface::New
static autoPtr< sampledSurface > New(const word &name, const polyMesh &, const dictionary &)
Return a reference to the selected surface.
Definition: sampledSurface.C:117
Foam::sampledSurface::area
scalar area() const
The total surface area.
Definition: sampledSurface.C:228
Foam::dictionary::lookupOrDefault
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
Definition: dictionaryTemplates.C:33
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::sampledSurface::project
void project(Field< ReturnType > &, const Field< Type > &) const
Project field onto surface.
Definition: sampledSurfaceTemplates.C:108
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::vectorField
Field< vector > vectorField
Specialisation of Field<T> for vector.
Definition: primitiveFieldsFwd.H:49
Foam::deleteDemandDrivenData
void deleteDemandDrivenData(DataPtr &dataPtr)
Definition: demandDrivenData.H:40
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:365
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:43
Foam::interpolate
bool interpolate(const vector &p1, const vector &p2, const vector &o, vector &n, scalar l)
Definition: curveTools.C:75
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
sampledSurface.H
Foam::sampledSurface::Cf
virtual const vectorField & Cf() const
Return face centres as vectorField.
Definition: sampledSurface.C:217
Foam::sampledSurface
An abstract class for surfaces with sampling.
Definition: sampledSurface.H:77
Foam::sampledSurface::magSf
virtual const scalarField & magSf() const
Return face area magnitudes.
Definition: sampledSurface.C:206
Foam::sampledSurface::print
virtual void print(Ostream &) const
Write.
Definition: sampledSurface.C:341
Foam::operator<<
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:130
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
s
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::autoPtr< Foam::sampledSurface >
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::sumOp
Definition: ops.H:162
Foam::sampledSurface::SfPtr_
vectorField * SfPtr_
Face area vectors.
Definition: sampledSurface.H:94
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::sampledSurface::~sampledSurface
virtual ~sampledSurface()
Destructor.
Definition: sampledSurface.C:187
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::sum
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:333
Foam::sampledSurface::clearGeom
virtual void clearGeom() const
Definition: sampledSurface.C:42
Foam::sampledSurface::magSfPtr_
scalarField * magSfPtr_
Mag face area vectors.
Definition: sampledSurface.H:97
Foam::surfaceSphericalTensorField
GeometricField< sphericalTensor, fvsPatchField, surfaceMesh > surfaceSphericalTensorField
Definition: surfaceFieldsFwd.H:57
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::surfaceSymmTensorField
GeometricField< symmTensor, fvsPatchField, surfaceMesh > surfaceSymmTensorField
Definition: surfaceFieldsFwd.H:59
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::sampledSurface::area_
scalar area_
Total surface area.
Definition: sampledSurface.H:103
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::sampledSurface::CfPtr_
vectorField * CfPtr_
Face centres.
Definition: sampledSurface.H:100
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::sampledSurface::makeMagSf
void makeMagSf() const
Make magSf.
Definition: sampledSurface.C:72