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