/usr/include/trilinos/TOpEleWiseBoundsHelpers.hpp is in libtrilinos-rol-dev 12.10.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | // @HEADER
// ***********************************************************************
//
// RTOp: Interfaces and Support Software for Vector Reduction Transformation
// Operations
// Copyright (2006) Sandia Corporation
//
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
// license for use of this work by or on behalf of the U.S. Government.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
//
// ***********************************************************************
// @HEADER
#ifndef TOP_ELE_WISE_BOUNDS_HELPERS_HPP
#define TOP_ELE_WISE_BOUNDS_HELPERS_HPP
#include "RTOpPack_RTOpTHelpers.hpp"
#include "Thyra_VectorBase.hpp"
#include <cmath>
namespace RTOpPack {
/** \brief Element-wise transformation operator for TOpEleWiseBound. */
template<class Scalar>
class TOpEleWiseBoundTransformation {
public:
void
operator() (const Scalar &v0, const Scalar &v1, Scalar &z0) const {
z0 = std::max (v0, std::min (v1, z0));
}
};
/** \brief Element-wise transformation operator for TOpEleWisePrune. */
template<class Scalar>
class TOpEleWisePruneLowerTransformation {
public:
TOpEleWisePruneLowerTransformation(const Scalar& eps) : eps_(eps) {}
void
operator() (const Scalar &v0, const Scalar &v1, const Scalar &v2,
Scalar &z0) const {
if ((v0 <= v1 + eps_) && (v2 > 0.0))
z0 = 0;
}
void
operator() (const Scalar &v0, const Scalar &v1, Scalar &z0) const {
if (v0 <= v1 + eps_)
z0 = 0;
}
private:
const Scalar& eps_;
};
/** \brief Element-wise transformation operator for TOpEleWisePrune. */
template<class Scalar>
class TOpEleWisePruneUpperTransformation {
public:
TOpEleWisePruneUpperTransformation(const Scalar& eps) : eps_(eps) {}
void
operator() (const Scalar &v0, const Scalar &v1, const Scalar &v2,
Scalar &z0) const {
if ((v0 >= v1 - eps_) && (v2 < 0.0))
z0 = 0;
}
void
operator() (const Scalar &v0, const Scalar &v1, Scalar &z0) const {
if (v0 >= v1 - eps_)
z0 = 0;
}
private:
const Scalar& eps_;
};
/** \brief Element-wise product update transformation operator:
* <tt>z0[i] *= min(v0[i],abs(z0[i]) * z0[i]/abs(z0[i]), i=0...n-1</tt>.
*/
template<class Scalar>
class TOpEleWiseBound : public TOp_2_1_Base<Scalar,
TOpEleWiseBoundTransformation<Scalar> > {
public:
typedef TOp_2_1_Base<Scalar, TOpEleWiseBoundTransformation<Scalar> > base_t;
/** \brief . */
TOpEleWiseBound () :
base_t (TOpEleWiseBoundTransformation<Scalar> ()) {
this->setOpNameBase ("TOpElemWiseBound");
}
};
/** \brief Element-wise product update transformation operator:
* <tt>z0[i] *= min(v0[i],abs(z0[i]) * z0[i]/abs(z0[i]), i=0...n-1</tt>.
*/
template<class Scalar>
class TOpEleWisePruneLower_3_1 : public TOp_3_1_Base<Scalar,
TOpEleWisePruneLowerTransformation<Scalar> > {
public:
typedef TOp_3_1_Base<Scalar, TOpEleWisePruneLowerTransformation<Scalar> > base_t;
/** \brief . */
TOpEleWisePruneLower_3_1 (const Scalar& eps) :
base_t (TOpEleWisePruneLowerTransformation<Scalar> (eps)) {
this->setOpNameBase ("TOpElemWisePruneLower_3_1");
}
};
/** \brief Element-wise product update transformation operator:
* <tt>z0[i] *= min(v0[i],abs(z0[i]) * z0[i]/abs(z0[i]), i=0...n-1</tt>.
*/
template<class Scalar>
class TOpEleWisePruneLower_2_1 : public TOp_2_1_Base<Scalar,
TOpEleWisePruneLowerTransformation<Scalar> > {
public:
typedef TOp_2_1_Base<Scalar, TOpEleWisePruneLowerTransformation<Scalar> > base_t;
/** \brief . */
TOpEleWisePruneLower_2_1 (const Scalar& eps) :
base_t (TOpEleWisePruneLowerTransformation<Scalar> (eps)) {
this->setOpNameBase ("TOpElemWisePruneLower_2_1");
}
};
/** \brief Element-wise product update transformation operator:
* <tt>z0[i] *= min(v0[i],abs(z0[i]) * z0[i]/abs(z0[i]), i=0...n-1</tt>.
*/
template<class Scalar>
class TOpEleWisePruneUpper_3_1 : public TOp_3_1_Base<Scalar,
TOpEleWisePruneUpperTransformation<Scalar> > {
public:
typedef TOp_3_1_Base<Scalar, TOpEleWisePruneUpperTransformation<Scalar> > base_t;
/** \brief . */
TOpEleWisePruneUpper_3_1 (const Scalar& eps) :
base_t (TOpEleWisePruneUpperTransformation<Scalar> (eps)) {
this->setOpNameBase ("TOpElemWisePruneUpper_3_1");
}
};
/** \brief Element-wise product update transformation operator:
* <tt>z0[i] *= min(v0[i],abs(z0[i]) * z0[i]/abs(z0[i]), i=0...n-1</tt>.
*/
template<class Scalar>
class TOpEleWisePruneUpper_2_1 : public TOp_2_1_Base<Scalar,
TOpEleWisePruneUpperTransformation<Scalar> > {
public:
typedef TOp_2_1_Base<Scalar, TOpEleWisePruneUpperTransformation<Scalar> > base_t;
/** \brief . */
TOpEleWisePruneUpper_2_1 (const Scalar& eps) :
base_t (TOpEleWisePruneUpperTransformation<Scalar> (eps)) {
this->setOpNameBase ("TOpElemWisePruneUpper_2_1");
}
};
} // namespace RTOpPack
namespace Thyra {
/** \brief Element-wise bound:
* <tt>x(i) *= max(x_lo(i), min(x_up(i), x(i) ) ), i = 0...y->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void
ele_wise_bound (const ::Thyra::VectorBase<Scalar>& x_lo,
const ::Thyra::VectorBase<Scalar>& x_up,
const Teuchos::Ptr< ::Thyra::VectorBase<Scalar> > &x) {
using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::null;
RTOpPack::TOpEleWiseBound<Scalar> ele_wise_bound_op;
::Thyra::applyOp<Scalar> (ele_wise_bound_op,
tuple (ptrInArg (x_lo), ptrInArg (x_up)), tuple (x),
null);
}
/** \brief Element-wise prune lower:
* <tt> if ((x(i) <= x_lo(i) + eps_) && (g(i) > 0.0)), v(i) = 0, i = 0...y->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void
ele_wise_prune_lower (const ::Thyra::VectorBase<Scalar>& x,
const ::Thyra::VectorBase<Scalar>& x_lo,
const ::Thyra::VectorBase<Scalar>& g,
const Teuchos::Ptr< ::Thyra::VectorBase<Scalar> > &v,
const Scalar& eps) {
using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::null;
RTOpPack::TOpEleWisePruneLower_3_1<Scalar> ele_wise_prune_op(eps);
::Thyra::applyOp<Scalar> (ele_wise_prune_op,
tuple (ptrInArg (x), ptrInArg (x_lo), ptrInArg (g)), tuple (v),
null);
}
/** \brief Element-wise prune lower:
* <tt> if (x(i) <= x_lo(i) + eps_), v(i) = 0, i = 0...y->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void
ele_wise_prune_lower (const ::Thyra::VectorBase<Scalar>& x,
const ::Thyra::VectorBase<Scalar>& x_lo,
const Teuchos::Ptr< ::Thyra::VectorBase<Scalar> > &v,
const Scalar& eps) {
using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::null;
RTOpPack::TOpEleWisePruneLower_2_1<Scalar> ele_wise_prune_op(eps);
::Thyra::applyOp<Scalar> (ele_wise_prune_op,
tuple (ptrInArg (x), ptrInArg (x_lo)), tuple (v),
null);
}
/** \brief Element-wise prune lower:
* <tt> if ((x(i) >= x_up(i) - eps_) && (g(i) < 0.0)), v(i) = 0, i = 0...y->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void
ele_wise_prune_upper (const ::Thyra::VectorBase<Scalar>& x,
const ::Thyra::VectorBase<Scalar>& x_up,
const ::Thyra::VectorBase<Scalar>& g,
const Teuchos::Ptr< ::Thyra::VectorBase<Scalar> > &v,
const Scalar& eps) {
using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::null;
RTOpPack::TOpEleWisePruneUpper_3_1<Scalar> ele_wise_prune_op(eps);
::Thyra::applyOp<Scalar> (ele_wise_prune_op,
tuple (ptrInArg (x), ptrInArg (x_up), ptrInArg (g)), tuple (v),
null);
}
/** \brief Element-wise prune lower:
* <tt> if (x(i) >= x_up(i) - eps_), v(i) = 0, i = 0...y->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void
ele_wise_prune_upper (const ::Thyra::VectorBase<Scalar>& x,
const ::Thyra::VectorBase<Scalar>& x_up,
const Teuchos::Ptr< ::Thyra::VectorBase<Scalar> > &v,
const Scalar& eps) {
using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::null;
RTOpPack::TOpEleWisePruneUpper_2_1<Scalar> ele_wise_prune_op(eps);
::Thyra::applyOp<Scalar> (ele_wise_prune_op,
tuple (ptrInArg (x), ptrInArg (x_up)), tuple (v),
null);
}
}
#endif // RTOPPACK_TOP_ELE_WISE_BOUND_HPP
|