LagrangianSubMesh.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) 2025-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 "LagrangianSubMesh.H"
27 #include "LagrangianSubFields.H"
28 #include "LagrangianMesh.H"
29 #include "tracking.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
36 }
37 
38 
39 // * * * * * * * * * * * * * * Private Constructors * * * * * * * * * * * * //
40 
41 Foam::LagrangianSubMesh::LagrangianSubMesh
42 (
43  const LagrangianMesh& mesh,
44  const LagrangianGroup group,
45  const label size,
46  const label start,
47  const uint64_t index
48 )
49 :
50  mesh_(mesh),
51  group_(group),
52  size_(size),
53  start_(start),
54  index_(index)
55 {}
56 
57 
58 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
59 
60 Foam::LagrangianSubMesh::LagrangianSubMesh
61 (
62  const LagrangianMesh& mesh,
63  const LagrangianGroup group,
64  const label size,
65  const label start
66 )
67 :
68  mesh_(mesh),
69  group_(group),
70  size_(size),
71  start_(start),
72  index_(mesh.subMeshIndex())
73 {}
74 
75 
76 Foam::LagrangianSubMesh::LagrangianSubMesh
77 (
78  const LagrangianMesh& mesh,
79  const labelList& groupOffsets,
81 )
82 :
83  mesh_(mesh),
84  group_(group),
85  size_
86  (
87  groupOffsets[static_cast<label>(group) + 1]
88  - groupOffsets[static_cast<label>(group)]
89  ),
90  start_(groupOffsets[static_cast<label>(group)]),
91  index_(mesh.subMeshIndex())
92 {}
93 
94 
95 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
96 
98 {}
99 
100 
101 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
102 
104 {
105  return mesh_;
106 }
107 
108 
110 {
111  return mesh_.time();
112 }
113 
114 
116 {
117  const word groupName = Foam::name(group());
118 
119  word fieldName = subFieldName;
120 
121  word::size_type subi = 0, i = 0;
122 
123  while (subi < subFieldName.size())
124  {
125  if
126  (
127  subFieldName[subi] != ':'
128  || subFieldName.size() < groupName.size() + subi + 1
129  || subFieldName(subi + 1, groupName.size()) != groupName
130  )
131  {
132  fieldName[i ++] = subFieldName[subi ++];
133  }
134  else
135  {
136  subi += groupName.size() + 1;
137  }
138  }
139 
140  return fieldName(i);
141 }
142 
143 
144 template<>
146 (
148 )
149 {
150  const LagrangianSubMesh& subMesh = fraction.mesh();
151 
152  tmp<vectorField> tnf(new vectorField(subMesh.size()));
153  vectorField& nf = tnf.ref();
154 
155  forAll(subMesh, subi)
156  {
157  nf[subi] =
159  (
160  subMesh.mesh().poly(),
161  subMesh.mesh().coordinates()[subi + subMesh.start()],
162  subMesh.mesh().celli()[subi + subMesh.start()],
163  subMesh.mesh().facei()[subi + subMesh.start()],
164  subMesh.mesh().faceTrii()[subi + subMesh.start()],
165  fraction[subi]
166  ).first();
167  }
168 
169  return tnf;
170 }
171 
172 
173 template<>
175 (
177 )
178 {
179  const LagrangianSubMesh& subMesh = fraction.mesh();
180 
181  return
183  (
184  subMesh.sub("nf"),
185  subMesh,
186  dimless,
187  nf<vectorField>(fraction)
188  );
189 }
190 
191 
192 template<>
194 (
196 ) const
197 {
198  tmp<vectorField> tnf(new vectorField(size()));
199  vectorField& nf = tnf.ref();
200 
201  forAll(*this, subi)
202  {
203  nf[subi] =
205  (
206  mesh().poly(),
207  mesh().coordinates()[subi + start()],
208  mesh().celli()[subi + start()],
209  mesh().facei()[subi + start()],
210  mesh().faceTrii()[subi + start()],
211  fraction[subi + start()]
212  ).first();
213  }
214 
215  return tnf;
216 }
217 
218 
219 template<>
221 (
223 ) const
224 {
225  return
227  (
228  sub("nf"),
229  *this,
230  dimless,
231  nf<vectorField>(fraction)
232  );
233 }
234 
235 
236 template<>
238 (
240 )
241 {
242  const LagrangianSubMesh& subMesh = fraction.mesh();
243 
244  tmp<vectorField> tUf(new vectorField(subMesh.size()));
245  vectorField& Uf = tUf.ref();
246 
247  forAll(subMesh, subi)
248  {
249  Uf[subi] =
251  (
252  subMesh.mesh().poly(),
253  subMesh.mesh().coordinates()[subi + subMesh.start()],
254  subMesh.mesh().celli()[subi + subMesh.start()],
255  subMesh.mesh().facei()[subi + subMesh.start()],
256  subMesh.mesh().faceTrii()[subi + subMesh.start()],
257  fraction[subi]
258  ).second()/subMesh.mesh().time().deltaTValue();
259  }
260 
261  return tUf;
262 }
263 
264 
265 template<>
267 (
269 )
270 {
271  const LagrangianSubMesh& subMesh = fraction.mesh();
272 
273  return
275  (
276  subMesh.sub("Uf"),
277  subMesh,
278  dimVelocity,
279  Uf<vectorField>(fraction)
280  );
281 }
282 
283 
284 template<>
286 (
288 ) const
289 {
290  tmp<vectorField> tUf(new vectorField(size()));
291  vectorField& Uf = tUf.ref();
292 
293  forAll(*this, subi)
294  {
295  Uf[subi] =
297  (
298  mesh().poly(),
299  mesh().coordinates()[subi + start()],
300  mesh().celli()[subi + start()],
301  mesh().facei()[subi + start()],
302  mesh().faceTrii()[subi + start()],
303  fraction[subi + start()]
304  ).second()/mesh().time().deltaTValue();
305  }
306 
307  return tUf;
308 }
309 
310 
311 template<>
313 (
315 ) const
316 {
317  return
319  (
320  sub("Uf"),
321  *this,
322  dimVelocity,
323  Uf<vectorField>(fraction)
324  );
325 }
326 
327 
328 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
329 
331 {
332  if (&mesh_ != &subMesh.mesh_)
333  {
335  << "Cannot combine sub-meshes which relate to different meshes"
336  << exit(FatalError);
337  }
338 
339  if (group_ != subMesh.group_)
340  {
342  << "Cannot combine sub-meshes with different groups "
343  << exit(FatalError);
344  }
345 
346  if (size_ + start_ != subMesh.start_)
347  {
349  << "Cannot combine sub-meshes that are not contiguous"
350  << exit(FatalError);
351  }
352 
353  size_ += subMesh.size_;
354 }
355 
356 
357 // ************************************************************************* //
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:73
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
static tmp< DimensionedField< Type, GeoMesh, PrimitiveField > > New(const word &name, const GeoMesh &mesh, const dimensionSet &, const PrimitiveField< Type > &)
Return a temporary field constructed from name, mesh,.
Class containing Lagrangian geometry and topology.
const Time & time() const
Return time.
const labelIODynamicField & faceTrii() const
Access the face-tet indices.
const labelIODynamicField & celli() const
Access the cell indices.
const polyMesh & poly() const
Access the poly mesh.
const barycentricIODynamicField & coordinates() const
Access the coordinates.
const labelIODynamicField & facei() const
Access the cell-face indices.
Mesh that relates to a sub-section of a Lagrangian mesh. This is used to construct fields that relate...
const Time & time() const
Return time.
static tmp< FieldType > nf(const LagrangianSubScalarSubField &fraction)
Return the face normals at the Lagrangian locations.
label size() const
Return size.
const objectRegistry & db() const
Return the object registry.
void operator+=(const LagrangianSubMesh &)
Add a sub-mesh to this one. Must relate to adjacent elements.
static tmp< FieldType > Uf(const LagrangianSubScalarSubField &fraction)
Return the face velocities at the Lagrangian locations.
word complete(const word &subFieldName) const
Return the name of a field corresponding to the complete mesh.
const LagrangianMesh & mesh() const
Return the mesh.
word sub(const word &fieldName) const
Return the name of a field corresponding to this sub-mesh.
label start() const
Return start.
scalar deltaTValue() const
Return time step value.
Definition: TimeStateI.H:34
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:433
Registry of regIOobjects.
const Time & time() const
Return time.
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 char *const group
Group name for atomic constants.
barycentric coordinates(const polyMesh &mesh, const point &position, const label celli, const label facei, const label faceTrii, const scalar stepFraction)
Return the coordinates given the position and tet topology.
Definition: tracking.C:1258
Pair< vector > faceNormalAndDisplacement(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label facei, const label faceTrii, const scalar stepFraction)
Return the normal of the corresponding point on the associated face and.
Definition: tracking.C:1301
const unitSet fraction
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
const dimensionSet & dimless
Definition: dimensions.C:138
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
const dimensionSet & dimVelocity
Definition: dimensions.C:154
Field< vector > vectorField
Specialisation of Field<T> for vector.
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
LagrangianGroup
Lagrangian group enumeration.
error FatalError
defineTypeNameAndDebug(atmosphericBoundaryLayer, 0)