LagrangianFieldReconstructor.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 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 
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
31 (
32  const fvMesh& completeFvMesh,
33  const PtrList<fvMesh>& procFvMeshes,
34  const labelListList& faceProcAddressing,
35  const labelListList& cellProcAddressing,
36  const word& LagrangianName
37 )
38 :
39  completeMesh_(completeFvMesh, LagrangianName, IOobject::NO_READ),
40  procMeshes_(procFvMeshes.size())
41 {
42  // Read the processor meshes
43  forAll(procMeshes_, proci)
44  {
45  procMeshes_.set
46  (
47  proci,
48  new LagrangianMesh(procFvMeshes[proci], LagrangianName)
49  );
50  }
51 
52  // Determine the size of the complete mesh
53  label completeSize = 0;
54  forAll(procMeshes_, proci)
55  {
56  completeSize += procMeshes_[proci].size();
57  }
58 
59  // Construct complete geometry and topology
60  barycentricField completeCoordinates(completeSize);
61  labelField completeCellIndices(completeSize, -1);
62  labelField completeFaceIndices(completeSize, -1);
63  labelField completeFaceTriIndices(completeSize, -1);
64  label i0 = 0;
65  forAll(procMeshes_, proci)
66  {
67  const label procSize = procMeshes_[proci].size();
68 
69  const labelField& procCelli = procMeshes_[proci].celli();
70  const labelField& procFacei = procMeshes_[proci].facei();
71 
72  SubList<barycentric>(completeCoordinates, procSize, i0) =
73  procMeshes_[proci].coordinates();
74  SubList<label>(completeCellIndices, procSize, i0) =
75  UIndirectList<label>(cellProcAddressing[proci], procCelli)();
76  SubList<label>(completeFaceIndices, procSize, i0) =
77  UIndirectList<label>(faceProcAddressing[proci], procFacei)();
78  SubList<label>(completeFaceTriIndices, procSize, i0) =
79  procMeshes_[proci].faceTrii();
80 
81  i0 += procMeshes_[proci].size();
82  }
83 
84  // If the owner has changed then the face will be numbered around in
85  // the opposite direction. Change the face triangle index accordingly.
86  const faceList& completeFaces = completeMesh_.mesh().faces();
87  forAll(completeCoordinates, i)
88  {
89  if (completeFaceIndices[i] < 0)
90  {
91  const label completeFacei = - completeFaceIndices[i] - 1;
92  const label completeFaceSize = completeFaces[completeFacei].size();
93 
94  completeFaceTriIndices[i] =
95  completeFaceSize - 1 - completeFaceTriIndices[i];
96  }
97  }
98 
99  // Remove the turning information to recover the actual face indices
100  completeFaceIndices = mag(completeFaceIndices) - 1;
101 
102  // Inject into the complete mesh
103  completeMesh_.inject
104  (
105  completeCoordinates,
106  completeCellIndices,
107  completeFaceIndices,
108  completeFaceTriIndices
109  );
110 }
111 
112 
113 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
114 
116 {}
117 
118 
119 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
120 
121 bool Foam::LagrangianFieldReconstructor::reconstructs
122 (
123  const IOobjectList& objects,
124  const HashSet<word>& selectedFields
125 )
126 {
127  bool result = false;
128 
129  #define RECONSTRUCTS_LAGRANGIAN_FIELDS_TYPE(Type, nullArg) \
130  result = \
131  result \
132  || reconstructs<LagrangianField<Type>> \
133  ( \
134  objects, \
135  selectedFields \
136  ) \
137  || reconstructs<LagrangianDynamicField<Type>> \
138  ( \
139  objects, \
140  selectedFields \
141  ) \
142  || reconstructs<LagrangianInternalField<Type>> \
143  ( \
144  objects, \
145  selectedFields \
146  ) \
147  || reconstructs<LagrangianInternalDynamicField<Type>> \
148  ( \
149  objects, \
150  selectedFields \
151  );
154  #undef RECONSTRUCTS_LAGRANGIAN_FIELDS_TYPE
155 
156  return result;
157 }
158 
159 
161 {
162  completeMesh_.write();
163 }
164 
165 
166 // ************************************************************************* //
#define RECONSTRUCTS_LAGRANGIAN_FIELDS_TYPE(Type, nullArg)
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
Pre-declare SubField and related Field type.
Definition: Field.H:83
A HashTable with keys but without contents.
Definition: HashSet.H:62
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:53
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
LagrangianFieldReconstructor(const fvMesh &completeFvMesh, const PtrList< fvMesh > &procFvMeshes, const labelListList &faceProcAddressing, const labelListList &cellProcAddressing, const word &LagrangianName)
Construct from components.
void reconstructPositions() const
Write the reconstructed positions.
Class containing Lagrangian geometry and topology.
LagrangianSubMesh inject(const barycentricField &coordinates, const labelField &celli, const labelField &facei, const labelField &faceTrii, const FieldNamesAndFields &... fieldNamesAndFields)
Inject specified elements into the mesh. This method does not.
const polyMesh & mesh() const
Access the mesh.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
A List obtained as a section of another List.
Definition: SubList.H:56
A List with indirect addressing.
Definition: UIndirectList.H:60
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:96
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1344
A class for handling words, derived from string.
Definition: word.H:62
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
void mag(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
FOR_ALL_FIELD_TYPES(makeFieldSourceTypedef)
objects