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-2021 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 
67  }
68  else
69  {
70  // Check if the fvOptions file is in system
71  io.instance() = mesh.time().system();
72 
73  if (io.typeHeaderOk<IOdictionary>(true))
74  {
75  Info<< "Creating finite volume options from "
76  << io.instance()/io.name() << nl
77  << endl;
78 
80  }
81  else
82  {
83  io.readOpt(IOobject::NO_READ);
84  }
85  }
86 
87  return io;
88 }
89 
90 
91 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
92 
93 Foam::fv::options::options
94 (
95  const fvMesh& mesh
96 )
97 :
98  IOdictionary(createIOobject(mesh)),
99  optionList(mesh, *this)
100 {}
101 
102 
104 {
105  options* ptr = mesh.thisDb().getObjectPtr<options>(typeName);
106 
107  if (!ptr)
108  {
110  << "Constructing " << typeName
111  << " for region " << mesh.name() << nl;
112 
113  ptr = new options(mesh);
115  }
116 
117  return *ptr;
118 }
119 
120 
122 {
124  {
125  optionList::read(*this);
126  return true;
127  }
128 
129  return false;
130 }
131 
132 
133 // ************************************************************************* //
IOdictionary(const IOobject &io, const dictionary *fallback=nullptr)
Construct given an IOobject and optional fallback dictionary content.
Definition: IOdictionary.C:30
defineTypeNameAndDebug(atmAmbientTurbSource, 0)
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
bool store()
Register object with its registry and transfer ownership to the registry.
Definition: regIOobjectI.H:36
Ignore writing from objectRegistry::writeObject()
Finite-volume options.
Definition: fvOptions.H:51
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:50
virtual bool read()
Read dictionary.
Definition: fvOptions.C:114
dynamicFvMesh & mesh
labelList fv(nPoints)
#define DebugInFunction
Report an information message using Foam::Info.
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
IOobject(const IOobject &)=default
Copy construct.
Nothing to be read.
messageStream Info
Information stream (stdout output on master, null elsewhere)
List of finite volume options.
Definition: fvOptionList.H:63
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
static options & New(const fvMesh &mesh)
Construct fvOptions and register to database if not present.
Definition: fvOptions.C:96
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
Namespace for OpenFOAM.
virtual bool read(const dictionary &dict)
Read dictionary.
Definition: fvOptionList.C:143