readFields.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-2021 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 "readFields.H"
27 
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
30 template<class Type, template<class> class PatchField, class GeoMesh>
32 (
33  const typename GeoMesh::Mesh& mesh,
34  const IOobjectList& objects,
35  PtrList<GeometricField<Type, PatchField, GeoMesh>>& fields,
36  const bool readOldTime
37 )
38 {
39  typedef GeometricField<Type, PatchField, GeoMesh> GeoField;
40 
41  // Search list of objects for fields of type GeomField
42  IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName));
43 
44  // Remove the cellDist field
45  IOobjectList::iterator celDistIter = fieldObjects.find("cellDist");
46  if (celDistIter != fieldObjects.end())
47  {
48  fieldObjects.erase(celDistIter);
49  }
50 
51  // Get sorted set of names (different processors might read objects in
52  // different order)
53  const wordList masterNames(fieldObjects.sortedNames());
54 
55  // Construct the fields
56  fields.setSize(masterNames.size());
57 
58  forAll(masterNames, i)
59  {
60  const IOobject& io = *fieldObjects[masterNames[i]];
61 
62  fields.set(i, new GeoField(io, mesh, readOldTime));
63  }
64 }
65 
66 
67 template<class Mesh, class GeoField>
69 (
70  const Mesh& mesh,
71  const IOobjectList& objects,
72  PtrList<GeoField>& fields
73 )
74 {
75  // Search list of objects for fields of type GeomField
76  IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName));
77 
78  // Construct the fields
79  fields.setSize(fieldObjects.size());
80 
81  // Get sorted set of names (different processors might read objects in
82  // different order)
83  const wordList masterNames(fieldObjects.sortedNames());
84 
85  // Construct the fields
86  fields.setSize(masterNames.size());
87 
88  forAll(masterNames, i)
89  {
90  const IOobject& io = *fieldObjects[masterNames[i]];
91 
92  fields.set(i, new GeoField(io, mesh));
93  }
94 }
95 
96 
97 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const HashSet< word > &selectedFields, LIFOStack< regIOobject *> &storedObjects)
Read the selected GeometricFields of the specified type.
Definition: ReadFields.C:244
List< word > wordList
A List of words.
Definition: fileName.H:54
void setSize(const label)
Reset size of List.
Definition: List.C:281