[P]arallel [Hi]gh-order [Li]brary for [P]DEs  Latest
Parallel High-Order Library for PDEs through hp-adaptive Discontinuous Galerkin methods
flow_solver_case_base.cpp
1 #include "flow_solver_case_base.h"
2 
3 namespace PHiLiP {
4 namespace FlowSolver {
5 
6 template<int dim, int nspecies, int nstate>
8  : initial_condition_function(InitialConditionFactory<dim, nspecies, nstate, double>::create_InitialConditionFunction(parameters_input))
9  , all_param(*parameters_input)
10  , mpi_communicator(MPI_COMM_WORLD)
11  , mpi_rank(dealii::Utilities::MPI::this_mpi_process(MPI_COMM_WORLD))
12  , n_mpi(dealii::Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD))
13  , pcout(std::cout, mpi_rank==0)
14  {}
15 
16 template<int dim, int nspecies, int nstate>
18 {
20  using Model_enum = Parameters::AllParameters::ModelType;
23 
24  const PDE_enum pde_type = this->all_param.pde_type;
25  std::string pde_string;
26  if (pde_type == PDE_enum::advection) {pde_string = "advection";}
27  if (pde_type == PDE_enum::advection_vector) {pde_string = "advection_vector";}
28  if (pde_type == PDE_enum::diffusion) {pde_string = "diffusion";}
29  if (pde_type == PDE_enum::convection_diffusion) {pde_string = "convection_diffusion";}
30  if (pde_type == PDE_enum::burgers_inviscid) {pde_string = "burgers_inviscid";}
31  if (pde_type == PDE_enum::burgers_viscous) {pde_string = "burgers_viscous";}
32  if (pde_type == PDE_enum::burgers_rewienski) {pde_string = "burgers_rewienski";}
33  if (pde_type == PDE_enum::mhd) {pde_string = "mhd";}
34  if (pde_type == PDE_enum::euler) {pde_string = "euler";}
35  if (pde_type == PDE_enum::navier_stokes) {pde_string = "navier_stokes";}
36  if (pde_type == PDE_enum::navier_stokes_channel_flow_constant_source_term)
37  {pde_string = "navier_stokes_channel_flow_constant_source_term";}
38  if (pde_type == PDE_enum::navier_stokes_channel_flow_constant_source_term_wall_model)
39  {pde_string = "navier_stokes_channel_flow_constant_source_term_wall_model";}
40 
41  if (pde_type == PDE_enum::physics_model || pde_type == PDE_enum::physics_model_filtered) {
42  if(pde_type == PDE_enum::physics_model) pde_string = "physics_model";
43  else if(pde_type == PDE_enum::physics_model_filtered) pde_string = "physics_model_filtered";
44  // add the model name + sub model name (if applicable)
45  const Model_enum model = this->all_param.model_type;
46  std::string model_string = "WARNING: invalid model";
47  if(model == Model_enum::large_eddy_simulation) {
48  // assign model string
49  model_string = "large_eddy_simulation";
50  // sub-grid scale (SGS)
51  const SGSModel_enum sgs_model = this->all_param.physics_model_param.SGS_model_type;
52  std::string sgs_model_string = "WARNING: invalid SGS model";
53  // assign SGS model string
54  if (sgs_model==SGSModel_enum::smagorinsky) sgs_model_string = "smagorinsky";
55  else if(sgs_model==SGSModel_enum::wall_adaptive_local_eddy_viscosity) sgs_model_string = "wall_adaptive_local_eddy_viscosity";
56  else if(sgs_model==SGSModel_enum::vreman) sgs_model_string = "vreman";
57  else if(sgs_model==SGSModel_enum::shear_improved_smagorinsky) sgs_model_string = "shear_improved_smagorinsky";
58  else if(sgs_model==SGSModel_enum::small_small_variational_multiscale) sgs_model_string = "small_small_variational_multiscale";
59  else if(sgs_model==SGSModel_enum::all_all_variational_multiscale) sgs_model_string = "all_all_variational_multiscale";
60  if(pde_string == "physics_model_filtered"){
61  pde_string += std::string(" (pL=") + std::to_string(this->all_param.physics_model_param.poly_degree_max_large_scales) + std::string(")");
62  }
63  pde_string += std::string(" (Model: ") + model_string + std::string(", SGS Model: ") + sgs_model_string + std::string(")");
64  } else if(model == Model_enum::navier_stokes_model) {
65  model_string = "navier_stokes_model";
66  }
67  else if(model == Model_enum::reynolds_averaged_navier_stokes) {
68  // assign model string
69  model_string = "reynolds_averaged_navier_stokes";
70  // reynolds-averaged navier-stokes (RANS)
71  const RANSModel_enum rans_model = this->all_param.physics_model_param.RANS_model_type;
72  std::string rans_model_string = "WARNING: invalid RANS model";
73  // assign RANS model string
74  if (rans_model==RANSModel_enum::SA_negative) rans_model_string = "SA_negative";
75  pde_string += std::string(" (Model: ") + model_string + std::string(", RANS Model: ") + rans_model_string + std::string(")");
76  }
77  if(pde_string == "physics_model") pde_string += std::string(" (Model: ") + model_string + std::string(")");
78  else if(pde_string == "physics_model_filtered") pde_string += std::string(" (pL=") + std::to_string(this->all_param.physics_model_param.poly_degree_max_large_scales) + std::string(") (Model: ") + model_string + std::string(")");
79  }
80 
81  return pde_string;
82 }
83 
84 template<int dim, int nspecies, int nstate>
86 {
87  // Get the flow case type
88  using FlowCaseEnum = Parameters::FlowSolverParam::FlowCaseType;
89  const FlowCaseEnum flow_case_type = this->all_param.flow_solver_param.flow_case_type;
90 
91  std::string flow_case_string;
92  if (flow_case_type == FlowCaseEnum::taylor_green_vortex) {flow_case_string = "taylor_green_vortex";}
93  if (flow_case_type == FlowCaseEnum::decaying_homogeneous_isotropic_turbulence)
94  {flow_case_string = "decaying_homogeneous_isotropic_turbulence";}
95  if (flow_case_type == FlowCaseEnum::burgers_viscous_snapshot) {flow_case_string = "burgers_viscous_snapshot";}
96  if (flow_case_type == FlowCaseEnum::burgers_rewienski_snapshot) {flow_case_string = "burgers_rewienski_snapshot";}
97  if (flow_case_type == FlowCaseEnum::naca0012) {flow_case_string = "naca0012";}
98  if (flow_case_type == FlowCaseEnum::periodic_1D_unsteady) {flow_case_string = "periodic_1D_unsteady";}
99  if (flow_case_type == FlowCaseEnum::gaussian_bump) {flow_case_string = "gaussian_bump";}
100  if (flow_case_type == FlowCaseEnum::advection_limiter) {flow_case_string = "advection_limiter";}
101  if (flow_case_type == FlowCaseEnum::dipole_wall_collision_normal)
102  {flow_case_string = "dipole_wall_collision_normal";}
103  if (flow_case_type == FlowCaseEnum::dipole_wall_collision_oblique)
104  {flow_case_string = "dipole_wall_collision_oblique";}
105  if (flow_case_type == FlowCaseEnum::channel_flow) {flow_case_string = "channel_flow";}
106 
107 
108  return flow_case_string;
109 }
110 
111 template <int dim, int nspecies, int nstate>
113 {
114  const std::string pde_string = this->get_pde_string();
115  pcout << "- PDE Type: " << pde_string << " " << "(dim=" << dim << ", nstate=" << nstate << ")" << std::endl;
116 
117  pcout << "- Polynomial degree: " << this->all_param.flow_solver_param.poly_degree << std::endl;
118  pcout << "- Maximum polynomial degree for adaptation: " << this->all_param.flow_solver_param.max_poly_degree_for_adaptation << std::endl;
119 
120  const unsigned int number_of_degrees_of_freedom_per_state = dg->dof_handler.n_dofs()/nstate;
121  const double number_of_degrees_of_freedom_per_dim = pow(number_of_degrees_of_freedom_per_state,(1.0/dim));
122  pcout << "- Degrees of freedom (per state): " << number_of_degrees_of_freedom_per_state << " " << "(" << number_of_degrees_of_freedom_per_dim << " per state per dim)" << std::endl;
123  pcout << "- Number of active cells: " << dg->triangulation->n_global_active_cells() << std::endl;
124 
125  const bool use_weak_form = this->all_param.use_weak_form;
126 
127  if (use_weak_form == false){
128  this->pcout << "- Using strong DG" << std::endl;
129 
130  // only print c param for strong DG as FR is implemented only for strong
131  std::string c_parameter_string;
133  FREnum fr_type = this->all_param.flux_reconstruction_type;
134  if (fr_type == FREnum::cDG) c_parameter_string = "cDG";
135  else if (fr_type == FREnum::cSD) c_parameter_string = "cSD";
136  else if (fr_type == FREnum::cHU) c_parameter_string = "cHU";
137  else if (fr_type == FREnum::cNegative) c_parameter_string = "cNegative";
138  else if (fr_type == FREnum::cNegative2) c_parameter_string = "cNegative2";
139  else if (fr_type == FREnum::cPlus) c_parameter_string = "cPlus";
140  else if (fr_type == FREnum::c10Thousand) c_parameter_string = "c10Thousand";
141  else if (fr_type == FREnum::cHULumped) c_parameter_string = "cHULumped";
142 
143  if (c_parameter_string == "cDG" ) {
144  // No additional output to indicate classical strong DG
145  } else {
146  if(fr_type == FREnum::user_specified_value) {
147  this->pcout << "- - Using user specified flux reconstruction c parameter: "
149  << std::endl;
150  }
151  else {
152  this->pcout << "- - Using flux reconstruction c parameter: " << c_parameter_string << std::endl;
153  }
154  }
155 
156  const bool use_split_form = this->all_param.use_split_form;
157  if (use_split_form){
158  this->pcout << "- - Using split form " << std::endl;
159  }
160  }
161  else{
162  this->pcout << "- Using weak DG" << std::endl;
163 
164  }
165 
166  const std::string flow_case_string = this->get_flow_case_string();
167  pcout << "- Flow case: " << flow_case_string << " " << std::flush;
168  if(this->all_param.flow_solver_param.steady_state == true) {
169  pcout << "(Steady state)" << std::endl;
170  } else {
171  pcout << "(Unsteady)" << std::endl;
172  pcout << "- - Final time: " << this->all_param.flow_solver_param.final_time << std::endl;
173  }
174 
176 }
177 
178 template <int dim, int nspecies, int nstate>
180 {
181  // Do nothing
182 }
183 
184 template <int dim, int nspecies, int nstate>
186 {
188  // Using constant time step in FlowSolver parameters.
190  } else {
191  // Using initial time step in ODE parameters.
193  }
194 }
195 
196 template <int dim, int nspecies, int nstate>
198 {
199  pcout << "ERROR: Base definition for get_adaptive_time_step() has not yet been implemented. " <<std::flush;
200  std::abort();
201  return 0.0;
202 }
203 
204 template <int dim, int nspecies, int nstate>
206 {
207  pcout << "ERROR: Base definition for get_adaptive_time_step_initial() has not yet been implemented. " <<std::flush;
208  std::abort();
209  return 0.0;
210 }
211 
212 template <int dim, int nspecies, int nstate>
214 {
215  // do nothing by default
216 }
217 
218 template <int dim, int nspecies, int nstate>
220  const std::shared_ptr <ODE::ODESolverBase<dim, nspecies, double>> /*ode_solver*/,
221  const std::shared_ptr <DGBase<dim, nspecies, double>> /*dg*/,
222  const std::shared_ptr <dealii::TableHandler> /*unsteady_data_table*/,
223  const bool /*do_write_unsteady_data_table_file*/)
224 {
225  // do nothing by default
226 }
227 
228 template <int dim, int nspecies, int nstate>
230  const double value,
231  const std::string value_string,
232  const std::shared_ptr <dealii::TableHandler> data_table) const
233 {
234  data_table->add_value(value_string, value);
235  data_table->set_precision(value_string, 16);
236  data_table->set_scientific(value_string, true);
237 }
238 
239 template <int dim, int nspecies, int nstate>
241 {
242  // Do nothing by default
243 }
244 
245 template <int dim, int nspecies, int nstate>
247  const double time_step_input)
248 {
249  this->time_step = time_step_input;
250 }
251 
252 template <int dim, int nspecies, int nstate>
254 {
255  return this->time_step;
256 }
257 
258 template <int dim, int nspecies, int nstate>
260  const std::shared_ptr <ODE::ODESolverBase<dim, nspecies, double>> /*ode_solver*/,
261  const std::shared_ptr <DGBase<dim, nspecies, double>> /*dg*/,
262  const double /*time_step*/)
263 {
264  // do nothing by default
265 }
266 
267 template <int dim, int nspecies, int nstate>
269  const std::shared_ptr <ODE::ODESolverBase<dim, nspecies, double>> /*ode_solver*/,
270  const std::shared_ptr <DGBase<dim, nspecies, double>> /*dg*/,
271  const double /*time_step*/)
272 {
273  // do nothing by default
274 }
275 
276 #if PHILIP_SPECIES==1
277  // Define a sequence of nstate in the range [1, 6]
278  #define POSSIBLE_NSTATE (1)(2)(3)(4)(5)(6)
279 
280  // Define a macro to instantiate FlowSolverCaseBase for a specific nstate
281  #define INSTANTIATE_FLOWSOLVER(r, data, nstate) \
282  template class FlowSolverCaseBase<PHILIP_DIM, PHILIP_SPECIES,nstate>;
283  BOOST_PP_SEQ_FOR_EACH(INSTANTIATE_FLOWSOLVER, _, POSSIBLE_NSTATE)
284 #else
286 #endif
287 
288 } // FlowSolver namespace
289 } // PHiLiP namespace
FlowCaseType
Selects the flow case to be simulated.
double final_time
Final solution time.
virtual double get_constant_time_step(std::shared_ptr< DGBase< dim, nspecies, double >> dg) const
Virtual function to compute the constant time step.
PartialDifferentialEquation pde_type
Store the PDE type to be solved.
virtual void set_higher_order_grid(std::shared_ptr< DGBase< dim, nspecies, double >> dg) const
Set higher order grid.
std::string get_pde_string() const
Returns the pde type string from the all_param class member.
FlowCaseType flow_case_type
Selected FlowCaseType from the input file.
const Parameters::AllParameters all_param
All parameters.
bool steady_state
Flag for solving steady state solution.
virtual void compute_Reynolds_stress(const std::shared_ptr< ODE::ODESolverBase< dim, nspecies, double >> ode_solver, const std::shared_ptr< DGBase< dim, nspecies, double >> dg, const double time_step)
Virtual function for computing time-averaged Reynolds Stresses for turbulent cases.
FlowSolverParam flow_solver_param
Contains the parameters for simulation cases (flow solver test)
double constant_time_step
Constant time step.
PartialDifferentialEquation
Possible Partial Differential Equations to solve.
virtual void compute_time_averaged_solution(const std::shared_ptr< ODE::ODESolverBase< dim, nspecies, double >> ode_solver, const std::shared_ptr< DGBase< dim, nspecies, double >> dg, const double time_step)
Virtual function for computing time-averaged solution for turbulent cases.
Files for the baseline physics.
Definition: ADTypes.hpp:10
Base class ODE solver.
bool use_weak_form
Flag to use weak or strong form of DG.
virtual double get_adaptive_time_step(std::shared_ptr< DGBase< dim, nspecies, double >> dg) const
Virtual function to compute the adaptive time step.
Flux_Reconstruction
Type of correction in Flux Reconstruction.
ModelType
Types of models available.
unsigned int poly_degree
Polynomial order (P) of the basis functions for DG.
virtual void steady_state_postprocessing(std::shared_ptr< DGBase< dim, nspecies, double >> dg) const
Virtual function for postprocessing when solving for steady state.
Main parameter class that contains the various other sub-parameter classes.
void display_flow_solver_setup(std::shared_ptr< DGBase< dim, nspecies, double >> dg) const
Displays the flow setup parameters.
virtual double get_adaptive_time_step_initial(std::shared_ptr< DGBase< dim, nspecies, double >> dg)
Virtual function to compute the initial adaptive time step.
SubGridScaleModel SGS_model_type
Store the SubGridScale (SGS) model type.
Flux_Reconstruction flux_reconstruction_type
Store flux reconstruction type.
ODESolverParam ode_solver_param
Contains parameters for ODE solver.
double initial_time_step
Time step used in ODE solver.
unsigned int poly_degree_max_large_scales
Max poly degree representing the large scales for LES VMS filtering.
virtual void display_additional_flow_case_specific_parameters() const =0
Display additional more specific flow case parameters.
Initial condition function factory.
double FR_user_specified_correction_parameter_value
User specified flux recontruction correction parameter value.
bool use_split_form
Flag to use split form.
ReynoldsAveragedNavierStokesModel
Types of Reynolds-averaged Navier-Stokes (RANS) models that can be used.
FlowSolverCaseBase(const Parameters::AllParameters *const parameters_input)
Constructor.
ReynoldsAveragedNavierStokesModel RANS_model_type
Store the Reynolds-averaged Navier-Stokes (RANS) model type.
std::string get_flow_case_string() const
Returns the flow case type string from the all_param class member.
dealii::ConditionalOStream pcout
ConditionalOStream.
void add_value_to_data_table(const double value, const std::string value_string, const std::shared_ptr< dealii::TableHandler > data_table) const
Add a value to a given data table with scientific format.
SubGridScaleModel
Types of sub-grid scale (SGS) models that can be used.
double get_time_step() const
Getter for time step.
ModelType model_type
Store the model type.
DGBase is independent of the number of state variables.
Definition: dg_base.hpp:82
virtual void modify_dg_object(std::shared_ptr< DGBase< dim, nspecies, double >> dg) const
Allows user to modify DG object during flow solver routines.
virtual void compute_unsteady_data_and_write_to_table(const std::shared_ptr< ODE::ODESolverBase< dim, nspecies, double >> ode_solver, const std::shared_ptr< DGBase< dim, nspecies, double >> dg, const std::shared_ptr< dealii::TableHandler > unsteady_data_table, const bool do_write_unsteady_data_table_file)
Virtual function to write unsteady snapshot data to table.
PhysicsModelParam physics_model_param
Contains parameters for Physics Model.
unsigned int max_poly_degree_for_adaptation
Maximum polynomial order of the DG basis functions for adaptation.
void set_time_step(const double time_step_input)
Setter for time step.