OGS
AverageMolarMass.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
5
8
10{
12{
13 name_ = std::move(name);
14}
15
17{
18 if (!(std::holds_alternative<Phase*>(scale_)))
19 {
21 "The property 'AverageMolarMass' is implemented on the 'phase' "
22 "scale only.");
23 }
24}
25
27 VariableArray const& variable_array,
28 ParameterLib::SpatialPosition const& pos, double const t,
29 double const dt) const
30{
31 auto phase = std::get<Phase*>(scale_);
32 auto const numberOfComponents = phase->numberOfComponents();
33 if (numberOfComponents < 1)
34 {
35 // if phase contains no components, jst return phase molar mass
36 return phase->property(PropertyType::molar_mass)
37 .template value<double>(variable_array, pos, t, dt);
38 }
39 else if (numberOfComponents > 2)
40 {
42 "AverageMolarMass::value only allows for phases consisting of up "
43 "to two components.");
44 }
45
46 // TODO (grunwald) : Task here is to retrieve the individual molar fractions
47 // of each compontne in the phase. Those are not static properties (as in
48 // case of molar mass), but they depend on some state-dependent rule. Option
49 // 1 is to call that rule here, option 2 would be to wrap this composition
50 // info into some container and to put it into the variable_array. This
51 // would have to be a vector of variable size, depending on the number of
52 // components. Unfortunately, the data types of MPL::VariableArray do not
53 // include such a type.
54 //
55 // Therefore, I go with option 1 here, which unfortunately only allows the
56 // use of binary mixtures at the moment.
57 auto const molar_fraction =
58 phase->property(PropertyType::mole_fraction)
59 .template value<Eigen::Vector2d>(variable_array, pos, t, dt);
60
61 double M = 0.;
62 for (size_t c = 0; c < numberOfComponents; c++)
63 {
64 auto const M_zeta =
65 phase->component(c)
67 .template value<double>(variable_array, pos, t, dt);
68 auto const xn_zeta = molar_fraction[c];
69
70 M += xn_zeta * M_zeta;
71 }
72
73 return M;
74}
75
77 VariableArray const& variable_array, Variable const variable,
78 ParameterLib::SpatialPosition const& pos, double const t,
79 double const dt) const
80{
81 if ((variable != Variable::gas_phase_pressure) &&
82 (variable != Variable::temperature))
83 {
85 "AverageMolarMass::dValue is implemented for derivatives with "
86 "respect to phase_pressure or temperature only.");
87 }
88
89 auto phase = std::get<Phase*>(scale_);
90
91 auto const numberOfComponents = phase->numberOfComponents();
92 if (numberOfComponents <= 1)
93 {
94 return 0.;
95 }
96 else if (numberOfComponents > 2)
97 {
99 "AverageMolarMass::dValue is currently implemented two or less "
100 "phase components only.");
101 }
102
103 // TODO (grunwald) : This should return a vector of length
104 // phase->numberOfComponents(). Currently, this feature is implemented
105 // for binary phases only.
106 auto const dxnC = phase->property(PropertyType::mole_fraction)
107 .template dValue<Eigen::Vector2d>(
108 variable_array, variable, pos, t, dt)[0];
109
110 auto const M_0 = phase->component(0)
111 .property(PropertyType::molar_mass)
112 .template value<double>(variable_array, pos, t, dt);
113 auto const M_1 = phase->component(1)
114 .property(PropertyType::molar_mass)
115 .template value<double>(variable_array, pos, t, dt);
116
117 return dxnC * (M_0 - M_1);
118
119} // namespace MaterialPropertyLib
120
122 VariableArray const& /*variable_array*/, Variable const /*variable1*/,
123 Variable const /*variable2*/, ParameterLib::SpatialPosition const& /*pos*/,
124 double const /*t*/, double const /*dt*/) const
125{
126 OGS_FATAL("AverageMolarMass::d2Value is not yet implemented.");
127
128 return 0.;
129}
130
131} // namespace MaterialPropertyLib
#define OGS_FATAL(...)
Definition Error.h:19
PropertyDataType dValue(VariableArray const &variable_array, Variable const variable, ParameterLib::SpatialPosition const &, double const, double const) const override
PropertyDataType d2Value(VariableArray const &variable_array, Variable const variable1, Variable const variable2, ParameterLib::SpatialPosition const &pos, double const t, double const dt) const override
Default implementation: 2nd derivative of any constant property is zero.
virtual PropertyDataType value() const
std::variant< Medium *, Phase *, Component * > scale_
std::variant< double, Eigen::Matrix< double, 2, 1 >, Eigen::Matrix< double, 3, 1 >, Eigen::Matrix< double, 2, 2 >, Eigen::Matrix< double, 3, 3 >, Eigen::Matrix< double, 4, 1 >, Eigen::Matrix< double, 6, 1 >, Eigen::MatrixXd > PropertyDataType