OGS
SigmoidFunction.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
4#include "SigmoidFunction.h"
5
7{
8SigmoidFunction::SigmoidFunction(double const k, double const T_c,
9 double const S_r)
10 : k_(k), T_c_(T_c), S_r(S_r)
11{
12}
13
14double SigmoidFunction::value(double const& T) const
15{
16 double const x = k_ * (T - T_c_);
17
18 // Cutting off at the last x producing a (non-normal) return value because
19 // std::exp(x) produces +infinity beyond this point, approximately 709.78.
20 // The reason for using hex representation is that the value is unambiguous.
21 if (x > 0x1.62e42fefa39efp+9)
22 {
23 return 0.;
24 }
25
26 return (1. - S_r) / (1. + std::exp(x));
27}
28
29double SigmoidFunction::dValue(double const& T) const
30{
31 double const f = value(T);
32 if (f * f == 0)
33 {
34 return 0;
35 }
36 double const x = k_ * (T - T_c_);
37 return -k_ * std::exp(x) * (f * f) / (1. - S_r);
38}
39
40double SigmoidFunction::d2Value(double const& T) const
41{
42 double const fT = dValue(T);
43 if (fT == 0)
44 {
45 return 0;
46 }
47
48 double const f = value(T);
49 return fT * (k_ + 2 * fT / f);
50}
51
52} // namespace MaterialPropertyLib
double dValue(double const &T) const
SigmoidFunction(double const k, double const T_c, double const S_r)
double d2Value(double const &T) const
double value(double const &T) const
constexpr double T_c
Critical temperature.