[P]arallel [Hi]gh-order [Li]brary for [P]DEs  Latest
Parallel High-Order Library for PDEs through hp-adaptive Discontinuous Galerkin methods
naca0012_unsteady_check_quick.cpp
1 #include "naca0012_unsteady_check_quick.h"
2 #include "flow_solver/flow_solver_factory.h"
3 #include "flow_solver/flow_solver_cases/naca0012.h"
4 
5 namespace PHiLiP {
6 namespace Tests {
7 
8 template <int dim, int nstate>
10  const PHiLiP::Parameters::AllParameters *const parameters_input,
11  const dealii::ParameterHandler &parameter_handler_input)
12  : TestsBase::TestsBase(parameters_input)
13  , parameter_handler(parameter_handler_input)
14 {}
15 
16 template <int dim, int nstate>
17 Parameters::AllParameters NACA0012UnsteadyCheckQuick<dim,nstate>::reinit_params(const bool use_weak_form_input, const bool use_two_point_flux_input) const
18 {
20 
21  parameters.use_weak_form = use_weak_form_input;
23  parameters.conv_num_flux_type = (use_two_point_flux_input) ? ConvFluxEnum::two_point_flux : ConvFluxEnum::roe;
24  parameters.use_split_form = use_two_point_flux_input;
25 
26  return parameters;
27 }
28 
29 template <int dim, int nstate>
31 {
32  const int n_runs = 3;
33  double lift_calculated[n_runs] = {0};
34  double drag_calculated[n_runs] = {0};
35 
36  const bool use_weak_form[3] = {true, false, false}; // choose weak or strong
37  const bool use_two_point_flux[3] = {false, false, true}; // choose two point flux or roe flux
38  for (unsigned int irun = 0; irun < n_runs; ++irun) {
39 
40  this->pcout << "=====================================================" << std::endl;
41  // Make new parameters according to the current run
42  const Parameters::AllParameters params_loop = reinit_params(use_weak_form[irun], use_two_point_flux[irun]);
43 
44  if (use_weak_form[irun]){
45  this->pcout << "Initialized parameters with weak form." << std::endl;
46  } else{
47  this->pcout << "Initialized parameters with strong form." << std::endl;
48  }
49 
50  if (use_two_point_flux[irun]){
51  this->pcout << "Using two-point flux." << std::endl;
52  } else{
53  this->pcout << "Using roe flux." << std::endl;
54  }
55  this->pcout << std::endl;
56 
57  // Initialize flow_solver
58  std::unique_ptr<FlowSolver::FlowSolver<dim,nstate>> flow_solver_loop = FlowSolver::FlowSolverFactory<dim,nstate>::select_flow_case(&params_loop, parameter_handler);
59 
60  static_cast<void>(flow_solver_loop->run());
61  std::unique_ptr<FlowSolver::NACA0012<dim, nstate>> flow_solver_case_loop = std::make_unique<FlowSolver::NACA0012<dim,nstate>>(this->all_parameters);
62  lift_calculated[irun] = flow_solver_case_loop->compute_lift((flow_solver_loop->dg));
63  drag_calculated[irun] = flow_solver_case_loop->compute_drag((flow_solver_loop->dg));
64  this->pcout << "Finished run." << std::endl;
65  this->pcout << "Calculated lift value was : " << lift_calculated[irun] << std::endl
66  << "Calculated drag value was : " << drag_calculated[irun] << std::endl;
67  this->pcout << "=====================================================" << std::endl;
68  }
69 
70  const double acceptable_tolerance = 0.00001;
71  int testfail = 0;
72 
73  // For now, allow split form to have a different end value. Leaving as a condition so we can reevaluate this choice later.
74  const bool allow_strong_split_to_be_different = true;
75 
76  this->pcout << std::endl
77  << "Finished runs. Summary of results: " << std::endl
78  << "Scheme | Lift | Drag" << std::endl
79  << "------------------------------------" << std::endl
80  << "Weak, roe | " << lift_calculated[0] << " | " << drag_calculated[0] << std::endl
81  << "Strong, roe | " << lift_calculated[1] << " | " << drag_calculated[1] << std::endl
82  << "Strong, split | " << lift_calculated[2] << " | " << drag_calculated[2] << std::endl;
83 
84  if (allow_strong_split_to_be_different) {
85  if ((abs(lift_calculated[0]-lift_calculated[1]) > acceptable_tolerance)
86  || (abs(drag_calculated[0]-drag_calculated[1]) > acceptable_tolerance)){
87  testfail = 1;
88  }
89  } else{
90  const double lift_max = *std::max_element(lift_calculated, lift_calculated+n_runs);
91  const double lift_min = *std::min_element(lift_calculated, lift_calculated+n_runs);
92  const double drag_max = *std::max_element(drag_calculated, drag_calculated+n_runs);
93  const double drag_min = *std::min_element(drag_calculated, drag_calculated+n_runs);
94  if ((abs(lift_max - lift_min) > acceptable_tolerance)
95  || (abs(drag_max - drag_min) > acceptable_tolerance)){
96  testfail = 1;
97  }
98 
99  }
100  if (testfail == 1){
101  this->pcout << "Test failing: difference is not within the allowable tolerance of " << acceptable_tolerance << std::endl;
102  this->pcout << "If this test is failing, please check the *vtu output." << std::endl;
103  } else {
104  this->pcout << "Test passing: lift and drag close to the expected value." << std::endl;
105  }
106 
107  return testfail;
108 }
109 
110 #if PHILIP_DIM==2
112 #endif
113 } // Tests namespace
114 } // PHiLiP namespace
Parameters::AllParameters reinit_params(const bool use_weak_form_input, const bool use_two_point_flux_input) const
Reinit parameters based on specified weak/strong form and convective num flux.
Files for the baseline physics.
Definition: ADTypes.hpp:10
bool use_weak_form
Flag to use weak or strong form of DG.
Main parameter class that contains the various other sub-parameter classes.
const dealii::ParameterHandler & parameter_handler
Parameter handler for storing the .prm file being ran.
static std::unique_ptr< FlowSolver< dim, nstate > > select_flow_case(const Parameters::AllParameters *const parameters_input, const dealii::ParameterHandler &parameter_handler_input)
Factory to return the correct flow solver given input file.
const Parameters::AllParameters *const all_parameters
Pointer to all parameters.
Definition: tests.h:20
NACA0012UnsteadyCheckQuick(const Parameters::AllParameters *const parameters_input, const dealii::ParameterHandler &parameter_handler_input)
Constructor.
bool use_split_form
Flag to use split form.
ConvectiveNumericalFlux
Possible convective numerical flux types.
ConvectiveNumericalFlux conv_num_flux_type
Store convective flux type.
dealii::ConditionalOStream pcout
ConditionalOStream.
Definition: tests.h:45
Base class of all the tests.
Definition: tests.h:17