/usr/include/trilinos/Rythmos_ImplicitRKStepper_def.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 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 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 | //@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_IMPLICIT_RK_STEPPER_DEF_H
#define Rythmos_IMPLICIT_RK_STEPPER_DEF_H
#include "Rythmos_ImplicitRKStepper_decl.hpp"
#include "Rythmos_StepperHelpers.hpp"
#include "Rythmos_SingleResidualModelEvaluator.hpp"
#include "Rythmos_ImplicitRKModelEvaluator.hpp"
#include "Rythmos_DiagonalImplicitRKModelEvaluator.hpp"
#include "Rythmos_RKButcherTableau.hpp"
#include "Rythmos_RKButcherTableauHelpers.hpp"
#include "Thyra_ModelEvaluatorHelpers.hpp"
#include "Thyra_ProductVectorSpaceBase.hpp"
#include "Thyra_AssertOp.hpp"
#include "Thyra_TestingTools.hpp"
#include "Rythmos_ImplicitBDFStepperRampingStepControl.hpp"
#include "Teuchos_VerboseObjectParameterListHelpers.hpp"
#include "Teuchos_as.hpp"
namespace Rythmos {
/** \brief Nonmember constructor.
*
* \relates ImplicitRKStepper
*/
template<class Scalar>
RCP<ImplicitRKStepper<Scalar> >
implicitRKStepper()
{
RCP<ImplicitRKStepper<Scalar> > stepper(new ImplicitRKStepper<Scalar>());
return stepper;
}
template<class Scalar>
RCP<ImplicitRKStepper<Scalar> >
implicitRKStepper(
const RCP<const Thyra::ModelEvaluator<Scalar> >& model,
const RCP<Thyra::NonlinearSolverBase<Scalar> >& solver,
const RCP<Thyra::LinearOpWithSolveFactoryBase<Scalar> >& irk_W_factory,
const RCP<const RKButcherTableauBase<Scalar> >& irkbt
)
{
RCP<ImplicitRKStepper<Scalar> > stepper(new ImplicitRKStepper<Scalar>());
stepper->setModel(model);
stepper->setSolver(solver);
stepper->set_W_factory(irk_W_factory);
stepper->setRKButcherTableau(irkbt);
return stepper;
}
// ////////////////////////////
// Defintions
// Constructors, intializers, Misc.
template<class Scalar>
ImplicitRKStepper<Scalar>::ImplicitRKStepper()
{
this->defaultInitializeAll_();
irkButcherTableau_ = rKButcherTableau<Scalar>();
numSteps_ = 0;
}
template<class Scalar>
void ImplicitRKStepper<Scalar>::defaultInitializeAll_()
{
isInitialized_ = false;
model_ = Teuchos::null;
solver_ = Teuchos::null;
irk_W_factory_ = Teuchos::null;
paramList_ = Teuchos::null;
//basePoint_;
x_ = Teuchos::null;
x_old_ = Teuchos::null;
x_dot_ = Teuchos::null;
//timeRange_;
irkModel_ = Teuchos::null;
irkButcherTableau_ = Teuchos::null;
isDirk_ = false;
numSteps_ = -1;
haveInitialCondition_ = false;
x_stage_bar_ = Teuchos::null;
}
template<class Scalar>
void ImplicitRKStepper<Scalar>::set_W_factory(
const RCP<Thyra::LinearOpWithSolveFactoryBase<Scalar> > &irk_W_factory
)
{
TEUCHOS_ASSERT( !is_null(irk_W_factory) );
irk_W_factory_ = irk_W_factory;
}
template<class Scalar>
RCP<const Thyra::LinearOpWithSolveFactoryBase<Scalar> > ImplicitRKStepper<Scalar>::get_W_factory() const
{
return irk_W_factory_;
}
// Overridden from SolverAcceptingStepperBase
template<class Scalar>
void ImplicitRKStepper<Scalar>::setSolver(
const RCP<Thyra::NonlinearSolverBase<Scalar> > &solver
)
{
TEUCHOS_TEST_FOR_EXCEPT(is_null(solver));
solver_ = solver;
}
template<class Scalar>
RCP<Thyra::NonlinearSolverBase<Scalar> >
ImplicitRKStepper<Scalar>::getNonconstSolver()
{
return solver_;
}
template<class Scalar>
RCP<const Thyra::NonlinearSolverBase<Scalar> >
ImplicitRKStepper<Scalar>::getSolver() const
{
return solver_;
}
// Overridden from StepperBase
template<class Scalar>
bool ImplicitRKStepper<Scalar>::isImplicit() const
{
return true;
}
template<class Scalar>
bool ImplicitRKStepper<Scalar>::supportsCloning() const
{
return true;
}
template<class Scalar>
RCP<StepperBase<Scalar> >
ImplicitRKStepper<Scalar>::cloneStepperAlgorithm() const
{
// Just use the interface to clone the algorithm in a basically
// uninitialized state
RCP<ImplicitRKStepper<Scalar> >
stepper = Teuchos::rcp(new ImplicitRKStepper<Scalar>());
if (!is_null(model_)) {
stepper->setModel(model_); // Shallow copy is okay!
}
if (!is_null(irkButcherTableau_)) {
// 06/16/09 tscoffe: should we clone the RKBT here?
stepper->setRKButcherTableau(irkButcherTableau_);
}
if (!is_null(solver_)) {
stepper->setSolver(solver_->cloneNonlinearSolver().assert_not_null());
}
if (!is_null(irk_W_factory_)) {
// 06/16/09 tscoffe: should we clone the W_factory here?
stepper->set_W_factory(irk_W_factory_);
}
if (!is_null(paramList_)) {
stepper->setParameterList(Teuchos::parameterList(*paramList_));
}
return stepper;
}
template<class Scalar>
RCP<StepControlStrategyBase<Scalar> > ImplicitRKStepper<Scalar>::getNonconstStepControlStrategy()
{
return(stepControl_);
}
template<class Scalar>
RCP<const StepControlStrategyBase<Scalar> > ImplicitRKStepper<Scalar>::getStepControlStrategy() const
{
return(stepControl_);
}
template<class Scalar>
void ImplicitRKStepper<Scalar>::setStepControlStrategy(const RCP<StepControlStrategyBase<Scalar> >& stepControl)
{
TEUCHOS_TEST_FOR_EXCEPTION(stepControl == Teuchos::null,std::logic_error,"Error, stepControl == Teuchos::null!\n");
stepControl_ = stepControl;
}
template<class Scalar>
void ImplicitRKStepper<Scalar>::setModel(
const RCP<const Thyra::ModelEvaluator<Scalar> >& model
)
{
TEUCHOS_TEST_FOR_EXCEPT(is_null(model));
assertValidModel( *this, *model );
model_ = model;
}
template<class Scalar>
void ImplicitRKStepper<Scalar>::setNonconstModel(
const RCP<Thyra::ModelEvaluator<Scalar> >& model
)
{
this->setModel(model); // TODO 09/09/09 tscoffe: use ConstNonconstObjectContainer!
}
template<class Scalar>
RCP<const Thyra::ModelEvaluator<Scalar> >
ImplicitRKStepper<Scalar>::getModel() const
{
return model_;
}
template<class Scalar>
RCP<Thyra::ModelEvaluator<Scalar> >
ImplicitRKStepper<Scalar>::getNonconstModel()
{
return Teuchos::null;
}
template<class Scalar>
void ImplicitRKStepper<Scalar>::setInitialCondition(
const Thyra::ModelEvaluatorBase::InArgs<Scalar> &initialCondition
)
{
typedef ScalarTraits<Scalar> ST;
typedef Thyra::ModelEvaluatorBase MEB;
basePoint_ = initialCondition;
// x
RCP<const Thyra::VectorBase<Scalar> >
x_init = initialCondition.get_x();
#ifdef HAVE_RYTHMOS_DEBUG
TEUCHOS_TEST_FOR_EXCEPTION(
is_null(x_init), std::logic_error,
"Error, if the client passes in an intial condition to setInitialCondition(...),\n"
"then x can not be null!" );
#endif
x_ = x_init->clone_v();
// for the embedded RK method
xhat_ = x_init->clone_v();
ee_ = x_init->clone_v();
// x_dot
x_dot_ = createMember(x_->space());
RCP<const Thyra::VectorBase<Scalar> >
x_dot_init = initialCondition.get_x_dot();
if (!is_null(x_dot_init))
assign(x_dot_.ptr(),*x_dot_init);
else
assign(x_dot_.ptr(),ST::zero());
// t
const Scalar t =
(
initialCondition.supports(MEB::IN_ARG_t)
? initialCondition.get_t()
: ST::zero()
);
timeRange_ = timeRange(t,t);
// x_old
x_old_ = x_->clone_v();
haveInitialCondition_ = true;
}
template<class Scalar>
Thyra::ModelEvaluatorBase::InArgs<Scalar>
ImplicitRKStepper<Scalar>::getInitialCondition() const
{
return basePoint_;
}
template<class Scalar>
Scalar ImplicitRKStepper<Scalar>::takeStep(Scalar dt, StepSizeType stepSizeType)
{
Scalar stepSizeTaken;
using Teuchos::as;
using Teuchos::incrVerbLevel;
typedef Thyra::NonlinearSolverBase<Scalar> NSB;
typedef Teuchos::VerboseObjectTempState<NSB> VOTSNSB;
RCP<FancyOStream> out = this->getOStream();
Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
Teuchos::OSTab ostab(out,1,"takeStep");
VOTSNSB solver_outputTempState(solver_,out,incrVerbLevel(verbLevel,-1));
// not needed for this
int desiredOrder;
if ( !is_null(out) && as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW) ) {
*out
<< "\nEntering "
<< Teuchos::TypeNameTraits<ImplicitRKStepper<Scalar> >::name()
<< "::takeStep("<<dt<<","<<toString(stepSizeType)<<") ...\n";
}
if (!isInitialized_) {
initialize_();
}
if (stepSizeType == STEP_TYPE_FIXED) {
stepSizeTaken = takeFixedStep_(dt , stepSizeType);
return stepSizeTaken;
} else {
isVariableStep_ = true;
stepControl_->setOStream(out);
stepControl_->setVerbLevel(verbLevel);
rkNewtonConvergenceStatus_ = -1;
while (rkNewtonConvergenceStatus_ < 0){
stepControl_->setRequestedStepSize(*this, dt, stepSizeType);
stepControl_->nextStepSize(*this, &dt, &stepSizeType, &desiredOrder);
stepSizeTaken = takeVariableStep_(dt, stepSizeType);
}
return stepSizeTaken;
}
}
template<class Scalar>
Scalar ImplicitRKStepper<Scalar>::takeFixedStep_(Scalar dt, StepSizeType stepSizeType)
{
using Teuchos::as;
using Teuchos::incrVerbLevel;
typedef ScalarTraits<Scalar> ST;
typedef Thyra::NonlinearSolverBase<Scalar> NSB;
typedef Teuchos::VerboseObjectTempState<NSB> VOTSNSB;
RCP<FancyOStream> out = this->getOStream();
Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
Teuchos::OSTab ostab(out,1,"takeStep");
VOTSNSB solver_outputTempState(solver_,out,incrVerbLevel(verbLevel,-1));
if ( !is_null(out) && as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW) ) {
*out
<< "\nEntering "
<< Teuchos::TypeNameTraits<ImplicitRKStepper<Scalar> >::name()
<< "::takeFixedStep_("<<dt<<","<<toString(stepSizeType)<<") ...\n";
}
if (!isInitialized_) {
initialize_();
}
TEUCHOS_TEST_FOR_EXCEPT( stepSizeType != STEP_TYPE_FIXED ); // ToDo: Handle variable case later
// A) Set up the IRK ModelEvaluator so that it can represent the time step
// equation to be solved.
// Set irkModel_ with x_old_, t_old_, and dt
V_V( x_old_.ptr(), *x_ );
Scalar current_dt = dt;
Scalar t = timeRange_.upper();
// B) Solve the timestep equation
// Set the guess for the stage derivatives to zero (unless we can think of
// something better)
V_S( Teuchos::rcp_dynamic_cast<Thyra::VectorBase<Scalar> >(x_stage_bar_).ptr(), ST::zero() );
if (!isDirk_) { // General Implicit RK Case:
RCP<ImplicitRKModelEvaluator<Scalar> > firkModel_ =
Teuchos::rcp_dynamic_cast<ImplicitRKModelEvaluator<Scalar> >(irkModel_,true);
firkModel_->setTimeStepPoint( x_old_, t, current_dt );
// Solve timestep equation
solver_->solve( &*x_stage_bar_ );
} else { // Diagonal Implicit RK Case:
RCP<DiagonalImplicitRKModelEvaluator<Scalar> > dirkModel_ =
Teuchos::rcp_dynamic_cast<DiagonalImplicitRKModelEvaluator<Scalar> >(irkModel_,true);
dirkModel_->setTimeStepPoint( x_old_, t, current_dt );
int numStages = irkButcherTableau_->numStages();
for (int stage=0 ; stage < numStages ; ++stage) {
dirkModel_->setCurrentStage(stage);
solver_->solve( &*(x_stage_bar_->getNonconstVectorBlock(stage)) );
dirkModel_->setStageSolution( stage, *(x_stage_bar_->getVectorBlock(stage)) );
}
}
// C) Complete the step ...
// Combine the stage derivatives with the Butcher tableau "b" vector to obtain the solution at the final time.
// x_{k+1} = x_k + dt*sum_{i}^{p}(b_i*x_stage_bar_[i])
assembleIRKSolution( irkButcherTableau_->b(), current_dt, *x_old_, *x_stage_bar_,
outArg(*x_)
);
// Update time range
timeRange_ = timeRange(t,t+current_dt);
numSteps_++;
return current_dt;
}
template<class Scalar>
Scalar ImplicitRKStepper<Scalar>::takeVariableStep_(Scalar dt, StepSizeType stepSizeType)
{
using Teuchos::as;
using Teuchos::incrVerbLevel;
typedef ScalarTraits<Scalar> ST;
typedef Thyra::NonlinearSolverBase<Scalar> NSB;
typedef Teuchos::VerboseObjectTempState<NSB> VOTSNSB;
RCP<FancyOStream> out = this->getOStream();
Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
Teuchos::OSTab ostab(out,1,"takeStep");
VOTSNSB solver_outputTempState(solver_,out,incrVerbLevel(verbLevel,-1));
AttemptedStepStatusFlag status;
Scalar dt_old = dt;
if ( !is_null(out) && as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW) ) {
*out
<< "\nEntering "
<< Teuchos::TypeNameTraits<ImplicitRKStepper<Scalar> >::name()
<< "::takeVariableStep_("<<dt<<","<<toString(stepSizeType)<<") ...\n";
}
if (!isInitialized_) {
initialize_();
}
// A) Set up the IRK ModelEvaluator so that it can represent the time step
// equation to be solved.
// Set irkModel_ with x_old_, t_old_, and dt
V_V( x_old_.ptr(), *x_ );
Scalar current_dt = dt;
Scalar t = timeRange_.upper();
Scalar dt_to_return;
// B) Solve the timestep equation
// Set the guess for the stage derivatives to zero (unless we can think of
// something better)
V_S( Teuchos::rcp_dynamic_cast<Thyra::VectorBase<Scalar> >(x_stage_bar_).ptr(), ST::zero() );
if (!isDirk_) { // General Implicit RK Case:
RCP<ImplicitRKModelEvaluator<Scalar> > firkModel_ =
Teuchos::rcp_dynamic_cast<ImplicitRKModelEvaluator<Scalar> >(irkModel_,true);
firkModel_->setTimeStepPoint( x_old_, t, current_dt );
// Solve timestep equation
solver_->solve( &*x_stage_bar_ );
} else { // Diagonal Implicit RK Case:
RCP<DiagonalImplicitRKModelEvaluator<Scalar> > dirkModel_ =
Teuchos::rcp_dynamic_cast<DiagonalImplicitRKModelEvaluator<Scalar> >(irkModel_,true);
dirkModel_->setTimeStepPoint( x_old_, t, current_dt );
int numStages = irkButcherTableau_->numStages();
for (int stage=0 ; stage < numStages ; ++stage) {
dirkModel_->setCurrentStage(stage);
nonlinearSolveStatus_ = solver_->solve( &*(x_stage_bar_->getNonconstVectorBlock(stage)) );
if (nonlinearSolveStatus_.solveStatus == Thyra::SOLVE_STATUS_CONVERGED) {
rkNewtonConvergenceStatus_ = 0;
} else {
rkNewtonConvergenceStatus_ = -1;
}
// for now setCorrection just sets the rkNewtonConvergenceStatus_ in the stepControl
// and this is used by acceptStep method of the stepControl
stepControl_->setCorrection(*this, (x_stage_bar_->getNonconstVectorBlock(stage)), Teuchos::null , rkNewtonConvergenceStatus_);
bool stepPass = stepControl_->acceptStep(*this, &LETvalue_);
if (!stepPass) { // stepPass = false
stepLETStatus_ = STEP_LET_STATUS_FAILED;
rkNewtonConvergenceStatus_ = -1; // just making sure here
break; // leave the for loop
} else { // stepPass = true
stepLETStatus_ = STEP_LET_STATUS_PASSED;
dirkModel_->setStageSolution( stage, *(x_stage_bar_->getVectorBlock(stage)) );
rkNewtonConvergenceStatus_ = 0; // just making sure here
}
}
// if none of the stages failed, then I can complete the step
}
// check the nonlinearSolveStatus
if ( rkNewtonConvergenceStatus_ == 0) {
/*
* if the solver has converged, then I can go ahead and combine the stage solutions
* and get the new solution
*/
// C) Complete the step ...
// Combine the stage derivatives with the Butcher tableau "b" vector to obtain the solution at the final time.
// x_{k+1} = x_k + dt*sum_{i}^{p}(b_i*x_stage_bar_[i])
assembleIRKSolution( irkButcherTableau_->b(), current_dt, *x_old_, *x_stage_bar_,
outArg(*x_)
);
//if using embedded method, estimate LTE
if (irkButcherTableau_->isEmbeddedMethod() ){
assembleIRKSolution( irkButcherTableau_->bhat(), current_dt, *x_old_, *x_stage_bar_,
outArg(*xhat_)
);
// ee_ = (x_ - xhat_)
Thyra::V_VmV(ee_.ptr(), *x_, *xhat_);
stepControl_->setCorrection(*this, x_, ee_ , rkNewtonConvergenceStatus_);
bool stepPass = stepControl_->acceptStep(*this, &LETvalue_);
if (!stepPass) { // stepPass = false
stepLETStatus_ = STEP_LET_STATUS_FAILED;
rkNewtonConvergenceStatus_ = -1; // just making sure here
} else { // stepPass = true
stepLETStatus_ = STEP_LET_STATUS_PASSED;
rkNewtonConvergenceStatus_ = 0; // just making sure here
}
}
}
if (rkNewtonConvergenceStatus_ == 0) {
// Update time range
timeRange_ = timeRange(t,t+current_dt);
numSteps_++;
// completeStep only if the none of the stage solution's failed to converged
stepControl_->completeStep(*this);
dt_to_return = current_dt;
} else {
rkNewtonConvergenceStatus_ = -1;
status = stepControl_-> rejectStep(*this); // reject the stage value
(void) status; // avoid "set but not used" build warning
dt_to_return = dt_old;
}
return dt_to_return;
}
template<class Scalar>
const StepStatus<Scalar> ImplicitRKStepper<Scalar>::getStepStatus() const
{
StepStatus<Scalar> stepStatus;
if (!isInitialized_) {
stepStatus.stepStatus = STEP_STATUS_UNINITIALIZED;
stepStatus.message = "This stepper is uninitialized.";
// return stepStatus;
}
else if (numSteps_ > 0) {
stepStatus.stepStatus = STEP_STATUS_CONVERGED;
}
else {
stepStatus.stepStatus = STEP_STATUS_UNKNOWN;
}
stepStatus.stepSize = timeRange_.length();
stepStatus.order = irkButcherTableau_->order();
stepStatus.time = timeRange_.upper();
if(Teuchos::nonnull(x_))
stepStatus.solution = x_;
else
stepStatus.solution = Teuchos::null;
stepStatus.solutionDot = Teuchos::null;
return(stepStatus);
}
// Overridden from InterpolationBufferBase
template<class Scalar>
RCP<const Thyra::VectorSpaceBase<Scalar> >
ImplicitRKStepper<Scalar>::get_x_space() const
{
return ( !is_null(model_) ? model_->get_x_space() : Teuchos::null );
}
template<class Scalar>
void ImplicitRKStepper<Scalar>::addPoints(
const Array<Scalar>& time_vec
,const Array<RCP<const Thyra::VectorBase<Scalar> > >& x_vec
,const Array<RCP<const Thyra::VectorBase<Scalar> > >& xdot_vec
)
{
TEUCHOS_TEST_FOR_EXCEPT(true);
}
template<class Scalar>
TimeRange<Scalar> ImplicitRKStepper<Scalar>::getTimeRange() const
{
return timeRange_;
}
template<class Scalar>
void ImplicitRKStepper<Scalar>::getPoints(
const Array<Scalar>& time_vec
,Array<RCP<const Thyra::VectorBase<Scalar> > >* x_vec
,Array<RCP<const Thyra::VectorBase<Scalar> > >* xdot_vec
,Array<ScalarMag>* accuracy_vec) const
{
using Teuchos::constOptInArg;
using Teuchos::null;
TEUCHOS_ASSERT(haveInitialCondition_);
defaultGetPoints<Scalar>(
timeRange_.lower(), constOptInArg(*x_old_),
Ptr<const VectorBase<Scalar> >(null), // Sun
timeRange_.upper(), constOptInArg(*x_),
Ptr<const VectorBase<Scalar> >(null), // Sun
time_vec,
ptr(x_vec), ptr(xdot_vec), ptr(accuracy_vec),
Ptr<InterpolatorBase<Scalar> >(null) // For Sun
);
// 04/17/09 tscoffe: Currently, we don't have x_dot to pass out (TODO)
}
template<class Scalar>
void ImplicitRKStepper<Scalar>::getNodes(Array<Scalar>* time_vec) const
{
TEUCHOS_ASSERT( time_vec != NULL );
time_vec->clear();
if (!haveInitialCondition_) {
return;
}
time_vec->push_back(timeRange_.lower());
if (numSteps_ > 0) {
time_vec->push_back(timeRange_.upper());
}
}
template<class Scalar>
void ImplicitRKStepper<Scalar>::removeNodes(Array<Scalar>& time_vec)
{
TEUCHOS_TEST_FOR_EXCEPT(true);
}
template<class Scalar>
int ImplicitRKStepper<Scalar>::getOrder() const
{
return irkButcherTableau_->order();
}
// Overridden from Teuchos::ParameterListAcceptor
template <class Scalar>
void ImplicitRKStepper<Scalar>::setParameterList(
RCP<ParameterList> const& paramList
)
{
TEUCHOS_TEST_FOR_EXCEPT(is_null(paramList));
paramList->validateParametersAndSetDefaults(*this->getValidParameters());
paramList_ = paramList;
Teuchos::readVerboseObjectSublist(&*paramList_,this);
}
template <class Scalar>
RCP<ParameterList>
ImplicitRKStepper<Scalar>::getNonconstParameterList()
{
return(paramList_);
}
template <class Scalar>
RCP<ParameterList>
ImplicitRKStepper<Scalar>::unsetParameterList()
{
RCP<ParameterList>
temp_param_list = paramList_;
paramList_ = Teuchos::null;
return(temp_param_list);
}
template<class Scalar>
RCP<const ParameterList>
ImplicitRKStepper<Scalar>::getValidParameters() const
{
static RCP<const ParameterList> validPL;
if (is_null(validPL)) {
RCP<ParameterList> pl = Teuchos::parameterList();
if (isVariableStep_){
pl->sublist(RythmosStepControlSettings_name);
}
Teuchos::setupVerboseObjectSublist(&*pl);
validPL = pl;
}
return validPL;
}
// Overridden from Teuchos::Describable
template<class Scalar>
void ImplicitRKStepper<Scalar>::describe(
FancyOStream &out,
const Teuchos::EVerbosityLevel verbLevel
) const
{
using std::endl;
using Teuchos::as;
if (!isInitialized_) {
out << this->description() << " : This stepper is not initialized yet" << std::endl;
return;
}
if (
as<int>(verbLevel) == as<int>(Teuchos::VERB_DEFAULT)
||
as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW)
)
{
out << this->description() << ":" << endl;
Teuchos::OSTab tab(out);
out << "model = " << Teuchos::describe(*model_,verbLevel);
out << "solver = " << Teuchos::describe(*solver_,verbLevel);
out << "irk_W_factory = " << Teuchos::describe(*irk_W_factory_,verbLevel);
}
}
// private
template <class Scalar>
void ImplicitRKStepper<Scalar>::initialize_()
{
// typedef ScalarTraits<Scalar> ST; // unused
using Teuchos::rcp_dynamic_cast;
TEUCHOS_TEST_FOR_EXCEPT(is_null(model_));
TEUCHOS_TEST_FOR_EXCEPT(is_null(solver_));
TEUCHOS_TEST_FOR_EXCEPT(irkButcherTableau_->numStages() == 0);
TEUCHOS_ASSERT(haveInitialCondition_);
#ifdef HAVE_RYTHMOS_DEBUG
THYRA_ASSERT_VEC_SPACES(
"Rythmos::ImplicitRKStepper::initialize_(...)",
*x_->space(), *model_->get_x_space() );
#endif
if (isVariableStep_ ) {
// Initialize StepControl
isEmbeddedRK_ = irkButcherTableau_->isEmbeddedMethod(); // determine if RK method is an embedded method
if (stepControl_ == Teuchos::null) {
RCP<ImplicitBDFStepperRampingStepControl<Scalar> > rkStepControl =
Teuchos::rcp(new ImplicitBDFStepperRampingStepControl<Scalar>());
//RCP<StepControlStrategyBase<Scalar> > rkStepControl =
//Teuchos::rcp(new StepControlStrategyBase<Scalar>());
RCP<Teuchos::ParameterList> stepControlPL =
Teuchos::sublist(paramList_ , RythmosStepControlSettings_name);
rkStepControl->setParameterList(stepControlPL);
this->setStepControlStrategy(rkStepControl);
stepControl_->initialize(*this);
}
}
// Set up the IRK mdoel
if (!isDirk_) { // General Implicit RK
TEUCHOS_TEST_FOR_EXCEPT(is_null(irk_W_factory_));
irkModel_ = implicitRKModelEvaluator(
model_,basePoint_,irk_W_factory_,irkButcherTableau_);
} else { // Diagonal Implicit RK
irkModel_ = diagonalImplicitRKModelEvaluator(
model_,basePoint_,irk_W_factory_,irkButcherTableau_);
}
solver_->setModel(irkModel_);
// Set up the vector of stage derivatives ...
const int numStages = irkButcherTableau_->numStages();
RCP<const Thyra::ProductVectorSpaceBase<Scalar> > pvs = productVectorSpace(model_->get_x_space(),numStages);
RCP<const Thyra::VectorSpaceBase<Scalar> > vs = rcp_dynamic_cast<const Thyra::VectorSpaceBase<Scalar> >(pvs,true);
x_stage_bar_ = rcp_dynamic_cast<Thyra::ProductVectorBase<Scalar> >(createMember(vs),true);
// x_stage_bar_ = rcp_dynamic_cast<Thyra::ProductVectorBase<Scalar> >(
// createMember(irkModel_->get_x_space())
// );
isInitialized_ = true;
}
template <class Scalar>
void ImplicitRKStepper<Scalar>::setRKButcherTableau( const RCP<const RKButcherTableauBase<Scalar> > &rkButcherTableau )
{
TEUCHOS_ASSERT( !is_null(rkButcherTableau) );
TEUCHOS_TEST_FOR_EXCEPTION( isInitialized_, std::logic_error,
"Error! The RK Butcher Tableau cannot be changed after internal initialization!"
);
validateIRKButcherTableau(*rkButcherTableau);
irkButcherTableau_ = rkButcherTableau;
E_RKButcherTableauTypes rkType = determineRKBTType<Scalar>(*irkButcherTableau_);
if (
(rkType == RYTHMOS_RK_BUTCHER_TABLEAU_TYPE_DIRK)
|| (rkType == RYTHMOS_RK_BUTCHER_TABLEAU_TYPE_SDIRK)
|| (irkButcherTableau_->numStages() == 1)
)
{
isDirk_ = true;
}
}
template <class Scalar>
RCP<const RKButcherTableauBase<Scalar> > ImplicitRKStepper<Scalar>::getRKButcherTableau() const
{
return irkButcherTableau_;
}
template<class Scalar>
void ImplicitRKStepper<Scalar>::setDirk(bool isDirk)
{
TEUCHOS_TEST_FOR_EXCEPTION(isInitialized_, std::logic_error,
"Error! Cannot change DIRK flag after internal initialization is completed\n"
);
if (isDirk == true) {
E_RKButcherTableauTypes rkType = determineRKBTType<Scalar>(*irkButcherTableau_);
bool RKBT_is_DIRK = (
(rkType == RYTHMOS_RK_BUTCHER_TABLEAU_TYPE_DIRK)
|| (rkType == RYTHMOS_RK_BUTCHER_TABLEAU_TYPE_SDIRK)
|| (irkButcherTableau_->numStages() == 1)
);
TEUCHOS_TEST_FOR_EXCEPTION( !RKBT_is_DIRK, std::logic_error,
"Error! Cannot set DIRK flag on a non-DIRK RK Butcher Tableau\n"
);
} else { // isDirk = false;
isDirk_ = isDirk;
}
}
//
// Explicit Instantiation macro
//
// Must be expanded from within the Rythmos namespace!
//
#define RYTHMOS_IMPLICIT_RK_STEPPER_INSTANT(SCALAR) \
\
template class ImplicitRKStepper< SCALAR >; \
\
template RCP< ImplicitRKStepper< SCALAR > > \
implicitRKStepper(); \
\
template RCP< ImplicitRKStepper< SCALAR > > \
implicitRKStepper( \
const RCP<const Thyra::ModelEvaluator< SCALAR > >& model, \
const RCP<Thyra::NonlinearSolverBase< SCALAR > >& solver, \
const RCP<Thyra::LinearOpWithSolveFactoryBase< SCALAR > >& irk_W_factory, \
const RCP<const RKButcherTableauBase< SCALAR > >& irkbt \
);
} // namespace Rythmos
#endif //Rythmos_IMPLICIT_RK_STEPPER_DEF_H
|