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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2019-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 "fvOptions.H"
30 #include "fvMesh.H"
31 #include "Time.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  namespace fv
38  {
39  defineTypeNameAndDebug(options, 0);
40  }
41 }
42 
43 
44 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
45 
46 Foam::IOobject Foam::fv::options::createIOobject
47 (
48  const fvMesh& mesh
49 ) const
50 {
51  IOobject io
52  (
53  typeName,
54  mesh.time().constant(),
55  mesh,
58  );
59 
60  if (io.typeHeaderOk<IOdictionary>(true))
61  {
62  Info<< "Creating finite volume options from "
63  << io.instance()/io.name() << nl
64  << endl;
65 
66  io.readOpt() = IOobject::MUST_READ_IF_MODIFIED;
67  return io;
68  }
69  else
70  {
71  // Check if the fvOptions file is in system
72  io.instance() = mesh.time().system();
73 
74  if (io.typeHeaderOk<IOdictionary>(true))
75  {
76  Info<< "Creating finite volume options from "
77  << io.instance()/io.name() << nl
78  << endl;
79 
80  io.readOpt() = IOobject::MUST_READ_IF_MODIFIED;
81  return io;
82  }
83  else
84  {
85  io.readOpt() = IOobject::NO_READ;
86  return io;
87  }
88  }
89 }
90 
91 
92 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
93 
94 Foam::fv::options::options
95 (
96  const fvMesh& mesh
97 )
98 :
99  IOdictionary(createIOobject(mesh)),
100  optionList(mesh, *this)
101 {}
102 
103 
105 {
106  if (mesh.thisDb().foundObject<options>(typeName))
107  {
108  return const_cast<options&>
109  (
110  mesh.lookupObject<options>(typeName)
111  );
112  }
113  else
114  {
116  << "Constructing " << typeName
117  << " for region " << mesh.name() << nl;
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 
134  return false;
135 }
136 
137 
138 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
fvOptions.H
Foam::IOdictionary::IOdictionary
IOdictionary(const IOobject &)
Construct given an IOobject.
Definition: IOdictionary.C:35
Foam::fv::options::New
static options & New(const fvMesh &mesh)
Construct fvOptions and register to database if not present.
Definition: fvOptions.C:104
Foam::IOobject::IOobject
IOobject(const IOobject &)=default
Copy construct.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::regIOobject::store
bool store()
Definition: regIOobjectI.H:37
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
DebugInFunction
#define DebugInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:365
Foam::fv::options::read
virtual bool read()
Read dictionary.
Definition: fvOptions.C:126
Foam::fv::options
Finite-volume options.
Definition: fvOptions.H:55
Foam::blockMeshTools::read
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:33
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:83
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
fv
labelList fv(nPoints)
Time.H
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::IOobject::MUST_READ_IF_MODIFIED
Definition: IOobject.H:121
Foam::fv::defineTypeNameAndDebug
defineTypeNameAndDebug(atmAmbientTurbSource, 0)
Foam::IOobject::NO_READ
Definition: IOobject.H:123
Foam::fv::optionList
List of finite volume options.
Definition: fvOptionList.H:69
Foam::fv::optionList::read
virtual bool read(const dictionary &dict)
Read dictionary.
Definition: fvOptionList.C:160
Foam::IOobject::MUST_READ
Definition: IOobject.H:120