solver.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) 2007-2019 PCOpt/NTUA
9 Copyright (C) 2013-2019 FOSS GP
10 Copyright (C) 2019-2020 OpenCFD Ltd.
11-------------------------------------------------------------------------------
12License
13 This file is part of OpenFOAM.
14
15 OpenFOAM is free software: you can redistribute it and/or modify it
16 under the terms of the GNU General Public License as published by
17 the Free Software Foundation, either version 3 of the License, or
18 (at your option) any later version.
19
20 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
21 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
27
28\*---------------------------------------------------------------------------*/
29
30#include "solver.H"
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
35{
37}
38
39// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40
42(
43 fvMesh& mesh,
44 const word& managerType,
45 const dictionary& dict
46)
47:
49 (
51 (
52 dict.dictName(),
53 mesh.time().timeName(),
54 fileName("uniform")/fileName("solvers"),
55 mesh,
56 IOobject::READ_IF_PRESENT,
57 IOobject::AUTO_WRITE
58 ),
59 word::null // avoid type checking since dictionary is read using the
60 // derived type name and type() will result in "solver" here
61 ),
62 mesh_(mesh),
63 managerType_(managerType),
64 dict_(dict),
65 solverName_(dict.dictName()),
66 active_(dict.getOrDefault("active", true)),
67 optTypeSource_(nullptr),
68 vars_(nullptr)
69{}
70
71
72// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
73
75{
76 optTypeSource_ = 0;
77}
78
79
80// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
81
83{
84 dict_ = dict;
85
86 // Note: Slightly dangerous to change active_ while the solver is
87 // running. At the very least, this should trigger writing before stopping.
88 // Additional problems if we have an adjontSolver corresponding to a
89 // constraint. To be revisited
90 //active_ = dict.getOrDefault<bool>("active", true);
91
92 return true;
93}
94
95
97{
98 return mesh_;
99}
100
102{
103 return solverName_;
104}
105
106
108{
109 return active_;
110}
111
112
114{
115 return dict_;
116}
117
118
120{
121 return vars_();
122}
123
124
126{
127 return vars_();
128}
129
130
132{
133 // Does nothing in the base class
134}
135
136
138{
139 restoreInitValues();
140}
141
142
144{
145 // Does nothing in the base class
146}
147
148
150(
151 const autoPtr<volScalarField>& optSourcePtr
152)
153{
154 if (optSourcePtr)
155 {
156 const volScalarField& optSource = optSourcePtr();
157 optTypeSource_ = &optSource;
158 }
159}
160
161
162// ************************************************************************* //
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A class for handling file names.
Definition: fileName.H:76
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
Abstract base-class for lduMatrix solvers.
Definition: lduMatrix.H:99
localIOdictionary is derived from IOdictionary but excludes parallel master reading.
Base class for solution control classes.
Definition: solver.H:54
virtual ~solver()
Destructor.
Definition: solver.C:74
virtual bool active()
Return state of solver.
Definition: solver.C:107
virtual void restoreInitValues()
Restore initial field values if necessary.
Definition: solver.C:131
virtual bool readDict(const dictionary &dict)
Definition: solver.C:82
const variablesSet & getVariablesSet() const
Return constant reference to variableSet used by the solver.
Definition: solver.C:119
void updateOptTypeSource(const autoPtr< volScalarField > &optSourcePtr)
Update source term related to optimisationType.
Definition: solver.C:150
virtual const dictionary & dict() const
Return the solver dictionary.
Definition: solver.C:113
virtual void preLoop()
Functions to be called before loop.
Definition: solver.C:137
const fvMesh & mesh() const
Return the solver mesh.
Definition: solver.C:96
const word & solverName() const
Return the solver name.
Definition: solver.C:101
virtual void postLoop()
Functions to be called after loop.
Definition: solver.C:143
Base class for creating a set of variables.
Definition: variablesSet.H:50
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
dynamicFvMesh & mesh
const word dictName("faMeshDefinition")
word timeName
Definition: getTimeIndex.H:3
Namespace for OpenFOAM.
dictionary dict