Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
tracer_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
7
8template <int dim>
9void
11{
12 // Initialize size of arrays
13 this->n_q_points = fe_values_tracer.get_quadrature().size();
14 this->n_dofs = fe_values_tracer.get_fe().n_dofs_per_cell();
15
16 // Initialize arrays related to quadrature
17 this->JxW.reinit(n_q_points);
18
19 // Forcing term array
20 this->source = std::vector<double>(n_q_points);
21
22 // Initialize arrays related to velocity
23 this->velocities.first_vector_component = 0;
24 // Velocity
25 this->velocity_values = std::vector<Tensor<1, dim>>(n_q_points);
26 this->velocity_divergences = std::vector<double>(n_q_points);
27
28 // Tracer
29 this->tracer_values = std::vector<double>(n_q_points);
30 this->tracer_gradients = std::vector<Tensor<1, dim>>(n_q_points);
32 std::vector<Tensor<1, dim>>(this->n_q_points);
33 this->tracer_laplacians = std::vector<double>(n_q_points);
34 this->tracer_diffusivity = std::vector<double>(n_q_points);
35 this->tracer_diffusivity_0 = std::vector<double>(n_q_points);
36 this->tracer_diffusivity_1 = std::vector<double>(n_q_points);
37 this->tracer_reaction_prefactor = std::vector<double>(n_q_points);
38 this->grad_tracer_reaction_prefactor = std::vector<double>(n_q_points);
39
40 // Arrays related to the faces, which are only used by the DG assemblers
41 const unsigned int n_face_q_points =
42 fe_interface_values_tracer.get_quadrature().size();
43 const unsigned int max_n_interface_dofs = 2 * n_dofs;
44 this->tracer_diffusivity_face = std::vector<double>(n_face_q_points);
45 this->face_velocity_values = std::vector<Tensor<1, dim>>(n_face_q_points);
46 this->values_here = std::vector<double>(n_face_q_points);
47 this->values_there = std::vector<double>(n_face_q_points);
48 this->tracer_value_jump = std::vector<double>(n_face_q_points);
49 this->gradients_here = std::vector<Tensor<1, dim>>(n_face_q_points);
50 this->tracer_average_gradient = std::vector<Tensor<1, dim>>(n_face_q_points);
51 this->face_phi_here.reinit(n_face_q_points, max_n_interface_dofs);
52 this->face_phi_there.reinit(n_face_q_points, max_n_interface_dofs);
53 this->face_jump_phi.reinit(n_face_q_points, max_n_interface_dofs);
54 this->face_average_grad_phi_dot_n.reinit(n_face_q_points,
55 max_n_interface_dofs);
56
57 // Solid signed distance function
58 if (properties_manager.field_is_required(field::levelset))
59 this->sdf_values = std::vector<double>(n_q_points);
60
61 // Velocity for BDF schemes
63 std::vector<std::vector<double>>(maximum_number_of_previous_solutions(),
64 std::vector<double>(n_q_points));
65
66 // Initialize arrays related to shape functions
67 // Velocity shape functions
68 this->phi.reinit(n_q_points, n_dofs);
69 this->grad_phi.reinit(n_q_points, n_dofs);
70 if (!uses_dg)
71 {
72 this->hess_phi.reinit(n_q_points, n_dofs);
73 this->laplacian_phi.reinit(n_q_points, n_dofs);
74 }
75
76 if (properties_manager.field_is_required(field::levelset))
77 fields.insert(
78 std::pair<field, std::vector<double>>(field::levelset, n_q_points));
80 fields.insert(
81 std::pair<field, std::vector<double>>(field::tracer_concentration,
82 n_q_points));
83}
84
85
86template <int dim>
87void
89{
90 if (properties_manager.field_is_required(field::levelset))
92
95 this->tracer_values,
96 this->fields);
97
98 switch (properties_manager.get_number_of_fluids())
99 {
100 case 1:
101 {
102 const auto diffusivity_model =
103 properties_manager.get_tracer_diffusivity();
104 diffusivity_model->vector_value(fields, tracer_diffusivity);
105 const auto reaction_prefactor_model =
106 properties_manager.get_tracer_reaction_prefactor();
107 reaction_prefactor_model->vector_value(fields,
109 reaction_prefactor_model->vector_jacobian(
110 fields,
113
114 break;
115 }
116 case 2:
117 {
118 throw std::runtime_error(
119 "Unsupported number of fluids (2) with the tracer physics.");
120 // In this case, we need both density and viscosity
121 const auto diffusivity_models =
122 properties_manager.get_tracer_diffusivity_vector();
123
124 diffusivity_models[0]->vector_value(fields, tracer_diffusivity_0);
125 diffusivity_models[1]->vector_value(fields, tracer_diffusivity_1);
126
127 // TODO Incomplete at the present time because the tracer CLS
128 // complete is not finished Blend the physical properties
129 // using the CLS field
130 // for (unsigned int q = 0; q < this->n_q_points; ++q)
131 // {
132 // tracer_diffusivity[q] =
133 // calculate_point_property(this->phase_values[q],
134 // this->density_0[q],
135 // this->density_1[q]);
136 // }
137 break;
138 }
139 default:
140 throw std::runtime_error("Unsupported number of fluids (>2)");
141 }
142}
143
144
145template class TracerScratchData<2>;
146template class TracerScratchData<3>;
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
Class that stores the information required by the assembly procedure for a Tracer advection-diffusion...
std::vector< Tensor< 1, dim > > face_velocity_values
std::vector< double > tracer_values
std::vector< Tensor< 1, dim > > previous_tracer_gradients
FEValuesExtractors::Vector velocities
std::vector< double > tracer_diffusivity_0
std::vector< double > tracer_diffusivity_1
Table< 2, double > face_average_grad_phi_dot_n
std::vector< double > values_there
std::vector< Tensor< 1, dim > > velocity_values
std::vector< double > grad_tracer_reaction_prefactor
std::vector< double > velocity_divergences
void allocate() override
Allocates the memory for the scratch.
std::vector< std::vector< double > > previous_tracer_values
std::vector< double > tracer_diffusivity
Table< 1, double > JxW
FEInterfaceValues< dim > fe_interface_values_tracer
std::vector< Tensor< 1, dim > > tracer_average_gradient
std::vector< double > tracer_reaction_prefactor
std::vector< double > sdf_values
Table< 2, double > laplacian_phi
std::map< field, std::vector< double > > fields
void calculate_physical_properties()
Calculates the physical properties. This function calculates the physical properties that may be requ...
std::vector< Tensor< 1, dim > > tracer_gradients
Table< 2, Tensor< 2, dim > > hess_phi
std::vector< double > source
std::vector< double > tracer_value_jump
std::vector< double > values_here
Table< 2, double > face_jump_phi
Table< 2, double > face_phi_there
PhysicalPropertiesManager properties_manager
Table< 2, double > face_phi_here
std::vector< double > tracer_laplacians
Table< 2, Tensor< 1, dim > > grad_phi
Table< 2, double > phi
std::vector< double > tracer_diffusivity_face
std::vector< Tensor< 1, dim > > gradients_here
FEValues< dim > fe_values_tracer
void set_field_vector(const field &id, const std::vector< double > &data, std::map< field, std::vector< double > > &fields)