OGS
WaterDensityIAPWSIF97Region1.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
6#include <cmath>
7
8#include "BaseLib/Error.h"
11
12namespace MaterialPropertyLib
13{
14
16 VariableArray const& variable_array,
17 ParameterLib::SpatialPosition const& /*pos*/, double const /*t*/,
18 double const /*dt*/) const
19{
20 double const p = std::max(0.0, variable_array.liquid_phase_pressure);
21 double const T = variable_array.temperature;
22 const double tau = ref_T_ / T;
23 const double pi = p / ref_p_;
24
25 return ref_p_ /
27 gibbs_free_energy_.get_dgamma_dpi(tau, pi));
28}
29
31 VariableArray const& variable_array, Variable const variable,
32 ParameterLib::SpatialPosition const& /*pos*/, double const /*t*/,
33 double const /*dt*/) const
34{
35 const double T = variable_array.temperature;
36 double const p = std::max(0.0, variable_array.liquid_phase_pressure);
37
38 const double tau = ref_T_ / T;
39 const double pi = p / ref_p_;
40
41 const double dgamma_dpi = gibbs_free_energy_.get_dgamma_dpi(tau, pi);
42
43 switch (variable)
44 {
46 return -(ref_p_ -
47 tau * ref_p_ *
48 gibbs_free_energy_.get_dgamma_dtau_dpi(tau, pi) /
49 dgamma_dpi) /
50 (MaterialLib::PhysicalConstant::SpecificGasConstant::
51 WaterIF97 *
52 T * T * dgamma_dpi);
54 // Consistency with value(): below the pressure clamp p = max(0,
55 // p_LR) the density is constant in pressure, so its derivative is
56 // zero. Returning the analytic derivative evaluated at the
57 // clamped pressure would feed the Jacobian a phantom liquid
58 // compressibility wherever p_LR < 0 (strongly desaturated
59 // states).
60 if (variable_array.liquid_phase_pressure < 0.0)
61 {
62 return 0.0;
63 }
64 return -gibbs_free_energy_.get_dgamma_dpi_dpi(tau, pi) /
65 (MaterialLib::PhysicalConstant::SpecificGasConstant::
66 WaterIF97 *
67 T * dgamma_dpi * dgamma_dpi);
69 return 0.0;
70
71 default:
73 "WaterDensityIAPWSIF97Region1::dValue is implemented for "
74 "derivatives with "
75 "respect to temperature or liquid_phase_pressure only.");
76 }
77}
78
79} // namespace MaterialPropertyLib
#define OGS_FATAL(...)
Definition Error.h:10
virtual PropertyDataType value() const
PropertyDataType dValue(VariableArray const &variable_array, Variable const variable, ParameterLib::SpatialPosition const &pos, double const t, double const dt) const override
static constexpr double ref_p_
reference pressure in Pa.
const MaterialLib::Fluid::DimensionLessGibbsFreeEnergyRegion1 gibbs_free_energy_
static constexpr double ref_T_
reference temperature in K.
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