lagrangianReconstructorTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2018-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "IOField.H"
30 #include "CompactIOField.H"
31 #include "Time.H"
32 
33 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
34 
35 template<class Type>
38 (
39  const word& cloudName,
40  const word& fieldName
41 )
42 {
43  // Construct empty field on mesh
44  auto tfield = tmp<IOField<Type>>::New
45  (
46  IOobject
47  (
48  fieldName,
49  mesh_.time().timeName(),
51  mesh_,
54  ),
55  Field<Type>()
56  );
57  auto& field = tfield.ref();
58 
59  for (const fvMesh& localMesh : procMeshes_)
60  {
61  // Check object on local mesh
62  IOobject localIOobject
63  (
64  fieldName,
65  localMesh.time().timeName(),
67  localMesh,
70  );
71 
72  if (localIOobject.typeHeaderOk<IOField<Type>>(true))
73  {
74  IOField<Type> localField(localIOobject);
75 
76  const label offset = field.size();
77  field.setSize(offset + localField.size());
78 
79  forAll(localField, j)
80  {
81  field[offset + j] = localField[j];
82  }
83  }
84  }
85 
86  return tfield;
87 }
88 
89 
90 template<class Type>
93 (
94  const word& cloudName,
95  const word& fieldName
96 )
97 {
98  // Construct empty field on mesh
99  auto tfield = tmp<CompactIOField<Field<Type>, Type>>::New
100  (
101  IOobject
102  (
103  fieldName,
104  mesh_.time().timeName(),
106  mesh_,
109  ),
110  Field<Field<Type>>()
111  );
112  auto& field = tfield.ref();
113 
114  for (const fvMesh& localMesh : procMeshes_)
115  {
116  // Check object on local mesh
117  IOobject localIOobject
118  (
119  fieldName,
120  localMesh.time().timeName(),
122  localMesh,
125  );
126 
127  if
128  (
129  localIOobject.typeHeaderOk<CompactIOField<Field<Type>, Type>>
130  (
131  false
132  )
133  || localIOobject.typeHeaderOk<IOField<Field<Type>>>(false)
134  )
135  {
136  CompactIOField<Field<Type>, Type> localField(localIOobject);
137 
138  const label offset = field.size();
139  field.setSize(offset + localField.size());
140 
141  forAll(localField, j)
142  {
143  field[offset + j] = localField[j];
144  }
145  }
146  }
148  return tfield;
149 }
150 
151 
152 template<class Type>
154 (
155  const word& cloudName,
156  const UPtrList<const IOobject>& fieldObjects
157 )
158 {
159  typedef IOField<Type> fieldType;
160 
161  label nFields = 0;
162 
163  for (const IOobject& io : fieldObjects)
164  {
165  if (io.isHeaderClass<fieldType>())
166  {
167  if (verbose_)
168  {
169  if (!nFields)
170  {
171  Info<< " Reconstructing lagrangian "
172  << fieldType::typeName << "s\n" << nl;
173  }
174  Info<< " " << io.name() << endl;
175  }
176  ++nFields;
177 
178  reconstructField<Type>(cloudName, io.name())().write();
179  }
180  }
181 
182  if (verbose_ && nFields) Info<< endl;
183  return nFields;
184 }
185 
186 
187 template<class Type>
189 (
190  const word& cloudName,
191  const IOobjectList& objects,
192  const wordRes& selectedFields
193 )
194 {
195  typedef IOField<Type> fieldType;
196 
197  return reconstructFields<Type>
198  (
199  cloudName,
200  (
201  selectedFields.empty()
202  ? objects.csorted<fieldType>()
203  : objects.csorted<fieldType>(selectedFields)
204  )
205  );
206 }
207 
208 
209 template<class Type>
211 (
212  const word& cloudName,
213  const IOobjectList& objects,
214  const wordRes& selectedFields
215 )
216 {
217  typedef CompactIOField<Field<Type>, Type> fieldType;
218  typedef IOField<Field<Type>> fieldTypeB;
219 
220  UPtrList<const IOobject> fieldObjects;
221 
222  if (selectedFields.empty())
223  {
224  fieldObjects.push_back(objects.csorted<fieldType>());
225  fieldObjects.push_back(objects.csorted<fieldTypeB>());
226  }
227  else
228  {
229  fieldObjects.push_back(objects.csorted<fieldType>(selectedFields));
230  fieldObjects.push_back(objects.csorted<fieldTypeB>(selectedFields));
231  }
232 
233  Foam::sort(fieldObjects, nameOp<IOobject>());
234 
235  label nFields = 0;
236  for (const IOobject& io : fieldObjects)
237  {
238  if (verbose_)
239  {
240  if (!nFields)
241  {
242  Info<< " Reconstructing lagrangian "
243  << fieldType::typeName << "s\n" << nl;
244  }
245  Info<< " " << io.name() << endl;
246  }
247  ++nFields;
248 
249  reconstructFieldField<Type>(cloudName, io.name())().write();
250  }
251 
252  if (verbose_ && nFields) Info<< endl;
253  return nFields;
254 }
255 
256 
257 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
label reconstructFieldFields(const word &cloudName, const IOobjectList &objects, const wordRes &selectedFields=wordRes())
Reconstruct multiple field-field for given cloud.
rDeltaTY field()
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable, so the various sorted methods should be used if traversing in parallel.
Definition: IOobjectList.H:55
tmp< CompactIOField< Field< Type >, Type > > reconstructFieldField(const word &cloudName, const word &fieldName)
Reconstruct a single field-field for given cloud.
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:195
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Definition: UList.H:666
tmp< IOField< Type > > reconstructField(const word &cloudName, const word &fieldName)
Reconstruct a single field for given cloud.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
Ignore writing from objectRegistry::writeObject()
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:360
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
Generic templated field type.
Definition: Field.H:62
const word cloudName(propsDict.get< word >("cloud"))
A class for handling words, derived from Foam::string.
Definition: word.H:63
void push_back(T *ptr)
Append an element to the end of the list.
Definition: UPtrListI.H:265
void sort(UList< T > &list)
Sort the list.
Definition: UList.C:296
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:53
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: HashTable.H:106
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value formatted with the given precision.
Definition: Time.C:714
A Field of objects of type <T> with automated input and output using a compact storage. Behaves like IOField except when binary output in case it writes a CompactListList.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Nothing to be read.
messageStream Info
Information stream (stdout output on master, null elsewhere)
label reconstructFields(const word &cloudName, const UPtrList< const IOobject > &fieldObjects)
Reconstruct multiple fields for given cloud.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
UPtrList< const IOobject > csorted() const
The sorted list of IOobjects with headerClassName == Type::typeName.
A primitive field of type <T> with automated input and output.
bool isHeaderClass() const
Check if headerClassName() equals Type::typeName.
Definition: IOobjectI.H:258
static const word prefix
The prefix to local: lagrangian.
Definition: cloud.H:79