LagrangianFieldReconstructorTemplates.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 #include "LagrangianFields.H"
28 #include "IOobjectList.H"
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 template<class GeoField>
33 bool Foam::LagrangianFieldReconstructor::reconstructs
34 (
35  const IOobjectList& objects,
36  const HashSet<word>& selectedFields
37 )
38 {
39  IOobjectList fields = objects.lookupClass(GeoField::typeName);
40 
41  if (fields.size() && selectedFields.empty())
42  {
43  return true;
44  }
45 
46  forAllConstIter(IOobjectList, fields, fieldIter)
47  {
48  if (selectedFields.found(fieldIter()->name()))
49  {
50  return true;
51  }
52  }
53 
54  return false;
55 }
56 
57 
58 template
59 <
60  class Type,
61  template<class> class PrimitiveField,
62  template<class, class, template<class> class> class GeoField
63 >
64 Foam::tmp<PrimitiveField<Type>>
65 Foam::LagrangianFieldReconstructor::reconstructLagrangianPrimitiveField
66 (
67  const PtrList<GeoField<Type, LagrangianMesh, PrimitiveField>>&
68  procFields
69 ) const
70 {
72  (
73  new PrimitiveField<Type>(completeMesh_.size())
74  );
75  PrimitiveField<Type>& result = tresult.ref();
76 
77  // Expand dynamic primitive fields to their full size
78  result.setSize(completeMesh_.size());
79 
80  label i0 = 0;
81  forAll(procMeshes_, proci)
82  {
83  SubList<Type>(result, procMeshes_[proci].size(), i0) =
84  procFields[proci].primitiveField();
85 
86  i0 += procMeshes_[proci].size();
87  }
88 
89  return tresult;
90 }
91 
92 
93 template<class Type, template<class> class PrimitiveField>
95 Foam::LagrangianFieldReconstructor::reconstructLagrangianField
96 (
98  procFields
99 ) const
100 {
101  return
103  (
105  (
106  IOobject
107  (
108  procFields[0].name(),
109  completeMesh_.time().name(),
110  completeMesh_,
113  ),
114  completeMesh_,
115  procFields[0].dimensions(),
116  reconstructLagrangianPrimitiveField(procFields)()
117  )
118  );
119 }
120 
121 
122 template<class Type, template<class> class PrimitiveField>
124 Foam::LagrangianFieldReconstructor::reconstructLagrangianField
125 (
127  procFields
128 ) const
129 {
130  // Construct a list of patch fields. Clone the global fields. Ignore
131  // processor-specific ones. Note that we supply the processor-zero field as
132  // the internal field reference. This is a placeholder and will get
133  // replaced by the complete field when this set of patch fields is cloned
134  // to produce the final field.
135  PtrList<LagrangianPatchField<Type>> completePatchFields
136  (
137  completeMesh_.boundary().size()
138  );
139  forAll(completeMesh_.boundary(), completePatchi)
140  {
141  completePatchFields.set
142  (
143  completePatchi,
144  procFields[0].boundaryField()[completePatchi].clone
145  (
146  procFields[0]
147  )
148  );
149  }
150 
151  // Construct and return the complete field
152  return
154  (
156  (
157  IOobject
158  (
159  procFields[0].name(),
160  completeMesh_.time().name(),
161  completeMesh_,
164  ),
165  completeMesh_,
166  procFields[0].dimensions(),
167  reconstructLagrangianPrimitiveField(procFields)(),
168  completePatchFields,
169  procFields[0].sources().table()
170  )
171  );
172 }
173 
174 
175 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
176 
177 template<class GeoField>
180 (
181  const IOobject& fieldIo
182 ) const
183 {
184  // Read the fields from all the processors
185  PtrList<GeoField> procFields(procMeshes_.size());
186  forAll(procMeshes_, proci)
187  {
188  procFields.set
189  (
190  proci,
191  new GeoField
192  (
193  IOobject
194  (
195  fieldIo.name(),
196  procMeshes_[proci].time().name(),
197  procMeshes_[proci],
200  false
201  ),
202  procMeshes_[proci]
203  )
204  );
205  }
206 
207  // Reconstruct and return
208  return reconstructLagrangianField(procFields);
209 }
210 
211 
212 template<class GeoField>
214 (
215  const IOobjectList& objects,
216  const HashSet<word>& selectedFields
217 ) const
218 {
219  IOobjectList fields = objects.lookupClass(GeoField::typeName);
220 
221  if (fields.size())
222  {
223  Info<< nl << " Reconstructing " << GeoField::typeName << "s"
224  << nl << endl;
225 
226  forAllConstIter(IOobjectList, fields, fieldIter)
227  {
228  if
229  (
230  selectedFields.empty()
231  || selectedFields.found(fieldIter()->name())
232  )
233  {
234  Info<< " " << fieldIter()->name() << endl;
235 
236  reconstructField<GeoField>(*fieldIter())().write();
237  }
238  }
239  }
240 }
241 
242 
243 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:476
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Generic GeometricField class.
A HashTable with keys but without contents.
Definition: HashSet.H:62
bool empty() const
Return true if the hash table is empty.
Definition: HashTableI.H:72
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:138
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
const word & name() const
Return name.
Definition: IOobject.H:307
tmp< GeoField > reconstructField(const IOobject &) const
Read and reconstruct a field.
void reconstructFields(const IOobjectList &objects, const HashSet< word > &selectedFields) const
Read, reconstruct and write all/selected Lagrangian fields.
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
bool set(const label) const
Is element set.
Definition: PtrListI.H:62
label size() const
Return the number of elements in the UList.
Definition: UListI.H:311
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
Info<< "Calculating turbulent flame speed field St\n"<< endl;volScalarField St(IOobject("St", runTime.name(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), flameWrinkling->Xi() *Su);multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:234
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
Namespace for OpenFOAM.
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:258
messageStream Info
T clone(const T &t)
Definition: List.H:55
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
static const char nl
Definition: Ostream.H:267
objects