readFieldsTemplates.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-2016 OpenFOAM Foundation
9  Copyright (C) 2015-2020 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 "readFields.H"
30 #include "volFields.H"
31 #include "surfaceFields.H"
32 #include "Time.H"
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 template<class Type>
38 {
40  typedef typename VolFieldType::Internal IntVolFieldType;
41  typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
43 
44  if (foundObject<VolFieldType>(fieldName))
45  {
46  DebugInfo
47  << "readFields : " << VolFieldType::typeName
48  << " " << fieldName << " already in database"
49  << endl;
50  }
51  else if (foundObject<IntVolFieldType>(fieldName))
52  {
53  DebugInfo
54  << "readFields : " << IntVolFieldType::typeName
55  << " " << fieldName << " already in database"
56  << endl;
57  }
58  else if (foundObject<SurfaceFieldType>(fieldName))
59  {
60  DebugInfo
61  << "readFields: " << SurfaceFieldType::typeName
62  << " " << fieldName << " already exists in database"
63  << " already in database" << endl;
64  }
72  else
73  {
74  IOobject fieldHeader
75  (
76  fieldName,
77  mesh_.time().timeName(),
78  mesh_,
81  );
82 
83  if (fieldHeader.typeHeaderOk<VolFieldType>(true, true, false))
84  {
85  // Store field on mesh database
86  Log << " Reading " << fieldName << endl;
87  auto* fldPtr(new VolFieldType(fieldHeader, mesh_));
88  mesh_.objectRegistry::store(fldPtr);
89  return true;
90  }
91  else if (fieldHeader.typeHeaderOk<IntVolFieldType>(true, true, false))
92  {
93  // Store field on mesh database
94  Log << " Reading " << fieldName << endl;
95  auto* fldPtr(new IntVolFieldType(fieldHeader, mesh_));
96  mesh_.objectRegistry::store(fldPtr);
97  return true;
98  }
99  else if (fieldHeader.typeHeaderOk<SurfaceFieldType>(true, true, false))
100  {
101  // Store field on mesh database
102  Log << " Reading " << fieldName << endl;
103  auto* fldPtr(new SurfaceFieldType(fieldHeader, mesh_));
104  mesh_.objectRegistry::store(fldPtr);
105  return true;
106  }
121  }
122 
123  return false;
124 }
125 
126 
127 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
volFields.H
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Log
#define Log
Definition: PDRblock.C:34
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:785
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
surfaceFields.H
Foam::surfaceFields.
readFields.H
Time.H
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition: messageStream.H:354
Foam::functionObjects::readFields::loadField
bool loadField(const word &)
Load field.
Definition: readFieldsTemplates.C:37
Foam::functionObjects::fvMeshFunctionObject::mesh_
const fvMesh & mesh_
Reference to the fvMesh.
Definition: fvMeshFunctionObject.H:73
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:248
Foam::GeometricField< Type, fvPatchField, volMesh >
Foam::IOobject::MUST_READ
Definition: IOobject.H:120