|
| 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> |
| 10 | +ExactSolutionFunction_Zero<dim,nstate,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> |
| 18 | +inline real ExactSolutionFunction_Zero<dim,nstate,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> |
| 29 | +ExactSolutionFunction_1DSine<dim,nstate,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> |
| 37 | +inline real ExactSolutionFunction_1DSine<dim,nstate,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 | +//========================================================= |
| 52 | +// FLOW SOLVER -- Exact Solution Base Class + Factory |
| 53 | +//========================================================= |
| 54 | +template <int dim, int nstate, typename real> |
| 55 | +ExactSolutionFunction<dim,nstate,real> |
| 56 | +::ExactSolutionFunction () |
| 57 | + : dealii::Function<dim,real>(nstate) |
| 58 | +{ |
| 59 | + //do nothing |
| 60 | +} |
| 61 | + |
| 62 | +template <int dim, int nstate, typename real> |
| 63 | +std::shared_ptr<ExactSolutionFunction<dim, nstate, real>> |
| 64 | +ExactSolutionFactory<dim,nstate, real>::create_ExactSolutionFunction( |
| 65 | + const Parameters::FlowSolverParam& flow_solver_parameters, |
| 66 | + const double time_compare) |
| 67 | +{ |
| 68 | + // Get the flow case type |
| 69 | + const FlowCaseEnum flow_type = flow_solver_parameters.flow_case_type; |
| 70 | + if (flow_type == FlowCaseEnum::advection_periodic) { |
| 71 | + if constexpr (dim==1 && nstate==dim) return std::make_shared<ExactSolutionFunction_1DSine<dim,nstate,real> > (time_compare); |
| 72 | + } else { |
| 73 | + // Select zero function if there is no exact solution defined |
| 74 | + return std::make_shared<ExactSolutionFunction_Zero<dim,nstate,real>> (time_compare); |
| 75 | + } |
| 76 | + return nullptr; |
| 77 | +} |
| 78 | + |
| 79 | +template class ExactSolutionFunction <PHILIP_DIM,PHILIP_DIM, double>; |
| 80 | +template class ExactSolutionFunction <PHILIP_DIM,PHILIP_DIM+2, double>; |
| 81 | +template class ExactSolutionFactory <PHILIP_DIM, PHILIP_DIM+2, double>; |
| 82 | +template class ExactSolutionFactory <PHILIP_DIM, PHILIP_DIM, double>; |
| 83 | +template class ExactSolutionFunction_Zero <PHILIP_DIM,1, double>; |
| 84 | +template class ExactSolutionFunction_Zero <PHILIP_DIM,2, double>; |
| 85 | +template class ExactSolutionFunction_Zero <PHILIP_DIM,3, double>; |
| 86 | +template class ExactSolutionFunction_Zero <PHILIP_DIM,4, double>; |
| 87 | +template class ExactSolutionFunction_Zero <PHILIP_DIM,5, double>; |
| 88 | + |
| 89 | +} // PHiLiP namespace |
0 commit comments