All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fvOptions.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 "fvOptions.H"
27 #include "fvMesh.H"
28 #include "Time.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  namespace fv
35  {
36  defineTypeNameAndDebug(options, 0);
37  }
38 }
39 
40 
41 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
42 
43 Foam::IOobject Foam::fv::options::createIOobject
44 (
45  const fvMesh& mesh
46 ) const
47 {
48  IOobject io
49  (
50  typeName,
51  mesh.time().constant(),
52  mesh,
55  );
56 
57  if (io.typeHeaderOk<IOdictionary>(true))
58  {
59  Info<< "Creating finite volume options from "
60  << io.instance()/io.name() << nl
61  << endl;
62 
63  io.readOpt() = IOobject::MUST_READ_IF_MODIFIED;
64  return io;
65  }
66  else
67  {
68  // Check if the fvOptions file is in system
69  io.instance() = mesh.time().system();
70 
71  if (io.typeHeaderOk<IOdictionary>(true))
72  {
73  Info<< "Creating finite volume options from "
74  << io.instance()/io.name() << nl
75  << endl;
76 
77  io.readOpt() = IOobject::MUST_READ_IF_MODIFIED;
78  return io;
79  }
80  else
81  {
82  io.readOpt() = IOobject::NO_READ;
83  return io;
84  }
85  }
86 }
87 
88 
89 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
90 
92 (
93  const fvMesh& mesh
94 )
95 :
96  IOdictionary(createIOobject(mesh)),
97  optionList(mesh, *this)
98 {}
99 
100 
102 {
103  if (mesh.thisDb().foundObject<options>(typeName))
104  {
105  return const_cast<options&>
106  (
107  mesh.lookupObject<options>(typeName)
108  );
109  }
110  else
111  {
112  if (debug)
113  {
115  << "Constructing " << typeName
116  << " for region " << mesh.name() << endl;
117  }
118 
119  options* objectPtr = new options(mesh);
120  regIOobject::store(objectPtr);
121  return *objectPtr;
122  }
123 }
124 
125 
127 {
129  {
130  optionList::read(*this);
131  return true;
132  }
133  else
134  {
135  return false;
136  }
137 }
138 
139 
140 // ************************************************************************* //
defineTypeNameAndDebug(option, 0)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
bool foundObject(const word &name) const
Is the named Type found?
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
Finite-volume options.
Definition: fvOptions.H:52
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
virtual const objectRegistry & thisDb() const
Return the object registry - resolve conflict polyMesh/lduMesh.
Definition: fvMesh.H:245
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:52
virtual bool read()
Read dictionary.
Definition: fvOptions.C:126
dynamicFvMesh & mesh
labelList fv(nPoints)
void store()
Transfer ownership of this object to its registry.
Definition: regIOobjectI.H:34
static const char nl
Definition: Ostream.H:260
options(const fvMesh &mesh)
Construct from components with list of field names.
Definition: fvOptions.C:92
const word & name() const
Return reference to name.
Definition: fvMesh.H:253
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
messageStream Info
List of finite volume options.
Definition: fvOptionList.H:64
static options & New(const fvMesh &mesh)
Construct fvOptions and register to datbase if not present.
Definition: fvOptions.C:101
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
Namespace for OpenFOAM.
virtual bool read(const dictionary &dict)
Read dictionary.
Definition: fvOptionList.C:157
#define InfoInFunction
Report an information message using Foam::Info.