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