All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2018 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 "GeometricField.H"
27 #include "readFields.H"
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 template<class Type, template<class> class PatchField, class GeoMesh>
33 (
34  const typename GeoMesh::Mesh& mesh,
35  const IOobjectList& objects,
36  PtrList<GeometricField<Type, PatchField, GeoMesh>>& fields,
37  const bool readOldTime
38 )
39 {
40  typedef GeometricField<Type, PatchField, GeoMesh> GeoField;
41 
42  // Search list of objects for fields of type GeomField
43  IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName));
44 
45  // Remove the cellDist field
46  IOobjectList::iterator celDistIter = fieldObjects.find("cellDist");
47  if (celDistIter != fieldObjects.end())
48  {
49  fieldObjects.erase(celDistIter);
50  }
51 
52  // Get sorted set of names (different processors might read objects in
53  // different order)
54  const wordList masterNames(fieldObjects.sortedNames());
55 
56  // Construct the fields
57  fields.setSize(masterNames.size());
58 
59  forAll(masterNames, i)
60  {
61  const IOobject& io = *fieldObjects[masterNames[i]];
62 
63  fields.set(i, new GeoField(io, mesh, readOldTime));
64  }
65 }
66 
67 
68 template<class Mesh, class GeoField>
70 (
71  const Mesh& mesh,
72  const IOobjectList& objects,
73  PtrList<GeoField>& fields
74 )
75 {
76  // Search list of objects for fields of type GeomField
77  IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName));
78 
79  // Construct the fields
80  fields.setSize(fieldObjects.size());
81 
82  // Get sorted set of names (different processors might read objects in
83  // different order)
84  const wordList masterNames(fieldObjects.sortedNames());
85 
86  // Construct the fields
87  fields.setSize(masterNames.size());
88 
89  forAll(masterNames, i)
90  {
91  const IOobject& io = *fieldObjects[masterNames[i]];
92 
93  fields.set(i, new GeoField(io, mesh));
94  }
95 }
96 
97 
98 // ************************************************************************* //
#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