libMesh
Loading...
Searching...
No Matches
time_solver.h
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3
4// This library is free software; you can redistribute it and/or
5// modify it under the terms of the GNU Lesser General Public
6// License as published by the Free Software Foundation; either
7// version 2.1 of the License, or (at your option) any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// Lesser General Public License for more details.
13
14// You should have received a copy of the GNU Lesser General Public
15// License along with this library; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18
19
20#ifndef LIBMESH_TIME_SOLVER_H
21#define LIBMESH_TIME_SOLVER_H
22
23// Local includes
24#include "libmesh/libmesh_common.h"
25#include "libmesh/reference_counted_object.h"
26
27// C++ includes
28#include <memory>
29
30namespace libMesh
31{
32
33// Forward Declarations
34class DiffContext;
35class DiffSolver;
36class DifferentiablePhysics;
37class DifferentiableSystem;
38class ParameterVector;
39class SensitivityData;
40class SolutionHistory;
41class SystemNorm;
42class QoISet;
43class AdjointRefinementEstimator;
44class ErrorVector;
45
46template <typename T>
47class LinearSolver;
48
63class TimeSolver : public ReferenceCountedObject<TimeSolver>
64{
65public:
70
75 explicit
76 TimeSolver (sys_type & s);
77
81 virtual ~TimeSolver ();
82
87 virtual void init ();
88
93 virtual void init_adjoints ();
94
100 virtual void init_data ();
101
106 virtual void reinit ();
107
114 virtual void solve ();
115
122 virtual void advance_timestep ();
123
128 virtual std::pair<unsigned int, Real> adjoint_solve (const QoISet & qoi_indices);
129
135 virtual void adjoint_advance_timestep ();
136
141 virtual void retrieve_timestep();
142
146 virtual void integrate_qoi_timestep();
147
152 virtual void integrate_adjoint_sensitivity(const QoISet & qois, const ParameterVector & parameter_vector, SensitivityData & sensitivities);
153
154#ifdef LIBMESH_ENABLE_AMR
162 virtual void integrate_adjoint_refinement_error_estimate(AdjointRefinementEstimator & adjoint_refinement_error_estimator, ErrorVector & QoI_elementwise_error);
163#endif // LIBMESH_ENABLE_AMR
164
174 virtual bool element_residual (bool request_jacobian,
175 DiffContext &) = 0;
176
186 virtual bool side_residual (bool request_jacobian,
187 DiffContext &) = 0;
188
198 virtual bool nonlocal_residual (bool request_jacobian,
199 DiffContext &) = 0;
200
205 virtual void before_timestep () {}
206
210 const sys_type & system () const { return _system; }
211
215 sys_type & system () { return _system; }
216
220 virtual std::unique_ptr<DiffSolver> & diff_solver() { return _diff_solver; }
221
225 virtual std::unique_ptr<LinearSolver<Number>> & linear_solver() { return _linear_solver; }
226
230 bool quiet;
231
241 virtual Real du(const SystemNorm & norm) const = 0;
242
246 virtual bool is_steady() const = 0;
247
260
265 void set_solution_history(const SolutionHistory & _solution_history);
266
272
277 bool is_adjoint() const
278 { return _is_adjoint; }
279
284 void set_is_adjoint(bool _is_adjoint_value)
285 { _is_adjoint = _is_adjoint_value; }
286
296
297protected:
298
302 std::unique_ptr<DiffSolver> _diff_solver;
303
307 std::unique_ptr<LinearSolver<Number>> _linear_solver;
308
313
319 std::unique_ptr<SolutionHistory> solution_history;
320
326
327 typedef void (DiffContext::*ReinitFuncType) (Real);
328
333
334private:
335
341
342};
343
344
345} // namespace libMesh
346
347
348#endif // LIBMESH_TIME_SOLVER_H
This class implements a "brute force" goal-oriented error estimator which computes an estimate of err...
This class provides all data required for a physics package (e.g.
This class provides a specific system class.
This class provides a specific system class.
Definition diff_system.h:57
The ErrorVector is a specialization of the StatisticsVector for error data computed on a finite eleme...
Data structure for specifying which Parameters should be independent variables in a parameter sensiti...
Data structure for specifying which Quantities of Interest should be calculated in an adjoint or a pa...
Definition qoi_set.h:46
This class implements reference counting.
Data structure for holding completed parameter sensitivity calculations.
A SolutionHistory class that enables the storage and retrieval of timesteps and (in the future) adapt...
This class defines a norm/seminorm to be applied to a NumericVector which contains coefficients in a ...
Definition system_norm.h:50
This is a generic class that defines a solver to handle time integration of DifferentiableSystems.
Definition time_solver.h:64
virtual ~TimeSolver()
Destructor.
virtual void init_adjoints()
Initialize any adjoint related data structures, based on the number of qois.
Definition time_solver.C:83
virtual void init()
The initialization function.
Definition time_solver.C:72
sys_type & system()
void set_is_adjoint(bool _is_adjoint_value)
Accessor for setting whether we need to do a primal or adjoint solve.
sys_type & _system
A reference to the system we are solving.
void(DiffContext::* ReinitFuncType)(Real)
bool is_adjoint() const
Accessor for querying whether we need to do a primal or adjoint solve.
virtual void integrate_qoi_timestep()
A method to integrate the system::QoI functionals.
void set_solution_history(const SolutionHistory &_solution_history)
A setter function users will employ if they need to do something other than save no solution history.
const sys_type & system() const
virtual std::unique_ptr< DiffSolver > & diff_solver()
An implicit linear or nonlinear solver to use at each timestep.
virtual std::unique_ptr< LinearSolver< Number > > & linear_solver()
An implicit linear solver to use for adjoint and sensitivity problems.
DifferentiableSystem sys_type
The type of system.
Definition time_solver.h:69
SolutionHistory & get_solution_history()
A getter function that returns a reference to the solution history object owned by TimeSolver.
virtual bool is_steady() const =0
Is this effectively a steady-state solver?
std::unique_ptr< DiffSolver > _diff_solver
An implicit linear or nonlinear solver to use at each timestep.
bool _is_adjoint
This boolean tells the TimeSolver whether we are solving a primal or adjoint problem.
bool(DifferentiablePhysics::* ResFuncType)(bool, DiffContext &)
Definitions of argument types for use in refactoring subclasses.
Real last_deltat
The deltat for the last completed timestep before the current one.
unsigned int reduce_deltat_on_diffsolver_failure
This value (which defaults to zero) is the number of times the TimeSolver is allowed to halve deltat ...
std::unique_ptr< LinearSolver< Number > > _linear_solver
An implicit linear solver to use for adjoint problems.
virtual void solve()
This method solves for the solution at the next timestep (or solves for a steady-state solution).
virtual void init_data()
The data initialization function.
Definition time_solver.C:97
virtual void retrieve_timestep()
This method retrieves all the stored solutions at the current system.time.
virtual void reinit()
The reinitialization function.
Definition time_solver.C:54
virtual std::pair< unsigned int, Real > adjoint_solve(const QoISet &qoi_indices)
This method solves for the adjoint solution at the next adjoint timestep (or a steady state adjoint s...
virtual Real last_completed_timestep_size()
Returns system.deltat if fixed timestep solver is used, the complete timestep size (sum of all subste...
virtual void before_timestep()
This method is for subclasses or users to override to do arbitrary processing between timesteps.
virtual void integrate_adjoint_refinement_error_estimate(AdjointRefinementEstimator &adjoint_refinement_error_estimator, ErrorVector &QoI_elementwise_error)
A method to compute the adjoint refinement error estimate at the current timestep.
virtual bool nonlocal_residual(bool request_jacobian, DiffContext &)=0
This method uses the DifferentiablePhysics nonlocal_time_derivative(), nonlocal_constraint(),...
std::unique_ptr< SolutionHistory > solution_history
A std::unique_ptr to a SolutionHistory object.
virtual void adjoint_advance_timestep()
This method advances the adjoint solution to the previous timestep, after an adjoint_solve() has been...
virtual Real du(const SystemNorm &norm) const =0
Computes the size of ||u^{n+1} - u^{n}|| in some norm.
virtual bool element_residual(bool request_jacobian, DiffContext &)=0
This method uses the DifferentiablePhysics element_time_derivative(), element_constraint(),...
bool quiet
Print extra debugging information if quiet == false.
virtual void integrate_adjoint_sensitivity(const QoISet &qois, const ParameterVector &parameter_vector, SensitivityData &sensitivities)
A method to integrate the adjoint sensitivity w.r.t a given parameter vector.
virtual void advance_timestep()
This method advances the solution to the next timestep, after a solve() has been performed.
virtual bool side_residual(bool request_jacobian, DiffContext &)=0
This method uses the DifferentiablePhysics side_time_derivative(), side_constraint(),...
The libMesh namespace provides an interface to certain functionality in the library.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real