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 | Copyright (C) 2011 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
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 #include "volFields.H"
28 #include "surfaceFields.H"
29 #include "Time.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 template<class Type>
34 void Foam::readFields::loadField(const word& fieldName) const
35 {
38 
39  if (obr_.foundObject<vfType>(fieldName))
40  {
41  if (debug)
42  {
43  Info<< "readFields: " << vfType::typeName << " "
44  << fieldName << " already exists in database"
45  << endl;
46  }
47  }
48  else if (obr_.foundObject<sfType>(fieldName))
49  {
50  if (debug)
51  {
52  Info<< "readFields: " << sfType::typeName << " "
53  << fieldName << " already exists in database"
54  << endl;
55  }
56  }
57  else
58  {
59  const fvMesh& mesh = refCast<const fvMesh>(obr_);
60 
61  IOobject fieldHeader
62  (
63  fieldName,
64  mesh.time().timeName(),
65  mesh,
68  );
69 
70  if
71  (
72  fieldHeader.headerOk()
73  && fieldHeader.headerClassName() == vfType::typeName
74  )
75  {
76  // Store field on mesh database
77  if (log_) Info<< " Reading " << fieldName << endl;
78  vfType* vfPtr = new vfType(fieldHeader, mesh);
79  mesh.objectRegistry::store(vfPtr);
80  }
81  else if
82  (
83  fieldHeader.headerOk()
84  && fieldHeader.headerClassName() == sfType::typeName
85  )
86  {
87  // Store field on mesh database
88  if (log_) Info<< " Reading " << fieldName << endl;
89  sfType* sfPtr = new sfType(fieldHeader, mesh);
90  mesh.objectRegistry::store(sfPtr);
91  }
92  }
93 }
94 
95 
96 // ************************************************************************* //
volFields.H
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
readFields.H
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:108
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
surfaceFields.H
Foam::surfaceFields.
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:118
Foam::IOobject::headerOk
bool headerOk()
Read and check header info.
Definition: IOobject.C:439
Foam::readFields::log_
Switch log_
Switch to send output to Info as well as to file.
Definition: readFields.H:122
Foam::IOobject::headerClassName
const word & headerClassName() const
Return name of the class name read from header.
Definition: IOobject.H:279
Foam::Info
messageStream Info
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Foam::objectRegistry::foundObject
bool foundObject(const word &name) const
Is the named Type found?
Definition: objectRegistryTemplates.C:142
Foam::readFields::loadField
void loadField(const word &) const
Definition: readFieldsTemplates.C:34
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::readFields::obr_
const objectRegistry & obr_
Definition: readFields.H:113