fvOptions.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-2015 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 
44 (
45  const fvMesh& mesh
46 ) const
47 {
48  IOobject io
49  (
50  typeName,
51  mesh.time().constant(),
52  mesh,
53  IOobject::MUST_READ,
54  IOobject::NO_WRITE
55  );
56 
57  if (io.headerOk())
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.headerOk())
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  Info<< "No finite volume options present" << nl << endl;
83 
84  io.readOpt() = IOobject::NO_READ;
85  return io;
86  }
87  }
88 }
89 
90 
91 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
92 
94 (
95  const fvMesh& mesh
96 )
97 :
98  IOdictionary(createIOobject(mesh)),
99  optionList(mesh, *this)
100 {}
101 
102 
104 {
105  if (mesh.thisDb().foundObject<options>(typeName))
106  {
107  return const_cast<options&>
108  (
109  mesh.lookupObject<options>(typeName)
110  );
111  }
112  else
113  {
114  if (debug)
115  {
117  << "Constructing " << typeName
118  << " for region " << mesh.name() << endl;
119  }
120 
121  options* objectPtr = new options(mesh);
122  regIOobject::store(objectPtr);
123  return *objectPtr;
124  }
125 }
126 
127 
129 {
131  {
132  optionList::read(*this);
133  return true;
134  }
135  else
136  {
137  return false;
138  }
139 }
140 
141 
142 // ************************************************************************* //
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
InfoInFunction
#define InfoInFunction
Report a information message using Foam::Info.
Definition: messageStream.H:281
fvOptions.H
Foam::fv::options::New
static options & New(const fvMesh &mesh)
Construct fvOptions and register to datbase if not present.
Definition: fvOptions.C:103
Foam::read
bool read(const char *, int32_t &)
Definition: int32IO.C:87
Foam::fv::options::createIOobject
IOobject createIOobject(const fvMesh &mesh) const
Create IO object if dictionary is present.
Definition: fvOptions.C:44
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::IOobject::instance
const fileName & instance() const
Definition: IOobject.H:350
Foam::IOobject::headerOk
bool headerOk()
Read and check header info.
Definition: IOobject.C:439
Foam::IOobject::readOpt
readOption readOpt() const
Definition: IOobject.H:317
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::fv::options::read
virtual bool read()
Read dictionary.
Definition: fvOptions.C:128
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobject.H:273
Foam::fv::options
Finite-volume options.
Definition: fvOptions.H:52
Foam::fv::options::options
options(const options &)
Disallow default bitwise copy construct.
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
fv
labelList fv(nPoints)
Foam::fv::defineTypeNameAndDebug
defineTypeNameAndDebug(option, 0)
Foam::regIOobject::store
void store()
Transfer ownership of this object to its registry.
Definition: regIOobjectI.H:34
Foam::fv::optionList
List of finite volume options.
Definition: fvOptionList.H:64
Foam::fv::optionList::read
virtual bool read(const dictionary &dict)
Read dictionary.
Definition: fvOptionList.C:139