LagrangianFieldDecomposerTemplates.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::LagrangianFieldDecomposer::decomposes(const IOobjectList& objects)
34 {
35  return !objects.lookupClass(GeoField::typeName).empty();
36 }
37 
38 
39 template<class Type, template<class> class PrimitiveField>
41 <
43 >
44 Foam::LagrangianFieldDecomposer::decomposeLagrangianField
45 (
46  const DimensionedField<Type, LagrangianMesh, PrimitiveField>& completeField
47 ) const
48 {
49  PtrList<DimensionedField<Type, LagrangianMesh, PrimitiveField>>
50  procFields(procMeshes_.size());
51 
52  forAll(procMeshes_, proci)
53  {
54  procFields.set
55  (
56  proci,
57  new DimensionedField<Type, LagrangianMesh, PrimitiveField>
58  (
59  IOobject
60  (
61  completeField.name(),
62  procMeshes_[proci].time().name(),
63  procMeshes_[proci],
66  ),
67  procMeshes_[proci],
68  completeField.dimensions(),
69  PrimitiveField<Type>
70  (
71  completeField,
72  particleProcAddressing_[proci]
73  )
74  )
75  );
76  }
77 
78  return procFields;
79 }
80 
81 
82 template<class Type, template<class> class PrimitiveField>
84 <
86 >
87 Foam::LagrangianFieldDecomposer::decomposeLagrangianField
88 (
89  const GeometricField<Type, LagrangianMesh, PrimitiveField>& completeField
90 ) const
91 {
92  PtrList<GeometricField<Type, LagrangianMesh, PrimitiveField>>
93  procFields(procMeshes_.size());
94 
95  forAll(procMeshes_, proci)
96  {
97  // Construct a list of patch fields. Clone the global fields.
98  // Null-construct new processor-specific ones. Note that we supply the
99  // complete field as the internal field reference. This is a
100  // placeholder and will get replaced with the processor field when this
101  // set of patch fields is cloned to produce the final field.
102  PtrList<LagrangianPatchField<Type>> procPatchFields
103  (
104  procMeshes_[proci].boundary().size()
105  );
106  forAll(completeField.boundaryField(), completePatchi)
107  {
108  procPatchFields.set
109  (
110  completePatchi,
111  completeField.boundaryField()[completePatchi].clone
112  (
113  completeField
114  )
115  );
116  }
117  for
118  (
119  label procPatchi = completeMesh_.boundary().size();
120  procPatchi < procMeshes_[proci].boundary().size();
121  ++ procPatchi
122  )
123  {
124  procPatchFields.set
125  (
126  procPatchi,
128  (
129  procMeshes_[proci].boundary()[procPatchi].type(),
130  procMeshes_[proci].boundary()[procPatchi],
131  completeField
132  )
133  );
134  }
135 
136  // Construct the field
137  procFields.set
138  (
139  proci,
140  new GeometricField<Type, LagrangianMesh, PrimitiveField>
141  (
142  IOobject
143  (
144  completeField.name(),
145  procMeshes_[proci].time().name(),
146  procMeshes_[proci],
149  ),
150  procMeshes_[proci],
151  completeField.dimensions(),
152  PrimitiveField<Type>
153  (
154  completeField,
155  particleProcAddressing_[proci]
156  ),
157  procPatchFields,
158  completeField.sources().table()
159  )
160  );
161  }
162 
163  return procFields;
164 }
165 
166 
167 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
168 
169 template<class GeoField>
172 (
173  const IOobject& fieldIo
174 ) const
175 {
176  return
177  decomposeLagrangianField
178  (
179  GeoField
180  (
181  IOobject
182  (
183  fieldIo.name(),
184  completeMesh_.time().name(),
185  completeMesh_,
188  false
189  ),
190  completeMesh_
191  )
192  );
193 }
194 
195 
196 template<class GeoField>
198 (
199  const IOobjectList& objects
200 ) const
201 {
202  IOobjectList fields = objects.lookupClass(GeoField::typeName);
203 
204  if (fields.size())
205  {
206  Info<< nl << " Decomposing " << GeoField::typeName << "s"
207  << nl << endl;
208 
209  forAllConstIter(IOobjectList, fields, fieldIter)
210  {
211  Info<< " " << fieldIter()->name() << endl;
212 
213  const PtrList<GeoField> procFields =
214  decomposeField<GeoField>(*fieldIter());
215 
216  forAll(procFields, proci)
217  {
218  procFields[proci].write();
219  }
220  }
221  }
222 }
223 
224 
225 // ************************************************************************* //
#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.
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
void decomposeFields(const IOobjectList &objects) const
Read, decompose and write all Lagrangian fields.
PtrList< GeoField > decomposeField(const IOobject &) const
Read and decompose a field.
static autoPtr< LagrangianPatchField< Type > > New(const word &patchFieldType, const word &actualPatchType, const LagrangianPatch &p, const regIOobject &)
Return a pointer to a new LagrangianPatchField with a given type.
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
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
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
static const char nl
Definition: Ostream.H:267
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
faceListList boundary(nPatches)
objects