[P]arallel [Hi]gh-order [Li]brary for [P]DEs  Latest
Parallel High-Order Library for PDEs through hp-adaptive Discontinuous Galerkin methods
algebraic_rrk_ode_solver.cpp
1 #include "algebraic_rrk_ode_solver.h"
2 
3 namespace PHiLiP {
4 namespace ODE {
5 
6 template <int dim, typename real, typename MeshType>
8  std::shared_ptr<RKTableauBase<dim,real,MeshType>> rk_tableau_input)
9  : RRKODESolverBase<dim,real,MeshType>(rk_tableau_input)
10 {
11  // Do nothing
12 }
13 
14 template <int dim, typename real, typename MeshType>
16  std::shared_ptr<DGBase<dim,real,MeshType>> dg,
17  const std::vector<dealii::LinearAlgebra::distributed::Vector<double>> &rk_stage,
18  const dealii::LinearAlgebra::distributed::Vector<double> &/*solution_update*/
19  )
20 {
21  //See Ketcheson 2019, Eq. 2.4
22  double gamma = 1;
23  double denominator = 0;
24  double numerator = 0;
25  for (int i = 0; i < this->n_rk_stages; ++i){
26  const double b_i = this->butcher_tableau->get_b(i);
27  for (int j = 0; j < this->n_rk_stages; ++j){
28  real inner_product = compute_inner_product(rk_stage[i],rk_stage[j], dg);
29  numerator += b_i * this-> butcher_tableau->get_a(i,j) * inner_product;
30  denominator += b_i * this->butcher_tableau->get_b(j) * inner_product;
31  }
32  }
33  numerator *= 2;
34  gamma = (denominator < 1E-8) ? 1 : numerator/denominator;
35  return gamma;
36 }
37 
38 template <int dim, typename real, typename MeshType>
40  const dealii::LinearAlgebra::distributed::Vector<double> &stage_i,
41  const dealii::LinearAlgebra::distributed::Vector<double> &stage_j,
42  std::shared_ptr<DGBase<dim,real,MeshType>> dg
43  ) const
44 {
45  // Calculate by matrix-vector product u_i^T M u_j
46  dealii::LinearAlgebra::distributed::Vector<double> temp;
47  temp.reinit(stage_j);
48 
49  if(dg->all_parameters->use_inverse_mass_on_the_fly){
50  dg->apply_global_mass_matrix(stage_j, temp);
51  } else{
52  dg->global_mass_matrix.vmult(temp,stage_j);
53  } //replace stage_j with M*stage_j
54 
55  const double result = temp * stage_i;
56  return result;
57 }
58 
61 #if PHILIP_DIM != 1
63 #endif
64 
65 } // ODESolver namespace
66 } // PHiLiP namespace
const int n_rk_stages
Number of RK stages.
AlgebraicRRKODESolver(std::shared_ptr< RKTableauBase< dim, real, MeshType >> rk_tableau_input)
Default constructor that will set the constants.
Files for the baseline physics.
Definition: ADTypes.hpp:10
real compute_relaxation_parameter(const real dt, std::shared_ptr< DGBase< dim, real, MeshType >> dg, const std::vector< dealii::LinearAlgebra::distributed::Vector< double >> &rk_stage, const dealii::LinearAlgebra::distributed::Vector< double > &) override
real compute_inner_product(const dealii::LinearAlgebra::distributed::Vector< double > &stage_i, const dealii::LinearAlgebra::distributed::Vector< double > &stage_j, std::shared_ptr< DGBase< dim, real, MeshType >> dg) const
Compute inner product according to the nodes being used.
Base class for storing the RK method.
DGBase is independent of the number of state variables.
Definition: dg_base.hpp:82
std::shared_ptr< RKTableauBase< dim, real, MeshType > > butcher_tableau
Store pointer to RK tableau.
Relaxation Runge-Kutta ODE solver base class.