Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
navier_stokes_scratch_data.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2021-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#include <core/bdf.h>
5#include <core/utilities.h>
6
8
9template <int dim>
10void
12{
13 // Initialize size of arrays
14 this->n_q_points = fe_values.get_quadrature().size();
15 this->n_dofs = fe_values.get_fe().n_dofs_per_cell();
16
17 // Initialize arrays related to quadrature
18 this->JxW.reinit(n_q_points);
19
20 // Initialize component array
21 this->components = std::vector<unsigned int>(n_dofs);
22
23 // Forcing term array
24 this->rhs_force =
25 std::vector<Vector<double>>(n_q_points, Vector<double>(dim + 1));
26 this->force = std::vector<Tensor<1, dim>>(n_q_points);
27 this->mass_source = std::vector<double>(n_q_points);
28
29 // Initialize arrays related to velocity and pressure
30 this->velocities.first_vector_component = 0;
31 this->pressure.component = dim;
32
33 // Velocity
34 this->velocity_values = std::vector<Tensor<1, dim>>(n_q_points);
35 this->velocity_divergences = std::vector<double>(n_q_points);
36 this->velocity_gradients = std::vector<Tensor<2, dim>>(n_q_points);
37 this->velocity_laplacians = std::vector<Tensor<1, dim>>(n_q_points);
38 this->velocity_hessians = std::vector<Tensor<3, dim>>(n_q_points);
39 this->velocity_gradient_divergence = std::vector<Tensor<1, dim>>(n_q_points);
40 this->shear_rate = std::vector<double>(n_q_points);
41 this->advective_velocity = std::vector<Tensor<1, dim>>(n_q_points);
42
43 // For SDIRK method: sum(a_ij * k_j)
44 if (this->simulation_control->is_sdirk())
45 {
46 this->sdirk_stage_sum = std::vector<Tensor<1, dim>>(n_q_points);
47 }
48
49 // Velocity for BDF schemes
50 this->previous_velocity_values = std::vector<std::vector<Tensor<1, dim>>>(
52 std::vector<Tensor<1, dim>>(n_q_points));
53
54 // Pressure
55 this->pressure_values = std::vector<double>(n_q_points);
56 this->pressure_gradients = std::vector<Tensor<1, dim>>(n_q_points);
58
59 // Pressure for BDF schemes (compressible Navier-Stokes)
61 std::vector<std::vector<double>>(maximum_number_of_previous_solutions(),
62 std::vector<double>(n_q_points));
63 // Initialize arrays related to shape functions
64 // Velocity shape functions
65 this->phi_u.reinit(n_q_points, n_dofs);
66 this->grad_phi_u.reinit(n_q_points, n_dofs);
67 this->div_phi_u.reinit(n_q_points, n_dofs);
68 this->hess_phi_u.reinit(n_q_points, n_dofs);
69 this->laplacian_phi_u.reinit(n_q_points, n_dofs);
71
72 // Pressure shape functions
73 this->phi_p.reinit(n_q_points, n_dofs);
74 this->grad_phi_p.reinit(n_q_points, n_dofs);
75
76 // Physical properties
77 fields.insert(
78 std::pair<field, std::vector<double>>(field::pressure, n_q_points));
79 fields.insert(
80 std::pair<field, std::vector<double>>(field::shear_rate, n_q_points));
81
82 density = std::vector<double>(n_q_points);
83 dynamic_viscosity = std::vector<double>(n_q_points);
84 kinematic_viscosity = std::vector<double>(n_q_points);
87 thermal_expansion = std::vector<double>(n_q_points);
88 density_thermal_expansion = std::vector<double>(n_q_points);
90
92 std::vector<std::vector<double>>(maximum_number_of_previous_solutions(),
93 std::vector<double>(this->n_q_points));
94}
95
96
97template <int dim>
98void
100 const FiniteElement<dim> &fe,
101 const Quadrature<dim> &quadrature,
102 const Mapping<dim> &mapping,
103 const Parameters::CLS_PhaseFilter &phase_filter_parameters)
104{
105 gather_cls = true;
106 fe_values_cls = std::make_shared<FEValues<dim>>(
107 mapping, fe, quadrature, update_values | update_gradients);
109 std::make_shared<FEPointEvaluation<1, dim>>(mapping, fe, update_values);
110
111 // Allocate CLS values
112 phase_values = std::vector<double>(this->n_q_points);
113 filtered_phase_values = std::vector<double>(this->n_q_points);
115 std::vector<std::vector<double>>(maximum_number_of_previous_solutions(),
116 std::vector<double>(this->n_q_points));
117 // For STF calculation
118 phase_gradient_values = std::vector<Tensor<1, dim>>(this->n_q_points);
120 std::vector<Tensor<1, dim>>(this->n_q_points);
121
122 // Allocate physical properties
123 density_0 = std::vector<double>(n_q_points);
124 density_1 = std::vector<double>(n_q_points);
125 dynamic_viscosity_0 = std::vector<double>(n_q_points);
126 dynamic_viscosity_1 = std::vector<double>(n_q_points);
129 thermal_expansion_0 = std::vector<double>(n_q_points);
130 thermal_expansion_1 = std::vector<double>(n_q_points);
131 surface_tension = std::vector<double>(n_q_points);
132 surface_tension_gradient = std::vector<double>(n_q_points);
133 compressibility_multiplier = std::vector<double>(n_q_points);
134
135 // Create filter
136 filter = ConservativeLevelSetFilterBase::model_cast(phase_filter_parameters);
137}
138
139
140template <int dim>
141void
143 const FiniteElement<dim> &fe,
144 const Quadrature<dim> &quadrature,
145 const Mapping<dim> &mapping,
146 const std::shared_ptr<ConservativeLevelSetFilterBase> &filter)
147{
148 gather_cls = true;
149 fe_values_cls = std::make_shared<FEValues<dim>>(
150 mapping, fe, quadrature, update_values | update_gradients);
152 std::make_shared<FEPointEvaluation<1, dim>>(mapping, fe, update_values);
153
154 // Allocate CLS values
155 phase_values = std::vector<double>(this->n_q_points);
156 filtered_phase_values = std::vector<double>(this->n_q_points);
158 std::vector<std::vector<double>>(maximum_number_of_previous_solutions(),
159 std::vector<double>(this->n_q_points));
160 // For STF calculation
161 phase_gradient_values = std::vector<Tensor<1, dim>>(this->n_q_points);
163 std::vector<Tensor<1, dim>>(this->n_q_points);
164
165 // Allocate physical properties
166 density_0 = std::vector<double>(n_q_points);
167 density_1 = std::vector<double>(n_q_points);
168 dynamic_viscosity_0 = std::vector<double>(n_q_points);
169 dynamic_viscosity_1 = std::vector<double>(n_q_points);
172 thermal_expansion_0 = std::vector<double>(n_q_points);
173 thermal_expansion_1 = std::vector<double>(n_q_points);
174 surface_tension = std::vector<double>(n_q_points);
175 surface_tension_gradient = std::vector<double>(n_q_points);
176 compressibility_multiplier = std::vector<double>(n_q_points);
177
178 // Create filter
179 this->filter = filter;
180}
181
182
183template <int dim>
184void
186 const FiniteElement<dim> &fe,
187 const Quadrature<dim> &quadrature,
188 const Mapping<dim> &mapping,
189 const Parameters::CahnHilliard &cahn_hilliard_parameters)
190{
192 fe_values_cahn_hilliard = std::make_shared<FEValues<dim>>(
193 mapping, fe, quadrature, update_values | update_gradients);
194
195 // Allocate CahnHilliard values
196 phase_order_cahn_hilliard_values = std::vector<double>(this->n_q_points);
198 std::vector<double>(this->n_q_points);
199
200 // Allocate CahnHilliard gradients
202 std::vector<Tensor<1, dim>>(this->n_q_points);
203
204 // For STF calculation
206 std::vector<double>(this->n_q_points);
207
208 fields.insert(
209 std::pair<field, std::vector<double>>(field::phase_order_cahn_hilliard,
210 n_q_points));
211 fields.insert(std::pair<field, std::vector<double>>(
213
214 // Allocate physical properties
215 density_0 = std::vector<double>(n_q_points);
216 density_1 = std::vector<double>(n_q_points);
217 dynamic_viscosity_0 = std::vector<double>(n_q_points);
218 dynamic_viscosity_1 = std::vector<double>(n_q_points);
221 thermal_expansion_0 = std::vector<double>(n_q_points);
222 thermal_expansion_1 = std::vector<double>(n_q_points);
223 surface_tension = std::vector<double>(n_q_points);
224 surface_tension_gradient = std::vector<double>(n_q_points);
225
226 // Create filter
228 CahnHilliardFilterBase::model_cast(cahn_hilliard_parameters);
229}
230
231template <int dim>
232void
234 const FiniteElement<dim> &fe,
235 const Quadrature<dim> &quadrature,
236 const Mapping<dim> &mapping,
237 const std::shared_ptr<CahnHilliardFilterBase> &cahn_hilliard_filter)
238{
240 fe_values_cahn_hilliard = std::make_shared<FEValues<dim>>(
241 mapping, fe, quadrature, update_values | update_gradients);
242
243 // Allocate CahnHilliard values
244 phase_order_cahn_hilliard_values = std::vector<double>(this->n_q_points);
246 std::vector<double>(this->n_q_points);
247
248 // Allocate CahnHilliard gradients
250 std::vector<Tensor<1, dim>>(this->n_q_points);
251
252 // For STF calculation
254 std::vector<double>(this->n_q_points);
255
256 fields.insert(
257 std::pair<field, std::vector<double>>(field::phase_order_cahn_hilliard,
258 n_q_points));
259
260 fields.insert(std::pair<field, std::vector<double>>(
262
263 // Allocate physical properties
264 density_0 = std::vector<double>(n_q_points);
265 density_1 = std::vector<double>(n_q_points);
266 dynamic_viscosity_0 = std::vector<double>(n_q_points);
267 dynamic_viscosity_1 = std::vector<double>(n_q_points);
270 thermal_expansion_0 = std::vector<double>(n_q_points);
271 thermal_expansion_1 = std::vector<double>(n_q_points);
272 surface_tension = std::vector<double>(n_q_points);
273 surface_tension_gradient = std::vector<double>(n_q_points);
274
275 // Create filter
276 this->cahn_hilliard_filter = cahn_hilliard_filter;
277}
278
279
280template <int dim>
281void
283 const FiniteElement<dim> &fe_projected_phase_indicator_gradient,
284 const Quadrature<dim> &quadrature,
285 const Mapping<dim> &mapping)
286{
289 std::make_shared<FEValues<dim>>(mapping,
290 fe_projected_phase_indicator_gradient,
291 quadrature,
292 update_values | update_gradients);
293
294 // phase indicator gradient (PIG)
296 std::vector<Tensor<1, dim>>(this->n_q_points);
297}
298
299
300template <int dim>
301void
303 const FiniteElement<dim> &fe_curvature,
304 const Quadrature<dim> &quadrature,
305 const Mapping<dim> &mapping)
306{
307 gather_curvature = true;
308 fe_values_curvature = std::make_shared<FEValues<dim>>(
309 mapping, fe_curvature, quadrature, update_values | update_gradients);
310
311 // curvature
312 curvature_values = std::vector<double>(this->n_q_points);
313}
314
315
316template <int dim>
317void
319 const FiniteElement<dim> &fe,
320 const Quadrature<dim> &quadrature,
321 const Mapping<dim> &mapping)
322{
324 // The hessian is needed to calculate the gradient of the velocity divergence
325 // term in the stress tensor
326 gather_hessian = true;
327
328 // Contrary to the other physics, we enable the calculation of the JxW values
329 // on the void fraction
331 std::make_shared<FEValues<dim>>(mapping,
332 fe,
333 quadrature,
334 update_values | update_gradients |
335 update_JxW_values);
337 std::make_shared<FEPointEvaluation<1, dim>>(mapping, fe, update_values);
338
339 // Void Fraction
340 void_fraction_values = std::vector<double>(this->n_q_points);
342 std::vector<std::vector<double>>(maximum_number_of_previous_solutions(),
343 std::vector<double>(this->n_q_points));
344 void_fraction_gradient_values = std::vector<Tensor<1, dim>>(this->n_q_points);
345}
346
347template <int dim>
348void
350 const Quadrature<dim> &quadrature,
351 const Mapping<dim> &mapping,
352 const FiniteElement<dim> &fe_particle_drag_proj,
353 const FiniteElement<dim> &fe_particle_two_way_coupling_force_proj,
354 const FiniteElement<dim> &fe_particle_velocity_proj,
355 const FiniteElement<dim> &fe_particle_momentum_transfer_coefficient)
356{
358
359 fe_values_particle_drag = std::make_shared<FEValues<dim>>(
360 mapping, fe_particle_drag_proj, quadrature, update_values);
361
363 std::make_shared<FEValues<dim>>(mapping,
364 fe_particle_two_way_coupling_force_proj,
365 quadrature,
366 update_values);
367 fe_values_particle_velocity = std::make_shared<FEValues<dim>>(
368 mapping, fe_particle_velocity_proj, quadrature, update_values);
370 std::make_shared<FEValues<dim>>(mapping,
371 fe_particle_momentum_transfer_coefficient,
372 quadrature,
373 update_values);
374
375 particle_drag_values = std::vector<Tensor<1, dim>>(this->n_q_points);
377 std::vector<Tensor<1, dim>>(this->n_q_points);
378 particle_velocity_values = std::vector<Tensor<1, dim>>(this->n_q_points);
380 std::vector<double>(this->n_q_points);
381}
382
383template <int dim>
384void
386 const unsigned int n_global_max_particles_per_cell,
387 const bool enable_void_fraction_interpolation)
388{
390 max_number_of_particles_per_cell = n_global_max_particles_per_cell;
391 interpolated_void_fraction = enable_void_fraction_interpolation;
392
393 // Reinitialize vectors used to store flow information at the particle
394 // location that do not rely on a quadrature
396 std::vector<Tensor<1, dim>>(n_global_max_particles_per_cell);
398 std::vector<Tensor<1, dim>>(n_global_max_particles_per_cell);
399 Re_particle = std::vector<double>(n_global_max_particles_per_cell);
400
401 // This table is not used within an FeValues so we can avoid resizing it
402 // dynamically
403 density_at_particle_location.resize(n_global_max_particles_per_cell);
405 n_global_max_particles_per_cell);
406}
407
408template <int dim>
409void
414
415template <int dim>
416void
418{
419 Tensor<1, dim> velocity_ale;
420 std::shared_ptr<Functions::ParsedFunction<dim>> velocity_ale_function =
421 ale.velocity;
422 Vector<double> velocity_ale_vector(dim);
423
424 for (unsigned int q = 0; q < n_q_points; ++q)
425 {
426 velocity_ale_function->vector_value(quadrature_points[q],
427 velocity_ale_vector);
428 for (int d = 0; d < dim; ++d)
429 velocity_ale[d] = velocity_ale_vector[d];
430
431 // Subtract u_ale from the advective velocity
432 this->advective_velocity[q] -= velocity_ale;
433 }
434}
435
436template <int dim>
437void
442
443template <int dim>
444void
446 const typename DoFHandler<dim>::active_cell_iterator &cell,
447 const Parameters::Mortar<dim> &mortar_parameters)
448{
449 // Get updated rotor angular velocity
450 mortar_parameters.rotor_angular_velocity->set_time(
451 this->simulation_control->get_current_time());
452 const double rotor_angular_velocity =
453 mortar_parameters.rotor_angular_velocity->value(Point<dim>());
454
455 // Apply prescribed rotor angular velocity only at rotor cells
456 // (material_id = 1)
457 double omega = 0.0;
458 if (cell->material_id() == 1)
459 omega = rotor_angular_velocity;
460
461 // The mortar implementation is not defined for more than two
462 // materials. Throw when running debug mode as a security measure to prevent
463 // this case
464 Assert(
465 cell->material_id() < 2,
466 ExcMessage(
467 "The material id in a cell was identified as equal or greater than 2, however the mortar implementation is not defined for more than two materials."));
468
469 // Compute rotor linear velocity at quadrature points
470 rotor_linear_velocity_values = std::vector<Tensor<1, dim>>(this->n_q_points);
471 for (unsigned int q = 0; q < n_q_points; ++q)
472 {
473 // Shift quadrature point by the center of rotation
474 const auto p =
475 fe_values.quadrature_point(q) - mortar_parameters.center_of_rotation;
476
477 // Compute terms of u_ale
480 omega, p, mortar_parameters.rotation_axis_direction);
481
482 // Subtract u_ale from the advective velocity
484 }
485}
486
487
488template <int dim>
489void
491 const FiniteElement<dim> &fe,
492 const Quadrature<dim> &quadrature,
493 const Mapping<dim> &mapping)
494{
495 gather_temperature = true;
496 fe_values_temperature = std::make_shared<FEValues<dim>>(
497 mapping, fe, quadrature, update_values | update_gradients);
498
499 temperature_values = std::vector<double>(this->n_q_points);
501 std::vector<std::vector<double>>(maximum_number_of_previous_solutions(),
502 std::vector<double>(this->n_q_points));
503 temperature_gradients = std::vector<Tensor<1, dim>>(this->n_q_points);
504 previous_temperature_gradients = std::vector<std::vector<Tensor<1, dim>>>(
506 std::vector<Tensor<1, dim>>(this->n_q_points));
507 fields.insert(
508 std::pair<field, std::vector<double>>(field::temperature, n_q_points));
509}
510
511
512template <int dim>
513void
515{
516 if (properties_manager.field_is_required(field::temperature) &&
518 {
520 this->temperature_values,
521 this->fields);
522 }
523
524 if (properties_manager.field_is_required(field::pressure))
525 {
527 }
528
529 if (properties_manager.field_is_required(field::shear_rate))
530 {
531 for (unsigned int q = 0; q < n_q_points; ++q)
532 {
533 // Calculate shear rate (at each q)
534 const Tensor<2, dim> shear_rate_tensor =
535 velocity_gradients[q] + transpose(velocity_gradients[q]);
536
537 // Calculate the shear rate magnitude
538 shear_rate[q] = calculate_shear_rate_magnitude(shear_rate_tensor);
539 }
540
542 }
543
544 switch (properties_manager.get_number_of_fluids())
545 {
546 case 1:
547 {
548 // In the case of an incompressible flow, viscosity is the only
549 // required property
550 const auto rheology_model = properties_manager.get_rheology();
551 rheology_model->vector_value(fields, kinematic_viscosity);
552
553 rheology_model->get_kinematic_viscosity_for_stabilization_vector(
555
557 rheology_model->get_kinematic_viscosity_scale();
558
559 if (!properties_manager.density_is_constant())
560 {
561 // For a weakly compressible flow, density variations will play a
562 // role
563 const auto density_model = properties_manager.get_density();
564 density_model->vector_value(fields, density);
565 density_psi = density_model->get_psi();
566 density_ref = density_model->get_density_ref();
567 // Dynamic viscosity is also necessary for compressible flows
568 rheology_model->get_dynamic_viscosity_vector(density_ref,
569 fields,
571 rheology_model->get_dynamic_viscosity_for_stabilization_vector(
573 }
574 else
575 {
576 density_scale = properties_manager.get_density_scale();
577 }
578
579 if (properties_manager.is_non_newtonian())
580 {
581 // Calculate derivative of viscosity with respect to shear rate
582 rheology_model->vector_jacobian(
584 }
585
587 {
588 const auto thermal_expansion_model =
589 properties_manager.get_thermal_expansion();
590 thermal_expansion_model->vector_value(fields, thermal_expansion);
591 }
592 break;
593 }
594 case 2:
595 {
596 // We need both density and viscosity
597 const auto density_model_0 = properties_manager.get_density(0);
598 const auto rheology_model_0 = properties_manager.get_rheology(0);
599 const auto density_model_1 = properties_manager.get_density(1);
600 const auto rheology_model_1 = properties_manager.get_rheology(1);
601
602 density_ref_0 = density_model_0->get_density_ref();
603 density_ref_1 = density_model_1->get_density_ref();
604
606 rheology_model_0->get_kinematic_viscosity_scale();
608 rheology_model_1->get_kinematic_viscosity_scale();
609
612
613 // Gather properties from material interactions if necessary
614 if (properties_manager.get_number_of_material_interactions() > 0)
615 {
616 const auto material_interaction_id =
617 properties_manager.get_material_interaction_id(
619 // Gather surface tension
620 const auto surface_tension_model =
621 properties_manager.get_surface_tension(material_interaction_id);
622 surface_tension_model->vector_value(fields, surface_tension);
623 // Gather surface tension gradient only if necessary
624 if (!properties_manager.surface_tension_is_constant())
625 surface_tension_model->vector_jacobian(
627 }
628
629 density_model_0->vector_value(fields, density_0);
630 rheology_model_0->get_dynamic_viscosity_vector(density_ref_0,
631 fields,
633 rheology_model_0->get_dynamic_viscosity_for_stabilization_vector(
635
636 density_model_1->vector_value(fields, density_1);
637 rheology_model_1->get_dynamic_viscosity_vector(density_ref_1,
638 fields,
640 rheology_model_1->get_dynamic_viscosity_for_stabilization_vector(
643 {
644 const auto thermal_expansion_model_0 =
645 properties_manager.get_thermal_expansion(0);
646 const auto thermal_expansion_model_1 =
647 properties_manager.get_thermal_expansion(1);
648 thermal_expansion_model_0->vector_value(fields,
650 thermal_expansion_model_1->vector_value(fields,
652 }
653
655 {
656 for (unsigned int q = 0; q < this->n_q_points; ++q)
657 {
658 double filtered_phase_value = this->filtered_phase_values[q];
659
660 density[q] = calculate_point_property(filtered_phase_value,
661 this->density_0[q],
662 this->density_1[q]);
663
665 calculate_point_property(filtered_phase_value,
666 this->dynamic_viscosity_0[q],
667 this->dynamic_viscosity_1[q]);
668
670
673 filtered_phase_value,
676
678 calculate_point_property(filtered_phase_value,
679 this->thermal_expansion_0[q],
680 this->thermal_expansion_1[q]);
681
682 // Phase interpolate the product rho*beta per-phase to avoid
683 // cross term error from bilinear phase interpolation:
684 // interp_lin(rho)*interp_lin(beta) != interp_lin(rho*beta)
686 filtered_phase_value,
687 this->density_0[q] * this->thermal_expansion_0[q],
688 this->density_1[q] * this->thermal_expansion_1[q]);
689 }
690
691 // Gather density_psi for isothermal compressible NS equations
692 if (!properties_manager.density_is_constant())
693 {
694 density_psi_0 = density_model_0->get_psi();
695 density_psi_1 = density_model_1->get_psi();
696
697 for (unsigned int q = 0; q < this->n_q_points; ++q)
698 {
699 double filtered_phase_value =
700 this->filtered_phase_values[q];
701 // To avoid calculating twice in the assemblers
703 filtered_phase_value *
707 }
708 }
709
710 for (unsigned p = 0; p < previous_phase_values.size(); ++p)
711 {
712 // Blend the physical properties using the CLS field
713 for (unsigned int q = 0; q < this->n_q_points; ++q)
714 {
715 // Calculate previous density (right now assumes constant
716 // density model per phase)
718 filter->filter_phase(this->previous_phase_values[p][q]),
719 this->density_0[q],
720 this->density_1[q]);
721 }
722 }
723 break;
724 }
725 else if (gather_cahn_hilliard && !gather_cls)
726 {
727 // Blend the physical properties using the CahnHilliard field
728 for (unsigned int q = 0; q < this->n_q_points; ++q)
729 {
730 double phase_order_cahn_hilliard_value =
732
734 phase_order_cahn_hilliard_value,
735 this->density_0[q],
736 this->density_1[q]);
737
739 phase_order_cahn_hilliard_value,
740 this->dynamic_viscosity_0[q],
741 this->dynamic_viscosity_1[q]);
742
745 phase_order_cahn_hilliard_value,
748 }
749 break;
750 }
751 break;
752 }
753 default:
754 throw std::runtime_error("Unsupported number of fluids (>2)");
755 }
756}
757
758template <int dim>
759template <typename PropertiesIndex>
760void
762{
763 for (auto &particle : pic)
764 {
765 auto particle_properties = particle.get_properties();
766 // Set the particle_fluid_interactions properties and vectors to 0
767 for (int d = 0; d < dim; ++d)
768 {
769 particle_properties[PropertiesIndex::fem_force_two_way_coupling_x +
770 d] = 0.;
771 particle_properties[PropertiesIndex::fem_force_one_way_coupling_x +
772 d] = 0.;
773 particle_properties[PropertiesIndex::fem_drag_x + d] = 0.;
774 particle_properties[PropertiesIndex::fem_torque_x + d] = 0.;
776 }
777 }
778}
779
780template <int dim>
781template <typename PropertiesIndex>
782void
784{
786 // Loop over particles in cell
787 this->total_particle_volume = 0;
788 unsigned int i_particle = 0;
789
790 for (auto &particle : pic)
791 {
792 auto particle_properties = particle.get_properties();
793 // Stores the values of particle velocity in a tensor
794 particle_velocity[i_particle][0] =
795 particle_properties[PropertiesIndex::v_x];
796 particle_velocity[i_particle][1] =
797 particle_properties[PropertiesIndex::v_y];
798 if constexpr (dim == 3)
799 particle_velocity[i_particle][2] =
800 particle_properties[PropertiesIndex::v_z];
801
804 M_PI * pow(particle_properties[PropertiesIndex::dp], dim) / (2 * dim);
805
807 i_particle++;
808 }
809 number_of_particles = i_particle;
810 if (number_of_particles != 0)
811 { // Calculate the average particle velocity within the cell
814 }
815}
816
817template <int dim>
818void
820 const double &total_particle_volume)
821{
823 this->fe_values_void_fraction->get_JxW_values());
824
825 // The cell_void_fraction vector needs to be resized to the correct size
826 // since the quadrature used in the FEValues for the void fraction will
827 // be tailored exactly to the number of particles.
828 // We also initialize it to zero and it will be filled if a cell-averaged
829 // void fraction is used.
831
833 {
834 double cell_void_fraction_bulk = 0;
835 cell_void_fraction_bulk =
837
838 for (unsigned int j = 0; j < number_of_particles; ++j)
839 cell_void_fraction[j] = cell_void_fraction_bulk;
840 }
841}
842
843template <int dim>
844Quadrature<dim>
846{
847 // Create local vector that will be used to spawn an in-situ quadrature to
848 // interpolate at the locations of the particles
849 std::vector<Point<dim>> particle_reference_location(number_of_particles);
850 std::vector<double> particle_weights(number_of_particles, 1);
851 unsigned int i_particle = 0;
852
853 // Loop over particles in cell and cache their reference location
854 for (auto &particle : pic)
855 {
856 // Store particle positions and weights
857 // Reference location of the particle
858 particle_reference_location[i_particle] =
859 particle.get_reference_location();
860 i_particle++;
861 }
862
863 // Return a quadrature for the Navier-Stokes equations that is based on the
864 // particle reference location
865 return Quadrature<dim>(particle_reference_location, particle_weights);
866}
867template class NavierStokesScratchData<2>;
868template class NavierStokesScratchData<3>;
869
870template void
873
874template void
877
878template void
881
882template void
885
886template void
889
890template void
893
894template void
897
898template void
unsigned int maximum_number_of_previous_solutions()
Get the maximum number of previous time steps supposed by the BDF schemes implemented in Lethe.
Definition bdf.h:84
static std::shared_ptr< CahnHilliardFilterBase > model_cast(const Parameters::CahnHilliard &cahn_hilliard_parameters)
Instantiate and return a pointer to a CahnHilliardFilterBase object by casting it to the proper child...
static std::shared_ptr< ConservativeLevelSetFilterBase > model_cast(const Parameters::CLS_PhaseFilter &phase_filter_parameters)
Instantiate and return a pointer to a ConservativeLevelSetFilterBase object by casting it to the prop...
Definition cls_filter.cc:7
Class that stores the information required by the assembly procedure for a Navier-Stokes equation....
void enable_projected_phase_indicator_gradient(const FiniteElement< dim > &fe_projected_phase_indicator_gradient, const Quadrature< dim > &quadrature, const Mapping< dim > &mapping)
std::vector< std::vector< double > > previous_phase_values
std::vector< Tensor< 1, dim > > sdirk_stage_sum
void enable_cahn_hilliard(const FiniteElement< dim > &fe, const Quadrature< dim > &quadrature, const Mapping< dim > &mapping, const Parameters::CahnHilliard &cahn_hilliard_parameters)
enable_cahn_hilliard Enables the collection of the CahnHilliard data by the scratch
std::vector< double > thermal_expansion_1
std::vector< Tensor< 1, dim > > force
void extract_particle_properties()
Extracts the velocity of the particles and calculates their total volume in the cell....
std::shared_ptr< FEValues< dim > > fe_values_particle_momentum_transfer_coefficient
void reinit_mortar(const typename DoFHandler< dim >::active_cell_iterator &cell, const Parameters::Mortar< dim > &mortar_parameters)
Renitialize the content of the scratch data for mortar.
std::vector< Tensor< 1, dim > > projected_phase_indicator_gradient_values
double kinematic_viscosity_scale_0
Scale of the kinematic viscosity for fluid 0.
std::vector< double > density_thermal_expansion
FEValuesExtractors::Vector velocities
std::shared_ptr< FEValues< dim > > fe_values_cls
std::vector< Tensor< 3, dim > > velocity_hessians
void enable_void_fraction(const FiniteElement< dim > &fe, const Quadrature< dim > &quadrature, const Mapping< dim > &mapping)
enable_void_fraction Enables the collection of the void fraction data by the scratch
std::vector< Tensor< 1, dim > > void_fraction_gradient_values
void calculate_physical_properties()
Calculates the physical properties. This function calculates the physical properties that may be requ...
std::shared_ptr< FEValues< dim > > fe_values_cahn_hilliard
std::vector< std::vector< Tensor< 1, dim > > > previous_velocity_values
std::vector< Tensor< 1, dim > > phase_order_cahn_hilliard_gradients
void enable_ale()
enable_ale Enables the calculation of the ALE velocity
std::shared_ptr< FEValues< dim > > fe_values_particle_velocity
std::vector< Tensor< 1, dim > > temperature_gradients
std::shared_ptr< FEPointEvaluation< 1, dim > > point_evaluator_cls
std::vector< Tensor< 1, dim > > phase_gradient_values
std::vector< std::vector< double > > previous_pressure_values
std::vector< std::vector< Tensor< 1, dim > > > previous_temperature_gradients
std::shared_ptr< FEValues< dim > > fe_values_void_fraction
std::vector< std::vector< double > > previous_temperature_values
std::vector< unsigned int > components
void enable_mortar()
enable_mortar Enables the calculation of ALE velocity within the mortar feature
std::shared_ptr< FEValues< dim > > fe_values_particle_drag
std::vector< double > cell_void_fraction
std::vector< double > compressibility_multiplier
std::vector< Tensor< 2, dim > > velocity_gradients
std::vector< double > surface_tension_gradient
void enable_heat_transfer(const FiniteElement< dim > &fe, const Quadrature< dim > &quadrature, const Mapping< dim > &mapping)
enable_heat_transfer Enables the collection of the heat transfer data (Temperature field) by the scra...
std::vector< std::vector< double > > previous_density
void reinit_ale(const Parameters::ALE< dim > &ale)
Renitialize the content of the scratch data for ALE.
FEValuesExtractors::Scalar pressure
std::vector< Point< dim > > particle_reference_location
void enable_particle_fluid_interactions(const unsigned int n_global_max_particles_per_cell, const bool enable_void_fraction_interpolation)
enable_particle_fluid_interactions Enables the calculation of the fluid information at the particle l...
std::vector< Tensor< 1, dim > > particle_two_way_coupling_force_values
std::vector< Point< dim > > quadrature_points
std::vector< Tensor< 1, dim > > fluid_particle_relative_velocity_at_particle_location
std::vector< double > particle_momentum_transfer_coefficient_values
Table< 2, Tensor< 1, dim > > phi_u
std::vector< Tensor< 1, dim > > advective_velocity
std::vector< double > void_fraction_values
std::vector< double > dynamic_viscosity_for_stabilization_1
std::map< field, std::vector< double > > fields
std::vector< Tensor< 1, dim > > particle_velocity_values
std::shared_ptr< ConservativeLevelSetFilterBase > filter
std::vector< double > dynamic_viscosity_0
std::vector< double > kinematic_viscosity
std::vector< double > thermal_expansion_0
std::vector< Tensor< 1, dim > > velocity_values
std::shared_ptr< FEValues< dim > > fe_values_temperature
void enable_cls(const FiniteElement< dim > &fe, const Quadrature< dim > &quadrature, const Mapping< dim > &mapping, const Parameters::CLS_PhaseFilter &phase_filter_parameters)
enable_cls Enables the collection of the CLS data by the scratch
Table< 2, Tensor< 2, dim > > grad_phi_u
Table< 2, Tensor< 3, dim > > hess_phi_u
std::shared_ptr< CahnHilliardFilterBase > cahn_hilliard_filter
Particles::ParticleHandler< dim >::particle_iterator_range pic
void enable_curvature(const FiniteElement< dim > &fe_curvature, const Quadrature< dim > &quadrature, const Mapping< dim > &mapping)
Table< 2, Tensor< 1, dim > > laplacian_phi_u
Quadrature< dim > gather_particles_reference_location()
Creates an object of type Quadrature<dim> that contains the particle reference location....
std::vector< std::vector< double > > previous_void_fraction_values
std::vector< double > phase_order_cahn_hilliard_values
std::vector< Tensor< 1, dim > > particle_velocity
std::vector< Tensor< 1, dim > > filtered_phase_gradient_values
std::shared_ptr< FEPointEvaluation< 1, dim > > point_evaluator_void_fraction
std::shared_ptr< FEValues< dim > > fe_values_projected_phase_indicator_gradient
void reinit_particle_fluid_forces()
Reinitializes the fluid forces and torques on the particles in the cell to zero.
std::vector< double > dynamic_viscosity_1
std::vector< double > temperature_values
std::vector< Tensor< 1, dim > > velocity_gradient_divergence
const std::shared_ptr< SimulationControl > simulation_control
std::vector< double > kinematic_viscosity_for_stabilization
std::vector< Vector< double > > rhs_force
std::vector< double > filtered_phase_values
std::vector< Tensor< 1, dim > > particle_drag_values
void allocate() override
Allocates the memory for the scratch.
std::vector< double > velocity_divergences
std::vector< Tensor< 1, dim > > rotor_linear_velocity_values
std::vector< double > dynamic_viscosity_for_stabilization
Values of the dynamic viscosity used in the SUPG and PSPG stabilizations.
std::vector< double > density_at_particle_location
std::vector< double > kinematic_viscosity_at_particle_location
void enable_particle_field_projection(const Quadrature< dim > &quadrature, const Mapping< dim > &mapping, const FiniteElement< dim > &fe_particle_drag_proj, const FiniteElement< dim > &fe_particle_two_way_coupling_force_proj, const FiniteElement< dim > &fe_particle_velocity_proj, const FiniteElement< dim > &fe_particle_momentum_transfer_coefficient)
enable_particle_field_projection Enables the collection of the particle fields projection data by the...
Table< 2, Tensor< 1, dim > > grad_phi_p
std::vector< double > dynamic_viscosity
std::vector< double > grad_kinematic_viscosity_shear_rate
std::shared_ptr< FEValues< dim > > fe_values_curvature
std::vector< double > filtered_phase_order_cahn_hilliard_values
std::vector< Tensor< 1, dim > > pressure_gradients
Tensor< 1, dim > explicit_particle_volumetric_acceleration_on_fluid
Table< 2, Tensor< 1, dim > > gradient_divergence_phi_u
std::vector< double > thermal_expansion
void calculate_cell_void_fraction(const double &total_particle_volume)
Computes the cell void fraction.
std::vector< Tensor< 1, dim > > velocity_laplacians
const PhysicalPropertiesManager properties_manager
std::vector< double > dynamic_viscosity_for_stabilization_0
std::shared_ptr< FEValues< dim > > fe_values_particle_two_way_coupling_force
std::vector< double > chemical_potential_cahn_hilliard_values
double kinematic_viscosity_scale_1
Scale of the kinematic viscosity for fluid 1.
An interface for all the common parameters required to consider a moving frame of reference in a simp...
Definition ale.h:25
std::shared_ptr< Functions::ParsedFunction< dim > > velocity
ALE velocity function.
Definition ale.h:56
double compute_cell_measure_with_JxW(const std::vector< double > &JxW_values)
Computes the area (2D) or volume (3D) of the cell by integrating 1 over the cell, by summing JxW valu...
Definition utilities.h:1017
double calculate_point_property(const double phase, const double property0, const double property1)
Calculate the equivalent properties for a given phase. Method called in quadrature points loops in CL...
Definition utilities.h:307
double calculate_point_property_cahn_hilliard(const double phase_cahn_hilliard, const double property0, const double property1)
Calculate the equivalent property for a given phase.
Definition utilities.h:380
PropertiesIndex
Particle property indices for CFD-DEM multiphysics simulations.
PropertiesIndex
Particle property indices for CFD-DEM simulations.
Tensor< 1, dim > angular_to_linear_velocity(const double omega, const Tensor< 1, dim > &point, const unsigned int rotation_axis_direction=2)
Transform angular velocity into linear velocity considering that the angular velocity omega is consta...
@ phase_order_cahn_hilliard_filtered
void set_field_vector(const field &id, const std::vector< double > &data, std::map< field, std::vector< double > > &fields)
double calculate_shear_rate_magnitude(const Tensor< 2, dim > shear_rate)
Calculates the magnitude of the shear rate tensor given as input.
Parameters for the phase filtration.
Mortar - Defines parameters used to construct mortar elements.
Point< dim > center_of_rotation
Center of rotation of the rotor domain.
std::shared_ptr< Functions::ParsedFunction< dim > > rotor_angular_velocity
Angular velocity of the rotor domain.
unsigned int rotation_axis_direction
Rotation axis direction.