sampledPatch.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 "sampledPatch.H"
27 #include "dictionary.H"
28 #include "polyMesh.H"
29 #include "polyPatch.H"
30 #include "volFields.H"
31 #include "surfaceFields.H"
32 
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39  defineTypeNameAndDebug(sampledPatch, 0);
40  addNamedToRunTimeSelectionTable(sampledSurface, sampledPatch, word, patch);
41 }
42 
43 
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45 
47 (
48  const word& name,
49  const polyMesh& mesh,
50  const wordReList& patchNames,
51  const bool triangulate
52 )
53 :
55  patchNames_(patchNames),
56  triangulate_(triangulate),
57  needsUpdate_(true)
58 {}
59 
60 
62 (
63  const word& name,
64  const polyMesh& mesh,
65  const dictionary& dict
66 )
67 :
69  patchNames_(dict.lookup("patches")),
70  triangulate_(dict.lookupOrDefault("triangulate", false)),
71  needsUpdate_(true)
72 {}
73 
74 
75 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
76 
78 {}
79 
80 
81 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
82 
84 {
85  if (patchIDs_.empty())
86  {
87  patchIDs_ = mesh().boundaryMesh().patchSet(patchNames_).sortedToc();
88  }
89  return patchIDs_;
90 }
91 
92 
94 {
95  return needsUpdate_;
96 }
97 
98 
100 {
101  // already marked as expired
102  if (needsUpdate_)
103  {
104  return false;
105  }
106 
109  patchIDs_.clear();
110  patchIndex_.clear();
111  patchFaceLabels_.clear();
112  patchStart_.clear();
113 
114  needsUpdate_ = true;
115  return true;
116 }
117 
118 
120 {
121  if (!needsUpdate_)
122  {
123  return false;
124  }
125 
126  label sz = 0;
127  forAll(patchIDs(), i)
128  {
129  label patchI = patchIDs()[i];
130  const polyPatch& pp = mesh().boundaryMesh()[patchI];
131 
132  if (isA<emptyPolyPatch>(pp))
133  {
135  << "Cannot sample an empty patch. Patch " << pp.name()
136  << exit(FatalError);
137  }
138 
139  sz += pp.size();
140  }
141 
142  // For every face (or triangle) the originating patch and local face in the
143  // patch.
144  patchIndex_.setSize(sz);
145  patchFaceLabels_.setSize(sz);
146  patchStart_.setSize(patchIDs().size());
147  labelList meshFaceLabels(sz);
148 
149  sz = 0;
150 
151  forAll(patchIDs(), i)
152  {
153  label patchI = patchIDs()[i];
154 
155  patchStart_[i] = sz;
156 
157  const polyPatch& pp = mesh().boundaryMesh()[patchI];
158 
159  forAll(pp, j)
160  {
161  patchIndex_[sz] = i;
162  patchFaceLabels_[sz] = j;
163  meshFaceLabels[sz] = pp.start()+j;
164  sz++;
165  }
166  }
167 
168  indirectPrimitivePatch allPatches
169  (
170  IndirectList<face>(mesh().faces(), meshFaceLabels),
171  mesh().points()
172  );
173 
174  this->storedPoints() = allPatches.localPoints();
175  this->storedFaces() = allPatches.localFaces();
176 
177 
178  // triangulate uses remapFaces()
179  // - this is somewhat less efficient since it recopies the faces
180  // that we just created, but we probably don't want to do this
181  // too often anyhow.
182  if (triangulate_)
183  {
184  MeshStorage::triangulate();
185  }
186 
187  if (debug)
188  {
189  print(Pout);
190  Pout<< endl;
191  }
192 
193  needsUpdate_ = false;
194  return true;
195 }
196 
197 
198 // remap action on triangulation
200 {
201  // recalculate the cells cut
202  if (notNull(faceMap) && faceMap.size())
203  {
204  MeshStorage::remapFaces(faceMap);
205  patchFaceLabels_ = labelList
206  (
207  UIndirectList<label>(patchFaceLabels_, faceMap)
208  );
209  patchIndex_ = labelList
210  (
211  UIndirectList<label>(patchIndex_, faceMap)
212  );
213 
214  // Redo patchStart.
215  if (patchIndex_.size() > 0)
216  {
217  patchStart_[patchIndex_[0]] = 0;
218  for (label i = 1; i < patchIndex_.size(); i++)
219  {
220  if (patchIndex_[i] != patchIndex_[i-1])
221  {
222  patchStart_[patchIndex_[i]] = i;
223  }
224  }
225  }
226  }
227 }
228 
229 
231 (
232  const volScalarField& vField
233 ) const
234 {
235  return sampleField(vField);
236 }
237 
238 
240 (
241  const volVectorField& vField
242 ) const
243 {
244  return sampleField(vField);
245 }
246 
247 
249 (
250  const volSphericalTensorField& vField
251 ) const
252 {
253  return sampleField(vField);
254 }
255 
256 
258 (
259  const volSymmTensorField& vField
260 ) const
261 {
262  return sampleField(vField);
263 }
264 
265 
267 (
268  const volTensorField& vField
269 ) const
270 {
271  return sampleField(vField);
272 }
273 
274 
276 (
277  const surfaceScalarField& sField
278 ) const
279 {
280  return sampleField(sField);
281 }
282 
283 
285 (
286  const surfaceVectorField& sField
287 ) const
288 {
289  return sampleField(sField);
290 }
291 
292 
294 (
295  const surfaceSphericalTensorField& sField
296 ) const
297 {
298  return sampleField(sField);
299 }
300 
301 
303 (
304  const surfaceSymmTensorField& sField
305 ) const
306 {
307  return sampleField(sField);
308 }
309 
310 
312 (
313  const surfaceTensorField& sField
314 ) const
315 {
316  return sampleField(sField);
317 }
318 
319 
321 (
322  const interpolation<scalar>& interpolator
323 ) const
324 {
325  return interpolateField(interpolator);
326 }
327 
328 
330 (
331  const interpolation<vector>& interpolator
332 ) const
333 {
334  return interpolateField(interpolator);
335 }
336 
337 
339 (
340  const interpolation<sphericalTensor>& interpolator
341 ) const
342 {
343  return interpolateField(interpolator);
344 }
345 
346 
348 (
349  const interpolation<symmTensor>& interpolator
350 ) const
351 {
352  return interpolateField(interpolator);
353 }
354 
355 
357 (
358  const interpolation<tensor>& interpolator
359 ) const
360 {
361  return interpolateField(interpolator);
362 }
363 
364 
366 {
367  os << "sampledPatch: " << name() << " :"
368  << " patches:" << patchNames()
369  << " faces:" << faces().size()
370  << " points:" << points().size();
371 }
372 
373 
374 // ************************************************************************* //
volFields.H
sampledPatch.H
Foam::volTensorField
GeometricField< tensor, fvPatchField, volMesh > volTensorField
Definition: volFieldsFwd.H:59
Foam::sampledPatch::needsUpdate
virtual bool needsUpdate() const
Does the surface need an update?
Definition: sampledPatch.C:93
Foam::addNamedToRunTimeSelectionTable
addNamedToRunTimeSelectionTable(fvPatch, cyclicAMIFvPatch, polyPatch, cyclicPeriodicAMI)
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeFast.C:90
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
print
void print(const char *msg, Ostream &os, const PtrList< GeoField > &flds)
Definition: foamToVTK.C:164
Foam::sampledPatch::patchIDs
const labelList & patchIDs() const
Definition: sampledPatch.C:83
Foam::labelList
List< label > labelList
A List of labels.
Definition: labelList.H:56
clear
UEqn clear()
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
polyPatch.H
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::notNull
bool notNull(const T &t)
Return true if t is not a reference to the nullObject of type T.
Definition: nullObjectI.H:46
Foam::PrimitivePatch::localPoints
const Field< PointType > & localPoints() const
Return pointField of points in patch.
Definition: PrimitivePatchTemplate.C:432
Foam::surfaceTensorField
GeometricField< tensor, fvsPatchField, surfaceMesh > surfaceTensorField
Definition: surfaceFieldsFwd.H:60
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
surfaceFields.H
Foam::surfaceFields.
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::label
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
Foam::sampledPatch::print
virtual void print(Ostream &) const
Write.
Definition: sampledPatch.C:365
Foam::volSymmTensorField
GeometricField< symmTensor, fvPatchField, volMesh > volSymmTensorField
Definition: volFieldsFwd.H:58
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::sampledPatch::~sampledPatch
virtual ~sampledPatch()
Destructor.
Definition: sampledPatch.C:77
Foam::IndirectList
A List with indirect addressing.
Definition: IndirectList.H:102
Foam::sampledSurface
An abstract class for surfaces with sampling.
Definition: sampledSurface.H:77
Foam::sampledPatch::remapFaces
virtual void remapFaces(const labelUList &faceMap)
Re-map action on triangulation or cleanup.
Definition: sampledPatch.C:199
patchNames
wordList patchNames(nPatches)
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 any number of values (e....
Definition: dictionary.H:137
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::HashTable::sortedToc
List< Key > sortedToc() const
Return the table of contents as a sorted list.
Definition: HashTable.C:216
Foam::polyPatch::start
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:312
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::sampledPatch::update
virtual bool update()
Update the surface as required.
Definition: sampledPatch.C:119
Foam::sampledPatch::sampledPatch
sampledPatch(const word &name, const polyMesh &mesh, const wordReList &patchNames, const bool triangulate=false)
Construct from components.
Definition: sampledPatch.C:47
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::sampledPatch::sample
virtual tmp< scalarField > sample(const volScalarField &) const
Sample field on surface.
Definition: sampledPatch.C:231
Foam::Pout
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
Foam::surfaceScalarField
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
Definition: surfaceFieldsFwd.H:52
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::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
Foam::sampledPatch::expire
virtual bool expire()
Mark the surface as needing an update.
Definition: sampledPatch.C:99
points
const pointField & points
Definition: gmvOutputHeader.H:1
dictionary.H
Foam::sampledSurface::clearGeom
virtual void clearGeom() const
Definition: sampledSurface.C:42
Foam::PrimitivePatch::localFaces
const List< Face > & localFaces() const
Return patch faces addressing into local point list.
Definition: PrimitivePatchTemplate.C:372
Foam::UIndirectList
A List with indirect addressing.
Definition: fvMatrix.H:106
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::surfaceVectorField
GeometricField< vector, fvsPatchField, surfaceMesh > surfaceVectorField
Definition: surfaceFieldsFwd.H:55
Foam::polyBoundaryMesh::patchSet
labelHashSet patchSet(const UList< wordRe > &patchNames, const bool warnNotFound=true, const bool usePatchGroups=true) const
Return the set of patch IDs corresponding to the given names.
Definition: polyBoundaryMesh.C:750
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::sampledSurface::interpolate
bool interpolate() const
Interpolation requested for surface.
Definition: sampledSurface.H:256
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::patchIdentifier::name
const word & name() const
Return name.
Definition: patchIdentifier.H:109
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatchTemplate.H:88