65class SourceTermCalculator
67 using This = SourceTermCalculator<dim, Number>;
68 using VectorType = dealii::LinearAlgebra::distributed::Vector<Number>;
70 using CellIntegratorScalar = CellIntegrator<dim, 1, Number>;
71 using CellIntegratorVector = CellIntegrator<dim, dim, Number>;
73 using scalar = dealii::VectorizedArray<Number>;
74 using qpoint = dealii::Point<dim, dealii::VectorizedArray<Number>>;
77 SourceTermCalculator() : matrix_free(
nullptr), time(std::numeric_limits<double>::min())
82 setup(dealii::MatrixFree<dim, Number>
const & matrix_free_in,
85 matrix_free = &matrix_free_in;
90 evaluate_integrate(VectorType & dst,
91 dealii::Function<dim> & analytical_source_term,
92 double const evaluation_time)
94 time = evaluation_time;
96 dst.zero_out_ghost_values();
98 analytical_source_term.set_time(time);
100 matrix_free->cell_loop(&This::compute_source_term,
this, dst, analytical_source_term,
true);
105 evaluate_integrate(VectorType & dst,
106 VectorType
const & velocity_cfd_in,
107 VectorType
const & pressure_cfd_in,
108 VectorType
const & pressure_cfd_time_derivative_in,
109 double const evaluation_time)
111 time = evaluation_time;
113 dst.zero_out_ghost_values();
115 if(data.consider_convection)
117 velocity_cfd.reset(velocity_cfd_in);
118 velocity_cfd->update_ghost_values();
120 pressure_cfd.reset(pressure_cfd_in);
121 pressure_cfd->update_ghost_values();
124 matrix_free->cell_loop(
125 &This::compute_source_term,
this, dst, pressure_cfd_time_derivative_in,
true);
130 compute_source_term(dealii::MatrixFree<dim, Number>
const & matrix_free_in,
132 VectorType
const & dp_cfd_dt,
133 std::pair<unsigned int, unsigned int>
const & cell_range)
const
135 CellIntegratorScalar dpdt(matrix_free_in, data.dof_index_pressure, data.quad_index);
136 CellIntegratorScalar p(matrix_free_in, data.dof_index_pressure, data.quad_index);
137 CellIntegratorVector u(matrix_free_in, data.dof_index_velocity, data.quad_index);
139 auto get_scaling_factor = get_scaling_function();
141 Number
const m_rho_c2 =
142 static_cast<Number
>(-data.density / (data.speed_of_sound * data.speed_of_sound));
144 for(
unsigned int cell = cell_range.first; cell < cell_range.second; ++cell)
147 dpdt.gather_evaluate(dp_cfd_dt, dealii::EvaluationFlags::values);
149 if(data.consider_convection)
152 p.gather_evaluate(*pressure_cfd, dealii::EvaluationFlags::gradients);
154 u.gather_evaluate(*velocity_cfd, dealii::EvaluationFlags::values);
156 for(
unsigned int q = 0; q < dpdt.n_q_points; ++q)
158 scalar flux = m_rho_c2 * (dpdt.get_value(q) + u.get_value(q) * p.get_gradient(q));
161 flux *= get_scaling_factor(dpdt.quadrature_point(q));
163 dpdt.submit_value(flux, q);
168 for(
unsigned int q = 0; q < dpdt.n_q_points; ++q)
170 scalar flux = m_rho_c2 * dpdt.get_value(q);
173 flux *= get_scaling_factor(dpdt.quadrature_point(q));
175 dpdt.submit_value(flux, q);
179 dpdt.integrate_scatter(dealii::EvaluationFlags::values, dst);
184 compute_source_term(dealii::MatrixFree<dim, Number>
const & matrix_free_in,
186 dealii::Function<dim>
const & analytical_source_term,
187 std::pair<unsigned int, unsigned int>
const & cell_range)
const
189 CellIntegratorScalar dpdt(matrix_free_in, data.dof_index_pressure, data.quad_index);
191 auto get_scaling_factor = get_scaling_function();
193 for(
unsigned int cell = cell_range.first; cell < cell_range.second; ++cell)
197 for(
unsigned int q = 0; q < dpdt.n_q_points; ++q)
199 scalar flux = FunctionEvaluator<0, dim, Number>::value(analytical_source_term,
200 dpdt.quadrature_point(q));
203 flux *= get_scaling_factor(dpdt.quadrature_point(q));
205 dpdt.submit_value(flux, q);
208 dpdt.integrate_scatter(dealii::EvaluationFlags::values, dst);
212 std::function<scalar(qpoint
const &)>
213 get_scaling_function()
const
220 AssertThrow(data.blend_in_function !=
nullptr,
221 dealii::ExcMessage(
"No blend-in function provided."));
224 bool const space_dependent_scaling =
225 data.blend_in_function !=
nullptr ? data.blend_in_function->varies_in_space(time) :
false;
226 Number
const pure_temporal_scaling_factor =
227 (not space_dependent_scaling) ? data.blend_in_function->compute_time_factor(time) : 1.0;
229 if(space_dependent_scaling)
231 return [&](qpoint
const & q) {
232 return FunctionEvaluator<0, dim, Number>::value(*data.blend_in_function, q, time);
239 [pure_temporal_scaling_factor](qpoint
const &) {
return pure_temporal_scaling_factor; };
244 dealii::MatrixFree<dim, Number>
const * matrix_free;