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-2019 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 GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
42 
43  if (foundObject<VolFieldType>(fieldName))
44  {
45  DebugInfo
46  << "readFields : " << VolFieldType::typeName
47  << " " << fieldName << " already in database"
48  << endl;
49  }
50  else if (foundObject<SurfaceFieldType>(fieldName))
51  {
52  DebugInfo
53  << "readFields: " << SurfaceFieldType::typeName
54  << " " << fieldName << " already exists in database"
55  << " already in database" << endl;
56  }
64  else
65  {
66  IOobject fieldHeader
67  (
68  fieldName,
69  mesh_.time().timeName(),
70  mesh_,
73  );
74 
75  if (fieldHeader.typeHeaderOk<VolFieldType>(true, true, false))
76  {
77  // Store field on mesh database
78  Log << " Reading " << fieldName << endl;
79  VolFieldType* fldPtr(new VolFieldType(fieldHeader, mesh_));
80  mesh_.objectRegistry::store(fldPtr);
81  return true;
82  }
83  else if (fieldHeader.typeHeaderOk<SurfaceFieldType>(true, true, false))
84  {
85  // Store field on mesh database
86  Log << " Reading " << fieldName << endl;
87  SurfaceFieldType* fldPtr(new SurfaceFieldType(fieldHeader, mesh_));
88  mesh_.objectRegistry::store(fldPtr);
89  return true;
90  }
105  }
106 
107  return false;
108 }
109 
110 
111 // ************************************************************************* //
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
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:764
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
surfaceFields.H
Foam::surfaceFields.
readFields.H
Time.H
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition: messageStream.H:350
Foam::functionObjects::readFields::loadField
bool loadField(const word &)
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:246
Foam::GeometricField< Type, fvPatchField, volMesh >
Log
#define Log
Report write to Foam::Info if the local log switch is true.
Definition: messageStream.H:332
Foam::IOobject::MUST_READ
Definition: IOobject.H:120