-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Low storage runge kutta #259
Draft
jocelynpoon
wants to merge
26
commits into
dougshidong:master
Choose a base branch
from
jocelynpoon:low_storage_runge_kutta
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
4f19280
First commit of new Low Storage RK ODESolver. [Does not compile]
jocelynpoon 93f71f1
low storage test
jocelynpoon 01d72b3
compiles
jocelynpoon ca60d55
this works
jocelynpoon 555565c
compiles
jocelynpoon 8cb35d8
compiles but time step does not change as expected
jocelynpoon 303cbf6
fixed w term need to fix dt
jocelynpoon d858fe7
this runs
jocelynpoon 35170cc
step size change
jocelynpoon 15ad87c
save
jocelynpoon 820d80c
works with mpi > 1
jocelynpoon e758b4a
update
jocelynpoon ee073a4
add test euler inviscid tgv largest stable cfl
jocelynpoon 7acd254
add 3s*+ method and RK3(2)5F[3S*+]
jocelynpoon 40d4e00
low storage algorithms, need to fix coefficients for RK3_2_5F_3SStarPlus
jocelynpoon 659719b
correct convergence for both algorithms (3S* and 3S*+)
jocelynpoon 4a99eac
add tolerances as parameters
jocelynpoon ac2b446
tolerance parameters work
jocelynpoon 8836f90
documentation and basic changes
jocelynpoon fa1c9ce
move code around
jocelynpoon ea7cc56
clean up code
jocelynpoon c633755
add code for automatic initial step size
jocelynpoon 59f3165
update to automatic initial time step, add ode_output param
jocelynpoon 940d163
add tolerance and beta parameters to own lsrk parameter subsection
jocelynpoon 26efcdf
Add RK4(3)9F[3S*+] method
jocelynpoon 48d3ff6
add RK5_4_10F_3SStarPlus scheme
jocelynpoon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,271 @@ | ||
#include "low_storage_runge_kutta_ode_solver.h" | ||
|
||
namespace PHiLiP { | ||
namespace ODE { | ||
|
||
template <int dim, typename real, int n_rk_stages, typename MeshType> | ||
LowStorageRungeKuttaODESolver<dim,real,n_rk_stages, MeshType>::LowStorageRungeKuttaODESolver(std::shared_ptr< DGBase<dim, real, MeshType> > dg_input, | ||
std::shared_ptr<LowStorageRKTableauBase<dim,real,MeshType>> rk_tableau_input, | ||
std::shared_ptr<EmptyRRKBase<dim,real,MeshType>> RRK_object_input) | ||
: ODESolverBase<dim,real,MeshType>(dg_input) | ||
, butcher_tableau(rk_tableau_input) | ||
, relaxation_runge_kutta(RRK_object_input) | ||
{ epsilon[0] = 1.0; | ||
epsilon[1] = 1.0; | ||
epsilon[2] = 1.0; | ||
} | ||
|
||
template <int dim, typename real, int n_rk_stages, typename MeshType> | ||
void LowStorageRungeKuttaODESolver<dim,real,n_rk_stages, MeshType>::step_in_time (real dt, const bool /*pseudotime*/) | ||
{ | ||
this->original_time_step = dt; | ||
this->solution_update = this->dg->solution; //storing u_n | ||
double sum_delta = 0.0; | ||
|
||
storage_register_1.reinit(this->solution_update); | ||
storage_register_2.reinit(this->solution_update); | ||
storage_register_1 = this->dg->solution; | ||
storage_register_2 *= 0; | ||
storage_register_3 = storage_register_1; | ||
rhs = storage_register_1; | ||
if (is_3Sstarplus == true){ | ||
storage_register_4 = storage_register_1; | ||
} | ||
|
||
for (int i = 1; i < n_rk_stages +1; i++ ){ | ||
storage_register_2.add(this->butcher_tableau->get_delta(i-1) , storage_register_1); | ||
this->dg->solution = rhs; | ||
cpethrick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Apply limiter at every RK stage | ||
if (this->limiter) { | ||
this->limiter->limit(this->dg->solution, | ||
this->dg->dof_handler, | ||
this->dg->fe_collection, | ||
this->dg->volume_quadrature_collection, | ||
this->dg->high_order_grid->fe_system.tensor_degree(), | ||
this->dg->max_degree, | ||
this->dg->oneD_fe_collection_1state, | ||
this->dg->oneD_quadrature_collection); | ||
} | ||
this->dg->assemble_residual(); | ||
this->dg->apply_inverse_global_mass_matrix(this->dg->right_hand_side, rhs); | ||
storage_register_1 *= this->butcher_tableau->get_gamma(i, 0); | ||
storage_register_1.add(this->butcher_tableau->get_gamma(i, 1), storage_register_2); | ||
storage_register_1.add(this->butcher_tableau->get_gamma(i, 2), storage_register_3); | ||
rhs *= dt; | ||
storage_register_1.add(this->butcher_tableau->get_beta(i), rhs); | ||
if (is_3Sstarplus == true){ | ||
storage_register_4.add(this->butcher_tableau->get_b_hat(i-1), rhs); | ||
} | ||
rhs = storage_register_1; | ||
} | ||
|
||
if (is_3Sstarplus == false){ | ||
for (int i = 0; i < num_delta; i++){ | ||
sum_delta = sum_delta + this->butcher_tableau->get_delta(i); | ||
} | ||
storage_register_2.add(this->butcher_tableau->get_delta(n_rk_stages), storage_register_1); | ||
storage_register_2.add(this->butcher_tableau->get_delta(n_rk_stages+1), storage_register_3); | ||
storage_register_2 /= sum_delta; | ||
} | ||
else if (is_3Sstarplus == true){ | ||
this->dg->solution = rhs; | ||
// Apply limiter at every RK stage | ||
if (this->limiter) { | ||
this->limiter->limit(this->dg->solution, | ||
this->dg->dof_handler, | ||
this->dg->fe_collection, | ||
this->dg->volume_quadrature_collection, | ||
this->dg->high_order_grid->fe_system.tensor_degree(), | ||
this->dg->max_degree, | ||
this->dg->oneD_fe_collection_1state, | ||
this->dg->oneD_quadrature_collection); | ||
} | ||
this->dg->assemble_residual(); | ||
this->dg->apply_inverse_global_mass_matrix(this->dg->right_hand_side, rhs); | ||
rhs *= dt; | ||
storage_register_4.add(this->butcher_tableau->get_b_hat(n_rk_stages), rhs); | ||
|
||
} | ||
this->dg->solution = storage_register_1; | ||
|
||
// Apply limiter at every RK stage | ||
if (this->limiter) { | ||
this->limiter->limit(this->dg->solution, | ||
this->dg->dof_handler, | ||
this->dg->fe_collection, | ||
this->dg->volume_quadrature_collection, | ||
this->dg->high_order_grid->fe_system.tensor_degree(), | ||
this->dg->max_degree, | ||
this->dg->oneD_fe_collection_1state, | ||
this->dg->oneD_quadrature_collection); | ||
} | ||
|
||
if ((this->ode_param.ode_output) == Parameters::OutputEnum::verbose && | ||
(this->current_iteration%this->ode_param.print_iteration_modulo) == 0 ) { | ||
this->pcout << " Evaluating system update... " << std::endl; | ||
} | ||
|
||
this->pcout << std::endl; | ||
++(this->current_iteration); | ||
this->current_time += dt; | ||
this->pcout << " Time is: " << this->current_time <<std::endl; | ||
this->pcout << std::endl; | ||
} | ||
|
||
template <int dim, typename real, int n_rk_stages, typename MeshType> | ||
double LowStorageRungeKuttaODESolver<dim,real,n_rk_stages, MeshType>::get_automatic_error_adaptive_step_size (real dt, const bool /*pseudotime*/) | ||
{ | ||
double error = 0.0; | ||
w = 0.0; | ||
|
||
// error based step size | ||
if (is_3Sstarplus == false){ | ||
// loop sums elements at each mpi processor | ||
for (dealii::LinearAlgebra::distributed::Vector<double>::size_type i = 0; i < storage_register_1.local_size(); ++i) { | ||
error = storage_register_1.local_element(i) - storage_register_2.local_element(i); | ||
w = w + pow(error / (atol + rtol * std::max(std::abs(storage_register_1.local_element(i)), std::abs(storage_register_2.local_element(i)))), 2); | ||
} | ||
} | ||
else if (is_3Sstarplus == true){ | ||
// loop sums elements at each mpi processor | ||
for (dealii::LinearAlgebra::distributed::Vector<double>::size_type i = 0; i < storage_register_1.local_size(); ++i) { | ||
error = storage_register_1.local_element(i) - storage_register_4.local_element(i); | ||
w = w + pow(error / (atol + rtol * std::max(std::abs(storage_register_1.local_element(i)), std::abs(storage_register_4.local_element(i)))), 2); | ||
} | ||
} | ||
this->pcout << std::endl; | ||
|
||
// sum over all elements | ||
w = dealii::Utilities::MPI::sum(w, this->mpi_communicator); | ||
w = pow(w / global_size, 0.5); | ||
epsilon[2] = epsilon[1]; | ||
epsilon[1] = epsilon[0]; | ||
epsilon[0] = 1.0 / w; | ||
dt = pow(epsilon[0], 1.0 * beta1/rk_order) * pow(epsilon[1], 1.0 * beta2/rk_order) * pow(epsilon[2], 1.0 * beta3/rk_order) * dt; | ||
return dt; | ||
} | ||
|
||
template <int dim, typename real, int n_rk_stages, typename MeshType> | ||
double LowStorageRungeKuttaODESolver<dim,real,n_rk_stages, MeshType>::get_automatic_initial_step_size (real dt, const bool /*pseudotime*/) | ||
{ | ||
// h will store the starting step size | ||
double h0 = 0.0; | ||
double h1 = 0.0; | ||
|
||
// d estimates the derivate of the solution | ||
double d0 = 0.0; | ||
double d1 = 0.0; | ||
double d2 = 0.0; | ||
|
||
/// Storage of the solution to calculate the initial time step | ||
dealii::LinearAlgebra::distributed::Vector<double> u_n; | ||
dealii::LinearAlgebra::distributed::Vector<double> rhs_initial; | ||
|
||
this->solution_update = this->dg->solution; | ||
u_n.reinit(this->solution_update); | ||
rhs_initial.reinit(this->solution_update); | ||
storage_register_1.reinit(this->solution_update); | ||
storage_register_1 = this->dg->solution; | ||
u_n = storage_register_1; | ||
rhs_initial = storage_register_1; | ||
|
||
d0 = u_n.linfty_norm(); | ||
|
||
this->dg->solution = rhs_initial; | ||
this->dg->assemble_residual(); | ||
this->dg->apply_inverse_global_mass_matrix(this->dg->right_hand_side, rhs_initial); | ||
|
||
d1 = rhs_initial.linfty_norm(); | ||
|
||
if (d0 < pow(10, -5) || d1 < pow(10, -5)){ | ||
h0 = pow(10, -6); | ||
}else{ | ||
h0 = 0.01 * d0 / d1; | ||
} | ||
|
||
u_n.add(h0, rhs_initial); | ||
this->dg->solution = u_n; | ||
this->dg->assemble_residual(); | ||
this->dg->apply_inverse_global_mass_matrix(this->dg->right_hand_side, u_n); | ||
|
||
// Calculate d2 | ||
u_n.add(-1, rhs_initial); | ||
d2 = u_n.linfty_norm(); | ||
d2 /= h0; | ||
|
||
if (std::max(d1, d2) <= pow(10, -15)) | ||
{ | ||
h1 = std::max(pow(10, -6), pow(10, -3)); | ||
} | ||
else | ||
{ | ||
h1 = 0.01 / std::max(d1, d2); | ||
} | ||
|
||
dt = std::min(100 * h0, h1); | ||
this->dg->solution = storage_register_1; | ||
return dt; | ||
} | ||
|
||
|
||
template <int dim, typename real, int n_rk_stages, typename MeshType> | ||
void LowStorageRungeKuttaODESolver<dim,real,n_rk_stages, MeshType>::allocate_ode_system () | ||
{ | ||
this->solution_update.reinit(this->dg->solution); | ||
storage_register_1.reinit(this->solution_update); | ||
|
||
atol = this->ode_param.atol; | ||
rtol = this->ode_param.rtol; | ||
rk_order = this->ode_param.rk_order; | ||
is_3Sstarplus = this->ode_param.is_3Sstarplus; | ||
num_delta = this->ode_param.num_delta; | ||
beta1 = this->ode_param.beta1; | ||
beta2 = this->ode_param.beta2; | ||
beta3 = this->ode_param.beta3; | ||
|
||
global_size = dealii::Utilities::MPI::sum(storage_register_1.local_size(), this->mpi_communicator); | ||
this->pcout << "Allocating ODE system..." << std::flush; | ||
this->solution_update.reinit(this->dg->right_hand_side); | ||
if(this->all_parameters->use_inverse_mass_on_the_fly == false) { | ||
this->pcout << " evaluating inverse mass matrix..." << std::flush; | ||
this->dg->evaluate_mass_matrices(true); // creates and stores global inverse mass matrix | ||
//RRK needs both mass matrix and inverse mass matrix | ||
using ODEEnum = Parameters::ODESolverParam::ODESolverEnum; | ||
ODEEnum ode_type = this->ode_param.ode_solver_type; | ||
if (ode_type == ODEEnum::rrk_explicit_solver){ | ||
this->dg->evaluate_mass_matrices(false); // creates and stores global mass matrix | ||
} | ||
} | ||
|
||
this->pcout << std::endl; | ||
|
||
this->butcher_tableau->set_tableau(); | ||
} | ||
|
||
template class LowStorageRungeKuttaODESolver<PHILIP_DIM, double,1, dealii::Triangulation<PHILIP_DIM> >; | ||
template class LowStorageRungeKuttaODESolver<PHILIP_DIM, double,2, dealii::Triangulation<PHILIP_DIM> >; | ||
template class LowStorageRungeKuttaODESolver<PHILIP_DIM, double,3, dealii::Triangulation<PHILIP_DIM> >; | ||
template class LowStorageRungeKuttaODESolver<PHILIP_DIM, double,4, dealii::Triangulation<PHILIP_DIM> >; | ||
template class LowStorageRungeKuttaODESolver<PHILIP_DIM, double,5, dealii::Triangulation<PHILIP_DIM> >; | ||
template class LowStorageRungeKuttaODESolver<PHILIP_DIM, double,9, dealii::Triangulation<PHILIP_DIM> >; | ||
template class LowStorageRungeKuttaODESolver<PHILIP_DIM, double,10, dealii::Triangulation<PHILIP_DIM> >; | ||
template class LowStorageRungeKuttaODESolver<PHILIP_DIM, double,1, dealii::parallel::shared::Triangulation<PHILIP_DIM> >; | ||
template class LowStorageRungeKuttaODESolver<PHILIP_DIM, double,2, dealii::parallel::shared::Triangulation<PHILIP_DIM> >; | ||
template class LowStorageRungeKuttaODESolver<PHILIP_DIM, double,3, dealii::parallel::shared::Triangulation<PHILIP_DIM> >; | ||
template class LowStorageRungeKuttaODESolver<PHILIP_DIM, double,4, dealii::parallel::shared::Triangulation<PHILIP_DIM> >; | ||
template class LowStorageRungeKuttaODESolver<PHILIP_DIM, double,5, dealii::parallel::shared::Triangulation<PHILIP_DIM> >; | ||
template class LowStorageRungeKuttaODESolver<PHILIP_DIM, double,9, dealii::parallel::shared::Triangulation<PHILIP_DIM> >; | ||
template class LowStorageRungeKuttaODESolver<PHILIP_DIM, double,10, dealii::parallel::shared::Triangulation<PHILIP_DIM> >; | ||
#if PHILIP_DIM != 1 | ||
template class LowStorageRungeKuttaODESolver<PHILIP_DIM, double,1, dealii::parallel::distributed::Triangulation<PHILIP_DIM> >; | ||
template class LowStorageRungeKuttaODESolver<PHILIP_DIM, double,2, dealii::parallel::distributed::Triangulation<PHILIP_DIM> >; | ||
template class LowStorageRungeKuttaODESolver<PHILIP_DIM, double,3, dealii::parallel::distributed::Triangulation<PHILIP_DIM> >; | ||
template class LowStorageRungeKuttaODESolver<PHILIP_DIM, double,4, dealii::parallel::distributed::Triangulation<PHILIP_DIM> >; | ||
template class LowStorageRungeKuttaODESolver<PHILIP_DIM, double,5, dealii::parallel::distributed::Triangulation<PHILIP_DIM> >; | ||
template class LowStorageRungeKuttaODESolver<PHILIP_DIM, double,9, dealii::parallel::distributed::Triangulation<PHILIP_DIM> >; | ||
template class LowStorageRungeKuttaODESolver<PHILIP_DIM, double,10, dealii::parallel::distributed::Triangulation<PHILIP_DIM> >; | ||
#endif | ||
|
||
} // ODESolver namespace | ||
} // PHiLiP namespace |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! The organization looks good.