70 typedef dealii::LinearAlgebra::distributed::Vector<Number> VectorType;
72 typedef CellIntegrator<dim, dim, Number> CellIntegratorVelocity;
73 typedef FaceIntegrator<dim, dim, Number> FaceIntegratorVelocity;
75 typedef dealii::VectorizedArray<Number> scalar;
76 typedef dealii::Tensor<1, dim, dealii::VectorizedArray<Number>> vector;
78 typedef CellIntegrator<dim, 1, Number> IntegratorCell;
79 typedef FaceIntegrator<dim, 1, Number> IntegratorFace;
83 reinit(dealii::MatrixFree<dim, Number>
const & matrix_free,
85 unsigned int const quad_index,
86 bool const use_own_velocity_storage)
90 if(data.velocity_type == TypeVelocityField::DoFVector)
93 std::make_shared<CellIntegratorVelocity>(matrix_free, data.dof_index_velocity, quad_index);
95 integrator_velocity_m = std::make_shared<FaceIntegratorVelocity>(matrix_free,
97 data.dof_index_velocity,
100 integrator_velocity_p = std::make_shared<FaceIntegratorVelocity>(matrix_free,
102 data.dof_index_velocity,
105 if(use_own_velocity_storage)
108 matrix_free.initialize_dof_vector(velocity.own(), data.dof_index_velocity);
114 get_integrator_flags()
const
118 if(data.formulation == FormulationConvectiveTerm::DivergenceFormulation)
120 flags.cell_evaluate = dealii::EvaluationFlags::values;
121 flags.cell_integrate = dealii::EvaluationFlags::gradients;
123 else if(data.formulation == FormulationConvectiveTerm::ConvectiveFormulation)
125 flags.cell_evaluate = dealii::EvaluationFlags::gradients;
126 flags.cell_integrate = dealii::EvaluationFlags::values;
130 AssertThrow(
false, dealii::ExcMessage(
"Not implemented."));
133 flags.face_evaluate = dealii::EvaluationFlags::values;
134 flags.face_integrate = dealii::EvaluationFlags::values;
144 flags.cells = dealii::update_gradients | dealii::update_JxW_values |
145 dealii::update_quadrature_points;
146 flags.inner_faces = dealii::update_JxW_values | dealii::update_quadrature_points |
147 dealii::update_normal_vectors;
148 flags.boundary_faces =
149 dealii::update_JxW_values | dealii::update_quadrature_points | dealii::update_normal_vectors;
154 dealii::LinearAlgebra::distributed::Vector<Number>
const &
161 set_velocity_copy(VectorType
const & velocity_in)
const
163 AssertThrow(data.velocity_type == TypeVelocityField::DoFVector,
164 dealii::ExcMessage(
"Invalid parameter velocity_type."));
166 velocity.own() = velocity_in;
168 velocity->update_ghost_values();
172 set_velocity_ptr(VectorType
const & velocity_in)
const
174 AssertThrow(data.velocity_type == TypeVelocityField::DoFVector,
175 dealii::ExcMessage(
"Invalid parameter velocity_type."));
177 velocity.reset(velocity_in);
179 velocity->update_ghost_values();
183 reinit_cell(
unsigned int const cell)
const
185 if(data.velocity_type == TypeVelocityField::DoFVector)
187 integrator_velocity->reinit(cell);
188 integrator_velocity->gather_evaluate(*velocity, dealii::EvaluationFlags::values);
193 reinit_face(
unsigned int const face)
const
195 if(data.velocity_type == TypeVelocityField::DoFVector)
197 integrator_velocity_m->reinit(face);
198 integrator_velocity_m->gather_evaluate(*velocity, dealii::EvaluationFlags::values);
200 integrator_velocity_p->reinit(face);
201 integrator_velocity_p->gather_evaluate(*velocity, dealii::EvaluationFlags::values);
206 reinit_boundary_face(
unsigned int const face)
const
208 if(data.velocity_type == TypeVelocityField::DoFVector)
210 integrator_velocity_m->reinit(face);
211 integrator_velocity_m->gather_evaluate(*velocity, dealii::EvaluationFlags::values);
216 reinit_face_cell_based(
unsigned int const cell,
217 unsigned int const face,
218 dealii::types::boundary_id
const boundary_id)
const
220 if(data.velocity_type == TypeVelocityField::DoFVector)
222 integrator_velocity_m->reinit(cell, face);
223 integrator_velocity_m->gather_evaluate(*velocity, dealii::EvaluationFlags::values);
225 if(boundary_id == dealii::numbers::internal_face_boundary_id)
238 inline DEAL_II_ALWAYS_INLINE
240 calculate_central_flux(scalar
const & value_m,
241 scalar
const & value_p,
242 scalar
const & normal_velocity)
const
244 scalar average_value = 0.5 * (value_m + value_p);
246 return normal_velocity * average_value;
252 inline DEAL_II_ALWAYS_INLINE
254 calculate_central_flux(scalar
const & value_m,
255 scalar
const & value_p,
256 scalar
const & normal_velocity_m,
257 scalar
const & normal_velocity_p)
const
259 return 0.5 * (normal_velocity_m * value_m + normal_velocity_p * value_p);
265 inline DEAL_II_ALWAYS_INLINE
267 calculate_lax_friedrichs_flux(scalar
const & value_m,
268 scalar
const & value_p,
269 scalar
const & normal_velocity)
const
271 scalar average_value = 0.5 * (value_m + value_p);
272 scalar jump_value = value_m - value_p;
273 scalar lambda = std::abs(normal_velocity);
275 return normal_velocity * average_value + 0.5 * lambda * jump_value;
281 inline DEAL_II_ALWAYS_INLINE
283 calculate_lax_friedrichs_flux(scalar
const & value_m,
284 scalar
const & value_p,
285 scalar
const & normal_velocity_m,
286 scalar
const & normal_velocity_p)
const
288 scalar jump_value = value_m - value_p;
289 scalar lambda = std::max(std::abs(normal_velocity_m), std::abs(normal_velocity_p));
291 return 0.5 * (normal_velocity_m * value_m + normal_velocity_p * value_p) +
292 0.5 * lambda * jump_value;
299 inline DEAL_II_ALWAYS_INLINE
301 calculate_flux(
unsigned int const q,
302 IntegratorFace & integrator,
303 scalar
const & value_m,
304 scalar
const & value_p,
305 vector
const & normal_m,
307 bool const exterior_velocity_available)
const
309 scalar flux = dealii::make_vectorized_array<Number>(0.0);
311 if(data.velocity_type == TypeVelocityField::Function)
313 dealii::Point<dim, scalar> q_points = integrator.quadrature_point(q);
315 vector velocity = FunctionEvaluator<1, dim, Number>::value(*(data.velocity), q_points, time);
317 scalar normal_velocity = velocity * normal_m;
321 if(data.numerical_flux_formulation == NumericalFluxConvectiveOperator::CentralFlux)
323 flux = calculate_central_flux(value_m, value_p, normal_velocity);
325 else if(data.numerical_flux_formulation == NumericalFluxConvectiveOperator::LaxFriedrichsFlux)
327 flux = calculate_lax_friedrichs_flux(value_m, value_p, normal_velocity);
330 else if(data.velocity_type == TypeVelocityField::DoFVector)
332 vector velocity_m = integrator_velocity_m->get_value(q);
334 exterior_velocity_available ? integrator_velocity_p->get_value(q) : velocity_m;
336 scalar normal_velocity_m = velocity_m * normal_m;
337 scalar normal_velocity_p = velocity_p * normal_m;
339 if(data.formulation == FormulationConvectiveTerm::DivergenceFormulation)
341 if(data.numerical_flux_formulation == NumericalFluxConvectiveOperator::CentralFlux)
343 flux = calculate_central_flux(value_m, value_p, normal_velocity_m, normal_velocity_p);
345 else if(data.numerical_flux_formulation ==
346 NumericalFluxConvectiveOperator::LaxFriedrichsFlux)
349 calculate_lax_friedrichs_flux(value_m, value_p, normal_velocity_m, normal_velocity_p);
352 else if(data.formulation == FormulationConvectiveTerm::ConvectiveFormulation)
354 scalar normal_velocity = 0.5 * (normal_velocity_m + normal_velocity_p);
356 if(data.numerical_flux_formulation == NumericalFluxConvectiveOperator::CentralFlux)
358 flux = calculate_central_flux(value_m, value_p, normal_velocity);
360 else if(data.numerical_flux_formulation ==
361 NumericalFluxConvectiveOperator::LaxFriedrichsFlux)
363 flux = calculate_lax_friedrichs_flux(value_m, value_p, normal_velocity);
368 AssertThrow(
false, dealii::ExcMessage(
"Not implemented."));
373 AssertThrow(
false, dealii::ExcMessage(
"Not implemented."));
379 inline DEAL_II_ALWAYS_INLINE
381 calculate_average_velocity(
unsigned int const q,
382 IntegratorFace & integrator,
384 bool const exterior_velocity_available)
const
388 if(data.velocity_type == TypeVelocityField::Function)
390 dealii::Point<dim, scalar> q_points = integrator.quadrature_point(q);
392 velocity = FunctionEvaluator<1, dim, Number>::value(*(data.velocity), q_points, time);
394 else if(data.velocity_type == TypeVelocityField::DoFVector)
396 vector velocity_m = integrator_velocity_m->get_value(q);
398 exterior_velocity_available ? integrator_velocity_p->get_value(q) : velocity_m;
400 velocity = 0.5 * (velocity_m + velocity_p);
404 AssertThrow(
false, dealii::ExcMessage(
"Not implemented."));
410 inline DEAL_II_ALWAYS_INLINE
411 std::tuple<scalar, scalar>
412 calculate_flux_interior_and_neighbor(
unsigned int const q,
413 IntegratorFace & integrator,
414 scalar
const & value_m,
415 scalar
const & value_p,
416 vector
const & normal_m,
418 bool const exterior_velocity_available)
const
421 calculate_flux(q, integrator, value_m, value_p, normal_m, time, exterior_velocity_available);
422 scalar fluxP = -fluxM;
424 if(data.formulation == FormulationConvectiveTerm::ConvectiveFormulation)
427 calculate_average_velocity(q, integrator, time, exterior_velocity_available);
428 scalar normal_velocity = velocity * normal_m;
432 fluxM = fluxM - normal_velocity * value_m;
434 fluxP = fluxP + normal_velocity * value_p;
437 return std::make_tuple(fluxM, fluxP);
440 inline DEAL_II_ALWAYS_INLINE
442 calculate_flux_interior(
unsigned int const q,
443 IntegratorFace & integrator,
444 scalar
const & value_m,
445 scalar
const & value_p,
446 vector
const & normal_m,
448 bool const exterior_velocity_available)
const
451 calculate_flux(q, integrator, value_m, value_p, normal_m, time, exterior_velocity_available);
453 if(data.formulation == FormulationConvectiveTerm::ConvectiveFormulation)
456 calculate_average_velocity(q, integrator, time, exterior_velocity_available);
457 scalar normal_velocity = velocity * normal_m;
461 flux = flux - normal_velocity * value_m;
471 inline DEAL_II_ALWAYS_INLINE
473 get_volume_flux_divergence_form(scalar
const & value,
474 IntegratorCell & integrator,
475 unsigned int const q,
476 Number
const & time)
const
480 if(data.velocity_type == TypeVelocityField::Function)
482 velocity = FunctionEvaluator<1, dim, Number>::value(*(data.velocity),
483 integrator.quadrature_point(q),
486 else if(data.velocity_type == TypeVelocityField::DoFVector)
488 velocity = integrator_velocity->get_value(q);
492 AssertThrow(
false, dealii::ExcMessage(
"Not implemented."));
495 return (-value * velocity);
498 inline DEAL_II_ALWAYS_INLINE
500 get_volume_flux_convective_form(vector
const & gradient,
501 IntegratorCell & integrator,
502 unsigned int const q,
503 Number
const & time)
const
507 if(data.velocity_type == TypeVelocityField::Function)
509 velocity = FunctionEvaluator<1, dim, Number>::value(*(data.velocity),
510 integrator.quadrature_point(q),
513 else if(data.velocity_type == TypeVelocityField::DoFVector)
515 velocity = integrator_velocity->get_value(q);
519 AssertThrow(
false, dealii::ExcMessage(
"Not implemented."));
522 return (velocity * gradient);
530 std::shared_ptr<CellIntegratorVelocity> integrator_velocity;
531 std::shared_ptr<FaceIntegratorVelocity> integrator_velocity_m;
532 std::shared_ptr<FaceIntegratorVelocity> integrator_velocity_p;
554 typedef OperatorBase<dim, Number, 1> Base;
556 typedef typename Base::IntegratorCell IntegratorCell;
557 typedef typename Base::IntegratorFace IntegratorFace;
559 typedef typename Base::VectorType VectorType;
561 typedef dealii::VectorizedArray<Number> scalar;
562 typedef dealii::Tensor<1, dim, dealii::VectorizedArray<Number>> vector;
566 initialize(dealii::MatrixFree<dim, Number>
const & matrix_free,
567 dealii::AffineConstraints<Number>
const & affine_constraints,
571 dealii::LinearAlgebra::distributed::Vector<Number>
const &
572 get_velocity()
const;
575 set_velocity_copy(VectorType
const & velocity)
const;
578 set_velocity_ptr(VectorType
const & velocity)
const;
582 reinit_cell_derived(IntegratorCell & integrator,
unsigned int const cell)
const final;
585 reinit_face_derived(IntegratorFace & integrator_m,
586 IntegratorFace & integrator_p,
587 unsigned int const face)
const final;
590 reinit_boundary_face_derived(IntegratorFace & integrator_m,
unsigned int const face)
const final;
593 reinit_face_cell_based_derived(IntegratorFace & integrator_m,
594 IntegratorFace & integrator_p,
595 unsigned int const cell,
596 unsigned int const face,
597 dealii::types::boundary_id
const boundary_id)
const final;
600 do_cell_integral(IntegratorCell & integrator)
const final;
603 do_face_integral(IntegratorFace & integrator_m, IntegratorFace & integrator_p)
const final;
606 do_face_int_integral(IntegratorFace & integrator_m, IntegratorFace & integrator_p)
const final;
609 do_face_ext_integral(IntegratorFace & integrator_m, IntegratorFace & integrator_p)
const final;
612 do_boundary_integral(IntegratorFace & integrator_m,
613 OperatorType
const & operator_type,
614 dealii::types::boundary_id
const & boundary_id)
const final;
619 do_face_int_integral_cell_based(IntegratorFace & integrator_m,
620 IntegratorFace & integrator_p)
const final;
624 std::shared_ptr<Operators::ConvectiveKernel<dim, Number>> kernel;