[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 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, 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 nstate, typename real, typename MeshType>
46 
51 
56 
64 
72 }
73 
74 template <int dim, int nstate, typename real, typename MeshType>
76  std::shared_ptr<Physics::PhysicsBase<dim, nstate, real> > pde_physics_double_input,
77  std::shared_ptr<Physics::PhysicsBase<dim, nstate, FadType> > pde_physics_fad_input,
78  std::shared_ptr<Physics::PhysicsBase<dim, nstate, RadType> > pde_physics_rad_input,
79  std::shared_ptr<Physics::PhysicsBase<dim, nstate, FadFadType> > pde_physics_fad_fad_input,
80  std::shared_ptr<Physics::PhysicsBase<dim, 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 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 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, this->fe_collection,
120  this->volume_quadrature_collection, update_flags);
121 
122  // loop through all cells
123  for (auto cell : this->dof_handler.active_cell_iterators()) {
124  if (!(cell->is_locally_owned() || cell->is_ghost())) continue;
125 
126  // get FEValues of volume for current cell
127  const int i_fele = cell->active_fe_index();
128  const int i_quad = i_fele;
129  const int i_mapp = 0;
130  fe_values_collection_volume.reinit(cell, i_quad, i_mapp, i_fele);
131  const dealii::FEValues<dim, dim> &fe_values_volume = fe_values_collection_volume.get_present_fe_values();
132 
133  // get cell polynomial degree
134  const dealii::FESystem<dim, dim> &fe_high = this->fe_collection[i_fele];
135  const unsigned int cell_poly_degree = fe_high.tensor_degree();
136 
137  // get cell volume
138  const dealii::Quadrature<dim> &quadrature = fe_values_volume.get_quadrature();
139  const unsigned int n_quad_pts = quadrature.size();
140  const std::vector<real> &JxW = fe_values_volume.get_JxW_values();
141  real cell_volume_estimate = 0.0;
142  for (unsigned int iquad = 0; iquad < n_quad_pts; ++iquad) {
143  cell_volume_estimate = cell_volume_estimate + JxW[iquad];
144  }
145  const real cell_volume = cell_volume_estimate;
146 
147  // get cell index for assignment
148  const dealii::types::global_dof_index cell_index = cell->active_cell_index();
149  // const dealii::types::global_dof_index cell_index = cell->global_active_cell_index(); //
150  // https://www.dealii.org/current/doxygen/deal.II/classCellAccessor.html
151 
152  // assign values
153  // -- double
154  pde_model_double->cellwise_poly_degree[cell_index] = cell_poly_degree;
155  pde_model_double->cellwise_volume[cell_index] = cell_volume;
156  // -- FadType
157  pde_model_fad->cellwise_poly_degree[cell_index] = cell_poly_degree;
158  pde_model_fad->cellwise_volume[cell_index] = cell_volume;
159  // -- RadType
160  pde_model_rad->cellwise_poly_degree[cell_index] = cell_poly_degree;
161  pde_model_rad->cellwise_volume[cell_index] = cell_volume;
162  // -- FadFadType
163  pde_model_fad_fad->cellwise_poly_degree[cell_index] = cell_poly_degree;
164  pde_model_fad_fad->cellwise_volume[cell_index] = cell_volume;
165  // -- RadRadType
166  pde_model_rad_fad->cellwise_poly_degree[cell_index] = cell_poly_degree;
167  pde_model_rad_fad->cellwise_volume[cell_index] = cell_volume;
168  }
169  pde_model_double->cellwise_poly_degree.update_ghost_values();
170  pde_model_double->cellwise_volume.update_ghost_values();
171  pde_model_fad->cellwise_poly_degree.update_ghost_values();
172  pde_model_fad->cellwise_volume.update_ghost_values();
173  pde_model_rad->cellwise_poly_degree.update_ghost_values();
174  pde_model_rad->cellwise_volume.update_ghost_values();
175  pde_model_fad_fad->cellwise_poly_degree.update_ghost_values();
176  pde_model_fad_fad->cellwise_volume.update_ghost_values();
177  pde_model_rad_fad->cellwise_poly_degree.update_ghost_values();
178  pde_model_rad_fad->cellwise_volume.update_ghost_values();
179 }
180 
181 template <int dim, int nstate, typename real, typename MeshType>
183  this->use_auxiliary_eq = pde_physics_double->has_nonzero_diffusion;
184 }
185 
186 template <int dim, int nstate, typename real, typename MeshType>
187 real DGBaseState<dim, nstate, real, MeshType>::evaluate_CFL(std::vector<std::array<real, nstate> > soln_at_q,
188  const real artificial_dissipation, const real cell_diameter,
189  const unsigned int cell_degree) {
190  const unsigned int n_pts = soln_at_q.size();
191  std::vector<real> convective_eigenvalues(n_pts);
192  std::vector<real> viscosities(n_pts);
193  for (unsigned int isol = 0; isol < n_pts; ++isol) {
194  convective_eigenvalues[isol] = pde_physics_double->max_convective_eigenvalue(soln_at_q[isol]);
195  viscosities[isol] = pde_physics_double->max_viscous_eigenvalue(soln_at_q[isol]);
196  }
197  const real max_eig = *(std::max_element(convective_eigenvalues.begin(), convective_eigenvalues.end()));
198  const real max_diffusive = *(std::max_element(viscosities.begin(), viscosities.end()));
199 
200  // const real cfl_convective = cell_diameter / max_eig;
201  // const real cfl_diffusive = artificial_dissipation != 0.0 ? 0.5*cell_diameter*cell_diameter /
202  // artificial_dissipation : 1e200; real min_cfl = std::min(cfl_convective, cfl_diffusive) / (2*cell_degree + 1.0);
203 
204  const unsigned int p = std::max((unsigned int)1, cell_degree);
205  const real cfl_convective = (cell_diameter / max_eig) / (2 * p + 1); //(p * p);
206  const real cfl_diffusive = artificial_dissipation != 0.0
207  ? (0.5 * cell_diameter * cell_diameter / artificial_dissipation) / (p * p * p * p)
209  Parameters::ODESolverParam::ODESolverEnum::implicit_solver)
210  ? // if explicit use pseudotime stepping CFL
211  (0.5 * cell_diameter * cell_diameter / max_diffusive) / (2 * p + 1)
212  : 1e200);
213  real min_cfl = std::min(cfl_convective, cfl_diffusive);
214 
215  if (min_cfl >= 1e190) min_cfl = cell_diameter / 1;
216 
217  return min_cfl;
218 }
219 
220 // Define a sequence of indices representing the range [1, 5]
221 #define POSSIBLE_NSTATE (1)(2)(3)(4)(5)(6)
222 
223 // Define a macro to instantiate MyTemplate for a specific index
224 #define INSTANTIATE_DISTRIBUTED(r, data, index) \
225  template class DGBaseState <PHILIP_DIM, index, double, dealii::parallel::distributed::Triangulation<PHILIP_DIM>>;
226 
227 #if PHILIP_DIM!=1
228 BOOST_PP_SEQ_FOR_EACH(INSTANTIATE_DISTRIBUTED, _, POSSIBLE_NSTATE)
229 #endif
230 
231 #define INSTANTIATE_SHARED(r, data, index) \
232  template class DGBaseState <PHILIP_DIM, index, double, dealii::parallel::shared::Triangulation<PHILIP_DIM>>;
233 BOOST_PP_SEQ_FOR_EACH(INSTANTIATE_SHARED, _, POSSIBLE_NSTATE)
234 
235 #define INSTANTIATE_TRIA(r, data, index) \
236  template class DGBaseState <PHILIP_DIM, index, double, dealii::Triangulation<PHILIP_DIM>>;
237 BOOST_PP_SEQ_FOR_EACH(INSTANTIATE_TRIA, _, POSSIBLE_NSTATE)
238 
239 } // namespace PHiLiP
PartialDifferentialEquation pde_type
Store the PDE type to be solved.
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.
bool use_auxiliary_eq
Flag for using the auxiliary equation.
Definition: dg_base.hpp:938
std::unique_ptr< NumericalFlux::NumericalFluxDissipative< dim, nstate, real > > diss_num_flux_double
Dissipative numerical flux with real type.
void set_use_auxiliary_eq()
Set use_auxiliary_eq flag.
const Parameters::AllParameters *const all_parameters
Pointer to all parameters.
Definition: dg_base.hpp:91
Base class from which Advection, Diffusion, ConvectionDiffusion, and Euler is derived.
Definition: physics.h:34
static std::unique_ptr< NumericalFluxConvective< dim, 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, nstate, real >> physics_input)
Creates convective numerical flux (baseline flux + upwind term) based on input.
void update_model_variables()
Update the necessary variables declared in src/physics/model.h.
std::unique_ptr< NumericalFlux::NumericalFluxConvective< dim, nstate, FadFadType > > conv_num_flux_fad_fad
Convective numerical flux with FadFadType.
std::unique_ptr< NumericalFlux::NumericalFluxConvective< dim, nstate, real > > conv_num_flux_double
Convective numerical flux with real type.
std::shared_ptr< Triangulation > triangulation
Mesh.
Definition: dg_base.hpp:160
std::unique_ptr< NumericalFlux::NumericalFluxConvective< dim, nstate, FadType > > conv_num_flux_fad
Convective numerical flux with FadType.
Files for the baseline physics.
Definition: ADTypes.hpp:10
static std::unique_ptr< NumericalFluxDissipative< dim, nstate, real > > create_dissipative_numerical_flux(const AllParam::DissipativeNumericalFlux diss_num_flux_type, std::shared_ptr< Physics::PhysicsBase< dim, nstate, real >> physics_input, std::shared_ptr< ArtificialDissipationBase< dim, nstate >> artificial_dissipation_input)
Creates dissipative numerical flux based on input.
std::shared_ptr< Physics::ModelBase< dim, nstate, FadFadType > > pde_model_fad_fad
Contains the model terms of the PDEType == PhysicsModel with FadFadType.
std::shared_ptr< Physics::ModelBase< dim, nstate, real > > pde_model_double
Contains the model terms of the PDEType == PhysicsModel with real type.
std::unique_ptr< NumericalFlux::NumericalFluxConvective< dim, nstate, RadFadType > > conv_num_flux_rad_fad
Convective numerical flux with RadFadDtype.
MPI_Comm mpi_communicator
MPI communicator.
Definition: dg_base.hpp:893
Main parameter class that contains the various other sub-parameter classes.
void reset_numerical_fluxes()
Reinitializes the numerical fluxes based on the current physics.
std::unique_ptr< NumericalFlux::NumericalFluxDissipative< dim, nstate, RadFadType > > diss_num_flux_rad_fad
Dissipative numerical flux with RadFadDtype.
static std::shared_ptr< ArtificialDissipationBase< dim, nstate > > create_artificial_dissipation(const Parameters::AllParameters *const parameters_input)
Creates artificial dissipation type depending on input parameters.
std::shared_ptr< Physics::PhysicsBase< dim, nstate, FadFadType > > pde_physics_fad_fad
Contains the physics of the PDE with FadFadType.
ODESolverParam ode_solver_param
Contains parameters for ODE solver.
std::shared_ptr< Physics::ModelBase< dim, nstate, RadFadType > > pde_model_rad_fad
Contains the model terms of the PDEType == PhysicsModel with RadFadType.
std::shared_ptr< Physics::PhysicsBase< dim, nstate, real > > pde_physics_double
Contains the physics of the PDE with real type.
void allocate_model_variables()
Allocate the necessary variables declared in src/physics/model.h.
std::shared_ptr< Physics::PhysicsBase< dim, nstate, RadType > > pde_physics_rad
Contains the physics of the PDE with RadType.
static std::shared_ptr< ModelBase< dim, nstate, real > > create_Model(const Parameters::AllParameters *const parameters_input)
Factory to return the correct model given input parameters.
std::shared_ptr< ArtificialDissipationBase< dim, nstate > > artificial_dissip
Link to Artificial dissipation class (with three dissipation types, depending on the input)...
std::shared_ptr< HighOrderGrid< dim, real, MeshType > > high_order_grid
High order grid that will provide the MappingFEField.
Definition: dg_base.hpp:655
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.
std::shared_ptr< Physics::PhysicsBase< dim, nstate, RadFadType > > pde_physics_rad_fad
Contains the physics of the PDE with RadFadDtype.
std::unique_ptr< NumericalFlux::NumericalFluxDissipative< dim, nstate, FadType > > diss_num_flux_fad
Dissipative numerical flux with FadType.
std::shared_ptr< Physics::ModelBase< dim, nstate, FadType > > pde_model_fad
Contains the model terms of the PDEType == PhysicsModel with FadType.
std::unique_ptr< NumericalFlux::NumericalFluxDissipative< dim, nstate, RadType > > diss_num_flux_rad
Dissipative numerical flux with RadType.
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.
std::shared_ptr< Physics::ModelBase< dim, nstate, RadType > > pde_model_rad
Contains the model terms of the PDEType == PhysicsModel with RadType.
std::unique_ptr< NumericalFlux::NumericalFluxDissipative< dim, nstate, FadFadType > > diss_num_flux_fad_fad
Dissipative numerical flux with FadFadType.
std::shared_ptr< Physics::PhysicsBase< dim, nstate, FadType > > pde_physics_fad
Contains the physics of the PDE with FadType.
ConvectiveNumericalFlux conv_num_flux_type
Store convective flux type.
ODESolverEnum ode_solver_type
ODE solver type.
dealii::DoFHandler< dim > dof_handler
Finite Element Collection to represent the high-order grid.
Definition: dg_base.hpp:652
std::unique_ptr< NumericalFlux::NumericalFluxConvective< dim, nstate, RadType > > conv_num_flux_rad
Convective numerical flux with RadType.
DissipativeNumericalFlux diss_num_flux_type
Store diffusive flux type.
dealii::Vector< double > cell_volume
Time it takes for the maximum wavespeed to cross the cell domain.
Definition: dg_base.hpp:450
ModelType model_type
Store the model type.
DGBase is independent of the number of state variables.
Definition: dg_base.hpp:82
dealii::hp::QCollection< dim > volume_quadrature_collection
Finite Element Collection to represent the high-order grid.
Definition: dg_base.hpp:608
void set_physics(std::shared_ptr< Physics::PhysicsBase< dim, nstate, real > > pde_physics_double_input, std::shared_ptr< Physics::PhysicsBase< dim, nstate, FadType > > pde_physics_fad_input, std::shared_ptr< Physics::PhysicsBase< dim, nstate, RadType > > pde_physics_rad_input, std::shared_ptr< Physics::PhysicsBase< dim, nstate, FadFadType > > pde_physics_fad_fad_input, std::shared_ptr< Physics::PhysicsBase< dim, nstate, RadFadType > > pde_physics_rad_fad_input)
const dealii::hp::FECollection< dim > fe_collection
Finite Element Collection for p-finite-element to represent the solution.
Definition: dg_base.hpp:597