/usr/include/trilinos/Rythmos_ImplicitRKModelEvaluator.hpp is in libtrilinos-rythmos-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 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 | //@HEADER
// ***********************************************************************
//
// Rythmos Package
// 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.
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
// USA
// Questions? Contact Todd S. Coffey (tscoffe@sandia.gov)
//
// ***********************************************************************
//@HEADER
#ifndef RYTHMOS_IMPLICITRK_MODEL_EVALUATOR_HPP
#define RYTHMOS_IMPLICITRK_MODEL_EVALUATOR_HPP
#include "Rythmos_Types.hpp"
#include "Rythmos_RKButcherTableauHelpers.hpp"
#include "Thyra_StateFuncModelEvaluatorBase.hpp"
#include "Thyra_ModelEvaluatorHelpers.hpp"
#include "Thyra_ModelEvaluatorDelegatorBase.hpp"
#include "Thyra_DefaultProductVectorSpace.hpp"
#include "Thyra_DefaultBlockedLinearOp.hpp"
#include "Thyra_VectorStdOps.hpp"
#include "Thyra_TestingTools.hpp"
#include "Teuchos_as.hpp"
#include "Teuchos_SerialDenseMatrix.hpp"
#include "Teuchos_SerialDenseVector.hpp"
#include "Teuchos_Assert.hpp"
namespace Rythmos {
/** \brief . */
template<class Scalar>
class ImplicitRKModelEvaluator : virtual public Thyra::StateFuncModelEvaluatorBase<Scalar>
{
public:
/** \name Constructors/initializers/accessors */
//@{
/** \brief . */
ImplicitRKModelEvaluator();
/** \brief . */
void initializeIRKModel(
const RCP<const Thyra::ModelEvaluator<Scalar> >& daeModel,
const Thyra::ModelEvaluatorBase::InArgs<Scalar>& basePoint,
const RCP<Thyra::LinearOpWithSolveFactoryBase<Scalar> >& irk_W_factory,
const RCP<const RKButcherTableauBase<Scalar> >& irkButcherTableau
);
/** \brief . */
void setTimeStepPoint(
const RCP<const Thyra::VectorBase<Scalar> > &x_old,
const Scalar &t_old,
const Scalar &delta_t
);
//@}
/** \name Public functions overridden from ModelEvaluator */
//@{
/** \brief . */
RCP<const Thyra::VectorSpaceBase<Scalar> > get_x_space() const;
/** \brief . */
RCP<const Thyra::VectorSpaceBase<Scalar> > get_f_space() const;
/** \brief . */
RCP<Thyra::LinearOpBase<Scalar> > create_W_op() const;
/** \brief . */
RCP<const Thyra::LinearOpWithSolveFactoryBase<Scalar> > get_W_factory() const;
/** \breif . */
Thyra::ModelEvaluatorBase::InArgs<Scalar> getNominalValues() const;
/** \brief . */
Thyra::ModelEvaluatorBase::InArgs<Scalar> createInArgs() const;
//@}
private:
/** \name Private functions overridden from ModelEvaluatorDefaultBase */
//@{
/** \brief . */
Thyra::ModelEvaluatorBase::OutArgs<Scalar> createOutArgsImpl() const;
/** \brief . */
void evalModelImpl(
const Thyra::ModelEvaluatorBase::InArgs<Scalar>& inArgs,
const Thyra::ModelEvaluatorBase::OutArgs<Scalar>& outArgs
) const;
//@}
private:
RCP<const Thyra::ModelEvaluator<Scalar> > daeModel_;
Thyra::ModelEvaluatorBase::InArgs<Scalar> basePoint_;
RCP<Thyra::LinearOpWithSolveFactoryBase<Scalar> > irk_W_factory_;
RCP<const RKButcherTableauBase<Scalar> > irkButcherTableau_;
Thyra::ModelEvaluatorBase::InArgs<Scalar> inArgs_;
Thyra::ModelEvaluatorBase::OutArgs<Scalar> outArgs_;
Thyra::ModelEvaluatorBase::InArgs<Scalar> nominalValues_;
RCP<const Thyra::ProductVectorSpaceBase<Scalar> > x_bar_space_;
RCP<const Thyra::ProductVectorSpaceBase<Scalar> > f_bar_space_;
RCP<Thyra::LinearOpWithSolveFactoryBase<Scalar> > W_bar_factory_;
bool setTimeStepPointCalled_;
RCP<const Thyra::VectorBase<Scalar> > x_old_;
Scalar t_old_;
Scalar delta_t_;
bool isInitialized_;
};
/** \brief Nonmember constructor function.
*
* \relates ImplicitRKModelEvaluator
*/
template<class Scalar>
RCP<ImplicitRKModelEvaluator<Scalar> >
implicitRKModelEvaluator(
const RCP<const Thyra::ModelEvaluator<Scalar> >& daeModel,
const Thyra::ModelEvaluatorBase::InArgs<Scalar>& basePoint,
const RCP<Thyra::LinearOpWithSolveFactoryBase<Scalar> >& irk_W_factory,
const RCP<const RKButcherTableauBase<Scalar> >& irkButcherTableau
)
{
RCP<ImplicitRKModelEvaluator<Scalar> >
irkModel = rcp(new ImplicitRKModelEvaluator<Scalar>());
irkModel->initializeIRKModel(daeModel,basePoint,irk_W_factory,irkButcherTableau);
return irkModel;
}
// ///////////////////////
// Definition
// Constructors/initializers/accessors
template<class Scalar>
ImplicitRKModelEvaluator<Scalar>::ImplicitRKModelEvaluator()
{
setTimeStepPointCalled_ = false;
isInitialized_ = false;
}
// Overridden from ImplicitRKModelEvaluatorBase
template<class Scalar>
void ImplicitRKModelEvaluator<Scalar>::initializeIRKModel(
const RCP<const Thyra::ModelEvaluator<Scalar> >& daeModel,
const Thyra::ModelEvaluatorBase::InArgs<Scalar>& basePoint,
const RCP<Thyra::LinearOpWithSolveFactoryBase<Scalar> >& irk_W_factory,
const RCP<const RKButcherTableauBase<Scalar> >& irkButcherTableau
)
{
// ToDo: Assert input arguments!
// How do I verify the basePoint is an authentic InArgs from daeModel?
TEUCHOS_TEST_FOR_EXCEPTION(
is_null(basePoint.get_x()),
std::logic_error,
"Error! The basepoint x vector is null!"
);
TEUCHOS_TEST_FOR_EXCEPTION(
is_null(daeModel),
std::logic_error,
"Error! The model evaluator pointer is null!"
);
TEUCHOS_TEST_FOR_EXCEPTION(
!daeModel->get_x_space()->isCompatible(*(basePoint.get_x()->space())),
std::logic_error,
"Error! The basepoint input arguments are incompatible with the model evaluator vector space!"
);
TEUCHOS_TEST_FOR_EXCEPT(is_null(irk_W_factory));
daeModel_ = daeModel;
basePoint_ = basePoint;
irk_W_factory_ = irk_W_factory;
irkButcherTableau_ = irkButcherTableau;
const int numStages = irkButcherTableau_->numStages();
x_bar_space_ = productVectorSpace(daeModel_->get_x_space(),numStages);
f_bar_space_ = productVectorSpace(daeModel_->get_f_space(),numStages);
// HACK! Remove the preconditioner factory for now!
if (irk_W_factory_->acceptsPreconditionerFactory())
irk_W_factory_->unsetPreconditionerFactory();
// ToDo: create the block diagonal preconditioner factory and set this on
// irk_W_factory_!
// Set up prototypical InArgs
{
typedef Thyra::ModelEvaluatorBase MEB;
MEB::InArgsSetup<Scalar> inArgs;
inArgs.setModelEvalDescription(this->description());
inArgs.setSupports(MEB::IN_ARG_x);
inArgs_ = inArgs;
}
// Set up prototypical OutArgs
{
typedef Thyra::ModelEvaluatorBase MEB;
MEB::OutArgsSetup<Scalar> outArgs;
outArgs.setModelEvalDescription(this->description());
outArgs.setSupports(MEB::OUT_ARG_f);
outArgs.setSupports(MEB::OUT_ARG_W_op);
outArgs_ = outArgs;
}
// Set up nominal values
nominalValues_ = inArgs_;
isInitialized_ = true;
}
template<class Scalar>
void ImplicitRKModelEvaluator<Scalar>::setTimeStepPoint(
const RCP<const Thyra::VectorBase<Scalar> > &x_old,
const Scalar &t_old,
const Scalar &delta_t
)
{
typedef ScalarTraits<Scalar> ST;
TEUCHOS_TEST_FOR_EXCEPT( is_null(x_old) );
TEUCHOS_TEST_FOR_EXCEPT( delta_t <= ST::zero() );
// Verify x_old is compatible with the vector space in the DAE Model.
TEUCHOS_TEST_FOR_EXCEPTION(!daeModel_->get_x_space()->isCompatible(*(x_old->space())), std::logic_error,
"Error! The incoming VectorBase object is not compatible with the DAE model that was provided at initialization!");
x_old_ = x_old;
t_old_ = t_old;
delta_t_ = delta_t;
setTimeStepPointCalled_ = true;
}
// Overridden from ModelEvaluator
template<class Scalar>
RCP<const Thyra::VectorSpaceBase<Scalar> >
ImplicitRKModelEvaluator<Scalar>::get_x_space() const
{
TEUCHOS_TEST_FOR_EXCEPTION( !isInitialized_, std::logic_error,
"Error, initializeIRKModel must be called first!\n"
);
return x_bar_space_;
}
template<class Scalar>
RCP<const Thyra::VectorSpaceBase<Scalar> >
ImplicitRKModelEvaluator<Scalar>::get_f_space() const
{
TEUCHOS_TEST_FOR_EXCEPTION( !isInitialized_, std::logic_error,
"Error, initializeIRKModel must be called first!\n"
);
return f_bar_space_;
}
template<class Scalar>
RCP<Thyra::LinearOpBase<Scalar> >
ImplicitRKModelEvaluator<Scalar>::create_W_op() const
{
TEUCHOS_TEST_FOR_EXCEPTION( !isInitialized_, std::logic_error,
"Error, initializeIRKModel must be called first!\n"
);
// Create the block structure for W_op_bar right away!
const int numStages = irkButcherTableau_->numStages();
RCP<Thyra::PhysicallyBlockedLinearOpBase<Scalar> >
W_op_bar = Thyra::defaultBlockedLinearOp<Scalar>();
W_op_bar->beginBlockFill( f_bar_space_, x_bar_space_ );
for ( int i = 0; i < numStages; ++i )
for ( int j = 0; j < numStages; ++j )
W_op_bar->setNonconstBlock( i, j, daeModel_->create_W_op() );
W_op_bar->endBlockFill();
return W_op_bar;
}
template<class Scalar>
RCP<const Thyra::LinearOpWithSolveFactoryBase<Scalar> >
ImplicitRKModelEvaluator<Scalar>::get_W_factory() const
{
TEUCHOS_TEST_FOR_EXCEPTION( !isInitialized_, std::logic_error,
"Error, initializeIRKModel must be called first!\n"
);
return irk_W_factory_;
}
template<class Scalar>
Thyra::ModelEvaluatorBase::InArgs<Scalar>
ImplicitRKModelEvaluator<Scalar>::getNominalValues() const
{
TEUCHOS_TEST_FOR_EXCEPTION( !isInitialized_, std::logic_error,
"Error, initializeIRKModel must be called first!\n"
);
return nominalValues_;
}
template<class Scalar>
Thyra::ModelEvaluatorBase::InArgs<Scalar>
ImplicitRKModelEvaluator<Scalar>::createInArgs() const
{
TEUCHOS_TEST_FOR_EXCEPTION( !isInitialized_, std::logic_error,
"Error, initializeIRKModel must be called first!\n"
);
return inArgs_;
}
// Private functions overridden from ModelEvaluatorDefaultBase
template<class Scalar>
Thyra::ModelEvaluatorBase::OutArgs<Scalar>
ImplicitRKModelEvaluator<Scalar>::createOutArgsImpl() const
{
TEUCHOS_TEST_FOR_EXCEPTION( !isInitialized_, std::logic_error,
"Error, initializeIRKModel must be called first!\n"
);
return outArgs_;
}
template<class Scalar>
void ImplicitRKModelEvaluator<Scalar>::evalModelImpl(
const Thyra::ModelEvaluatorBase::InArgs<Scalar>& inArgs_bar,
const Thyra::ModelEvaluatorBase::OutArgs<Scalar>& outArgs_bar
) const
{
using Teuchos::rcp_dynamic_cast;
typedef ScalarTraits<Scalar> ST;
typedef Thyra::ModelEvaluatorBase MEB;
typedef Thyra::VectorBase<Scalar> VB;
typedef Thyra::ProductVectorBase<Scalar> PVB;
typedef Thyra::BlockedLinearOpBase<Scalar> BLWB;
TEUCHOS_TEST_FOR_EXCEPTION( !isInitialized_, std::logic_error,
"Error! initializeIRKModel must be called before evalModel\n"
);
TEUCHOS_TEST_FOR_EXCEPTION( !setTimeStepPointCalled_, std::logic_error,
"Error! setTimeStepPoint must be called before evalModel"
);
THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_BEGIN(
"Rythmos::ImplicitRKModelEvaluator",inArgs_bar,outArgs_bar,daeModel_
);
//
// A) Unwrap the inArgs and outArgs to get at product vectors and block op
//
const RCP<const PVB> x_bar = rcp_dynamic_cast<const PVB>(inArgs_bar.get_x(), true);
const RCP<PVB> f_bar = rcp_dynamic_cast<PVB>(outArgs_bar.get_f(), true);
const RCP<BLWB> W_op_bar = rcp_dynamic_cast<BLWB>(outArgs_bar.get_W_op(), true);
//
// B) Assemble f_bar and W_op_bar by looping over stages
//
MEB::InArgs<Scalar> daeInArgs = daeModel_->createInArgs();
MEB::OutArgs<Scalar> daeOutArgs = daeModel_->createOutArgs();
const RCP<VB> x_i = createMember(daeModel_->get_x_space());
daeInArgs.setArgs(basePoint_);
const int numStages = irkButcherTableau_->numStages();
for ( int i = 0; i < numStages; ++i ) {
// B.1) Setup the DAE's inArgs for stage f(i) ...
assembleIRKState( i, irkButcherTableau_->A(), delta_t_, *x_old_, *x_bar, outArg(*x_i) );
daeInArgs.set_x( x_i );
daeInArgs.set_x_dot( x_bar->getVectorBlock(i) );
daeInArgs.set_t( t_old_ + irkButcherTableau_->c()(i) * delta_t_ );
Scalar alpha = ST::zero();
if (i == 0) {
alpha = ST::one();
} else {
alpha = ST::zero();
}
Scalar beta = delta_t_ * irkButcherTableau_->A()(i,0);
daeInArgs.set_alpha( alpha );
daeInArgs.set_beta( beta );
// B.2) Setup the DAE's outArgs for stage f(i) ...
if (!is_null(f_bar))
daeOutArgs.set_f( f_bar->getNonconstVectorBlock(i) );
if (!is_null(W_op_bar)) {
daeOutArgs.set_W_op(W_op_bar->getNonconstBlock(i,0));
}
// B.3) Compute f_bar(i) and/or W_op_bar(i,0) ...
daeModel_->evalModel( daeInArgs, daeOutArgs );
daeOutArgs.set_f(Teuchos::null);
daeOutArgs.set_W_op(Teuchos::null);
// B.4) Evaluate the rest of the W_op_bar(i,j=1...numStages-1) ...
if (!is_null(W_op_bar)) {
for ( int j = 1; j < numStages; ++j ) {
alpha = ST::zero();
if (i == j) {
alpha = ST::one();
} else {
alpha = ST::zero();
}
beta = delta_t_ * irkButcherTableau_->A()(i,j);
daeInArgs.set_alpha( alpha );
daeInArgs.set_beta( beta );
daeOutArgs.set_W_op(W_op_bar->getNonconstBlock(i,j));
daeModel_->evalModel( daeInArgs, daeOutArgs );
daeOutArgs.set_W_op(Teuchos::null);
}
}
}
THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_END();
}
} // namespace Rythmos
#endif // RYTHMOS_IMPLICITRK_MODEL_EVALUATOR_HPP
|