44 #ifndef ROL_ABSOLUTEVALUE_HPP
45 #define ROL_ABSOLUTEVALUE_HPP
73 Real param = parlist.get(
"Smoothing Parameter",1.);
74 param_ = 1./((param > 0.) ? param : 1.);
75 std::string type = parlist.get(
"Absolute Value Approximation",
"true");
91 ROL_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
92 ">>> ERROR (ROL::AbsoluteValue): Absolute value approximation not defined!");
99 Real output = 0.0, e = 0.0;
100 if ( std::abs(
param_) > ROL_EPSILON<Real>() ) { e = 0.5/
param_; }
103 if ( input < -e ) { region = -1; }
104 else if ( input > e ) { region = 1; }
106 if ( deriv == 0 ) { output = std::abs(input); }
107 else if ( deriv == 1 ) { output = (input < 0.0 ? -1.0 : 1.0); }
108 else if ( deriv == 2 ) {
109 if ( region == -1 ) { output = 0.0; }
110 else if ( region == 0 ) { output = e*std::exp( -1.0/(1.0 - std::pow(std::abs(input/e),2.0)) ); }
111 else if ( region == 1 ) { output = 0.0; }
118 if ( deriv == 0 ) { output = std::sqrt(input*input + 1.0/
param_); }
119 else if ( deriv == 1 ) { output = input/std::sqrt(input*input+1.0/
param_); }
120 else if ( deriv == 2 ) { output = (1.0/
param_)/std::pow(input*input+1.0/
param_,1.5); }
126 if ( deriv == 0 ) { output = input*input/std::sqrt(input*input + 1.0/
param_); }
127 else if ( deriv == 1 ) { output = (2.0/
param_*input+std::pow(input,3.0)) /
128 std::pow(input*input+1.0/
param_,1.5); }
129 else if ( deriv == 2 ) { output = ((2.0/
param_-input*input)/
param_) /
130 std::pow(input*input+1.0/
param_,2.5); }
135 Real output = 0.0, e = 1.0;
136 if ( std::abs(
param_) > ROL_EPSILON<Real>() ) { e = 0.5/
param_; }
139 if ( input < -e ) { region = -1; }
140 else if ( input > e ) { region = 1; }
143 if ( std::abs(region) == 1 ) { output = std::abs(input); }
144 else if ( region == 0 ) { output = 1.875*std::pow(input*e,2.0) -
145 1.25 *std::pow(input*e,4.0) +
146 0.375*std::pow(input*e,6.0); }
148 else if ( deriv == 1 ) {
149 if ( std::abs(region) == 1 ) { output = (input < 0.0 ? -1.0 : 1.0); }
150 else if ( region == 0 ) { output = e*2.0*1.875*input*e -
151 e*4.0*1.25 *std::pow(input*e,3.0) +
152 e*6.0*0.375*std::pow(input*e,5.0); }
154 else if ( deriv == 2 ) {
155 if ( std::abs(region) == 1 ) { output = 0.0; }
156 else if ( region == 0 ) { output = e* 2.0*1.875 -
157 e*e*12.0*1.25 *std::pow(input*e,2.0) +
158 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)