sampledPatch.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 "sampledPatch.H"
27 #include "surfaceFields.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace sampledSurfaces
35 {
38 }
39 }
40 
41 
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43 
45 (
46  const word& name,
47  const polyMesh& mesh,
48  const wordReList& patchNames,
49  const bool triangulate
50 )
51 :
53  patchNames_(patchNames),
54  triangulate_(triangulate),
55  needsUpdate_(true)
56 {}
57 
58 
60 (
61  const word& name,
62  const polyMesh& mesh,
63  const dictionary& dict
64 )
65 :
67  patchNames_(dict.lookup("patches")),
68  triangulate_(dict.lookupOrDefault("triangulate", false)),
69  needsUpdate_(true)
70 {}
71 
72 
73 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
74 
76 {}
77 
78 
79 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
80 
82 {
83  if (patchIndices_.empty())
84  {
85  patchIndices_ =
86  mesh().boundary().patchSet(patchNames_, false).sortedToc();
87  }
88  return patchIndices_;
89 }
90 
91 
93 {
94  return needsUpdate_;
95 }
96 
97 
99 {
100  if (!needsUpdate_)
101  {
102  return false;
103  }
104 
105  label sz = 0;
106  forAll(patchIndices(), i)
107  {
108  label patchi = patchIndices()[i];
109  const polyPatch& pp = mesh().boundary()[patchi];
110 
111  if (isA<emptyPolyPatch>(pp))
112  {
114  << "Cannot sample an empty patch. Patch " << pp.name()
115  << exit(FatalError);
116  }
117 
118  sz += pp.size();
119  }
120 
121  // For every face (or triangle) the originating patch and local face in the
122  // patch.
123  patchIndex_.setSize(sz);
124  patchFaceLabels_.setSize(sz);
125  patchStart_.setSize(patchIndices().size());
126  labelList meshFaceLabels(sz);
127 
128  sz = 0;
129 
130  forAll(patchIndices(), i)
131  {
132  label patchi = patchIndices()[i];
133 
134  patchStart_[i] = sz;
135 
136  const polyPatch& pp = mesh().boundary()[patchi];
137 
138  forAll(pp, j)
139  {
140  patchIndex_[sz] = i;
141  patchFaceLabels_[sz] = j;
142  meshFaceLabels[sz] = pp.start()+j;
143  sz++;
144  }
145  }
146 
147  indirectPrimitivePatch allPatches
148  (
149  IndirectList<face>(mesh().faces(), meshFaceLabels),
150  mesh().points()
151  );
152 
153  this->storedPoints() = allPatches.localPoints();
154  this->storedFaces() = allPatches.localFaces();
155 
156 
157  // triangulate uses remapFaces()
158  // - this is somewhat less efficient since it recopies the faces
159  // that we just created, but we probably don't want to do this
160  // too often anyhow.
161  if (triangulate_)
162  {
164  }
165 
166  if (debug)
167  {
168  print(Pout);
169  Pout<< endl;
170  }
171 
172  needsUpdate_ = false;
173  return true;
174 }
175 
176 
177 // remap action on triangulation
178 void Foam::sampledSurfaces::patch::remapFaces(const labelUList& faceMap)
179 {
180  // recalculate the cells cut
181  if (notNull(faceMap) && faceMap.size())
182  {
184  patchFaceLabels_ = labelList
185  (
186  UIndirectList<label>(patchFaceLabels_, faceMap)
187  );
188  patchIndex_ = labelList
189  (
190  UIndirectList<label>(patchIndex_, faceMap)
191  );
192 
193  // Redo patchStart.
194  if (patchIndex_.size() > 0)
195  {
196  patchStart_[patchIndex_[0]] = 0;
197  for (label i = 1; i < patchIndex_.size(); i++)
198  {
199  if (patchIndex_[i] != patchIndex_[i-1])
200  {
201  patchStart_[patchIndex_[i]] = i;
202  }
203  }
204  }
205  }
206 }
207 
208 
209 #define IMPLEMENT_SAMPLE(Type, nullArg) \
210  Foam::tmp<Foam::Field<Foam::Type>> \
211  Foam::sampledSurfaces::patch::sample \
212  ( \
213  const VolField<Type>& vField \
214  ) const \
215  { \
216  return sampleField(vField); \
217  } \
218  \
219  Foam::tmp<Foam::Field<Foam::Type>> \
220  Foam::sampledSurfaces::patch::sample \
221  ( \
222  const SurfaceField<Type>& vField \
223  ) const \
224  { \
225  return sampleField(vField); \
226  }
228 #undef IMPLEMENT_SAMPLE
229 
230 
231 #define IMPLEMENT_INTERPOLATE(Type, nullArg) \
232  Foam::tmp<Foam::Field<Foam::Type>> \
233  Foam::sampledSurfaces::patch::interpolate \
234  ( \
235  const interpolation<Type>& interpolator \
236  ) const \
237  { \
238  return interpolateField(interpolator); \
239  }
241 #undef IMPLEMENT_INTERPOLATE
242 
243 
245 {
248 
249  patchIndices_.clear();
250  patchIndex_.clear();
251  patchFaceLabels_.clear();
252  patchStart_.clear();
253 
254  needsUpdate_ = true;
255 }
256 
257 
259 {
260  movePoints();
261 }
262 
263 
265 {
266  movePoints();
267 }
268 
269 
271 {
272  movePoints();
273 }
274 
275 
277 {
278  os << "patch: " << name() << " :"
279  << " patches:" << patchNames()
280  << " faces:" << faces().size()
281  << " points:" << points().size();
282 }
283 
284 
285 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Macros for easy insertion into run-time selection tables.
A List with indirect addressing.
Definition: IndirectList.H:105
virtual label triangulate()
Triangulate in-place, returning the number of triangles added.
virtual void remapFaces(const labelUList &faceMap)
Set new zones from faceMap.
virtual void clear()
Clear all storage.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
const List< FaceType > & localFaces() const
Return patch faces addressing into local point list.
const Field< PointType > & localPoints() const
Return pointField of points in patch.
A List with indirect addressing.
Definition: UIndirectList.H:61
label size() const
Return the number of elements in the UList.
Definition: UListI.H:311
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:932
const word & name() const
Return name.
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
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:71
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:277
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
An abstract class for surfaces with sampling.
virtual void clearGeom() const
A sampledSurface on patches. Non-triangulated by default.
Definition: sampledPatch.H:93
const labelList & patchIndices() const
Definition: sampledPatch.C:81
virtual ~patch()
Destructor.
Definition: sampledPatch.C:75
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
Definition: sampledPatch.C:258
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
Definition: sampledPatch.C:270
virtual void movePoints()
Update for mesh point-motion.
Definition: sampledPatch.C:244
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
Definition: sampledPatch.C:264
virtual bool needsUpdate() const
Does the surface need an update?
Definition: sampledPatch.C:92
virtual bool update()
Update the surface as required.
Definition: sampledPatch.C:98
virtual void print(Ostream &) const
Write.
Definition: sampledPatch.C:276
patch(const word &name, const polyMesh &mesh, const wordReList &patchNames, const bool triangulate=false)
Construct from components.
Definition: sampledPatch.C:45
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
label patchi
const pointField & points
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.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
List< label > labelList
A List of labels.
Definition: labelList.H:56
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
FOR_ALL_FIELD_TYPES(makeDimensionedPointFieldFunctions)
bool notNull(const T &t)
Return true if t is not a reference to the nullObject of type T.
Definition: nullObjectI.H:64
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
error FatalError
wordList patchNames(nPatches)
#define IMPLEMENT_INTERPOLATE(Type, nullArg)
Definition: sampledPatch.C:231
#define IMPLEMENT_SAMPLE(Type, nullArg)
Definition: sampledPatch.C:209
dictionary dict
Foam::surfaceFields.