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) 2011-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 "IOobjectList.H"
28 #include "CompactIOField.H"
29 #include "cloud.H"
30 
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 
33 template<class FieldType>
34 bool Foam::lagrangianFieldReconstructor::reconstructs
35 (
36  const IOobjectList& objects,
37  const HashSet<word>& selectedFields
38 )
39 {
40  IOobjectList fields = objects.lookupClass(FieldType::typeName);
41 
42  if (fields.size() && selectedFields.empty())
43  {
44  return true;
45  }
46 
47  forAllConstIter(IOobjectList, fields, fieldIter)
48  {
49  if (selectedFields.found(fieldIter()->name()))
50  {
51  return true;
52  }
53  }
54 
55  return false;
56 }
57 
58 
59 template
60 <
61  class Type,
62  template<class> class ReadIOContainer,
63  template<class> class IOContainer
64 >
65 void Foam::lagrangianFieldReconstructor::reconstructFields
66 (
67  const IOobjectList& objects,
68  const HashSet<word>& selectedFields
69 ) const
70 {
71  const word& fieldClassName = ReadIOContainer<Type>::typeName;
72 
73  IOobjectList fields = objects.lookupClass(fieldClassName);
74 
75  if (fields.size())
76  {
77  Info<< nl << " Reconstructing lagrangian "
78  << fieldClassName << "s" << nl << endl;
79 
80  forAllConstIter(IOobjectList, fields, fieldIter)
81  {
82  if
83  (
84  selectedFields.empty()
85  || selectedFields.found(fieldIter()->name())
86  )
87  {
88  Info<< " " << fieldIter()->name() << endl;
89 
90  reconstructField<Type, ReadIOContainer, IOContainer>
91  (
92  *fieldIter()
93  )().write();
94  }
95  }
96  }
97 }
98 
99 
100 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
101 
102 template
103 <
104  class Type,
105  template<class> class ReadIOContainer,
106  template<class> class IOContainer
107 >
110 (
111  const IOobject& fieldIoObject
112 ) const
113 {
114  // Construct the complete field
115  tmp<IOContainer<Type>> tfield
116  (
117  new IOContainer<Type>
118  (
119  IOobject
120  (
121  fieldIoObject.name(),
122  completeMesh_.time().name(),
123  lagrangian::cloud::prefix/cloudName_,
124  completeMesh_,
127  ),
128  Field<Type>(0)
129  )
130  );
131  Field<Type>& field = tfield.ref();
132 
133  // Combine the processor fields into the complete field
134  forAll(procMeshes_, proci)
135  {
137  (
138  fieldIoObject.name(),
139  procMeshes_[proci].time().name(),
140  lagrangian::cloud::prefix/cloudName_,
141  procMeshes_[proci],
144  );
145 
146  if (localIOobject.headerOk())
147  {
148  IOContainer<Type> fieldi(localIOobject);
149 
150  label offset = field.size();
151  field.setSize(offset + fieldi.size());
152 
153  forAll(fieldi, j)
154  {
155  field[offset + j] = fieldi[j];
156  }
157  }
158  }
159 
160  return tfield;
161 }
162 
163 
164 template<class Type>
165 void Foam::lagrangianFieldReconstructor::reconstructFields
166 (
167  const IOobjectList& o,
168  const HashSet<word>& sf
169 ) const
170 {
171  reconstructFields<Type, IOField, IOField>(o, sf);
172  reconstructFields<Field<Type>, IOField, CompactIOField>(o, sf);
173  reconstructFields<Field<Type>, CompactIOField, CompactIOField>(o, sf);
174 }
175 
176 
177 // ************************************************************************* //
#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
A Field of objects of type <Type> with automated input and output using a compact storage....
Pre-declare SubField and related Field type.
Definition: Field.H:83
A HashTable with keys but without contents.
Definition: HashSet.H:62
A primitive field of type <Type> with automated input and output.
Definition: IOField.H:53
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 size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
void setSize(const label)
Reset size of List.
Definition: List.C:281
tmp< IOContainer< Type > > reconstructField(const IOobject &fieldIoObject) const
Read and reconstruct a field.
static const word prefix
The prefix to local: lagrangian.
Definition: cloud.H:69
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
Templated form of IOobject providing type information for file reading and header type checking.
Definition: IOobject.H:530
bool headerOk()
Read header (uses typeGlobalFile to find file) and check.
volScalarField sf(fieldObject, mesh)
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.
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
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
void offset(label &lst, const label o)
static const char nl
Definition: Ostream.H:267
objects