libMesh
time_solver.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 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/diff_solver.h"
19 #include "libmesh/diff_system.h"
20 #include "libmesh/linear_solver.h"
21 #include "libmesh/time_solver.h"
22 #include "libmesh/no_solution_history.h"
23 #include "libmesh/auto_ptr.h" // libmesh_make_unique
24 
25 namespace libMesh
26 {
27 
29  : quiet (true),
30  reduce_deltat_on_diffsolver_failure (0),
31  _diff_solver (),
32  _linear_solver (),
33  _system (s),
34  solution_history(libmesh_make_unique<NoSolutionHistory>()),
35  _is_adjoint (false)
36 {
37 }
38 
39 
40 
42 {
43 }
44 
45 
46 
48 {
49  libmesh_assert(this->diff_solver().get());
50  libmesh_assert_equal_to (&(this->diff_solver()->system()), &(this->system()));
51  this->diff_solver()->reinit();
52 
53  libmesh_assert(this->linear_solver().get());
54  this->linear_solver()->clear();
55  if (libMesh::on_command_line("--solver-system-names"))
56  this->linear_solver()->init((_system.name()+"_").c_str());
57  else
58  this->linear_solver()->init();
59 }
60 
61 
62 
64 {
65  // If the user hasn't given us a solver to use,
66  // just build a default solver
67  if (this->diff_solver().get() == nullptr)
69 
70  if (this->linear_solver().get() == nullptr)
72 }
73 
74 
75 
77 {
78  this->diff_solver()->init();
79 
80  if (libMesh::on_command_line("--solver-system-names"))
81  this->linear_solver()->init((_system.name()+"_").c_str());
82  else
83  this->linear_solver()->init();
84 }
85 
86 
87 
89 {
90  libmesh_assert(this->diff_solver().get());
91  libmesh_assert_equal_to (&(this->diff_solver()->system()), &(this->system()));
92  this->diff_solver()->solve();
93 }
94 
95 
96 void TimeSolver::set_solution_history (const SolutionHistory & _solution_history)
97 {
98  solution_history = _solution_history.clone();
99 }
100 
102 {
103 }
104 
106 {
107 }
108 
110 {
111 }
112 
113 } // namespace libMesh
libMesh::TimeSolver::reinit
virtual void reinit()
The reinitialization function.
Definition: time_solver.C:47
libMesh::TimeSolver::~TimeSolver
virtual ~TimeSolver()
Destructor.
Definition: time_solver.C:41
libMesh::TimeSolver::init
virtual void init()
The initialization function.
Definition: time_solver.C:63
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::ParallelObject::comm
const Parallel::Communicator & comm() const
Definition: parallel_object.h:94
libMesh::TimeSolver::advance_timestep
virtual void advance_timestep()
This method advances the solution to the next timestep, after a solve() has been performed.
Definition: time_solver.C:101
libMesh::DifferentiableSystem
This class provides a specific system class.
Definition: diff_system.h:53
libMesh::NoSolutionHistory
'Save nothing' subclass of Solution History, this is the default.
Definition: no_solution_history.h:35
libMesh::TimeSolver::adjoint_advance_timestep
virtual void adjoint_advance_timestep()
This method advances the adjoint solution to the previous timestep, after an adjoint_solve() has been...
Definition: time_solver.C:105
libMesh::TimeSolver::set_solution_history
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.
Definition: time_solver.C:96
libMesh::TimeSolver::TimeSolver
TimeSolver(sys_type &s)
Constructor.
Definition: time_solver.C:28
libMesh::libmesh_assert
libmesh_assert(ctx)
libMesh::LinearSolver::build
static std::unique_ptr< LinearSolver< T > > build(const libMesh::Parallel::Communicator &comm_in, const SolverPackage solver_package=libMesh::default_solver_package())
Builds a LinearSolver using the linear solver package specified by solver_package.
Definition: linear_solver.C:57
libMesh::TimeSolver::linear_solver
virtual std::unique_ptr< LinearSolver< Number > > & linear_solver()
An implicit linear solver to use for adjoint and sensitivity problems.
Definition: time_solver.h:186
libMesh::TimeSolver::diff_solver
virtual std::unique_ptr< DiffSolver > & diff_solver()
An implicit linear or nonlinear solver to use at each timestep.
Definition: time_solver.h:181
libMesh::TimeSolver::_system
sys_type & _system
A reference to the system we are solving.
Definition: time_solver.h:257
libMesh::TimeSolver::init_data
virtual void init_data()
The data initialization function.
Definition: time_solver.C:76
libMesh::ReferenceElem::get
const Elem & get(const ElemType type_in)
Definition: reference_elem.C:237
libMesh::System::name
const std::string & name() const
Definition: system.h:2067
libMesh::TimeSolver::retrieve_timestep
virtual void retrieve_timestep()
This method retrieves all the stored solutions at the current system.time.
Definition: time_solver.C:109
libMesh::on_command_line
bool on_command_line(std::string arg)
Definition: libmesh.C:898
libMesh::DiffSolver::build
static std::unique_ptr< DiffSolver > build(sys_type &s)
Factory method.
Definition: diff_solver.C:53
libMesh::SolutionHistory::clone
virtual std::unique_ptr< SolutionHistory > clone() const =0
Cloning function for a std::unique_ptr, pure virtual, used in the setter function in time_solver....
libMesh::TimeSolver::system
const sys_type & system() const
Definition: time_solver.h:171
libMesh::TimeSolver::solution_history
std::unique_ptr< SolutionHistory > solution_history
A std::unique_ptr to a SolutionHistory object.
Definition: time_solver.h:264
libMesh::SolutionHistory
A SolutionHistory class that enables the storage and retrieval of timesteps and (in the future) adapt...
Definition: solution_history.h:35
libMesh::TimeSolver::solve
virtual void solve()
This method solves for the solution at the next timestep (or solves for a steady-state solution).
Definition: time_solver.C:88