reconstructLagrangianFields.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 | Copyright (C) 2011-2016 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 
26 #include "IOField.H"
27 #include "CompactIOField.H"
28 #include "Time.H"
29 
30 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
31 
32 template<class Type>
34 (
35  const word& cloudName,
36  const polyMesh& mesh,
37  const PtrList<fvMesh>& meshes,
38  const word& fieldName
39 )
40 {
41  // Construct empty field on mesh
42  tmp<IOField<Type>> tfield
43  (
44  new IOField<Type>
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>(0)
56  )
57  );
58  Field<Type>& field = tfield.ref();
59 
60  forAll(meshes, i)
61  {
62  // Check object on local mesh
63  IOobject localIOobject
64  (
65  fieldName,
66  meshes[i].time().timeName(),
67  cloud::prefix/cloudName,
68  meshes[i],
69  IOobject::MUST_READ,
70  IOobject::NO_WRITE
71  );
72 
73  if (localIOobject.headerOk())
74  {
75  IOField<Type> fieldi(localIOobject);
76 
77  label offset = field.size();
78  field.setSize(offset + fieldi.size());
79 
80  forAll(fieldi, j)
81  {
82  field[offset + j] = fieldi[j];
83  }
84  }
85  }
86 
87  return tfield;
88 }
89 
90 
91 template<class Type>
94 (
95  const word& cloudName,
96  const polyMesh& mesh,
97  const PtrList<fvMesh>& meshes,
98  const word& fieldName
99 )
100 {
101  // Construct empty field on mesh
102  tmp<CompactIOField<Field<Type>, Type >> tfield
103  (
104  new CompactIOField<Field<Type>, Type>
105  (
106  IOobject
107  (
108  fieldName,
109  mesh.time().timeName(),
110  cloud::prefix/cloudName,
111  mesh,
112  IOobject::NO_READ,
113  IOobject::NO_WRITE
114  ),
115  Field<Field<Type>>(0)
116  )
117  );
118  Field<Field<Type>>& field = tfield.ref();
119 
120  forAll(meshes, i)
121  {
122  // Check object on local mesh
123  IOobject localIOobject
124  (
125  fieldName,
126  meshes[i].time().timeName(),
127  cloud::prefix/cloudName,
128  meshes[i],
129  IOobject::MUST_READ,
130  IOobject::NO_WRITE
131  );
132 
133  if (localIOobject.headerOk())
134  {
135  CompactIOField<Field<Type>, Type> fieldi(localIOobject);
136 
137  label offset = field.size();
138  field.setSize(offset + fieldi.size());
139 
140  forAll(fieldi, j)
141  {
142  field[offset + j] = fieldi[j];
143  }
144  }
145  }
146 
147  return tfield;
148 }
149 
150 
151 
152 template<class Type>
154 (
155  const word& cloudName,
156  const polyMesh& mesh,
157  const PtrList<fvMesh>& meshes,
158  const IOobjectList& objects,
159  const HashSet<word>& selectedFields
160 )
161 {
162  const word fieldClassName(IOField<Type>::typeName);
163 
164  IOobjectList fields = objects.lookupClass(fieldClassName);
165 
166  if (fields.size())
167  {
168  Info<< " Reconstructing lagrangian "
169  << fieldClassName << "s\n" << endl;
170 
171  forAllConstIter(IOobjectList, fields, fieldIter)
172  {
173  if
174  (
175  selectedFields.empty()
176  || selectedFields.found(fieldIter()->name())
177  )
178  {
179  Info<< " " << fieldIter()->name() << endl;
180  reconstructLagrangianField<Type>
181  (
182  cloudName,
183  mesh,
184  meshes,
185  fieldIter()->name()
186  )().write();
187  }
188  }
189 
190  Info<< endl;
191  }
192 }
193 
194 
195 template<class Type>
197 (
198  const word& cloudName,
199  const polyMesh& mesh,
200  const PtrList<fvMesh>& meshes,
201  const IOobjectList& objects,
202  const HashSet<word>& selectedFields
203 )
204 {
205  {
206  const word fieldClassName(CompactIOField<Field<Type>, Type>::typeName);
207 
208  IOobjectList fields = objects.lookupClass(fieldClassName);
209 
210  if (fields.size())
211  {
212  Info<< " Reconstructing lagrangian "
213  << fieldClassName << "s\n" << endl;
214 
215  forAllConstIter(IOobjectList, fields, fieldIter)
216  {
217  if
218  (
219  selectedFields.empty()
220  || selectedFields.found(fieldIter()->name())
221  )
222  {
223  Info<< " " << fieldIter()->name() << endl;
224  reconstructLagrangianFieldField<Type>
225  (
226  cloudName,
227  mesh,
228  meshes,
229  fieldIter()->name()
230  )().write();
231  }
232  }
233 
234  Info<< endl;
235  }
236  }
237 
238  {
239  const word fieldClassName(IOField<Field<Type>>::typeName);
240 
241  IOobjectList fields = objects.lookupClass(fieldClassName);
242 
243  if (fields.size())
244  {
245  Info<< " Reconstructing lagrangian "
246  << fieldClassName << "s\n" << endl;
247 
248  forAllConstIter(IOobjectList, fields, fieldIter)
249  {
250  if
251  (
252  selectedFields.empty()
253  || selectedFields.found(fieldIter()->name())
254  )
255  {
256  Info<< " " << fieldIter()->name() << endl;
257  reconstructLagrangianFieldField<Type>
258  (
259  cloudName,
260  mesh,
261  meshes,
262  fieldIter()->name()
263  )().write();
264  }
265  }
266 
267  Info<< endl;
268  }
269  }
270 }
271 
272 
273 // ************************************************************************* //
A HashTable with keys but without contents.
Definition: HashSet.H:59
IOobjectList lookupClass(const word &className) const
Return the list for all IOobjects of a given class.
Definition: IOobjectList.C:197
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:50
void reconstructLagrangianFields(const word &cloudName, const polyMesh &mesh, const PtrList< fvMesh > &meshes, const IOobjectList &objects, const HashSet< word > &selectedFields)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
const word cloudName(propsDict.lookup("cloudName"))
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:97
tmp< CompactIOField< Field< Type >, Type > > reconstructLagrangianFieldField(const word &cloudName, const polyMesh &mesh, const PtrList< fvMesh > &meshes, const word &fieldName)
dynamicFvMesh & mesh
Pre-declare SubField and related Field type.
Definition: Field.H:57
A class for handling words, derived from string.
Definition: word.H:59
tmp< IOField< Type > > reconstructLagrangianField(const word &cloudName, const polyMesh &mesh, const PtrList< fvMesh > &meshes, const word &fieldName)
word timeName
Definition: getTimeIndex.H:3
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
bool empty() const
Return true if the hash table is empty.
bool found(const Key &) const
Return true if hashedEntry is found in table.
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:62
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.
messageStream Info
virtual Ostream & write(const token &)=0
Write next token to stream.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
A class for managing temporary objects.
Definition: PtrList.H:54
void reconstructLagrangianFieldFields(const word &cloudName, const polyMesh &mesh, const PtrList< fvMesh > &meshes, const IOobjectList &objects, const HashSet< word > &selectedFields)
A primitive field of type <T> with automated input and output.
Definition: IOField.H:50