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
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 // ************************************************************************* //
virtual void restoreInitValues()
Restore initial field values if necessary.
Definition: solver.C:124
Base class for solution control classes.
Definition: solver.H:45
void solveWithArgs(Type &type, List< void(Type::*)()> &funcs)
Main control loop.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
const fvMesh & mesh() const
Return the solver mesh.
Definition: solver.C:89
dictionary dict_
Dictionary holding the solver info.
Definition: solver.H:66
autoPtr< variablesSet > vars_
Base variableSet pointer.
Definition: solver.H:92
virtual void solveIter()=0
Execute one iteration of the solution algorithm.
localIOdictionary is derived from IOdictionary but excludes parallel master reading.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:752
virtual bool useSolverNameForFields() const =0
Use solver name as a suffix to the involved fields.
virtual bool active()
Return state of solver.
Definition: solver.C:100
A class for handling words, derived from Foam::string.
Definition: word.H:63
bool active_
Solve equations?
Definition: solver.H:76
TypeName("solver")
Run-time type information.
void operator=(const solver &)=delete
No copy assignment.
A special matrix type and solver, designed for finite volume solutions of scalar equations. Face addressing is used to make all matrix assembly and solution loops vectorise.
Definition: fvPatchField.H:64
solver(const solver &)=delete
No copy construct.
virtual bool loop()=0
Looper (advances iters, time step)
virtual const dictionary & dict() const
Return the solver dictionary.
Definition: solver.C:106
virtual ~solver()
Destructor.
Definition: solver.C:67
virtual bool readDict(const dictionary &dict)
Definition: solver.C:75
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
const volScalarField * optTypeSource_
Pointer to a source term coming from the optimisationType (e.g. porosity from topologyOptimisation) ...
Definition: solver.H:85
virtual void solve()=0
Main control loop.
virtual bool writeNow() const
Workaround for turbulent fields on multi-point runs.
Definition: solver.H:262
virtual void preLoop()
Functions to be called before loop.
Definition: solver.C:130
Base class for creating a set of variables.
Definition: variablesSet.H:43
virtual bool writeData(Ostream &) const
Required by regIOobject.
Definition: solver.H:246
const word & solverName() const
Return the solver name.
Definition: solver.C:94
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:79
const variablesSet & getVariablesSet() const
Return constant reference to variableSet used by the solver.
Definition: solver.C:112
virtual bool write(const bool valid=true) const
Workaround for turbulent fields on multi-point runs.
Definition: solver.H:254
fvMesh & mesh_
Reference to the mesh database.
Definition: solver.H:56
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
void updateOptTypeSource(const autoPtr< volScalarField > &optSourcePtr)
Update source term related to optimisationType.
Definition: solver.C:143
const word managerType_
The optimisation type.
Definition: solver.H:61
const word solverName_
Solver name.
Definition: solver.H:71
void addOptimisationTypeSource(fvMatrix< Type > &matrix) const
Add source from optimisationType to underlaying equation.
virtual void postLoop()
Functions to be called after loop.
Definition: solver.C:136
Namespace for OpenFOAM.