[P]arallel [Hi]gh-order [Li]brary for [P]DEs  Latest
Parallel High-Order Library for PDEs through hp-adaptive Discontinuous Galerkin methods
cube_flow_uniform_grid.cpp
1 #include "cube_flow_uniform_grid.h"
2 #include "physics/physics_factory.h"
3 
4 namespace PHiLiP {
5 namespace FlowSolver {
6 
7 template <int dim, int nstate>
8 CubeFlow_UniformGrid<dim, nstate>::CubeFlow_UniformGrid(const PHiLiP::Parameters::AllParameters *const parameters_input)
9  : FlowSolverCaseBase<dim, nstate>(parameters_input)
10 {
11  //create the Physics object
12  this->pde_physics = std::dynamic_pointer_cast<Physics::PhysicsBase<dim,nstate,double>>(
14 }
15 
16 template <int dim, int nstate>
18 {
19  // compute time step based on advection speed (i.e. maximum local wave speed)
20  const unsigned int number_of_degrees_of_freedom_per_state = dg->dof_handler.n_dofs()/nstate;
21  const double approximate_grid_spacing = (this->all_param.flow_solver_param.grid_right_bound-this->all_param.flow_solver_param.grid_left_bound)/pow(number_of_degrees_of_freedom_per_state,(1.0/dim));
22  const double cfl_number = this->all_param.flow_solver_param.courant_friedrichs_lewy_number;
23  const double time_step = cfl_number * approximate_grid_spacing / this->maximum_local_wave_speed;
24 
25  return time_step;
26 }
27 
28 template <int dim, int nstate>
30 {
31  // initialize the maximum local wave speed
32  update_maximum_local_wave_speed(*dg);
33  // compute time step based on advection speed (i.e. maximum local wave speed)
34  const double time_step = get_adaptive_time_step(dg);
35  return time_step;
36 }
37 
38 template<int dim, int nstate>
40 {
41  // Initialize the maximum local wave speed to zero
42  this->maximum_local_wave_speed = 0.0;
43 
44  // Overintegrate the error to make sure there is not integration error in the error estimate
45  int overintegrate = 10;
46  dealii::QGauss<dim> quad_extra(dg.max_degree+1+overintegrate);
47  dealii::FEValues<dim,dim> fe_values_extra(*(dg.high_order_grid->mapping_fe_field), dg.fe_collection[dg.max_degree], quad_extra,
48  dealii::update_values | dealii::update_gradients | dealii::update_JxW_values | dealii::update_quadrature_points);
49 
50  const unsigned int n_quad_pts = fe_values_extra.n_quadrature_points;
51  std::array<double,nstate> soln_at_q;
52 
53  std::vector<dealii::types::global_dof_index> dofs_indices (fe_values_extra.dofs_per_cell);
54  for (auto cell = dg.dof_handler.begin_active(); cell!=dg.dof_handler.end(); ++cell) {
55  if (!cell->is_locally_owned()) continue;
56  fe_values_extra.reinit (cell);
57  cell->get_dof_indices (dofs_indices);
58 
59  for (unsigned int iquad=0; iquad<n_quad_pts; ++iquad) {
60 
61  std::fill(soln_at_q.begin(), soln_at_q.end(), 0.0);
62  for (unsigned int idof=0; idof<fe_values_extra.dofs_per_cell; ++idof) {
63  const unsigned int istate = fe_values_extra.get_fe().system_to_component_index(idof).first;
64  soln_at_q[istate] += dg.solution[dofs_indices[idof]] * fe_values_extra.shape_value_component(idof, iquad, istate);
65  }
66 
67  // Update the maximum local wave speed (i.e. convective eigenvalue)
68  const double local_wave_speed = this->pde_physics->max_convective_eigenvalue(soln_at_q);
69  if(local_wave_speed > this->maximum_local_wave_speed) this->maximum_local_wave_speed = local_wave_speed;
70  }
71  }
72  this->maximum_local_wave_speed = dealii::Utilities::MPI::max(this->maximum_local_wave_speed, this->mpi_communicator);
73 }
74 
77 } // FlowSolver namespace
78 } // PHiLiP namespace
const Parameters::AllParameters all_param
All parameters.
const MPI_Comm mpi_communicator
MPI communicator.
virtual double get_adaptive_time_step(std::shared_ptr< DGBase< dim, double >> dg) const
Virtual function to compute the adaptive time step.
double courant_friedrichs_lewy_number
Courant-Friedrich-Lewy (CFL) number for constant time step.
FlowSolverParam flow_solver_param
Contains the parameters for simulation cases (flow solver test)
Files for the baseline physics.
Definition: ADTypes.hpp:10
Main parameter class that contains the various other sub-parameter classes.
dealii::LinearAlgebra::distributed::Vector< double > solution
Current modal coefficients of the solution.
Definition: dg_base.hpp:409
double grid_left_bound
Left bound of domain for hyper_cube mesh based cases.
void update_maximum_local_wave_speed(DGBase< dim, double > &dg)
Updates the maximum local wave speed.
const unsigned int max_degree
Maximum degree used for p-refi1nement.
Definition: dg_base.hpp:104
std::shared_ptr< HighOrderGrid< dim, real, MeshType > > high_order_grid
High order grid that will provide the MappingFEField.
Definition: dg_base.hpp:655
static std::shared_ptr< PhysicsBase< dim, nstate, real > > create_Physics(const Parameters::AllParameters *const parameters_input, std::shared_ptr< ModelBase< dim, nstate, real > > model_input=nullptr)
Factory to return the correct physics given input file.
dealii::DoFHandler< dim > dof_handler
Finite Element Collection to represent the high-order grid.
Definition: dg_base.hpp:652
double get_adaptive_time_step(std::shared_ptr< DGBase< dim, double >> dg) const override
Function to compute the adaptive time step.
double get_adaptive_time_step_initial(std::shared_ptr< DGBase< dim, double >> dg) override
Function to compute the initial adaptive time step.
double grid_right_bound
Right bound of domain for hyper_cube mesh based cases.
DGBase is independent of the number of state variables.
Definition: dg_base.hpp:82
const dealii::hp::FECollection< dim > fe_collection
Finite Element Collection for p-finite-element to represent the solution.
Definition: dg_base.hpp:597