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