/usr/include/trilinos/Thyra_DefaultModelEvaluatorWithSolveFactory.hpp is in libtrilinos-thyra-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 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | // @HEADER
// ***********************************************************************
//
// Thyra: Interfaces and Support for Abstract Numerical Algorithms
// Copyright (2004) 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 (bartlettra@ornl.gov)
//
// ***********************************************************************
// @HEADER
#ifndef THYRA_DEFAULT_MODEL_EVALUATOR_WITH_SOLVE_FACTORY_HPP
#define THYRA_DEFAULT_MODEL_EVALUATOR_WITH_SOLVE_FACTORY_HPP
#include "Thyra_ModelEvaluatorDelegatorBase.hpp"
#include "Thyra_LinearOpWithSolveFactoryHelpers.hpp"
#include "Teuchos_Time.hpp"
namespace Thyra {
/** \brief This class wraps any ModelEvaluator object and uses a compatible
* LinearOpWithSolveFactory object to create a LinearOpWithSolveBase version
* of W.
*
* ToDo: Finish documentation!
*
* \ingroup Thyra_Nonlin_ME_support_grp
*/
template<class Scalar>
class DefaultModelEvaluatorWithSolveFactory
: virtual public ModelEvaluatorDelegatorBase<Scalar>
{
public:
/** \name Constructors/initializers/accessors/utilities. */
//@{
/** \brief . */
DefaultModelEvaluatorWithSolveFactory();
/** \brief . */
DefaultModelEvaluatorWithSolveFactory(
const RCP<ModelEvaluator<Scalar> > &thyraModel,
const RCP<LinearOpWithSolveFactoryBase<Scalar> > &W_factory
);
/** \brief . */
void initialize(
const RCP<ModelEvaluator<Scalar> > &thyraModel,
const RCP<LinearOpWithSolveFactoryBase<Scalar> > &W_factory
);
/** \brief . */
void uninitialize(
RCP<ModelEvaluator<Scalar> > *thyraModel = NULL,
RCP<LinearOpWithSolveFactoryBase<Scalar> > *W_factory = NULL
);
//@}
/** \name Public functions overridden from Teuchos::Describable. */
//@{
/** \brief . */
std::string description() const;
//@}
/** \name Public functions overridden from ModelEvaluator. */
//@{
/** \brief . */
RCP<LinearOpWithSolveBase<Scalar> > create_W() const;
//@}
/** \name Public functions overridden from ModelEvaluatorDelegatorBase. */
//@{
/** \brief . */
RCP<const LinearOpWithSolveFactoryBase<Scalar> > get_W_factory() const;
//@}
private:
/** \name Private functions overridden from ModelEvaluatorDefaultBase. */
//@{
/** \brief . */
ModelEvaluatorBase::OutArgs<Scalar> createOutArgsImpl() const;
/** \brief . */
void evalModelImpl(
const ModelEvaluatorBase::InArgs<Scalar> &inArgs,
const ModelEvaluatorBase::OutArgs<Scalar> &outArgs
) const;
//@}
private:
RCP<LinearOpWithSolveFactoryBase<Scalar> > W_factory_;
};
// /////////////////////////////////
// Implementations
// Constructors/initializers/accessors/utilities
template<class Scalar>
DefaultModelEvaluatorWithSolveFactory<Scalar>::DefaultModelEvaluatorWithSolveFactory()
{}
template<class Scalar>
DefaultModelEvaluatorWithSolveFactory<Scalar>::DefaultModelEvaluatorWithSolveFactory(
const RCP<ModelEvaluator<Scalar> > &thyraModel,
const RCP<LinearOpWithSolveFactoryBase<Scalar> > &W_factory
)
{
initialize(thyraModel,W_factory);
}
template<class Scalar>
void DefaultModelEvaluatorWithSolveFactory<Scalar>::initialize(
const RCP<ModelEvaluator<Scalar> > &thyraModel,
const RCP<LinearOpWithSolveFactoryBase<Scalar> > &W_factory
)
{
this->ModelEvaluatorDelegatorBase<Scalar>::initialize(thyraModel);
W_factory_ = W_factory;
}
template<class Scalar>
void DefaultModelEvaluatorWithSolveFactory<Scalar>::uninitialize(
RCP<ModelEvaluator<Scalar> > *thyraModel,
RCP<LinearOpWithSolveFactoryBase<Scalar> > *W_factory
)
{
if(thyraModel) *thyraModel = this->getUnderlyingModel();
if(W_factory) *W_factory = W_factory_;
this->ModelEvaluatorDelegatorBase<Scalar>::uninitialize();
W_factory_ = Teuchos::null;
}
// Public functions overridden from Teuchos::Describable
template<class Scalar>
std::string DefaultModelEvaluatorWithSolveFactory<Scalar>::description() const
{
const RCP<const ModelEvaluator<Scalar> >
thyraModel = this->getUnderlyingModel();
std::ostringstream oss;
oss << "Thyra::DefaultModelEvaluatorWithSolveFactory{";
oss << "thyraModel=";
if(thyraModel.get())
oss << "\'"<<thyraModel->description()<<"\'";
else
oss << "NULL";
oss << ",W_factory=";
if(W_factory_.get())
oss << "\'"<<W_factory_->description()<<"\'";
else
oss << "NULL";
oss << "}";
return oss.str();
}
// Overridden from ModelEvaluator.
template<class Scalar>
RCP<LinearOpWithSolveBase<Scalar> >
DefaultModelEvaluatorWithSolveFactory<Scalar>::create_W() const
{
TEUCHOS_TEST_FOR_EXCEPTION(
W_factory_.get()==NULL, std::logic_error
,"Thyra::DefaultModelEvaluatorWithSolveFactory<Scalar>::create_W(): "
"Error, the client did not set a LinearOpWithSolveFactoryBase object for W!"
);
W_factory_->setOStream(this->getOStream());
W_factory_->setVerbLevel(this->getVerbLevel());
return W_factory_->createOp();
}
// Overridden from ModelEvaluatorDelegatorBase.
template<class Scalar>
RCP<const LinearOpWithSolveFactoryBase<Scalar> >
DefaultModelEvaluatorWithSolveFactory<Scalar>::get_W_factory() const
{
return W_factory_;
}
// Private functions overridden from ModelEvaluatorDefaultBase.
template<class Scalar>
ModelEvaluatorBase::OutArgs<Scalar>
DefaultModelEvaluatorWithSolveFactory<Scalar>::createOutArgsImpl() const
{
typedef ModelEvaluatorBase MEB;
const RCP<const ModelEvaluator<Scalar> >
thyraModel = this->getUnderlyingModel();
const MEB::OutArgs<Scalar> wrappedOutArgs = thyraModel->createOutArgs();
MEB::OutArgsSetup<Scalar> outArgs;
outArgs.setModelEvalDescription(this->description());
outArgs.set_Np_Ng(wrappedOutArgs.Np(),wrappedOutArgs.Ng());
outArgs.setSupports(wrappedOutArgs);
outArgs.setSupports(MEB::OUT_ARG_W,
wrappedOutArgs.supports(MEB::OUT_ARG_W_op)&&W_factory_.get()!=NULL);
return outArgs;
}
template<class Scalar>
void DefaultModelEvaluatorWithSolveFactory<Scalar>::evalModelImpl(
const ModelEvaluatorBase::InArgs<Scalar> &inArgs,
const ModelEvaluatorBase::OutArgs<Scalar> &outArgs
) const
{
typedef ModelEvaluatorBase MEB;
using Teuchos::rcp;
using Teuchos::rcp_const_cast;
using Teuchos::rcp_dynamic_cast;
using Teuchos::OSTab;
THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_BEGIN(
"Thyra::DefaultModelEvaluatorWithSolveFactory",inArgs,outArgs
);
Teuchos::Time timer("");
typedef Teuchos::VerboseObjectTempState<LinearOpWithSolveFactoryBase<Scalar> >
VOTSLOWSF;
VOTSLOWSF W_factory_outputTempState(W_factory_,out,verbLevel);
// InArgs
MEB::InArgs<Scalar> wrappedInArgs = thyraModel->createInArgs();
wrappedInArgs.setArgs(inArgs,true);
// OutArgs
MEB::OutArgs<Scalar> wrappedOutArgs = thyraModel->createOutArgs();
wrappedOutArgs.setArgs(outArgs,true);
RCP<LinearOpWithSolveBase<Scalar> > W;
RCP<const LinearOpBase<Scalar> > fwdW;
if( outArgs.supports(MEB::OUT_ARG_W) && (W = outArgs.get_W()).get() ) {
Thyra::uninitializeOp<Scalar>(*W_factory_, W.ptr(), outArg(fwdW));
{
// Handle this case later if we need to!
const bool both_W_and_W_op_requested = nonnull(outArgs.get_W_op());
TEUCHOS_TEST_FOR_EXCEPT(both_W_and_W_op_requested);
}
RCP<LinearOpBase<Scalar> > nonconst_fwdW;
if(fwdW.get()) {
nonconst_fwdW = rcp_const_cast<LinearOpBase<Scalar> >(fwdW);
}
else {
nonconst_fwdW = thyraModel->create_W_op();
fwdW = nonconst_fwdW;
}
wrappedOutArgs.set_W_op(nonconst_fwdW);
}
// Do the evaluation
if(out.get() && includesVerbLevel(verbLevel,Teuchos::VERB_LOW))
*out << "\nEvaluating the output functions on model \'"
<< thyraModel->description() << "\' ...\n";
timer.start(true);
thyraModel->evalModel(wrappedInArgs,wrappedOutArgs);
timer.stop();
if(out.get() && includesVerbLevel(verbLevel,Teuchos::VERB_LOW))
OSTab(out).o() << "\nTime to evaluate underlying model = "
<< timer.totalElapsedTime()<<" sec\n";
// Postprocess arguments
if(out.get() && includesVerbLevel(verbLevel,Teuchos::VERB_LOW))
*out << "\nPost processing the output objects ...\n";
timer.start(true);
if( W.get() ) {
Thyra::initializeOp<Scalar>(*W_factory_, fwdW, W.ptr());
W->setVerbLevel(this->getVerbLevel());
W->setOStream(this->getOStream());
}
timer.stop();
if(out.get() && includesVerbLevel(verbLevel,Teuchos::VERB_LOW))
OSTab(out).o() << "\nTime to process output objects = "
<< timer.totalElapsedTime()<<" sec\n";
THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_END();
}
} // namespace Thyra
#endif // THYRA_DEFAULT_MODEL_EVALUATOR_WITH_SOLVE_FACTORY_HPP
|