1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2020 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 #include "libmesh/time_solver.h"
19
20 #include "libmesh/diff_solver.h"
21 #include "libmesh/diff_system.h"
22 #include "libmesh/linear_solver.h"
23 #include "libmesh/no_solution_history.h"
24 #include "libmesh/auto_ptr.h" // libmesh_make_unique
25
26 namespace libMesh
27 {
28
TimeSolver(sys_type & s)29 TimeSolver::TimeSolver (sys_type & s)
30 : quiet (true),
31 reduce_deltat_on_diffsolver_failure (0),
32 _diff_solver (),
33 _linear_solver (),
34 _system (s),
35 solution_history(libmesh_make_unique<NoSolutionHistory>()),
36 _is_adjoint (false)
37 {
38 }
39
40
41
~TimeSolver()42 TimeSolver::~TimeSolver ()
43 {
44 }
45
46
47
reinit()48 void TimeSolver::reinit ()
49 {
50 libmesh_assert(this->diff_solver().get());
51 libmesh_assert_equal_to (&(this->diff_solver()->system()), &(this->system()));
52 this->diff_solver()->reinit();
53
54 libmesh_assert(this->linear_solver().get());
55 this->linear_solver()->clear();
56 if (libMesh::on_command_line("--solver-system-names"))
57 this->linear_solver()->init((_system.name()+"_").c_str());
58 else
59 this->linear_solver()->init();
60 }
61
62
63
init()64 void TimeSolver::init ()
65 {
66 // If the user hasn't given us a solver to use,
67 // just build a default solver
68 if (this->diff_solver().get() == nullptr)
69 this->diff_solver() = DiffSolver::build(_system);
70
71 if (this->linear_solver().get() == nullptr)
72 this->linear_solver() = LinearSolver<Number>::build(_system.comm());
73 }
74
75
76
init_data()77 void TimeSolver::init_data ()
78 {
79 this->diff_solver()->init();
80
81 if (libMesh::on_command_line("--solver-system-names"))
82 this->linear_solver()->init((_system.name()+"_").c_str());
83 else
84 this->linear_solver()->init();
85 }
86
87
88
solve()89 void TimeSolver::solve ()
90 {
91 libmesh_assert(this->diff_solver().get());
92 libmesh_assert_equal_to (&(this->diff_solver()->system()), &(this->system()));
93 this->diff_solver()->solve();
94 }
95
96
set_solution_history(const SolutionHistory & _solution_history)97 void TimeSolver::set_solution_history (const SolutionHistory & _solution_history)
98 {
99 solution_history = _solution_history.clone();
100 }
101
get_solution_history()102 SolutionHistory & TimeSolver::get_solution_history ()
103 {
104 return *solution_history;
105 }
106
advance_timestep()107 void TimeSolver::advance_timestep ()
108 {
109 }
110
adjoint_solve(const QoISet & qoi_indices)111 std::pair<unsigned int, Real> TimeSolver::adjoint_solve (const QoISet & qoi_indices)
112 {
113 libmesh_assert(this->diff_solver().get());
114 libmesh_assert_equal_to (&(this->diff_solver()->system()), &(this->system()));
115
116 return this->_system.ImplicitSystem::adjoint_solve(qoi_indices);
117 }
118
integrate_adjoint_sensitivity(const QoISet & qois,const ParameterVector & parameter_vector,SensitivityData & sensitivities)119 void TimeSolver::integrate_adjoint_sensitivity(const QoISet & qois, const ParameterVector & parameter_vector, SensitivityData & sensitivities)
120 {
121 // Base class assumes a direct steady state sensitivity calculation
122 this->_system.ImplicitSystem::adjoint_qoi_parameter_sensitivity(qois, parameter_vector, sensitivities);
123
124 return;
125 }
126
last_complete_deltat()127 Real TimeSolver::last_complete_deltat()
128 {
129 return _system.deltat;
130 }
131
adjoint_advance_timestep()132 void TimeSolver::adjoint_advance_timestep ()
133 {
134 }
135
retrieve_timestep()136 void TimeSolver::retrieve_timestep ()
137 {
138 }
139
140 } // namespace libMesh
141