include/meltpooldg/species_transport/effective_material_mixin.hpp Source File

Developer Documentation: include/meltpooldg/species_transport/effective_material_mixin.hpp Source File
Developer Documentation
effective_material_mixin.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <deal.II/base/vectorization.h>
4
5#include <boost/range/adaptor/indexed.hpp>
6
7#include <concepts>
8#include <type_traits>
9#include <utility>
10
12{
13 template <int n_species, typename number, typename ValueType, typename Derived>
15 {
22 ValueType
23 mole_fraction(const unsigned species_component) const
24 requires requires() {
25 {
26 std::declval<const Derived>().mass_fraction(species_component)
27 } -> std::convertible_to<ValueType>;
28 {
29 std::declval<const Derived>().molar_mass(species_component)
30 } -> std::convertible_to<ValueType>;
31 }
32 {
33 ValueType total_amount_of_substance = 0.;
34 for (unsigned int i = 0; i < n_species; ++i)
35 {
36 total_amount_of_substance += derived().mass_fraction(i) / derived().molar_mass(i);
37 }
38
39 ValueType species_amount_of_substance =
40 derived().mass_fraction(species_component) / derived().molar_mass(species_component);
41 return species_amount_of_substance / total_amount_of_substance;
42 }
43
58 ValueType
59 mixture_averaged_diffusion_coefficient(const unsigned int species_component) const
60 requires requires() {
61 {
62 std::declval<const Derived>().binary_diffusion_coefficient(species_component,
63 species_component)
64 } -> std::convertible_to<ValueType>;
65 {
66 std::declval<const Derived>().mass_fraction(species_component)
67 } -> std::convertible_to<ValueType>;
68 }
69 {
70 ValueType denominator = 0.;
71 for (unsigned int i = 0; i < n_species; ++i)
72 {
73 // If a single binary diffusion coefficient is zero, we simply do not take into account
74 // the diffusion of the respective species pair.
75 if (i != species_component and
76 derived().binary_diffusion_coefficient(species_component, i) > 0.)
77 {
78 denominator +=
79 mole_fraction(i) / derived().binary_diffusion_coefficient(species_component, i);
80 }
81 }
82
83 const auto compute_final_mixture_averaged_diffusion_coefficient =
84 [&](const ValueType &denominator) -> ValueType {
85 return (1. - derived().mass_fraction(species_component)) / denominator;
86 };
87
88 // If the denominator is zero, it means that the species does not diffuse with any other
89 // available species. In this case, we set the mixture-averaged diffusion coefficient to zero.
90 ValueType tolerance = ValueType(1e-20);
91 if constexpr (std::is_floating_point_v<ValueType>)
92 {
93 return denominator < tolerance ?
94 ValueType(0.) :
95 compute_final_mixture_averaged_diffusion_coefficient(denominator);
96 }
97 else
98 {
99 return dealii::compare_and_apply_mask<dealii::SIMDComparison::greater_than>(
100 denominator,
101 tolerance,
102 compute_final_mixture_averaged_diffusion_coefficient(denominator),
103 ValueType(0.));
104 }
105 }
106
114 template <typename ContainerType, typename SpeciesMaterial>
115 ValueType
116 effective_material_property(const ContainerType &species_material,
117 number SpeciesMaterial::*property) const
118 requires requires(int i) {
119 {
120 std::declval<const Derived>().mass_fraction(i)
121 } -> std::convertible_to<ValueType>;
122 }
123 {
124 ValueType result = 0.;
125 for (const auto [index, species] : species_material | boost::adaptors::indexed())
126 {
127 if (index >= n_species)
128 break;
129 result += derived().mass_fraction(index) * (species.*property);
130 }
131 return result;
132 }
133
134 private:
135 decltype(auto)
136 derived() const
137 {
138 return static_cast<const Derived &>(*this);
139 }
140 };
141} // namespace MeltPoolDG::SpeciesTransport
Definition boundary_conditions.hpp:8
Definition effective_material_mixin.hpp:15
decltype(auto) derived() const
Definition effective_material_mixin.hpp:136
ValueType effective_material_property(const ContainerType &species_material, number SpeciesMaterial::*property) const
Definition effective_material_mixin.hpp:116
ValueType mixture_averaged_diffusion_coefficient(const unsigned int species_component) const
Definition effective_material_mixin.hpp:59
ValueType mole_fraction(const unsigned species_component) const
Definition effective_material_mixin.hpp:23