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 -------------------------------------------------------------------------------
12 License
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 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(solver, 0);
37 }
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
42 (
43  fvMesh& mesh,
44  const word& managerType,
45  const dictionary& dict
46 )
47 :
49  (
50  IOobject
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 // ************************************************************************* //
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
solver.H
Foam::solver::solverName
const word & solverName() const
Return the solver name.
Definition: solver.C:101
Foam::solver::active
virtual bool active()
Return state of solver.
Definition: solver.C:107
Foam::solver::getVariablesSet
const variablesSet & getVariablesSet() const
Return constant reference to variableSet used by the solver.
Definition: solver.C:119
Foam::solver::preLoop
virtual void preLoop()
Functions to be called before loop.
Definition: solver.C:137
Foam::variablesSet
Base class for creating a set of variables.
Definition: variablesSet.H:49
Foam::solver::~solver
virtual ~solver()
Destructor.
Definition: solver.C:74
Foam::solver::postLoop
virtual void postLoop()
Functions to be called after loop.
Definition: solver.C:143
Foam::solver::updateOptTypeSource
void updateOptTypeSource(const autoPtr< volScalarField > &optSourcePtr)
Update source term related to optimisationType.
Definition: solver.C:150
Foam::solver::solver
solver(const solver &)=delete
No copy construct.
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::solver::restoreInitValues
virtual void restoreInitValues()
Restore initial field values if necessary.
Definition: solver.C:131
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::solver::mesh
const fvMesh & mesh() const
Return the solver mesh.
Definition: solver.C:96
Foam::solver::readDict
virtual bool readDict(const dictionary &dict)
Definition: solver.C:82
Foam::GeometricField< scalar, fvPatchField, volMesh >
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::localIOdictionary
localIOdictionary is derived from IOdictionary but excludes parallel master reading.
Definition: localIOdictionary.H:52
Foam::solver::dict
virtual const dictionary & dict() const
Return the solver dictionary.
Definition: solver.C:113
Foam::solver::optTypeSource_
const volScalarField * optTypeSource_
Definition: solver.H:78