[P]arallel [Hi]gh-order [Li]brary for [P]DEs  Latest
Parallel High-Order Library for PDEs through hp-adaptive Discontinuous Galerkin methods
model.cpp
1 #include <cmath>
2 #include <vector>
3 #include <boost/preprocessor/seq/for_each.hpp>
4 
5 #include "ADTypes.hpp"
6 
7 #include "model.h"
8 
9 namespace PHiLiP {
10 namespace Physics {
11 
12 //================================================================
13 // Models Base Class
14 //================================================================
15 template <int dim, int nspecies, int nstate, typename real>
17  std::shared_ptr< ManufacturedSolutionFunction<dim,nspecies,real> > manufactured_solution_function_input):
18  manufactured_solution_function(manufactured_solution_function_input)
19  , mpi_communicator(MPI_COMM_WORLD)
20  , pcout(std::cout, dealii::Utilities::MPI::this_mpi_process(mpi_communicator)==0)
21 {}
22 //----------------------------------------------------------------
23 template <int dim, int nspecies, int nstate, typename real>
24 std::array<real,nstate> ModelBase<dim, nspecies, nstate, real>
26  const dealii::Point<dim,real> &/*pos*/,
27  const std::array<real,nstate> &/*solution*/,
28  const std::array<dealii::Tensor<1,dim,real>,nstate> &/*solution_gradient*/,
29  const dealii::types::global_dof_index /*cell_index*/) const
30 {
31  std::array<real,nstate> physical_source;
32  physical_source.fill(0.0);
33  return physical_source;
34 }
35 //----------------------------------------------------------------
36 template <int dim, int nspecies, int nstate, typename real>
38 ::set_unfiltered_conservative_solution(const std::array<real,nstate> &unfiltered_conservative_solution_)
39 {
40  for(int s=0; s<nstate; ++s){
41  this->unfiltered_conservative_solution[s] = unfiltered_conservative_solution_[s];
42  }
43 }
44 //----------------------------------------------------------------
45 template <int dim, int nspecies, int nstate, typename real>
48  const dealii::Point<dim, real> &/*pos*/,
49  const dealii::Tensor<1,dim,real> &/*normal_int*/,
50  const std::array<real,nstate> &/*soln_int*/,
51  const std::array<dealii::Tensor<1,dim,real>,nstate> &/*soln_grad_int*/,
52  std::array<real,nstate> &/*soln_bc*/,
53  std::array<dealii::Tensor<1,dim,real>,nstate> &/*soln_grad_bc*/) const
54 {
55  // Do nothing for nstate==(dim+2)
56  if constexpr(nstate>(dim+2)) {
57  pcout << "Error: boundary_manufactured_solution() not implemented in class derived from ModelBase with nstate>(dim+2)." << std::endl;
58  pcout << "Aborting..." << std::endl;
59  std::abort();
60  }
61 }
62 //----------------------------------------------------------------
63 template <int dim, int nspecies, int nstate, typename real>
66  std::array<real,nstate> &/*soln_bc*/,
67  std::array<dealii::Tensor<1,dim,real>,nstate> &/*soln_grad_bc*/) const
68 {
69  // Do nothing for nstate==(dim+2)
70  if constexpr(nstate>(dim+2)) {
71  pcout << "Error: boundary_wall() not implemented in class derived from ModelBase with nstate>(dim+2)." << std::endl;
72  pcout << "Aborting..." << std::endl;
73  std::abort();
74  }
75 }
76 //----------------------------------------------------------------
77 template <int dim, int nspecies, int nstate, typename real>
80  const std::array<real,nstate> &/*soln_int*/,
81  const std::array<dealii::Tensor<1,dim,real>,nstate> &/*soln_grad_int*/,
82  std::array<real,nstate> &/*soln_bc*/,
83  std::array<dealii::Tensor<1,dim,real>,nstate> &/*soln_grad_bc*/) const
84 {
85  // Do nothing for nstate==(dim+2)
86  if constexpr(nstate>(dim+2)) {
87  pcout << "Error: boundary_outflow() not implemented in class derived from ModelBase with nstate>(dim+2)." << std::endl;
88  pcout << "Aborting..." << std::endl;
89  std::abort();
90  }
91 }
92 //----------------------------------------------------------------
93 template <int dim, int nspecies, int nstate, typename real>
96  const std::array<real,nstate> &/*soln_int*/,
97  const std::array<dealii::Tensor<1,dim,real>,nstate> &/*soln_grad_int*/,
98  std::array<real,nstate> &/*soln_bc*/,
99  std::array<dealii::Tensor<1,dim,real>,nstate> &/*soln_grad_bc*/) const
100 {
101  // Do nothing for nstate==(dim+2)
102  if constexpr(nstate>(dim+2)) {
103  pcout << "Error: boundary_inflow() not implemented in class derived from ModelBase with nstate>(dim+2)." << std::endl;
104  pcout << "Aborting..." << std::endl;
105  std::abort();
106  }
107 }
108 //----------------------------------------------------------------
109 template <int dim, int nspecies, int nstate, typename real>
112  std::array<real,nstate> &/*soln_bc*/) const
113 {
114  // Do nothing for nstate==(dim+2)
115  if constexpr(nstate>(dim+2)) {
116  pcout << "Error: boundary_farfield() not implemented in class derived from ModelBase with nstate>(dim+2)." << std::endl;
117  pcout << "Aborting..." << std::endl;
118  std::abort();
119  }
120 }
121 //----------------------------------------------------------------
122 template <int dim, int nspecies, int nstate, typename real>
125  const dealii::Tensor<1,dim,real> &/*normal_int*/,
126  const std::array<real,nstate> &/*soln_int*/,
127  const std::array<dealii::Tensor<1,dim,real>,nstate> &/*soln_grad_int*/,
128  std::array<real,nstate> &/*soln_bc*/,
129  std::array<dealii::Tensor<1,dim,real>,nstate> &/*soln_grad_bc*/) const
130 {
131  // Do nothing for nstate==(dim+2)
132  if constexpr(nstate>(dim+2)) {
133  pcout << "Error: boundary_slip_wall() not implemented in class derived from ModelBase with nstate>(dim+2)." << std::endl;
134  pcout << "Aborting..." << std::endl;
135  std::abort();
136  }
137 }
138 //----------------------------------------------------------------
139 template <int dim, int nspecies, int nstate, typename real>
142  const dealii::Tensor<1,dim,real> &/*normal_int*/,
143  const std::array<real,nstate> &/*soln_int*/,
144  std::array<real,nstate> &/*soln_bc*/) const
145 {
146  // Do nothing for nstate==(dim+2)
147  if constexpr(nstate>(dim+2)) {
148  pcout << "Error: boundary_riemann() not implemented in class derived from ModelBase with nstate>(dim+2)." << std::endl;
149  pcout << "Aborting..." << std::endl;
150  std::abort();
151  }
152 }
153 //----------------------------------------------------------------
154 template <int dim, int nspecies, int nstate, typename real>
157  const int boundary_type,
158  const dealii::Point<dim, real> &pos,
159  const dealii::Tensor<1,dim,real> &normal_int,
160  const std::array<real,nstate> &soln_int,
161  const std::array<dealii::Tensor<1,dim,real>,nstate> &soln_grad_int,
162  std::array<real,nstate> &soln_bc,
163  std::array<dealii::Tensor<1,dim,real>,nstate> &soln_grad_bc) const
164 {
165  if (boundary_type == 1000) {
166  // Manufactured solution boundary condition
167  boundary_manufactured_solution (pos, normal_int, soln_int, soln_grad_int, soln_bc, soln_grad_bc);
168  }
169  else if (boundary_type == 1001) {
170  // Wall boundary condition for working variables of RANS turbulence model
171  boundary_wall (soln_bc, soln_grad_bc);
172  }
173  else if (boundary_type == 1002) {
174  // Outflow boundary condition
175  boundary_outflow (soln_int, soln_grad_int, soln_bc, soln_grad_bc);
176  }
177  else if (boundary_type == 1003) {
178  // Inflow boundary condition
179  boundary_inflow (soln_int, soln_grad_int, soln_bc, soln_grad_bc);
180  }
181  else if (boundary_type == 1004) {
182  // Riemann-based farfield boundary condition
183  boundary_riemann (normal_int, soln_int, soln_bc);
184  }
185  else if (boundary_type == 1005) {
186  // Simple farfield boundary condition
187  boundary_farfield(soln_bc);
188  }
189  else if (boundary_type == 1006) {
190  // Slip wall boundary condition
191  boundary_slip_wall (normal_int, soln_int, soln_grad_int, soln_bc, soln_grad_bc);
192  }
193  else {
194  pcout << "Invalid boundary_type: " << boundary_type << " in ModelBase.cpp" << std::endl;
195  std::abort();
196  }
197  // Note: this does not get called when nstate==dim+2 since baseline physics takes care of it
198 }
199 //----------------------------------------------------------------
200 template <int dim, int nspecies, int nstate, typename real>
201 dealii::Vector<double> ModelBase<dim, nspecies, nstate, real>
203  const dealii::Vector<double> &uh,
204  const std::vector<dealii::Tensor<1,dim> > &/*duh*/,
205  const std::vector<dealii::Tensor<2,dim> > &/*dduh*/,
206  const dealii::Tensor<1,dim> &/*normals*/,
207  const dealii::Point<dim> &/*evaluation_points*/) const
208 {
209  dealii::Vector<double> computed_quantities(nstate-(dim+2));
210  for (unsigned int s=dim+2; s<nstate; ++s) {
211  computed_quantities(s-(dim+2)) = uh(s);
212  }
213  return computed_quantities;
214 }
215 //----------------------------------------------------------------
216 template <int dim, int nspecies, int nstate, typename real>
217 std::vector<std::string> ModelBase<dim, nspecies, nstate, real>
219 {
220  std::vector<std::string> names;
221  for (unsigned int s=dim+2; s<nstate; ++s) {
222  std::string varname = "state" + dealii::Utilities::int_to_string(s,1);
223  names.push_back(varname);
224  }
225  return names;
226 }
227 //----------------------------------------------------------------
228 template <int dim, int nspecies, int nstate, typename real>
229 std::vector<dealii::DataComponentInterpretation::DataComponentInterpretation> ModelBase<dim, nspecies, nstate, real>
231 {
232  namespace DCI = dealii::DataComponentInterpretation;
233  std::vector<DCI::DataComponentInterpretation> interpretation;
234  for (unsigned int s=dim+2; s<nstate; ++s) {
235  interpretation.push_back (DCI::component_is_scalar);
236  }
237  return interpretation;
238 }
239 
240 //----------------------------------------------------------------
241 //----------------------------------------------------------------
242 //----------------------------------------------------------------
243 // Instantiate explicitly
244 #if PHILIP_SPECIES==1
245  // Define a sequence of indices representing the range of nstate
246  #define POSSIBLE_NSTATE (1)(2)(3)(4)(5)(6)(8)
247 
248  // Define a macro to instantiate functions for a specific nstate
249  #define INSTANTIATE_FOR_NSTATE(r, data, nstate) \
250  template class ModelBase<PHILIP_DIM, PHILIP_SPECIES, nstate, double>; \
251  template class ModelBase<PHILIP_DIM, PHILIP_SPECIES, nstate, FadType>; \
252  template class ModelBase<PHILIP_DIM, PHILIP_SPECIES, nstate, RadType>; \
253  template class ModelBase<PHILIP_DIM, PHILIP_SPECIES, nstate, FadFadType>; \
254  template class ModelBase<PHILIP_DIM, PHILIP_SPECIES, nstate, RadFadType>;
255  BOOST_PP_SEQ_FOR_EACH(INSTANTIATE_FOR_NSTATE, _, POSSIBLE_NSTATE)
256 #else
257  #define POSSIBLE_TYPE (double)(FadType)(RadType)(FadFadType)(RadFadType)
258  #define INSTANTIATE_TYPES(r, data, type) \
259  template class ModelBase<PHILIP_DIM, PHILIP_SPECIES, PHILIP_DIM+PHILIP_SPECIES+1, type>;
260  BOOST_PP_SEQ_FOR_EACH(INSTANTIATE_TYPES, _, POSSIBLE_TYPE)
261 #endif
262 } // Physics namespace
263 } // PHiLiP namespace
virtual void set_unfiltered_conservative_solution(const std::array< real, nstate > &unfiltered_conservative_solution_)
Setter for the unfiltered conservative solution.
Definition: model.cpp:38
Manufactured solution used for grid studies to check convergence orders.
virtual std::vector< std::string > post_get_names() const
Returns names of the solution to be used by PhysicsPostprocessor to output current solution...
Definition: model.cpp:218
virtual void boundary_riemann(const dealii::Tensor< 1, dim, real > &normal_int, const std::array< real, nstate > &soln_int, std::array< real, nstate > &soln_bc) const
Riemann-based farfield boundary conditions based on freestream values.
Definition: model.cpp:141
Files for the baseline physics.
Definition: ADTypes.hpp:10
virtual std::array< real, nstate > physical_source_term(const dealii::Point< dim, real > &pos, const std::array< real, nstate > &solution, const std::array< dealii::Tensor< 1, dim, real >, nstate > &solution_gradient, const dealii::types::global_dof_index cell_index) const
Physical source terms additional to the baseline physics (including physical source terms in addition...
Definition: model.cpp:25
virtual void boundary_wall(std::array< real, nstate > &soln_bc, std::array< dealii::Tensor< 1, dim, real >, nstate > &soln_grad_bc) const
Wall boundary condition.
Definition: model.cpp:65
virtual void boundary_inflow(const std::array< real, nstate > &soln_int, const std::array< dealii::Tensor< 1, dim, real >, nstate > &soln_grad_int, std::array< real, nstate > &soln_bc, std::array< dealii::Tensor< 1, dim, real >, nstate > &soln_grad_bc) const
Inflow boundary conditions.
Definition: model.cpp:95
dealii::ConditionalOStream pcout
Parallel std::cout that only outputs on mpi_rank==0.
Definition: model.h:33
void boundary_face_values(const int boundary_type, const dealii::Point< dim, real > &pos, const dealii::Tensor< 1, dim, real > &normal, const std::array< real, nstate > &soln_int, const std::array< dealii::Tensor< 1, dim, real >, nstate > &soln_grad_int, std::array< real, nstate > &soln_bc, std::array< dealii::Tensor< 1, dim, real >, nstate > &soln_grad_bc) const
Boundary condition handler.
Definition: model.cpp:156
virtual void boundary_slip_wall(const dealii::Tensor< 1, dim, real > &normal_int, const std::array< real, nstate > &soln_int, const std::array< dealii::Tensor< 1, dim, real >, nstate > &soln_grad_int, std::array< real, nstate > &soln_bc, std::array< dealii::Tensor< 1, dim, real >, nstate > &soln_grad_bc) const
Slip wall boundary condition.
Definition: model.cpp:124
virtual void boundary_outflow(const std::array< real, nstate > &soln_int, const std::array< dealii::Tensor< 1, dim, real >, nstate > &soln_grad_int, std::array< real, nstate > &soln_bc, std::array< dealii::Tensor< 1, dim, real >, nstate > &soln_grad_bc) const
Outflow Boundary Condition.
Definition: model.cpp:79
ModelBase(std::shared_ptr< ManufacturedSolutionFunction< dim, nspecies, real > > manufactured_solution_function_input=nullptr)
Constructor.
Definition: model.cpp:16
virtual dealii::Vector< double > post_compute_derived_quantities_vector(const dealii::Vector< double > &uh, const std::vector< dealii::Tensor< 1, dim > > &, const std::vector< dealii::Tensor< 2, dim > > &, const dealii::Tensor< 1, dim > &, const dealii::Point< dim > &) const
Returns current vector solution to be used by PhysicsPostprocessor to output current solution...
Definition: model.cpp:202
virtual void boundary_manufactured_solution(const dealii::Point< dim, real > &pos, const dealii::Tensor< 1, dim, real > &normal_int, const std::array< real, nstate > &soln_int, const std::array< dealii::Tensor< 1, dim, real >, nstate > &soln_grad_int, std::array< real, nstate > &soln_bc, std::array< dealii::Tensor< 1, dim, real >, nstate > &soln_grad_bc) const
Evaluate the manufactured solution boundary conditions.
Definition: model.cpp:47
virtual void boundary_farfield(std::array< real, nstate > &soln_bc) const
Farfield boundary conditions based on freestream values.
Definition: model.cpp:111
virtual std::vector< dealii::DataComponentInterpretation::DataComponentInterpretation > post_get_data_component_interpretation() const
Returns DataComponentInterpretation of the solution to be used by PhysicsPostprocessor to output curr...
Definition: model.cpp:230
std::array< real, nstate > unfiltered_conservative_solution
The unfiltered conservative solution.
Definition: model.h:185