[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 
4 #include "ADTypes.hpp"
5 
6 #include "model.h"
7 
8 namespace PHiLiP {
9 namespace Physics {
10 
11 //================================================================
12 // Models Base Class
13 //================================================================
14 template <int dim, int nstate, typename real>
16  std::shared_ptr< ManufacturedSolutionFunction<dim,real> > manufactured_solution_function_input):
17  manufactured_solution_function(manufactured_solution_function_input)
18  , mpi_communicator(MPI_COMM_WORLD)
19  , pcout(std::cout, dealii::Utilities::MPI::this_mpi_process(mpi_communicator)==0)
20 {}
21 //----------------------------------------------------------------
22 template <int dim, int nstate, typename real>
23 std::array<real,nstate> ModelBase<dim, nstate, real>
25  const dealii::Point<dim,real> &/*pos*/,
26  const std::array<real,nstate> &/*solution*/,
27  const std::array<dealii::Tensor<1,dim,real>,nstate> &/*solution_gradient*/,
28  const dealii::types::global_dof_index /*cell_index*/) const
29 {
30  std::array<real,nstate> physical_source;
31  physical_source.fill(0.0);
32  return physical_source;
33 }
34 //----------------------------------------------------------------
35 template <int dim, int nstate, typename real>
38  const dealii::Point<dim, real> &/*pos*/,
39  const dealii::Tensor<1,dim,real> &/*normal_int*/,
40  const std::array<real,nstate> &/*soln_int*/,
41  const std::array<dealii::Tensor<1,dim,real>,nstate> &/*soln_grad_int*/,
42  std::array<real,nstate> &/*soln_bc*/,
43  std::array<dealii::Tensor<1,dim,real>,nstate> &/*soln_grad_bc*/) const
44 {
45  // Do nothing for nstate==(dim+2)
46  if constexpr(nstate>(dim+2)) {
47  pcout << "Error: boundary_manufactured_solution() not implemented in class derived from ModelBase with nstate>(dim+2)." << std::endl;
48  pcout << "Aborting..." << std::endl;
49  std::abort();
50  }
51 }
52 //----------------------------------------------------------------
53 template <int dim, int nstate, typename real>
56  std::array<real,nstate> &/*soln_bc*/,
57  std::array<dealii::Tensor<1,dim,real>,nstate> &/*soln_grad_bc*/) const
58 {
59  // Do nothing for nstate==(dim+2)
60  if constexpr(nstate>(dim+2)) {
61  pcout << "Error: boundary_wall() not implemented in class derived from ModelBase with nstate>(dim+2)." << std::endl;
62  pcout << "Aborting..." << std::endl;
63  std::abort();
64  }
65 }
66 //----------------------------------------------------------------
67 template <int dim, int nstate, typename real>
70  const std::array<real,nstate> &/*soln_int*/,
71  const std::array<dealii::Tensor<1,dim,real>,nstate> &/*soln_grad_int*/,
72  std::array<real,nstate> &/*soln_bc*/,
73  std::array<dealii::Tensor<1,dim,real>,nstate> &/*soln_grad_bc*/) const
74 {
75  // Do nothing for nstate==(dim+2)
76  if constexpr(nstate>(dim+2)) {
77  pcout << "Error: boundary_outflow() not implemented in class derived from ModelBase with nstate>(dim+2)." << std::endl;
78  pcout << "Aborting..." << std::endl;
79  std::abort();
80  }
81 }
82 //----------------------------------------------------------------
83 template <int dim, int nstate, typename real>
86  const std::array<real,nstate> &/*soln_int*/,
87  const std::array<dealii::Tensor<1,dim,real>,nstate> &/*soln_grad_int*/,
88  std::array<real,nstate> &/*soln_bc*/,
89  std::array<dealii::Tensor<1,dim,real>,nstate> &/*soln_grad_bc*/) const
90 {
91  // Do nothing for nstate==(dim+2)
92  if constexpr(nstate>(dim+2)) {
93  pcout << "Error: boundary_inflow() not implemented in class derived from ModelBase with nstate>(dim+2)." << std::endl;
94  pcout << "Aborting..." << std::endl;
95  std::abort();
96  }
97 }
98 //----------------------------------------------------------------
99 template <int dim, int nstate, typename real>
102  std::array<real,nstate> &/*soln_bc*/) const
103 {
104  // Do nothing for nstate==(dim+2)
105  if constexpr(nstate>(dim+2)) {
106  pcout << "Error: boundary_farfield() not implemented in class derived from ModelBase with nstate>(dim+2)." << std::endl;
107  pcout << "Aborting..." << std::endl;
108  std::abort();
109  }
110 }
111 //----------------------------------------------------------------
112 template <int dim, int nstate, typename real>
115  const dealii::Tensor<1,dim,real> &/*normal_int*/,
116  const std::array<real,nstate> &/*soln_int*/,
117  const std::array<dealii::Tensor<1,dim,real>,nstate> &/*soln_grad_int*/,
118  std::array<real,nstate> &/*soln_bc*/,
119  std::array<dealii::Tensor<1,dim,real>,nstate> &/*soln_grad_bc*/) const
120 {
121  // Do nothing for nstate==(dim+2)
122  if constexpr(nstate>(dim+2)) {
123  pcout << "Error: boundary_slip_wall() not implemented in class derived from ModelBase with nstate>(dim+2)." << std::endl;
124  pcout << "Aborting..." << std::endl;
125  std::abort();
126  }
127 }
128 //----------------------------------------------------------------
129 template <int dim, int nstate, typename real>
132  const dealii::Tensor<1,dim,real> &/*normal_int*/,
133  const std::array<real,nstate> &/*soln_int*/,
134  std::array<real,nstate> &/*soln_bc*/) const
135 {
136  // Do nothing for nstate==(dim+2)
137  if constexpr(nstate>(dim+2)) {
138  pcout << "Error: boundary_riemann() not implemented in class derived from ModelBase with nstate>(dim+2)." << std::endl;
139  pcout << "Aborting..." << std::endl;
140  std::abort();
141  }
142 }
143 //----------------------------------------------------------------
144 template <int dim, int nstate, typename real>
147  const int boundary_type,
148  const dealii::Point<dim, real> &pos,
149  const dealii::Tensor<1,dim,real> &normal_int,
150  const std::array<real,nstate> &soln_int,
151  const std::array<dealii::Tensor<1,dim,real>,nstate> &soln_grad_int,
152  std::array<real,nstate> &soln_bc,
153  std::array<dealii::Tensor<1,dim,real>,nstate> &soln_grad_bc) const
154 {
155  if (boundary_type == 1000) {
156  // Manufactured solution boundary condition
157  boundary_manufactured_solution (pos, normal_int, soln_int, soln_grad_int, soln_bc, soln_grad_bc);
158  }
159  else if (boundary_type == 1001) {
160  // Wall boundary condition for working variables of RANS turbulence model
161  boundary_wall (soln_bc, soln_grad_bc);
162  }
163  else if (boundary_type == 1002) {
164  // Outflow boundary condition
165  boundary_outflow (soln_int, soln_grad_int, soln_bc, soln_grad_bc);
166  }
167  else if (boundary_type == 1003) {
168  // Inflow boundary condition
169  boundary_inflow (soln_int, soln_grad_int, soln_bc, soln_grad_bc);
170  }
171  else if (boundary_type == 1004) {
172  // Riemann-based farfield boundary condition
173  boundary_riemann (normal_int, soln_int, soln_bc);
174  }
175  else if (boundary_type == 1005) {
176  // Simple farfield boundary condition
177  boundary_farfield(soln_bc);
178  }
179  else if (boundary_type == 1006) {
180  // Slip wall boundary condition
181  boundary_slip_wall (normal_int, soln_int, soln_grad_int, soln_bc, soln_grad_bc);
182  }
183  else {
184  pcout << "Invalid boundary_type: " << boundary_type << " in ModelBase.cpp" << std::endl;
185  std::abort();
186  }
187  // Note: this does not get called when nstate==dim+2 since baseline physics takes care of it
188 }
189 //----------------------------------------------------------------
190 template <int dim, int nstate, typename real>
191 dealii::Vector<double> ModelBase<dim, nstate, real>
193  const dealii::Vector<double> &uh,
194  const std::vector<dealii::Tensor<1,dim> > &/*duh*/,
195  const std::vector<dealii::Tensor<2,dim> > &/*dduh*/,
196  const dealii::Tensor<1,dim> &/*normals*/,
197  const dealii::Point<dim> &/*evaluation_points*/) const
198 {
199  dealii::Vector<double> computed_quantities(nstate-(dim+2));
200  for (unsigned int s=dim+2; s<nstate; ++s) {
201  computed_quantities(s-(dim+2)) = uh(s);
202  }
203  return computed_quantities;
204 }
205 //----------------------------------------------------------------
206 template <int dim, int nstate, typename real>
207 std::vector<std::string> ModelBase<dim, nstate, real>
209 {
210  std::vector<std::string> names;
211  for (unsigned int s=dim+2; s<nstate; ++s) {
212  std::string varname = "state" + dealii::Utilities::int_to_string(s,1);
213  names.push_back(varname);
214  }
215  return names;
216 }
217 //----------------------------------------------------------------
218 template <int dim, int nstate, typename real>
219 std::vector<dealii::DataComponentInterpretation::DataComponentInterpretation> ModelBase<dim, nstate, real>
221 {
222  namespace DCI = dealii::DataComponentInterpretation;
223  std::vector<DCI::DataComponentInterpretation> interpretation;
224  for (unsigned int s=dim+2; s<nstate; ++s) {
225  interpretation.push_back (DCI::component_is_scalar);
226  }
227  return interpretation;
228 }
229 
230 //----------------------------------------------------------------
231 //----------------------------------------------------------------
232 //----------------------------------------------------------------
233 // Instantiate explicitly
234 template class ModelBase<PHILIP_DIM, 1, double>;
235 template class ModelBase<PHILIP_DIM, 2, double>;
236 template class ModelBase<PHILIP_DIM, 3, double>;
237 template class ModelBase<PHILIP_DIM, 4, double>;
238 template class ModelBase<PHILIP_DIM, 5, double>;
239 template class ModelBase<PHILIP_DIM, 6, double>;
240 template class ModelBase<PHILIP_DIM, 8, double>;
241 
242 template class ModelBase<PHILIP_DIM, 1, FadType>;
243 template class ModelBase<PHILIP_DIM, 2, FadType>;
244 template class ModelBase<PHILIP_DIM, 3, FadType>;
245 template class ModelBase<PHILIP_DIM, 4, FadType>;
246 template class ModelBase<PHILIP_DIM, 5, FadType>;
247 template class ModelBase<PHILIP_DIM, 6, FadType>;
248 template class ModelBase<PHILIP_DIM, 8, FadType>;
249 
250 template class ModelBase<PHILIP_DIM, 1, RadType>;
251 template class ModelBase<PHILIP_DIM, 2, RadType>;
252 template class ModelBase<PHILIP_DIM, 3, RadType>;
253 template class ModelBase<PHILIP_DIM, 4, RadType>;
254 template class ModelBase<PHILIP_DIM, 5, RadType>;
255 template class ModelBase<PHILIP_DIM, 6, RadType>;
256 template class ModelBase<PHILIP_DIM, 8, RadType>;
257 
265 
273 
274 } // Physics namespace
275 } // PHiLiP namespace
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:220
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:55
dealii::ConditionalOStream pcout
Parallel std::cout that only outputs on mpi_rank==0.
Definition: model.h:33
Manufactured solution used for grid studies to check convergence orders.
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:85
Files for the baseline physics.
Definition: ADTypes.hpp:10
ModelBase(std::shared_ptr< ManufacturedSolutionFunction< dim, real > > manufactured_solution_function_input=nullptr)
Constructor.
Definition: model.cpp:15
Physics model additional terms and equations to the baseline physics.
Definition: model.h:18
virtual void boundary_farfield(std::array< real, nstate > &soln_bc) const
Farfield boundary conditions based on freestream values.
Definition: model.cpp:101
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:24
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:146
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:69
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:37
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:192
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:208