[P]arallel [Hi]gh-order [Li]brary for [P]DEs  Latest
Parallel High-Order Library for PDEs through hp-adaptive Discontinuous Galerkin methods
lift_drag.cpp
1 #include "lift_drag.hpp"
2 
3 namespace PHiLiP {
4 
5 template <int dim, int nspecies, int nstate,typename real,typename MeshType>
8  std::shared_ptr<DGBase<dim,nspecies,real,MeshType>> dg_input,
9  const Functional_types functional_type)
10  : Functional<dim,nspecies,nstate,real,MeshType>(dg_input)
11  , functional_type(functional_type)
12  , euler_fad_fad(dynamic_cast< Physics::Euler<dim,nspecies,dim+2,FadFadType> &>(*(this->physics_fad_fad)))
13  , angle_of_attack(this->euler_fad_fad.angle_of_attack)
14  , rotation_matrix(initialize_rotation_matrix(this->angle_of_attack))
15  , lift_vector(initialize_lift_vector(this->rotation_matrix))
16  , drag_vector(initialize_drag_vector(this->rotation_matrix))
17  , force_dimensionalization_factor(this->initialize_force_dimensionalization_factor())
18  , all_parameters(dg_input->all_parameters)
19 {
20  switch(functional_type) {
21  case Functional_types::lift : this->force_vector = lift_vector; break;
22  case Functional_types::drag : this->force_vector = drag_vector; break;
23  default: break;
24  }
25 }
26 
27 template <int dim, int nspecies, int nstate,typename real,typename MeshType>
30 {
31  const double ref_length = this->euler_fad_fad.ref_length;
32  const double dynamic_pressure_inf = this->euler_fad_fad.dynamic_pressure_inf;
33 
34  return 1.0 / (ref_length * dynamic_pressure_inf);
35 }
36 
37 template <int dim, int nspecies, int nstate,typename real,typename MeshType>
39 ::initialize_rotation_matrix(const double angle_of_attack)
40 {
41  dealii::Tensor<2,dim,double> rotation_matrix;
42  if constexpr (dim == 1) {
43  assert(false);
44  }
45 
46  rotation_matrix[0][0] = cos(angle_of_attack);
47  rotation_matrix[0][1] = -sin(angle_of_attack);
48  rotation_matrix[1][0] = sin(angle_of_attack);
49  rotation_matrix[1][1] = cos(angle_of_attack);
50 
51  if constexpr (dim == 3) {
52  rotation_matrix[0][2] = 0.0;
53  rotation_matrix[1][2] = 0.0;
54 
55  rotation_matrix[2][0] = 0.0;
56  rotation_matrix[2][1] = 0.0;
57  rotation_matrix[2][2] = 1.0;
58  }
59 
60  return rotation_matrix;
61 }
62 
63 template <int dim, int nspecies, int nstate,typename real,typename MeshType>
65 ::initialize_lift_vector (const dealii::Tensor<2,dim,double> &rotation_matrix)
66 {
67  dealii::Tensor<1,dim,double> lift_direction;
68  lift_direction[0] = 0.0;
69  lift_direction[1] = 1.0;
70 
71  if constexpr (dim == 1) {
72  assert(false);
73  }
74  if constexpr (dim == 3) {
75  lift_direction[2] = 0.0;
76  }
77 
78  dealii::Tensor<1,dim,double> vec;
79  vec = rotation_matrix * lift_direction;
80 
81  return vec;
82 }
83 
84 template <int dim, int nspecies, int nstate,typename real,typename MeshType>
86 ::initialize_drag_vector (const dealii::Tensor<2,dim,double> &rotation_matrix)
87 {
88  dealii::Tensor<1,dim,double> drag_direction;
89  drag_direction[0] = 1.0;
90  drag_direction[1] = 0.0;
91 
92  if constexpr (dim == 1) {
93  assert(false);
94  }
95  if constexpr (dim == 3) {
96  drag_direction[2] = 0.0;
97  }
98 
99  dealii::Tensor<1,dim,double> vec;
100  vec = rotation_matrix * drag_direction;
101 
102  return vec;
103 }
104 
105 template <int dim, int nspecies, int nstate,typename real,typename MeshType>
107 ::evaluate_functional(const bool compute_dIdW,
108  const bool compute_dIdX,
109  const bool compute_d2I)
110 {
111  double value = Functional<dim,nspecies,nstate,real,MeshType>::evaluate_functional(compute_dIdW, compute_dIdX, compute_d2I);
112 
113  return value;
114 }
115 
116 #if PHILIP_DIM!=1 && PHILIP_SPECIES==1
118 #endif
119 
120 } // PHiLiP namespace
121 
Files for the baseline physics.
Definition: ADTypes.hpp:10
virtual real evaluate_functional(const bool compute_dIdW=false, const bool compute_dIdX=false, const bool compute_d2I=false)
Evaluates the functional derivative with respect to the solution variable.
Definition: functional.cpp:794
dealii::Tensor< 1, dim, double > initialize_drag_vector(const dealii::Tensor< 2, dim, double > &rotation_matrix)
Initialize drag vector with given rotation matrix based on angle of attack.
Definition: lift_drag.cpp:86
dealii::Tensor< 2, dim, double > initialize_rotation_matrix(const double angle_of_attack)
Initialize rotation matrix based on given angle of attack.
Definition: lift_drag.cpp:39
dealii::Tensor< 1, dim, double > initialize_lift_vector(const dealii::Tensor< 2, dim, double > &rotation_matrix)
Initialize lift vector with given rotation matrix based on angle of attack.
Definition: lift_drag.cpp:65
double initialize_force_dimensionalization_factor()
Compute force dimensionalization factor.
Definition: lift_drag.cpp:29
Functional_types
Switch between lift and drag functional types.
Definition: lift_drag.hpp:23
Functional base class.
Definition: functional.h:43
DGBase is independent of the number of state variables.
Definition: dg_base.hpp:82
real evaluate_functional(const bool compute_dIdW=false, const bool compute_dIdX=false, const bool compute_d2I=false) override
Destructor.
Definition: lift_drag.cpp:107
LiftDragFunctional(std::shared_ptr< DGBase< dim, nspecies, real, MeshType >> dg_input, const Functional_types functional_type)
Constructor.
Definition: lift_drag.cpp:7
Sacado::Fad::DFad< FadType > FadFadType
Sacado AD type that allows 2nd derivatives.
Definition: lift_drag.hpp:26