lagrangianReconstructorFields.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 -------------------------------------------------------------------------------
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(),
50  cloud::prefix/cloudName,
51  mesh_,
52  IOobject::NO_READ,
53  IOobject::NO_WRITE
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(),
66  cloud::prefix/cloudName,
67  localMesh,
68  IOobject::MUST_READ,
69  IOobject::NO_WRITE
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(),
105  cloud::prefix/cloudName,
106  mesh_,
107  IOobject::NO_READ,
108  IOobject::NO_WRITE
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(),
121  cloud::prefix/cloudName,
122  localMesh,
123  IOobject::MUST_READ,
124  IOobject::NO_WRITE
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 
152 template<class Type>
154 (
155  const word& cloudName,
156  const IOobjectList& objects,
157  const UList<word>& fieldNames
158 )
159 {
160  typedef IOField<Type> fieldType;
161 
162  label nFields = 0;
163  for (const word& fieldName : fieldNames)
164  {
165  const IOobject* io = objects.cfindObject<fieldType>(fieldName);
166  if (io)
167  {
168  if (nFields++)
169  {
170  Info<< " Reconstructing lagrangian "
171  << fieldType::typeName << "s\n" << nl;
172  }
173  Info<< " " << fieldName << endl;
174 
175  reconstructField<Type>(cloudName, fieldName)().write();
176  }
177  }
178 
179  if (nFields) Info<< endl;
180  return nFields;
181 }
182 
183 
184 template<class Type>
186 (
187  const word& cloudName,
188  const IOobjectList& objects,
189  const wordRes& selectedFields
190 )
191 {
192  typedef IOField<Type> fieldType;
193 
194  const wordList fieldNames =
195  (
196  selectedFields.empty()
197  ? objects.sortedNames<fieldType>()
198  : objects.sortedNames<fieldType>(selectedFields)
199  );
200 
201  return reconstructFields<Type>(cloudName, objects, fieldNames);
202 }
203 
204 
205 template<class Type>
207 (
208  const word& cloudName,
209  const IOobjectList& objects,
210  const wordRes& selectedFields
211 )
212 {
213  typedef CompactIOField<Field<Type>, Type> fieldType;
214 
216  (
217  selectedFields.empty()
218  ? objects.names<fieldType>()
219  : objects.names<fieldType>(selectedFields)
220  );
221 
222  // Append IOField Field names
223  fieldNames.append
224  (
225  objects.empty()
226  ? objects.names<IOField<Field<Type>>>()
227  : objects.names<IOField<Field<Type>>>(selectedFields)
228  );
229 
231 
232  label nFields = 0;
233  for (const word& fieldName : fieldNames)
234  {
235  if (!nFields++)
236  {
237  Info<< " Reconstructing lagrangian "
238  << fieldType::typeName << "s\n" << nl;
239  }
240  Info<< " " << fieldName << endl;
241 
242  reconstructFieldField<Type>(cloudName, fieldName)().write();
243  }
244 
245  if (nFields) Info<< endl;
246  return nFields;
247 }
248 
249 
250 // ************************************************************************* //
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::lagrangianReconstructor::reconstructFieldField
tmp< CompactIOField< Field< Type >, Type > > reconstructFieldField(const word &cloudName, const word &fieldName)
Reconstruct a single field-field for given cloud.
cloudName
const word cloudName(propsDict.get< word >("cloud"))
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::IOField
A primitive field of type <T> with automated input and output.
Definition: foamVtkLagrangianWriter.H:61
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::lagrangianReconstructor::reconstructFieldFields
label reconstructFieldFields(const word &cloudName, const IOobjectList &objects, const wordRes &selectedFields=wordRes())
Reconstruct multiple field-field for given cloud.
Foam::IOobjectList::sortedNames
wordList sortedNames() const
The sorted names of the IOobjects.
Definition: IOobjectList.C:345
Foam::lagrangianReconstructor::reconstructFields
label reconstructFields(const word &cloudName, const IOobjectList &objects, const UList< word > &fieldNames)
Reconstruct multiple fields for given cloud.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::CompactIOField
A Field of objects of type <T> with automated input and output using a compact storage....
Definition: CompactIOField.H:53
Foam::IOobjectList::names
wordList names() const
The names of the IOobjects.
Definition: IOobjectList.C:310
Foam::lagrangianReconstructor::reconstructField
tmp< IOField< Type > > reconstructField(const word &cloudName, const word &fieldName)
Reconstruct a single field for given cloud.
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::sort
void sort(UList< T > &a)
Definition: UList.C:261
Foam::IOobjectList::cfindObject
const IOobject * cfindObject(const word &objName) const
Return const pointer to the object found by name.
Definition: IOobjectList.C:245
field
rDeltaTY field()
fieldNames
const wordRes fieldNames(propsDict.getOrDefault< wordRes >("fields", wordRes()))
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:55
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Time.H
Foam::nl
constexpr char nl
Definition: Ostream.H:404
IOField.H
Foam::List< word >
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:36
CompactIOField.H