solver.H
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 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 Class
29  Foam::solver
30 
31 Description
32  Base class for solution control classes
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef solver_H
37 #define solver_H
38 
39 #include "fvMesh.H"
40 #include "fvMatrix.H"
41 #include "localIOdictionary.H"
42 #include "variablesSet.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 /*---------------------------------------------------------------------------*\
49  Class solver Declaration
50 \*---------------------------------------------------------------------------*/
51 
52 class solver
53 :
54  public localIOdictionary
55 {
56 protected:
57 
58  // Protected Data
59 
60  //- Reference to the mesh database
61  fvMesh& mesh_;
62 
63  //- The optimisation type
64  const word managerType_;
65 
66  //- Dictionary holding the solver info
68 
69  //- Solver name
70  const word solverName_;
71 
72  //- Solve equations?
73  bool active_;
74 
75  //- Pointer to a source term coming from the optimisationType
76  //- (e.g. porosity from topologyOptimisation)
77  // Will never allocate new memory, so no need to be deleted
78  // in the destructor
80 
81  //- Base variableSet pointer.
82  // To be allocated in derived classes
84 
85 
86  // Protected Member Functions
87 
88  //- No copy construct
89  solver(const solver&) = delete;
90 
91  //- No copy assignment
92  void operator=(const solver&) = delete;
93 
94 
95 public:
96 
97 
98  // Static Data Members
99 
100  //- Run-time type information
101  TypeName("solver");
102 
103 
104  // Constructors
105 
106  //- Construct from mesh and dictionary
107  solver
108  (
109  fvMesh& mesh,
110  const word& managerType,
111  const dictionary& dict
112  );
113 
114 
115  //- Destructor
116  virtual ~solver();
117 
118 
119  // Member Functions
120 
121  virtual bool readDict(const dictionary& dict);
122 
123 
124  // Access
125 
126  //- Return the solver mesh
127  const fvMesh& mesh() const;
128 
129  //- Return the solver name
130  const word& solverName() const;
131 
132  //- Use solver name as a suffix to the involved fields
133  virtual bool useSolverNameForFields() const = 0;
134 
135  //- Return state of solver
136  virtual bool active();
137 
138  //- Return the solver dictionary
139  virtual const dictionary& dict() const;
140 
141  //- Return constant reference to variableSet used by the solver
142  const variablesSet& getVariablesSet() const;
143 
144  //- Return non-constant reference to variableSet used by the solver
146 
147 
148  // Evolution
149 
150  //- Execute one iteration of the solution algorithm
151  virtual void solveIter() = 0;
152 
153  //- Main control loop
154  virtual void solve() = 0;
155 
156  //- Looper (advances iters, time step)
157  virtual bool loop() = 0;
158 
159  //- Restore initial field values if necessary
160  virtual void restoreInitValues();
161 
162  //- Functions to be called before loop
163  virtual void preLoop();
164 
165  //- Functions to be called after loop
166  virtual void postLoop();
167 
168  //- Update source term related to optimisationType
170  (
171  const autoPtr<volScalarField>& optSourcePtr
172  );
173 
174  //- Main control loop.
175  // Gets a list of function pointers to be called at the end of
176  // each solver iteration
177  template<class Type>
178  void solveWithArgs
179  (
180  Type& type,
181  List<void (Type::*)()>& funcs
182  );
183 
184  //- Add source from optimisationType to underlaying equation
185  template<class Type>
186  void addOptimisationTypeSource(fvMatrix<Type>& matrix) const;
187 
188 
189  // IO
190 
191  //- Required by regIOobject
192  virtual bool writeData(Ostream&) const
193  {
194  return true;
195  }
196 
197  //- Workaround for turbulent fields on multi-point runs
198  virtual bool write(const bool valid = true) const
199  {
200  return false;
201  }
202 
203  //- Workaround for turbulent fields on multi-point runs
204  virtual bool writeNow() const
205  {
206  return false;
207  }
208 };
209 
210 
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 
213 } // End namespace Foam
214 
215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216 
217 #ifdef NoRepository
218 # include "solverTemplates.C"
219 #endif
220 
221 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
222 
223 #endif
224 
225 // ************************************************************************* //
Foam::solver::operator=
void operator=(const solver &)=delete
No copy assignment.
Foam::solver::TypeName
TypeName("solver")
Run-time type information.
Foam::solver::solve
virtual void solve()=0
Main control loop.
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::solver::writeData
virtual bool writeData(Ostream &) const
Required by regIOobject.
Definition: solver.H:191
Foam::solver::solverName
const word & solverName() const
Return the solver name.
Definition: solver.C:101
Foam::solver::write
virtual bool write(const bool valid=true) const
Workaround for turbulent fields on multi-point runs.
Definition: solver.H:197
solverTemplates.C
Foam::solver::mesh_
fvMesh & mesh_
Reference to the mesh database.
Definition: solver.H:60
Foam::solver::active
virtual bool active()
Return state of solver.
Definition: solver.C:107
Foam::solver::useSolverNameForFields
virtual bool useSolverNameForFields() const =0
Use solver name as a suffix to the involved fields.
Foam::solver::loop
virtual bool loop()=0
Looper (advances iters, time step)
Foam::solver::getVariablesSet
const variablesSet & getVariablesSet() const
Return constant reference to variableSet used by the solver.
Definition: solver.C:119
fvMatrix.H
Foam::solver::writeNow
virtual bool writeNow() const
Workaround for turbulent fields on multi-point runs.
Definition: solver.H:203
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::managerType_
const word managerType_
The optimisation type.
Definition: solver.H:63
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
Base class for solution control classes.
Definition: solver.H:51
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.
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::solver::solverName_
const word solverName_
Solver name.
Definition: solver.H:69
Foam::solver::addOptimisationTypeSource
void addOptimisationTypeSource(fvMatrix< Type > &matrix) const
Add source from optimisationType to underlaying equation.
Definition: solverTemplates.C:60
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
fvMesh.H
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::solveWithArgs
void solveWithArgs(Type &type, List< void(Type::*)()> &funcs)
Main control loop.
Definition: solverTemplates.C:36
Foam::solver::mesh
const fvMesh & mesh() const
Return the solver mesh.
Definition: solver.C:96
Foam::solver::vars_
autoPtr< variablesSet > vars_
Base variableSet pointer.
Definition: solver.H:82
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::solver::solveIter
virtual void solveIter()=0
Execute one iteration of the solution algorithm.
Foam::fvMatrix
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvPatchField.H:68
localIOdictionary.H
Foam::solver::readDict
virtual bool readDict(const dictionary &dict)
Definition: solver.C:82
Foam::solver::dict_
dictionary dict_
Dictionary holding the solver info.
Definition: solver.H:66
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::GeometricField< scalar, fvPatchField, volMesh >
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::active_
bool active_
Solve equations?
Definition: solver.H:72
variablesSet.H
Foam::solver::optTypeSource_
const volScalarField * optTypeSource_
Definition: solver.H:78