10 #ifndef ROL_ABSOLUTEVALUE_HPP
11 #define ROL_ABSOLUTEVALUE_HPP
15 #include "ROL_ParameterList.hpp"
40 Real param = parlist.get(
"Smoothing Parameter",1.);
41 param_ = 1./((param > 0.) ? param : 1.);
42 std::string type = parlist.get(
"Absolute Value Approximation",
"true");
58 ROL_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
59 ">>> ERROR (ROL::AbsoluteValue): Absolute value approximation not defined!");
66 Real output = 0.0, e = 0.0;
67 if ( std::abs(
param_) > ROL_EPSILON<Real>() ) { e = 0.5/
param_; }
70 if ( input < -e ) { region = -1; }
71 else if ( input > e ) { region = 1; }
73 if ( deriv == 0 ) { output = std::abs(input); }
74 else if ( deriv == 1 ) { output = (input < 0.0 ? -1.0 : 1.0); }
75 else if ( deriv == 2 ) {
76 if ( region == -1 ) { output = 0.0; }
77 else if ( region == 0 ) { output = e*std::exp( -1.0/(1.0 - std::pow(std::abs(input/e),2.0)) ); }
78 else if ( region == 1 ) { output = 0.0; }
85 if ( deriv == 0 ) { output = std::sqrt(input*input + 1.0/
param_); }
86 else if ( deriv == 1 ) { output = input/std::sqrt(input*input+1.0/
param_); }
87 else if ( deriv == 2 ) { output = (1.0/
param_)/std::pow(input*input+1.0/
param_,1.5); }
93 if ( deriv == 0 ) { output = input*input/std::sqrt(input*input + 1.0/
param_); }
94 else if ( deriv == 1 ) { output = (2.0/
param_*input+std::pow(input,3.0)) /
95 std::pow(input*input+1.0/
param_,1.5); }
96 else if ( deriv == 2 ) { output = ((2.0/
param_-input*input)/
param_) /
97 std::pow(input*input+1.0/
param_,2.5); }
102 Real output = 0.0, e = 1.0;
103 if ( std::abs(
param_) > ROL_EPSILON<Real>() ) { e = 0.5/
param_; }
106 if ( input < -e ) { region = -1; }
107 else if ( input > e ) { region = 1; }
110 if ( std::abs(region) == 1 ) { output = std::abs(input); }
111 else if ( region == 0 ) { output = 1.875*std::pow(input*e,2.0) -
112 1.25 *std::pow(input*e,4.0) +
113 0.375*std::pow(input*e,6.0); }
115 else if ( deriv == 1 ) {
116 if ( std::abs(region) == 1 ) { output = (input < 0.0 ? -1.0 : 1.0); }
117 else if ( region == 0 ) { output = e*2.0*1.875*input*e -
118 e*4.0*1.25 *std::pow(input*e,3.0) +
119 e*6.0*0.375*std::pow(input*e,5.0); }
121 else if ( deriv == 2 ) {
122 if ( std::abs(region) == 1 ) { output = 0.0; }
123 else if ( region == 0 ) { output = e* 2.0*1.875 -
124 e*e*12.0*1.25 *std::pow(input*e,2.0) +
125 e*e*30.0*0.375*std::pow(input*e,4.0); }
Real sqrtd_absolute_value(Real input, int deriv)
Contains definitions of custom data types in ROL.
Real c2_absolute_value(Real input, int deriv)
AbsoluteValue(Real param=1., EAbsoluteValue eav=ABSOLUTEVALUE_TRUE)
Real sqrt_absolute_value(Real input, int deriv)
AbsoluteValue(ROL::ParameterList &parlist)
Real evaluate(Real input, int deriv)
Real true_absolute_value(Real input, int deriv)