[P]arallel [Hi]gh-order [Li]brary for [P]DEs  Latest
Parallel High-Order Library for PDEs through hp-adaptive Discontinuous Galerkin methods
dg_base_state.cpp
1 #include <boost/preprocessor/seq/for_each.hpp>
2 
3 
4 #include "dg_base_state.hpp"
5 #include "physics/model_factory.h"
6 #include "physics/physics_factory.h"
7 
8 namespace PHiLiP {
9 
10 template <int dim, int nspecies, int nstate, typename real, typename MeshType>
12  const unsigned int degree, const unsigned int max_degree_input,
13  const unsigned int grid_degree_input,
14  const std::shared_ptr<Triangulation> triangulation_input)
15  : DGBase<dim, nspecies, real, MeshType>::DGBase(nstate, parameters_input, degree, max_degree_input, grid_degree_input,
16  triangulation_input) // Use DGBase constructor
17 {
19 
22 
25 
28 
32 
36 
38 }
39 
40 template <int dim, int nspecies, int nstate, typename real, typename MeshType>
46 
51 
56 
64 
72 }
73 
74 template <int dim, int nspecies, int nstate, typename real, typename MeshType>
76  std::shared_ptr<Physics::PhysicsBase<dim, nspecies, nstate, real> > pde_physics_double_input,
77  std::shared_ptr<Physics::PhysicsBase<dim, nspecies, nstate, FadType> > pde_physics_fad_input,
78  std::shared_ptr<Physics::PhysicsBase<dim, nspecies, nstate, RadType> > pde_physics_rad_input,
79  std::shared_ptr<Physics::PhysicsBase<dim, nspecies, nstate, FadFadType> > pde_physics_fad_fad_input,
80  std::shared_ptr<Physics::PhysicsBase<dim, nspecies, nstate, RadFadType> > pde_physics_rad_fad_input) {
81  pde_physics_double = pde_physics_double_input;
82  pde_physics_fad = pde_physics_fad_input;
83  pde_physics_rad = pde_physics_rad_input;
84  pde_physics_fad_fad = pde_physics_fad_fad_input;
85  pde_physics_rad_fad = pde_physics_rad_fad_input;
86 
88 }
89 
90 template <int dim, int nspecies, int nstate, typename real, typename MeshType>
92  // allocate all model variables for each ModelBase object
93  // -- double
94  pde_model_double->cellwise_poly_degree.reinit(this->triangulation->n_active_cells(), this->mpi_communicator);
95  pde_model_double->cellwise_volume.reinit(this->triangulation->n_active_cells(), this->mpi_communicator);
96  // -- FadType
97  pde_model_fad->cellwise_poly_degree.reinit(this->triangulation->n_active_cells(), this->mpi_communicator);
98  pde_model_fad->cellwise_volume.reinit(this->triangulation->n_active_cells(), this->mpi_communicator);
99  // -- RadType
100  pde_model_rad->cellwise_poly_degree.reinit(this->triangulation->n_active_cells(), this->mpi_communicator);
101  pde_model_rad->cellwise_volume.reinit(this->triangulation->n_active_cells(), this->mpi_communicator);
102  // -- FadFadType
103  pde_model_fad_fad->cellwise_poly_degree.reinit(this->triangulation->n_active_cells(), this->mpi_communicator);
104  pde_model_fad_fad->cellwise_volume.reinit(this->triangulation->n_active_cells(), this->mpi_communicator);
105  // -- RadFadType
106  pde_model_rad_fad->cellwise_poly_degree.reinit(this->triangulation->n_active_cells(), this->mpi_communicator);
107  pde_model_rad_fad->cellwise_volume.reinit(this->triangulation->n_active_cells(), this->mpi_communicator);
108 }
109 
110 template <int dim, int nspecies, int nstate, typename real, typename MeshType>
112  // allocate/reinit the model variables
114 
115  // get FEValues of volume
116  const auto mapping = (*(this->high_order_grid->mapping_fe_field));
117  dealii::hp::MappingCollection<dim> mapping_collection(mapping);
118  const dealii::UpdateFlags update_flags = dealii::update_values | dealii::update_JxW_values;
119  dealii::hp::FEValues<dim,dim> fe_values_collection_volume (mapping_collection,
120  this->fe_collection,
122  update_flags);
123 
124  // loop through all cells
125  for (auto cell : this->dof_handler.active_cell_iterators()) {
126  if (!(cell->is_locally_owned() || cell->is_ghost())) continue;
127 
128  // get FEValues of volume for current cell
129  const int i_fele = cell->active_fe_index();
130  const int i_quad = i_fele;
131  const int i_mapp = 0;
132  fe_values_collection_volume.reinit(cell, i_quad, i_mapp, i_fele);
133  const dealii::FEValues<dim,dim> &fe_values_volume = fe_values_collection_volume.get_present_fe_values();
134 
135  // get cell polynomial degree
136  const dealii::FESystem<dim,dim> &fe_high = this->fe_collection[i_fele];
137  const unsigned int cell_poly_degree = fe_high.tensor_degree();
138 
139  // get cell volume
140  const dealii::Quadrature<dim> &quadrature = fe_values_volume.get_quadrature();
141  const unsigned int n_quad_pts = quadrature.size();
142  const std::vector<real> &JxW = fe_values_volume.get_JxW_values();
143  real cell_volume_estimate = 0.0;
144  for (unsigned int iquad=0; iquad<n_quad_pts; ++iquad) {
145  cell_volume_estimate = cell_volume_estimate + JxW[iquad];
146  }
147  const real cell_volume = cell_volume_estimate;
148 
149  // get cell index for assignment
150  const dealii::types::global_dof_index cell_index = cell->active_cell_index();
151  // const dealii::types::global_dof_index cell_index = cell->global_active_cell_index(); // https://www.dealii.org/current/doxygen/deal.II/classCellAccessor.html
152 
153  // assign values
154  // -- double
155  pde_model_double->cellwise_poly_degree[cell_index] = cell_poly_degree;
156  pde_model_double->cellwise_volume[cell_index] = cell_volume;
157  // -- FadType
158  pde_model_fad->cellwise_poly_degree[cell_index] = cell_poly_degree;
159  pde_model_fad->cellwise_volume[cell_index] = cell_volume;
160  // -- RadType
161  pde_model_rad->cellwise_poly_degree[cell_index] = cell_poly_degree;
162  pde_model_rad->cellwise_volume[cell_index] = cell_volume;
163  // -- FadFadType
164  pde_model_fad_fad->cellwise_poly_degree[cell_index] = cell_poly_degree;
165  pde_model_fad_fad->cellwise_volume[cell_index] = cell_volume;
166  // -- RadRadType
167  pde_model_rad_fad->cellwise_poly_degree[cell_index] = cell_poly_degree;
168  pde_model_rad_fad->cellwise_volume[cell_index] = cell_volume;
169  }
170  pde_model_double->cellwise_poly_degree.update_ghost_values();
171  pde_model_double->cellwise_volume.update_ghost_values();
172  pde_model_fad->cellwise_poly_degree.update_ghost_values();
173  pde_model_fad->cellwise_volume.update_ghost_values();
174  pde_model_rad->cellwise_poly_degree.update_ghost_values();
175  pde_model_rad->cellwise_volume.update_ghost_values();
176  pde_model_fad_fad->cellwise_poly_degree.update_ghost_values();
177  pde_model_fad_fad->cellwise_volume.update_ghost_values();
178  pde_model_rad_fad->cellwise_poly_degree.update_ghost_values();
179  pde_model_rad_fad->cellwise_volume.update_ghost_values();
180 }
181 
182 template <int dim, int nspecies, int nstate, typename real, typename MeshType>
184  const double time_step)
185 {
186  // time_step
187  if(pde_model_double) pde_model_double->time_step = time_step;
188  if(pde_model_fad) pde_model_fad->time_step = time_step;
189  if(pde_model_rad) pde_model_rad->time_step = time_step;
190  if(pde_model_fad_fad) pde_model_fad_fad->time_step = time_step;
191  if(pde_model_rad_fad) pde_model_rad_fad->time_step = time_step;
192 }
193 
194 template <int dim, int nspecies, int nstate, typename real, typename MeshType>
196  this->use_auxiliary_eq = (pde_physics_double->has_nonzero_diffusion && !this->all_parameters->use_weak_form) ? true : false;
197 }
198 
199 template <int dim, int nspecies, int nstate, typename real, typename MeshType>
201 {
202  //if have source term need to store vol flux nodes.
204  || pde_physics_double->has_nonzero_physical_source);
205 }
206 
207 template <int dim, int nspecies, int nstate, typename real, typename MeshType>
209 {
210  //if all boundaries are periodic, we do not need to store surf flux nodes.
211  //for boundary conditions not periodic we need surface flux nodes
212  //should change this flag to something like if have face on boundary not periodic in the future
213  this->store_surf_flux_nodes = (this->all_parameters->all_boundaries_are_periodic) ? false : true;
214 }
215 
216 template <int dim, int nspecies, int nstate, typename real, typename MeshType>
217 real DGBaseState<dim, nspecies, nstate, real, MeshType>::evaluate_CFL(std::vector<std::array<real, nstate> > soln_at_q,
218  const real artificial_dissipation, const real cell_diameter,
219  const unsigned int cell_degree) {
220  const unsigned int n_pts = soln_at_q.size();
221  std::vector<real> convective_eigenvalues(n_pts);
222  std::vector<real> viscosities(n_pts);
223  for (unsigned int isol = 0; isol < n_pts; ++isol) {
224  convective_eigenvalues[isol] = pde_physics_double->max_convective_eigenvalue(soln_at_q[isol]);
225  viscosities[isol] = pde_physics_double->max_viscous_eigenvalue(soln_at_q[isol]);
226  }
227  const real max_eig = *(std::max_element(convective_eigenvalues.begin(), convective_eigenvalues.end()));
228  const real max_diffusive = *(std::max_element(viscosities.begin(), viscosities.end()));
229 
230  // const real cfl_convective = cell_diameter / max_eig;
231  // const real cfl_diffusive = artificial_dissipation != 0.0 ? 0.5*cell_diameter*cell_diameter /
232  // artificial_dissipation : 1e200; real min_cfl = std::min(cfl_convective, cfl_diffusive) / (2*cell_degree + 1.0);
233 
234  const unsigned int p = std::max((unsigned int)1, cell_degree);
235  const real cfl_convective = (cell_diameter / max_eig) / (2 * p + 1); //(p * p);
236  const real cfl_diffusive = artificial_dissipation != 0.0
237  ? (0.5 * cell_diameter * cell_diameter / artificial_dissipation) / (p * p * p * p)
239  Parameters::ODESolverParam::ODESolverEnum::implicit_solver)
240  ? // if explicit use pseudotime stepping CFL
241  (0.5 * cell_diameter * cell_diameter / max_diffusive) / (2 * p + 1)
242  : 1e200);
243  real min_cfl = std::min(cfl_convective, cfl_diffusive);
244 
245  if (min_cfl >= 1e190) min_cfl = cell_diameter / 1;
246 
247  return min_cfl;
248 }
249 
250 #if PHILIP_SPECIES==1
251  // Define a sequence of indices representing the range [1, 5]
252  #define POSSIBLE_NSTATE (1)(2)(3)(4)(5)(6)
253 
254  // Define a macro to instantiate MyTemplate for a specific index
255  #define INSTANTIATE_DISTRIBUTED(r, data, index) \
256  template class DGBaseState <PHILIP_DIM, PHILIP_SPECIES, index, double, dealii::parallel::distributed::Triangulation<PHILIP_DIM>>;
257 
258  #if PHILIP_DIM!=1
259  BOOST_PP_SEQ_FOR_EACH(INSTANTIATE_DISTRIBUTED, _, POSSIBLE_NSTATE)
260  #endif
261 
262  #define INSTANTIATE_TRIA(r, data, index) \
263  template class DGBaseState <PHILIP_DIM, PHILIP_SPECIES, index, double, dealii::parallel::shared::Triangulation<PHILIP_DIM>>; \
264  template class DGBaseState <PHILIP_DIM, PHILIP_SPECIES, index, double, dealii::Triangulation<PHILIP_DIM>>;
265  BOOST_PP_SEQ_FOR_EACH(INSTANTIATE_TRIA, _, POSSIBLE_NSTATE)
266 #else
267  #if PHILIP_DIM!=1
269  #endif
272 #endif
273 } // namespace PHiLiP
std::shared_ptr< Physics::ModelBase< dim, nspecies, nstate, FadFadType > > pde_model_fad_fad
Contains the model terms of the PDEType == PhysicsModel with FadFadType.
void set_use_auxiliary_eq()
Set use_auxiliary_eq flag.
PartialDifferentialEquation pde_type
Store the PDE type to be solved.
static std::shared_ptr< ArtificialDissipationBase< dim, nspecies, nstate > > create_artificial_dissipation(const Parameters::AllParameters *const parameters_input)
Creates artificial dissipation type depending on input parameters.
void set_store_vol_flux_nodes()
Set store_vol_flux_nodes flag.
bool all_boundaries_are_periodic
Flag to signal that all boundaries are periodic; if true surface flux nodes will not be stored for ef...
Base class from which Advection, Diffusion, ConvectionDiffusion, and Euler is derived.
Definition: physics.h:34
std::shared_ptr< Physics::ModelBase< dim, nspecies, nstate, RadFadType > > pde_model_rad_fad
Contains the model terms of the PDEType == PhysicsModel with RadFadType.
DGBaseState(const Parameters::AllParameters *const parameters_input, const unsigned int degree, const unsigned int max_degree_input, const unsigned int grid_degree_input, const std::shared_ptr< Triangulation > triangulation_input)
< Input parameters.
std::shared_ptr< ArtificialDissipationBase< dim, nspecies, nstate > > artificial_dissip
Link to Artificial dissipation class (with three dissipation types, depending on the input)...
Files for the baseline physics.
Definition: ADTypes.hpp:10
bool use_weak_form
Flag to use weak or strong form of DG.
ManufacturedSolutionParam manufactured_solution_param
Associated manufactured solution parameters.
std::shared_ptr< Physics::ModelBase< dim, nspecies, nstate, real > > pde_model_double
Contains the model terms of the PDEType == PhysicsModel with real type.
std::shared_ptr< HighOrderGrid< dim, real, MeshType > > high_order_grid
High order grid that will provide the MappingFEField.
Definition: dg_base.hpp:1178
dealii::hp::QCollection< dim > volume_quadrature_collection
Finite Element Collection to represent the high-order grid.
Definition: dg_base.hpp:1131
std::unique_ptr< NumericalFlux::NumericalFluxConvective< dim, nspecies, nstate, RadFadType > > conv_num_flux_rad_fad
Convective numerical flux with RadFadDtype.
std::shared_ptr< Physics::ModelBase< dim, nspecies, nstate, FadType > > pde_model_fad
Contains the model terms of the PDEType == PhysicsModel with FadType.
std::unique_ptr< NumericalFlux::NumericalFluxDissipative< dim, nspecies, nstate, FadType > > diss_num_flux_fad
Dissipative numerical flux with FadType.
std::shared_ptr< Physics::PhysicsBase< dim, nspecies, nstate, FadType > > pde_physics_fad
Contains the physics of the PDE with FadType.
Main parameter class that contains the various other sub-parameter classes.
void set_physics(std::shared_ptr< Physics::PhysicsBase< dim, nspecies, nstate, real > > pde_physics_double_input, std::shared_ptr< Physics::PhysicsBase< dim, nspecies, nstate, FadType > > pde_physics_fad_input, std::shared_ptr< Physics::PhysicsBase< dim, nspecies, nstate, RadType > > pde_physics_rad_input, std::shared_ptr< Physics::PhysicsBase< dim, nspecies, nstate, FadFadType > > pde_physics_fad_fad_input, std::shared_ptr< Physics::PhysicsBase< dim, nspecies, nstate, RadFadType > > pde_physics_rad_fad_input)
std::unique_ptr< NumericalFlux::NumericalFluxConvective< dim, nspecies, nstate, FadType > > conv_num_flux_fad
Convective numerical flux with FadType.
static std::unique_ptr< NumericalFluxConvective< dim, nspecies, nstate, real > > create_convective_numerical_flux(const AllParam::ConvectiveNumericalFlux conv_num_flux_type, const AllParam::PartialDifferentialEquation pde_type, const AllParam::ModelType model_type, std::shared_ptr< Physics::PhysicsBase< dim, nspecies, nstate, real >> physics_input)
Creates convective numerical flux (baseline flux + upwind term) based on input.
dealii::DoFHandler< dim > dof_handler
Finite Element Collection to represent the high-order grid.
Definition: dg_base.hpp:1175
ManufacturedConvergenceStudyParam manufactured_convergence_study_param
Contains parameters for manufactured convergence study.
ODESolverParam ode_solver_param
Contains parameters for ODE solver.
bool use_auxiliary_eq
Flag for using the auxiliary equation.
Definition: dg_base.hpp:1305
dealii::Vector< double > cell_volume
Time it takes for the maximum wavespeed to cross the cell domain.
Definition: dg_base.hpp:454
const Parameters::AllParameters *const all_parameters
Pointer to all parameters.
Definition: dg_base.hpp:91
MPI_Comm mpi_communicator
MPI communicator.
Definition: dg_base.hpp:1258
std::unique_ptr< NumericalFlux::NumericalFluxDissipative< dim, nspecies, nstate, RadType > > diss_num_flux_rad
Dissipative numerical flux with RadType.
virtual void update_model_variables()
Update the necessary variables declared in src/physics/model.h.
bool use_manufactured_source_term
Uses non-zero source term based on the manufactured solution and the PDE.
std::shared_ptr< Physics::PhysicsBase< dim, nspecies, nstate, FadFadType > > pde_physics_fad_fad
Contains the physics of the PDE with FadFadType.
static std::unique_ptr< NumericalFluxDissipative< dim, nspecies, nstate, real > > create_dissipative_numerical_flux(const AllParam::DissipativeNumericalFlux diss_num_flux_type, std::shared_ptr< Physics::PhysicsBase< dim, nspecies, nstate, real >> physics_input, std::shared_ptr< ArtificialDissipationBase< dim, nspecies, nstate >> artificial_dissipation_input)
Creates dissipative numerical flux based on input.
std::shared_ptr< Physics::PhysicsBase< dim, nspecies, nstate, RadFadType > > pde_physics_rad_fad
Contains the physics of the PDE with RadFadDtype.
std::unique_ptr< NumericalFlux::NumericalFluxConvective< dim, nspecies, nstate, real > > conv_num_flux_double
Convective numerical flux with real type.
ConvectiveNumericalFlux conv_num_flux_type
Store convective flux type.
Abstract class templated on the number of state variables.
std::shared_ptr< Physics::PhysicsBase< dim, nspecies, nstate, RadType > > pde_physics_rad
Contains the physics of the PDE with RadType.
bool store_surf_flux_nodes
Flag for storing surface flux nodes.
Definition: dg_base.hpp:1313
std::unique_ptr< NumericalFlux::NumericalFluxDissipative< dim, nspecies, nstate, FadFadType > > diss_num_flux_fad_fad
Dissipative numerical flux with FadFadType.
ODESolverEnum ode_solver_type
ODE solver type.
std::unique_ptr< NumericalFlux::NumericalFluxDissipative< dim, nspecies, nstate, RadFadType > > diss_num_flux_rad_fad
Dissipative numerical flux with RadFadDtype.
static std::shared_ptr< PhysicsBase< dim, nspecies, nstate, real > > create_Physics(const Parameters::AllParameters *const parameters_input, std::shared_ptr< ModelBase< dim, nspecies, nstate, real > > model_input=nullptr)
Factory to return the correct physics given input file.
void reset_numerical_fluxes()
Reinitializes the numerical fluxes based on the current physics.
void set_store_surf_flux_nodes()
Set store_surf_flux_nodes flag.
DissipativeNumericalFlux diss_num_flux_type
Store diffusive flux type.
std::shared_ptr< Triangulation > triangulation
Mesh.
Definition: dg_base.hpp:160
std::unique_ptr< NumericalFlux::NumericalFluxConvective< dim, nspecies, nstate, FadFadType > > conv_num_flux_fad_fad
Convective numerical flux with FadFadType.
const dealii::hp::FECollection< dim > fe_collection
Finite Element Collection for p-finite-element to represent the solution.
Definition: dg_base.hpp:1120
ModelType model_type
Store the model type.
DGBase is independent of the number of state variables.
Definition: dg_base.hpp:82
std::unique_ptr< NumericalFlux::NumericalFluxDissipative< dim, nspecies, nstate, real > > diss_num_flux_double
Dissipative numerical flux with real type.
void set_unsteady_model_time_step(const double time_step)
Set the necessary unsteady variables declared in src/physics/model.h.
std::shared_ptr< Physics::ModelBase< dim, nspecies, nstate, RadType > > pde_model_rad
Contains the model terms of the PDEType == PhysicsModel with RadType.
static std::shared_ptr< ModelBase< dim, nspecies, nstate, real > > create_Model(const Parameters::AllParameters *const parameters_input)
Factory to return the correct model given input parameters.
std::unique_ptr< NumericalFlux::NumericalFluxConvective< dim, nspecies, nstate, RadType > > conv_num_flux_rad
Convective numerical flux with RadType.
virtual void allocate_model_variables()
Allocate the necessary variables declared in src/physics/model.h.
std::shared_ptr< Physics::PhysicsBase< dim, nspecies, nstate, real > > pde_physics_double
Contains the physics of the PDE with real type.
real evaluate_CFL(std::vector< std::array< real, nstate > > soln_at_q, const real artificial_dissipation, const real cell_diameter, const unsigned int cell_degree)
Evaluate the time it takes for the maximum wavespeed to cross the cell domain.
bool store_vol_flux_nodes
Flag for storing volume flux nodes.
Definition: dg_base.hpp:1309