[P]arallel [Hi]gh-order [Li]brary for [P]DEs  Latest
Parallel High-Order Library for PDEs through hp-adaptive Discontinuous Galerkin methods
exact_solution.cpp
1 #include <deal.II/base/function.h>
2 #include "exact_solution.h"
3 
4 namespace PHiLiP {
5 
6 // ========================================================
7 // ZERO -- Returns zero everywhere; used a placeholder when no exact solution is defined.
8 // ========================================================
9 template <int dim, int nstate, typename real>
11 ::ExactSolutionFunction_Zero(double time_compare)
12  : ExactSolutionFunction<dim,nstate,real>()
13  , t(time_compare)
14 {
15 }
16 
17 template <int dim, int nstate, typename real>
19 ::value(const dealii::Point<dim,real> &/*point*/, const unsigned int /*istate*/) const
20 {
21  real value = 0;
22  return value;
23 }
24 
25 // ========================================================
26 // 1D SINE -- Exact solution for advection_explicit_time_study
27 // ========================================================
28 template <int dim, int nstate, typename real>
30 ::ExactSolutionFunction_1DSine (double time_compare)
31  : ExactSolutionFunction<dim,nstate,real>()
32  , t(time_compare)
33 {
34 }
35 
36 template <int dim, int nstate, typename real>
38 ::value(const dealii::Point<dim,real> &point, const unsigned int /*istate*/) const
39 {
40  double x_adv_speed = 1.0;
41 
42  real value = 0;
43  real pi = dealii::numbers::PI;
44  if(point[0] >= 0.0 && point[0] <= 2.0){
45  value = sin(2*pi*(point[0] - x_adv_speed * t)/2.0);
46  }
47  return value;
48 }
49 
50 // ========================================================
51 // Inviscid Isentropic Vortex
52 // ========================================================
53 template <int dim, int nstate, typename real>
56  : ExactSolutionFunction<dim,nstate,real>()
57  , t(time_compare)
58 {
59  // Nothing to do here yet
60 }
61 
62 template <int dim, int nstate, typename real>
64 ::value(const dealii::Point<dim,real> &point, const unsigned int istate) const
65 {
66  // Setting constants
67  const double L = 10.0; // half-width of domain
68  const double pi = dealii::numbers::PI;
69  const double gam = 1.4;
70  const double M_infty = sqrt(2/gam);
71  const double R = 1;
72  const double sigma = 1;
73  const double beta = M_infty * 5 * sqrt(2.0)/4.0/pi * exp(1.0/2.0);
74  const double alpha = pi/4; //rad
75 
76  // Centre of the vortex at t
77  const double x_travel = M_infty * t * cos(alpha);
78  const double x0 = 0.0 + x_travel;
79  const double y_travel = M_infty * t * sin(alpha);
80  const double y0 = 0.0 + y_travel;
81  const double x = std::fmod(point[0] - x0-L, 2*L)+L;
82  const double y = std::fmod(point[1] - y0-L, 2*L)+L;
83 
84  const double Omega = beta * exp(-0.5/sigma/sigma* (x/R * x/R + y/R * y/R));
85  const double delta_Ux = -y/R * Omega;
86  const double delta_Uy = x/R * Omega;
87  const double delta_T = -(gam-1.0)/2.0 * Omega * Omega;
88 
89  // Primitive
90  const double rho = pow((1 + delta_T), 1.0/(gam-1.0));
91  const double Ux = M_infty * cos(alpha) + delta_Ux;
92  const double Uy = M_infty * sin(alpha) + delta_Uy;
93  const double Uz = 0;
94  const double p = 1.0/gam*pow(1+delta_T, gam/(gam-1.0));
95 
96  //Convert to conservative variables
97  if (istate == 0) return rho; //density
98  else if (istate == nstate-1) return p/(gam-1.0) + 0.5 * rho * (Ux*Ux + Uy*Uy + Uz*Uz); //total energy
99  else if (istate == 1) return rho * Ux; //x-momentum
100  else if (istate == 2) return rho * Uy; //y-momentum
101  else if (istate == 3) return rho * Uz; //z-momentum
102  else return 0;
103 
104 }
105 
106 //=========================================================
107 // FLOW SOLVER -- Exact Solution Base Class + Factory
108 //=========================================================
109 template <int dim, int nstate, typename real>
112  : dealii::Function<dim,real>(nstate)
113 {
114  //do nothing
115 }
116 
117 template <int dim, int nstate, typename real>
118 std::shared_ptr<ExactSolutionFunction<dim, nstate, real>>
120  const Parameters::FlowSolverParam& flow_solver_parameters,
121  const double time_compare)
122 {
123  // Get the flow case type
124  const FlowCaseEnum flow_type = flow_solver_parameters.flow_case_type;
125  if (flow_type == FlowCaseEnum::periodic_1D_unsteady){
126  if constexpr (dim==1 && nstate==dim) return std::make_shared<ExactSolutionFunction_1DSine<dim,nstate,real> > (time_compare);
127  } else if (flow_type == FlowCaseEnum::isentropic_vortex){
128  if constexpr (dim>1 && nstate==dim+2) return std::make_shared<ExactSolutionFunction_IsentropicVortex<dim,nstate,real> > (time_compare);
129  } else {
130  // Select zero function if there is no exact solution defined
131  return std::make_shared<ExactSolutionFunction_Zero<dim,nstate,real>> (time_compare);
132  }
133  return nullptr;
134 }
135 
145 
146 #if PHILIP_DIM>1
148 #endif
149 } // PHiLiP namespace
FlowCaseType
Selects the flow case to be simulated.
FlowCaseType flow_case_type
Selected FlowCaseType from the input file.
Files for the baseline physics.
Definition: ADTypes.hpp:10
static std::shared_ptr< ExactSolutionFunction< dim, nstate, real > > create_ExactSolutionFunction(const Parameters::FlowSolverParam &flow_solver_parameters, const double time_compare)
Construct ExactSolutionFunction object from global parameter file.
Exact Solution Function: Zero Function; used as a placeholder when there is no exact solution...
ExactSolutionFunction()
< dealii::Function we are templating on
Parameters related to the flow solver.
real value(const dealii::Point< dim, real > &point, const unsigned int istate=0) const override
Value of the exact solution at a point.
Exact solution function factory.
ExactSolutionFunction_IsentropicVortex(double time_compare)
< dealii::Function we are templating on
ExactSolutionFunction_Zero(double time_compare)
< dealii::Function we are templating on
Exact solution function used for a particular flow setup/case.
ExactSolutionFunction_1DSine(double time_compare)
< dealii::Function we are templating on
real value(const dealii::Point< dim, real > &point, const unsigned int istate=0) const override
Value of the exact solution at a point.
Exact Solution Function: Isentropic vortex.
real value(const dealii::Point< dim, real > &point, const unsigned int istate=0) const override
Value of the exact solution at a point.