/usr/include/trilinos/Piro_TrapezoidRuleSolver_Def.hpp is in libtrilinos-piro-dev 12.12.1-5.
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 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 | // @HEADER
// ************************************************************************
//
// Piro: Strategy package for embedded analysis capabilitites
// Copyright (2010) Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// 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 Andy Salinger (agsalin@sandia.gov), Sandia
// National Laboratories.
//
// ************************************************************************
// @HEADER
#include <cmath>
#include "Piro_TransientDecorator.hpp"
template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, typename Node>
Piro::TrapezoidRuleSolver<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
TrapezoidRuleSolver(const Teuchos::RCP<Teuchos::ParameterList> &appParams_,
const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> > &model_,
const Teuchos::RCP<Thyra::AdaptiveSolutionManager> &solMgr_,
const Teuchos::RCP<Piro::ObserverBase<Scalar> > &observer_ ) :
appParams(appParams_),
model(Teuchos::rcp(new Piro::TrapezoidDecorator<Scalar, LocalOrdinal, GlobalOrdinal, Node>(model_))),
observer(observer_),
solMgr(solMgr_),
out(Teuchos::VerboseObjectBase::getDefaultOStream())
{
using Teuchos::RCP;
using Teuchos::rcp;
// Only non-null when adaptation is used
if(Teuchos::nonnull(solMgr)) {
solMgr->initialize(rcp(new Thyra::TransAdaptiveState(model_)));
}
num_p = model->Np();
num_g = model->Ng();
TEUCHOS_TEST_FOR_EXCEPTION(num_p > 1, Teuchos::Exceptions::InvalidParameter,
std::endl << "Error in Piro::TrapezoidRuleSolver " <<
"Not Implemented for Np>1 : " << num_p << std::endl);
TEUCHOS_TEST_FOR_EXCEPTION(num_g > 1, Teuchos::Exceptions::InvalidParameter,
std::endl << "Error in Piro::TrapezoidRuleSolver " <<
"Not Implemented for Ng>1 : " << num_g << std::endl);
*out << "\nA) Get the base parameter list ...\n";
RCP<Teuchos::ParameterList> trPL = sublist(appParams, "Trapezoid Rule", true);
trPL->validateParameters(*getValidTrapezoidRuleParameters(),0);
{
const std::string verbosity = trPL->get("Verbosity Level", "VERB_DEFAULT");
solnVerbLevel = Teuchos::VERB_DEFAULT;
if (verbosity == "VERB_NONE") solnVerbLevel = Teuchos::VERB_NONE;
else if (verbosity == "VERB_LOW") solnVerbLevel = Teuchos::VERB_LOW;
else if (verbosity == "VERB_MEDIUM") solnVerbLevel = Teuchos::VERB_MEDIUM;
else if (verbosity == "VERB_HIGH") solnVerbLevel = Teuchos::VERB_HIGH;
else if (verbosity == "VERB_EXTREME") solnVerbLevel = Teuchos::VERB_EXTREME;
}
numTimeSteps = trPL->get("Num Time Steps", 10);
t_final = trPL->get("Final Time", 0.1);
t_init = trPL->get("Initial Time", 0.0);
delta_t = t_final / numTimeSteps;
*out << "\nB) Using Trapezoid Decorator and NOX Solver\n";
// Construct NOX solver -- will look for NOX sublist -- this must be set!!
trPL->sublist("NOX").set("Reset Initial Guess",true);
noxSolver = Teuchos::rcp(new Piro::NOXSolver<Scalar>(trPL, model));
}
template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, typename Node>
Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
Piro::TrapezoidRuleSolver<Scalar, LocalOrdinal, GlobalOrdinal, Node>::get_p_space(int l) const
{
TEUCHOS_TEST_FOR_EXCEPTION(
l >= num_p || l < 0,
Teuchos::Exceptions::InvalidParameter,
std::endl <<
"Error in Piro::TrapezoidRuleSolver::get_p_map(): " <<
"Invalid parameter index l = " <<
l << std::endl);
return model->get_p_space(l);
}
template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, typename Node>
Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
Piro::TrapezoidRuleSolver<Scalar, LocalOrdinal, GlobalOrdinal, Node>::get_g_space(int j) const
{
TEUCHOS_TEST_FOR_EXCEPTION(
j > num_g || j < 0,
Teuchos::Exceptions::InvalidParameter,
std::endl <<
"Error in Piro::TrapezoidRuleSolver::get_g_map(): " <<
"Invalid response index j = " <<
j << std::endl);
if (j < num_g) {
return model->get_g_space(j);
} else {
// j == num_g
return model->get_x_space();
}
}
template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, typename Node>
Thyra::ModelEvaluatorBase::InArgs<Scalar>
Piro::TrapezoidRuleSolver<Scalar, LocalOrdinal, GlobalOrdinal, Node>::getNominalValues() const
{
Thyra::ModelEvaluatorBase::InArgs<Scalar> result = this->createInArgs();
const Thyra::ModelEvaluatorBase::InArgs<Scalar> modelNominalValues = model->getNominalValues();
for (int l = 0; l < num_p; ++l) {
result.set_p(l, modelNominalValues.get_p(l));
}
return result;
}
template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, typename Node>
Thyra::ModelEvaluatorBase::InArgs<Scalar>
Piro::TrapezoidRuleSolver<Scalar, LocalOrdinal, GlobalOrdinal, Node>::createInArgs() const
{
Thyra::ModelEvaluatorBase::InArgsSetup<Scalar> inArgs;
inArgs.setModelEvalDescription(this->description());
inArgs.set_Np(num_p);
return inArgs;
}
template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, typename Node>
Thyra::ModelEvaluatorBase::OutArgs<Scalar>
Piro::TrapezoidRuleSolver<Scalar, LocalOrdinal, GlobalOrdinal, Node>::createOutArgsImpl() const
{
Thyra::ModelEvaluatorBase::OutArgsSetup<Scalar> outArgs;
outArgs.setModelEvalDescription(this->description());
// One additional response slot for the solution vector
outArgs.set_Np_Ng(num_p, num_g + 1);
const Thyra::ModelEvaluatorBase::OutArgs<Scalar> modelOutArgs = model->createOutArgs();
if (num_p > 0) {
// Only one parameter supported
const int l = 0;
// Computing the DxDp sensitivity for a transient problem currently requires the evaluation of
// the mutilivector-based, Jacobian-oriented DfDp derivatives of the underlying transient model.
const Thyra::ModelEvaluatorBase::DerivativeSupport model_dfdp_support =
modelOutArgs.supports(Thyra::ModelEvaluatorBase::OUT_ARG_DfDp, l);
if (!model_dfdp_support.supports(Thyra::ModelEvaluatorBase::DERIV_MV_JACOBIAN_FORM)) {
// Ok to return early since only one parameter supported
return outArgs;
}
// Solution sensitivity
outArgs.setSupports(
Thyra::ModelEvaluatorBase::OUT_ARG_DgDp,
num_g,
l,
Thyra::ModelEvaluatorBase::DERIV_MV_JACOBIAN_FORM);
if (num_g > 0) {
// Only one response supported
const int j = 0;
const Thyra::ModelEvaluatorBase::DerivativeSupport model_dgdx_support =
modelOutArgs.supports(Thyra::ModelEvaluatorBase::OUT_ARG_DgDx, j);
if (!model_dgdx_support.none()) {
const Thyra::ModelEvaluatorBase::DerivativeSupport model_dgdp_support =
modelOutArgs.supports(Thyra::ModelEvaluatorBase::OUT_ARG_DgDp, j, l);
// Response sensitivity
Thyra::ModelEvaluatorBase::DerivativeSupport dgdp_support;
if (model_dgdp_support.supports(Thyra::ModelEvaluatorBase::DERIV_MV_JACOBIAN_FORM)) {
dgdp_support.plus(Thyra::ModelEvaluatorBase::DERIV_MV_JACOBIAN_FORM);
}
if (model_dgdp_support.supports(Thyra::ModelEvaluatorBase::DERIV_LINEAR_OP)) {
dgdp_support.plus(Thyra::ModelEvaluatorBase::DERIV_LINEAR_OP);
}
outArgs.setSupports(
Thyra::ModelEvaluatorBase::OUT_ARG_DgDp,
j,
l,
dgdp_support);
}
}
}
return outArgs;
}
template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, typename Node>
void
Piro::TrapezoidRuleSolver<Scalar, LocalOrdinal, GlobalOrdinal, Node>::evalModelImpl(
const Thyra::ModelEvaluatorBase::InArgs<Scalar>& inArgs,
const Thyra::ModelEvaluatorBase::OutArgs<Scalar>& outArgs) const
{
using Teuchos::RCP;
using Teuchos::rcp;
TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::is_null(model->get_x_dotdot()),
std::logic_error,
std::endl << "Error in Piro::TrapezoidRuleSolver " <<
"Model must specify soln, soln_dot, and soln_dotdot." << std::endl);
// noxSolver is the Piro::NOXSolver object
Thyra::ModelEvaluatorBase::InArgs<Scalar> nox_inargs = noxSolver->createInArgs();
Thyra::ModelEvaluatorBase::OutArgs<Scalar> nox_outargs = noxSolver->createOutArgs();
// Parse InArgs
RCP<const Thyra::VectorBase<Scalar> > p_in;
if (num_p > 0) {
p_in = inArgs.get_p(0);
nox_inargs.set_p(0, p_in);
}
// Parse OutArgs: always 1 extra
RCP<Thyra::VectorBase<Scalar> > g_out;
if (num_g > 0) {
g_out = outArgs.get_g(0);
nox_outargs.set_g(0, g_out);
}
RCP<Thyra::VectorBase<Scalar> > gx_out = outArgs.get_g(num_g);
if (Teuchos::is_null(gx_out)) {
// Solution not requested by caller as a response, create local temporary instead
// model is the Trapezoid decorator
gx_out = Thyra::createMember<Scalar>(model->get_x_space());
}
nox_outargs.set_g(num_g, gx_out);
// Build a multivector holding x (0th vector), v (1st vector), and a (2nd vector)
Teuchos::RCP<Thyra::MultiVectorBase<Scalar> > soln = createMembers(model->get_x_space(), 3);
// create a new vector and fill it with the contents of model->get_x()
Teuchos::RCP<Thyra::VectorBase<Scalar> > x = soln->col(0);
assign(x.ptr(), *model->getNominalValues().get_x());
Teuchos::RCP<Thyra::VectorBase<Scalar> > v = soln->col(1);
assign(v.ptr(), *model->getNominalValues().get_x_dot());
Teuchos::RCP<Thyra::VectorBase<Scalar> > a = soln->col(2);
assign(a.ptr(), *model->get_x_dotdot());
// Note that Thyra doesn't have x_dotdot - go get it from the transient decorator around the Albany model
// Teuchos::RCP<Thyra::VectorBase<Scalar> > a = model->get_x_dotdot()->clone_v();
Teuchos::RCP<Thyra::VectorBase<Scalar> > x_pred_a = Thyra::createMember<Scalar>(model->get_f_space());
Teuchos::RCP<Thyra::VectorBase<Scalar> > x_pred_v = Thyra::createMember<Scalar>(model->get_f_space());
Teuchos::RCP<Thyra::VectorBase<Scalar> > a_old = Thyra::createMember<Scalar>(model->get_f_space());
TEUCHOS_TEST_FOR_EXCEPTION(v == Teuchos::null || x == Teuchos::null,
Teuchos::Exceptions::InvalidParameter,
std::endl << "Error in Piro::TrapezoidRuleSolver " <<
"Requires initial x and x_dot: " << std::endl);
Scalar t = t_init;
// Observe initial condition
if (observer != Teuchos::null) observer->observeSolution(*soln, t);
Scalar nrm = norm_2(*v);
*out << "Initial Velocity = " << nrm << std::endl;
//calculate intial acceleration using small time step (1.0e-3*delta_t)
// AGS: Check this for inital velocity
{
Scalar pert= 1.0e6 * 4.0 / (delta_t * delta_t);
assign(x_pred_a.ptr(), *x);
assign(x_pred_v.ptr(), *x);
Vp_StV(x_pred_v.ptr(), sqrt(pert), *v);
model->injectData(x_pred_a, x_pred_a, pert, x_pred_v, sqrt(pert), t);
noxSolver->evalModel(nox_inargs, nox_outargs);
V_StVpStV(a.ptr(), pert, *gx_out, -pert, *x_pred_a);
nrm = norm_2(*a);
*out << "Calculated a_init = " << nrm << std::endl;
}
// Start integration loop
Scalar fdt2 = 4.0 / (delta_t * delta_t);
Scalar dt2f = delta_t * delta_t / 4.0;
Scalar hdt = delta_t/ 2.0;
Scalar tdt = 2.0 / delta_t;
// GAH time step loop
for (int timeStep = 1; timeStep <= numTimeSteps; timeStep++) {
t += delta_t;
if(Teuchos::nonnull(solMgr)){
solMgr->setIteration(timeStep);
solMgr->setTime(t);
}
// Adapt the mesh if the user has turned on adaptation
// and we have passed the criteria to adapt
if(Teuchos::nonnull(solMgr) &&
solMgr->isAdaptive() && solMgr->queryAdaptationCriteria()){
// Adapt the mesh, send exception if adaptation fails
TEUCHOS_TEST_FOR_EXCEPTION(
!solMgr->adaptProblem(),
std::logic_error,
"Error: Piro_TrapezoidRuleSolver, cannot adapt the mesh!" << std::endl);
// Gets the Thyra MV directly from the updated discretization
soln = solMgr->getCurrentSolution();
// create a new vector and fill it with the contents of model->get_x()
x = soln->col(0);
v = soln->col(1);
a = soln->col(2);
x_pred_a = Thyra::createMember<Scalar>(model->get_f_space());
x_pred_v = Thyra::createMember<Scalar>(model->get_f_space());
a_old = Thyra::createMember<Scalar>(model->get_f_space());
model->resize(x);
gx_out = Thyra::createMember<Scalar>(model->get_x_space());
nox_outargs.set_g(num_g, gx_out);
noxSolver->reset();
}
assign(a_old.ptr(), *a);
assign(x_pred_a.ptr(), *x);
Vp_StV(x_pred_a.ptr(), dt2f, *a);
Vp_StV(x_pred_a.ptr(), delta_t, *v);
assign(x_pred_v.ptr(), *x);
Vp_StV(x_pred_v.ptr(), hdt, *v);
model->injectData(x, x_pred_a, fdt2, x_pred_v, tdt, t);
noxSolver->evalModel(nox_inargs, nox_outargs);
// Copy out final solution from nonlinear solver
// *x = *gx_out;
assign(x.ptr(), *gx_out);
// Compute a and v and new conditions
V_StVpStV(a.ptr(), fdt2, *x, -fdt2, *x_pred_a);
Vp_StV(v.ptr(), hdt, *a);
Vp_StV(v.ptr(), hdt, *a_old);
// Should be equivalent to: v->Update(tdt, *x, -tdt, *x_pred_v, 0.0);
// Observe completed time step
if (observer != Teuchos::null) observer->observeSolution(*soln, t);
if (g_out != Teuchos::null)
*out << "Responses at time step(time) = " << timeStep << "("<<t<<")\n" << g_out << std::endl;
}
}
template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, typename Node>
Teuchos::RCP<const Teuchos::ParameterList>
Piro::TrapezoidRuleSolver<Scalar, LocalOrdinal, GlobalOrdinal, Node>::getValidTrapezoidRuleParameters() const
{
Teuchos::RCP<Teuchos::ParameterList> validPL =
Teuchos::rcp(new Teuchos::ParameterList("ValidTrapezoidRuleParams"));;
validPL->set<int>("Num Time Steps", 0, "");
validPL->set<double>("Final Time", 1.0, "");
validPL->set<double>("Initial Time", 0.0, "");
validPL->set<std::string>("Verbosity Level", "", "");
validPL->set<bool>("Invert Mass Matrix", false, "");
validPL->set<bool>("Lump Mass Matrix", false, "");
validPL->sublist("Stratimikos", false, "");
validPL->sublist("NOX", false, "");
return validPL;
}
/****************************************************************************/
template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, typename Node>
Piro::TrapezoidDecorator<Scalar, LocalOrdinal, GlobalOrdinal, Node>::TrapezoidDecorator(
const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model_) :
Thyra::ModelEvaluatorDelegatorBase<Scalar>(model_),
DMEWSF(Teuchos::rcp_dynamic_cast<Thyra::DefaultModelEvaluatorWithSolveFactory<Scalar> >(model_)),
fdt2(0.0),
tdt(0.0),
time(0.0),
out(Teuchos::VerboseObjectBase::getDefaultOStream())
{
using Teuchos::RCP;
using Teuchos::rcp;
using Teuchos::ParameterList;
TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::is_null(DMEWSF),
std::logic_error,
"Model passed into Trapezoid decorator does not cast to a Thyra::DefaultModelEvaluatorWithSolveFactory<Scalar>"
<< std::endl);
Thyra::ModelEvaluatorBase::InArgs<Scalar> state_ic = this->getUnderlyingModel()->getNominalValues();
xDotDot = Thyra::createMember<Scalar>(this->getUnderlyingModel()->get_x_space());
xDot = Thyra::createMember<Scalar>(this->getUnderlyingModel()->get_x_space());
x_pred_a = state_ic.get_x()->clone_v();
x_pred_v = state_ic.get_x()->clone_v();
x_save = state_ic.get_x()->clone_v();
}
template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, typename Node>
Teuchos::RCP<const Thyra::VectorBase<Scalar> >
Piro::TrapezoidDecorator<Scalar, LocalOrdinal, GlobalOrdinal, Node>::get_x() const
{
return x_save;
}
template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, typename Node>
Teuchos::RCP<const Thyra::VectorBase<Scalar> >
Piro::TrapezoidDecorator<Scalar, LocalOrdinal, GlobalOrdinal, Node>::get_x_dot() const
{
return xDot;
}
template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, typename Node>
Teuchos::RCP<const Thyra::VectorBase<Scalar> >
Piro::TrapezoidDecorator<Scalar, LocalOrdinal, GlobalOrdinal, Node>::get_x_dotdot() const
{
Teuchos::RCP<const Piro::TransientDecorator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > dec =
Teuchos::rcp_dynamic_cast<const Piro::TransientDecorator<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
(DMEWSF->getUnderlyingModel());
TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::is_null(dec),
std::logic_error,
"Underlying model in trapezoid decorator does not cast to a Piro::TransientDecorator<Scalar, LocalOrdinal, GlobalOrdinal, Node>"
<< std::endl);
return dec->get_x_dotdot();
}
template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, typename Node>
void
Piro::TrapezoidDecorator<Scalar, LocalOrdinal, GlobalOrdinal, Node>::reportFinalPoint(
const Thyra::ModelEvaluatorBase::InArgs<Scalar>& finalPoint,
const bool wasSolved)
{
// TODO
TEUCHOS_TEST_FOR_EXCEPTION(true,
Teuchos::Exceptions::InvalidParameter,
"Calling reportFinalPoint in Piro_TrapezoidDecorator_Def.hpp" << std::endl);
}
template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, typename Node>
void Piro::TrapezoidDecorator<Scalar, LocalOrdinal, GlobalOrdinal, Node>::injectData(
const Teuchos::RCP<Thyra::VectorBase<Scalar> >& x_,
const Teuchos::RCP<Thyra::VectorBase<Scalar> >& x_pred_a_, Scalar fdt2_,
const Teuchos::RCP<Thyra::VectorBase<Scalar> >& x_pred_v_, Scalar tdt_,
Scalar time_)
{
assign(x_save.ptr(), *x_);
assign(x_pred_a.ptr(), *x_pred_a_);
assign(x_pred_v.ptr(), *x_pred_v_);
fdt2 = fdt2_;
tdt = tdt_;
time = time_;
}
template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, typename Node>
void Piro::TrapezoidDecorator<Scalar, LocalOrdinal, GlobalOrdinal, Node>::resize(
const Teuchos::RCP<Thyra::VectorBase<Scalar> >& x_)
{
xDotDot = Thyra::createMember<Scalar>(x_->space());
xDot = Thyra::createMember<Scalar>(x_->space());
x_pred_a = x_->clone_v();
x_pred_v = x_->clone_v();
x_save = x_->clone_v();
}
template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, typename Node>
void Piro::TrapezoidDecorator<Scalar, LocalOrdinal, GlobalOrdinal, Node>::evalModelImpl(
const Thyra::ModelEvaluatorBase::InArgs<Scalar>& inArgs,
const Thyra::ModelEvaluatorBase::OutArgs<Scalar>& outArgs) const {
using Teuchos::RCP;
using Teuchos::rcp;
// Copy outArgs; add time term
Thyra::ModelEvaluatorBase::InArgs<Scalar> modelInArgs(inArgs);
Thyra::ModelEvaluatorBase::OutArgs<Scalar> modelOutArgs(outArgs);
V_StVpStV(xDotDot.ptr(), fdt2, *inArgs.get_x(), -fdt2, *x_pred_a);
V_StVpStV(xDot.ptr(), tdt, *inArgs.get_x(), -tdt, *x_pred_v);
modelInArgs.set_x_dot(xDot);
modelInArgs.set_alpha(tdt); // tdt = 2/dt
modelInArgs.set_beta(1.0);
modelInArgs.set_t(time);
// No xdotdot support in Thyra, so set directly in the model
// Need to set xdotdot and omega in the underlying model if the model is a DMEWSF
Teuchos::RCP<const Piro::TransientDecorator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > dec =
Teuchos::rcp_dynamic_cast<const Piro::TransientDecorator<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
(DMEWSF->getUnderlyingModel());
TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::is_null(dec),
std::logic_error,
"Underlying model in trapezoid decorator does not cast to a Piro::TransientDecorator<Scalar, LocalOrdinal, GlobalOrdinal, Node>"
<< std::endl);
dec->set_omega(fdt2); // fdt2 = 4/(dt)^2
dec->set_x_dotdot_data(xDotDot); // no xdotdot in Thyra inArgs
//Evaluate the underlying model
this->getUnderlyingModel()->evalModel(modelInArgs, modelOutArgs);
}
|