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 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
35template<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 (
47 (
48 fieldName,
49 mesh_.time().timeName(),
51 mesh_,
54 ),
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
90template<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 (
102 (
103 fieldName,
104 mesh_.time().timeName(),
106 mesh_,
109 ),
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 }
147
148 return tfield;
149}
150
151
152template<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
187template<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.sorted<fieldType>()
203 : objects.sorted<fieldType>(selectedFields)
204 )
205 );
206}
207
208
209template<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.append(objects.sorted<fieldType>());
225 fieldObjects.append(objects.sorted<fieldTypeB>());
226 }
227 else
228 {
229 fieldObjects.append(objects.sorted<fieldType>(selectedFields));
230 fieldObjects.append(objects.sorted<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// ************************************************************************* //
A Field of objects of type <T> with automated input and output using a compact storage....
Generic templated field type.
Definition: Field.H:82
A primitive field of type <T> with automated input and output.
Definition: IOField.H:58
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:59
UPtrList< const IOobject > sorted() const
The sorted list of IOobjects.
Definition: IOobjectList.C:336
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
bool isHeaderClass() const
Check if headerClassName() equals Type::typeName.
Definition: IOobjectI.H:156
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:65
bool typeHeaderOk(const bool checkType=true, const bool search=true, const bool verbose=true)
Read header (uses typeFilePath to find file) and check its info.
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
Definition: UListI.H:427
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: UPtrList.H:71
void append(T *ptr)
Append an element to the end of the list.
Definition: UPtrListI.H:197
static const word prefix
The prefix to local: lagrangian.
Definition: cloud.H:87
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:290
label reconstructFields(const word &cloudName, const UPtrList< const IOobject > &fieldObjects)
Reconstruct multiple fields for given cloud.
tmp< IOField< Type > > reconstructField(const word &cloudName, const word &fieldName)
Reconstruct a single field for given cloud.
label reconstructFieldFields(const word &cloudName, const IOobjectList &objects, const wordRes &selectedFields=wordRes())
Reconstruct multiple field-field for given cloud.
tmp< CompactIOField< Field< Type >, Type > > reconstructFieldField(const word &cloudName, const word &fieldName)
Reconstruct a single field-field for given cloud.
A class for managing temporary objects.
Definition: tmp.H:65
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
A class for handling words, derived from Foam::string.
Definition: word.H:68
rDeltaTY field()
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
void sort(UList< T > &list)
Sort the list.
Definition: UList.C:342
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
runTime write()
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
Extract name (as a word) from an object, typically using its name() method.
Definition: word.H:238
const word cloudName(propsDict.get< word >("cloud"))