Skip to content

Commit

Permalink
Merge pull request #7559 from trilinos/7549-Tempus-Adjustments-to-the…
Browse files Browse the repository at this point in the history
…-AppAction-Interface

Tempus: Adjustments to the AppAction Interface
  • Loading branch information
ccober6 authored Jun 30, 2020
2 parents 4874da5 + 7ba6f07 commit bd6bedc
Show file tree
Hide file tree
Showing 17 changed files with 364 additions and 89 deletions.
33 changes: 33 additions & 0 deletions packages/tempus/src/Tempus_RKButcherTableau.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,39 @@ class RKButcherTableau :
}
//@}

bool operator == (const RKButcherTableau & t) const {
const Scalar relTol = 1.0e-15;
if ( A_->numRows() != t.A_->numRows() ||
A_->numCols() != t.A_->numCols() ) {
return false;
} else {
int i, j;
for(i = 0; i < A_->numRows(); i++) {
for(j = 0; j < A_->numCols(); j++) {
if(std::abs((t.A_(i,j) - A_(i,j))/A_(i,j)) > relTol) return false;
}
}
}

if ( b_->length() != t.b_->length() ||
b_->length() != t.c_->length() ||
b_->length() != t.bstar_->length() ) {
return false;
} else {
int i;
for(i = 0; i < A_->numRows(); i++) {
if(std::abs((t.b_(i) - b_(i))/b_(i)) > relTol) return false;
if(std::abs((t.c_(i) - c_(i))/c_(i)) > relTol) return false;
if(std::abs((t.bstar_(i) - bstar_(i))/bstar_(i)) > relTol) return false;
}
}
return true;
}

bool operator != (const RKButcherTableau & t) const {
return !((*this) == t);
}

private:

RKButcherTableau();
Expand Down
15 changes: 3 additions & 12 deletions packages/tempus/src/Tempus_StepperDIRK_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include "Tempus_config.hpp"
#include "Tempus_StepperRKBase.hpp"
#include "Tempus_RKButcherTableau.hpp"
#include "Tempus_StepperImplicit.hpp"
#include "Tempus_WrapperModelEvaluator.hpp"
#ifndef TEMPUS_HIDE_DEPRECATED_CODE
Expand Down Expand Up @@ -165,9 +164,6 @@ class StepperDIRK : virtual public Tempus::StepperImplicit<Scalar>,
virtual Teuchos::RCP<StepperObserver<Scalar> > getObserver() const
{ return this->stepperObserver_; }
#endif
virtual Teuchos::RCP<const RKButcherTableau<Scalar> > getTableau()
{ return tableau_; }

/// Initialize after construction and changing input parameters.
virtual void initialize();

Expand All @@ -187,14 +183,11 @@ class StepperDIRK : virtual public Tempus::StepperImplicit<Scalar>,

/// Get a default (initial) StepperState
virtual Teuchos::RCP<Tempus::StepperState<Scalar> >getDefaultStepperState();
virtual Scalar getOrder() const{return tableau_->order();}
virtual Scalar getOrderMin() const{return tableau_->orderMin();}
virtual Scalar getOrderMax() const{return tableau_->orderMax();}

virtual bool isExplicit() const
{
const int numStages = tableau_->numStages();
Teuchos::SerialDenseMatrix<int,Scalar> A = tableau_->A();
const int numStages = this->tableau_->numStages();
Teuchos::SerialDenseMatrix<int,Scalar> A = this->tableau_->A();
bool isExplicit = false;
for (int i=0; i<numStages; ++i) if (A(i,i) == 0.0) isExplicit = true;
return isExplicit;
Expand All @@ -219,7 +212,7 @@ class StepperDIRK : virtual public Tempus::StepperImplicit<Scalar>,
/// Return alpha = d(xDot)/dx.
virtual Scalar getAlpha(const Scalar dt) const
{
const Teuchos::SerialDenseMatrix<int,Scalar> & A=tableau_->A();
const Teuchos::SerialDenseMatrix<int,Scalar> & A=this->tableau_->A();
return Scalar(1.0)/(dt*A(0,0)); // Getting the first diagonal coeff!
}
/// Return beta = d(x)/dx.
Expand Down Expand Up @@ -273,8 +266,6 @@ class StepperDIRK : virtual public Tempus::StepperImplicit<Scalar>,

virtual void setupTableau() = 0;

Teuchos::RCP<RKButcherTableau<Scalar> > tableau_;

std::vector<Teuchos::RCP<Thyra::VectorBase<Scalar> > > stageXDot_;
Teuchos::RCP<Thyra::VectorBase<Scalar> > xTilde_;

Expand Down
26 changes: 13 additions & 13 deletions packages/tempus/src/Tempus_StepperDIRK_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ template<class Scalar>
void StepperDIRK<Scalar>::initialize()
{
// Initialize the stage vectors
const int numStages = tableau_->numStages();
const int numStages = this->tableau_->numStages();
this->stageX_ = this->wrapperModel_->getNominalValues().get_x()->clone_v();
stageXDot_.resize(numStages);
for (int i=0; i<numStages; ++i) {
Expand All @@ -170,7 +170,7 @@ void StepperDIRK<Scalar>::initialize()
xTilde_ = Thyra::createMember(this->wrapperModel_->get_x_space());
assign(xTilde_.ptr(), Teuchos::ScalarTraits<Scalar>::zero());

if (tableau_->isEmbedded() and this->getUseEmbedded()) {
if (this->tableau_->isEmbedded() and this->getUseEmbedded()) {
ee_ = Thyra::createMember(this->wrapperModel_->get_f_space());
abs_u0 = Thyra::createMember(this->wrapperModel_->get_f_space());
abs_u = Thyra::createMember(this->wrapperModel_->get_f_space());
Expand Down Expand Up @@ -227,10 +227,10 @@ void StepperDIRK<Scalar>::takeStep(
const Scalar dt = workingState->getTimeStep();
const Scalar time = currentState->getTime();

const int numStages = tableau_->numStages();
Teuchos::SerialDenseMatrix<int,Scalar> A = tableau_->A();
Teuchos::SerialDenseVector<int,Scalar> b = tableau_->b();
Teuchos::SerialDenseVector<int,Scalar> c = tableau_->c();
const int numStages = this->tableau_->numStages();
Teuchos::SerialDenseMatrix<int,Scalar> A = this->tableau_->A();
Teuchos::SerialDenseVector<int,Scalar> b = this->tableau_->b();
Teuchos::SerialDenseVector<int,Scalar> c = this->tableau_->c();

// Reset non-zero initial guess.
if ( this->getResetInitialGuess() && (!this->getZeroInitialGuess()) )
Expand All @@ -253,8 +253,8 @@ void StepperDIRK<Scalar>::takeStep(
bool isNeeded = false;
for (int k=i+1; k<numStages; ++k) if (A(k,i) != 0.0) isNeeded = true;
if (b(i) != 0.0) isNeeded = true;
if (tableau_->isEmbedded() && this->getUseEmbedded() &&
tableau_->bstar()(i) != 0.0)
if (this->tableau_->isEmbedded() && this->getUseEmbedded() &&
this->tableau_->bstar()(i) != 0.0)
isNeeded = true;
if (isNeeded == false) {
assign(stageXDot_[i].ptr(), Teuchos::ScalarTraits<Scalar>::zero());
Expand Down Expand Up @@ -344,14 +344,14 @@ void StepperDIRK<Scalar>::takeStep(
}
}

if (tableau_->isEmbedded() and this->getUseEmbedded()) {
if (this->tableau_->isEmbedded() and this->getUseEmbedded()) {
const Scalar tolRel = workingState->getTolRel();
const Scalar tolAbs = workingState->getTolAbs();

// just compute the error weight vector
// (all that is needed is the error, and not the embedded solution)
Teuchos::SerialDenseVector<int,Scalar> errWght = b ;
errWght -= tableau_->bstar();
errWght -= this->tableau_->bstar();

// compute local truncation error estimate: | u^{n+1} - \hat{u}^{n+1} |
// Sum for solution: ee_n = Sum{ (b(i) - bstar(i)) * dt*f(i) }
Expand Down Expand Up @@ -422,8 +422,8 @@ void StepperDIRK<Scalar>::describe(
StepperImplicit<Scalar>::describe(out, verbLevel);

out << "--- StepperDIRK ---\n";
out << " tableau_ = " << tableau_ << std::endl;
if (tableau_ != Teuchos::null) tableau_->describe(out, verbLevel);
out << " tableau_ = " << this->tableau_ << std::endl;
if (this->tableau_ != Teuchos::null) this->tableau_->describe(out, verbLevel);
#ifndef TEMPUS_HIDE_DEPRECATED_CODE
out << " stepperObserver_ = " << stepperObserver_ << std::endl;
#endif
Expand Down Expand Up @@ -452,7 +452,7 @@ bool StepperDIRK<Scalar>::isValidSetup(Teuchos::FancyOStream & out) const
if ( !Stepper<Scalar>::isValidSetup(out) ) isValidSetup = false;
if ( !StepperImplicit<Scalar>::isValidSetup(out) ) isValidSetup = false;

if (tableau_ == Teuchos::null) {
if (this->tableau_ == Teuchos::null) {
isValidSetup = false;
out << "The tableau is not set!\n";
}
Expand Down
9 changes: 0 additions & 9 deletions packages/tempus/src/Tempus_StepperExplicitRK_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "Tempus_config.hpp"
#include "Tempus_StepperRKBase.hpp"
#include "Tempus_StepperExplicit.hpp"
#include "Tempus_RKButcherTableau.hpp"
#ifndef TEMPUS_HIDE_DEPRECATED_CODE
#include "Tempus_StepperRKObserverComposite.hpp"
#endif
Expand Down Expand Up @@ -111,9 +110,6 @@ class StepperExplicitRK : virtual public Tempus::StepperExplicit<Scalar>,
virtual Teuchos::RCP<StepperObserver<Scalar> > getObserver() const
{ return this->stepperObserver_; }
#endif
virtual Teuchos::RCP<const RKButcherTableau<Scalar> > getTableau()
{ return tableau_; }

/// Initialize during construction and after changing input parameters.
virtual void initialize();

Expand All @@ -127,9 +123,6 @@ class StepperExplicitRK : virtual public Tempus::StepperExplicit<Scalar>,

/// Get a default (initial) StepperState
virtual Teuchos::RCP<Tempus::StepperState<Scalar> > getDefaultStepperState();
virtual Scalar getOrder() const {return tableau_->order();}
virtual Scalar getOrderMin() const {return tableau_->orderMin();}
virtual Scalar getOrderMax() const {return tableau_->orderMax();}
virtual Scalar getInitTimeStep(
const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory) const;

Expand Down Expand Up @@ -191,8 +184,6 @@ class StepperExplicitRK : virtual public Tempus::StepperExplicit<Scalar>,
virtual void setupTableau() = 0;


Teuchos::RCP<RKButcherTableau<Scalar> > tableau_;

std::vector<Teuchos::RCP<Thyra::VectorBase<Scalar> > > stageXDot_;

#ifndef TEMPUS_HIDE_DEPRECATED_CODE
Expand Down
24 changes: 12 additions & 12 deletions packages/tempus/src/Tempus_StepperExplicitRK_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ void StepperExplicitRK<Scalar>::setObserver(
template<class Scalar>
void StepperExplicitRK<Scalar>::initialize()
{
TEUCHOS_TEST_FOR_EXCEPTION( tableau_ == Teuchos::null, std::logic_error,
TEUCHOS_TEST_FOR_EXCEPTION( this->tableau_ == Teuchos::null, std::logic_error,
"Error - Need to set the tableau, before calling "
"StepperExplicitRK::initialize()\n");

Expand All @@ -231,14 +231,14 @@ void StepperExplicitRK<Scalar>::initialize()
"StepperExplicitRK::initialize()\n");

// Initialize the stage vectors
int numStages = tableau_->numStages();
int numStages = this->tableau_->numStages();
stageXDot_.resize(numStages);
for (int i=0; i<numStages; ++i) {
stageXDot_[i] = Thyra::createMember(this->appModel_->get_f_space());
assign(stageXDot_[i].ptr(), Teuchos::ScalarTraits<Scalar>::zero());
}

if ( tableau_->isEmbedded() and this->getUseEmbedded() ){
if ( this->tableau_->isEmbedded() and this->getUseEmbedded() ){
ee_ = Thyra::createMember(this->appModel_->get_f_space());
abs_u0 = Thyra::createMember(this->appModel_->get_f_space());
abs_u = Thyra::createMember(this->appModel_->get_f_space());
Expand Down Expand Up @@ -295,10 +295,10 @@ void StepperExplicitRK<Scalar>::takeStep(
const Scalar dt = workingState->getTimeStep();
const Scalar time = currentState->getTime();

const int numStages = tableau_->numStages();
Teuchos::SerialDenseMatrix<int,Scalar> A = tableau_->A();
Teuchos::SerialDenseVector<int,Scalar> b = tableau_->b();
Teuchos::SerialDenseVector<int,Scalar> c = tableau_->c();
const int numStages = this->tableau_->numStages();
Teuchos::SerialDenseMatrix<int,Scalar> A = this->tableau_->A();
Teuchos::SerialDenseVector<int,Scalar> b = this->tableau_->b();
Teuchos::SerialDenseVector<int,Scalar> c = this->tableau_->c();

this->stageX_ = workingState->getX();
Thyra::assign(this->stageX_.ptr(), *(currentState->getX()));
Expand Down Expand Up @@ -376,15 +376,15 @@ void StepperExplicitRK<Scalar>::takeStep(
// can change the step status
workingState->setSolutionStatus(Status::PASSED);

if (tableau_->isEmbedded() and this->getUseEmbedded()) {
if (this->tableau_->isEmbedded() and this->getUseEmbedded()) {

const Scalar tolRel = workingState->getTolRel();
const Scalar tolAbs = workingState->getTolAbs();

// just compute the error weight vector
// (all that is needed is the error, and not the embedded solution)
Teuchos::SerialDenseVector<int,Scalar> errWght = b ;
errWght -= tableau_->bstar();
errWght -= this->tableau_->bstar();

//compute local truncation error estimate: | u^{n+1} - \hat{u}^{n+1} |
// Sum for solution: ee_n = Sum{ (b(i) - bstar(i)) * dt*f(i) }
Expand Down Expand Up @@ -452,8 +452,8 @@ void StepperExplicitRK<Scalar>::describe(
StepperExplicit<Scalar>::describe(out, verbLevel);

out << "--- StepperExplicitRK ---\n";
if (tableau_ != Teuchos::null) tableau_->describe(out, verbLevel);
out << " tableau_ = " << tableau_ << std::endl;
if (this->tableau_ != Teuchos::null) this->tableau_->describe(out, verbLevel);
out << " tableau_ = " << this->tableau_ << std::endl;
#ifndef TEMPUS_HIDE_DEPRECATED_CODE
out << " stepperObserver_ = " << stepperObserver_ << std::endl;
#endif
Expand Down Expand Up @@ -481,7 +481,7 @@ bool StepperExplicitRK<Scalar>::isValidSetup(Teuchos::FancyOStream & out) const
if ( !Stepper<Scalar>::isValidSetup(out) ) isValidSetup = false;
if ( !StepperExplicit<Scalar>::isValidSetup(out) ) isValidSetup = false;

if (tableau_ == Teuchos::null) {
if (this->tableau_ == Teuchos::null) {
isValidSetup = false;
out << "The tableau is not set!\n";
}
Expand Down
17 changes: 16 additions & 1 deletion packages/tempus/src/Tempus_StepperIMEX_RK_Partition_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,27 @@ class StepperIMEX_RK_Partition : virtual public Tempus::StepperImplicit<Scalar>,

/// \name Basic stepper methods
//@{
/// Returns the explicit tableau!
virtual Teuchos::RCP<const RKButcherTableau<Scalar> > getTableau() const
{ return getExplicitTableau(); }

/// Set both the explicit and implicit tableau from ParameterList
virtual void setTableaus(std::string stepperType = "",
Teuchos::RCP<const RKButcherTableau<Scalar> > explicitTableau = Teuchos::null,
Teuchos::RCP<const RKButcherTableau<Scalar> > implicitTableau = Teuchos::null);

/// Return explicit tableau.
virtual Teuchos::RCP<const RKButcherTableau<Scalar> > getExplicitTableau() const
{ return explicitTableau_; }

/// Set the explicit tableau from tableau
virtual void setExplicitTableau(
Teuchos::RCP<const RKButcherTableau<Scalar> > explicitTableau);

/// Return implicit tableau.
virtual Teuchos::RCP<const RKButcherTableau<Scalar> > getImplicitTableau() const
{ return implicitTableau_; }

/// Set the implicit tableau from tableau
virtual void setImplicitTableau(
Teuchos::RCP<const RKButcherTableau<Scalar> > implicitTableau);
Expand Down Expand Up @@ -417,7 +429,10 @@ class StepperIMEX_RK_Partition : virtual public Tempus::StepperImplicit<Scalar>,
virtual OrderODE getOrderODE() const {return FIRST_ORDER_ODE;}
//@}

Teuchos::RCP<Thyra::VectorBase<Scalar> >& getStageZ() {return stageZ_;};
/// Return the full stage solution which is Z (the concat of X and Y) for IMEX Partition.
Teuchos::RCP<Thyra::VectorBase<Scalar> > getStageX() {return stageZ_;}
/// Explicitly return the full stage solution, Z.
Teuchos::RCP<Thyra::VectorBase<Scalar> > getStageZ() {return stageZ_;};
std::vector<Teuchos::RCP<Thyra::VectorBase<Scalar> > >& getStageF() {return stageF_;};
std::vector<Teuchos::RCP<Thyra::VectorBase<Scalar> > >& getStageGx() {return stageGx_;};
Teuchos::RCP<Thyra::VectorBase<Scalar> >& getXTilde() {return xTilde_;};
Expand Down
12 changes: 12 additions & 0 deletions packages/tempus/src/Tempus_StepperIMEX_RK_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,15 +326,27 @@ class StepperIMEX_RK : virtual public Tempus::StepperImplicit<Scalar>,

/// \name Basic stepper methods
//@{
/// Returns the explicit tableau!
virtual Teuchos::RCP<const RKButcherTableau<Scalar> > getTableau() const
{ return getExplicitTableau(); }

/// Set both the explicit and implicit tableau from ParameterList
virtual void setTableaus( std::string stepperType = "",
Teuchos::RCP<const RKButcherTableau<Scalar> > explicitTableau = Teuchos::null,
Teuchos::RCP<const RKButcherTableau<Scalar> > implicitTableau = Teuchos::null);

/// Return explicit tableau.
virtual Teuchos::RCP<const RKButcherTableau<Scalar> > getExplicitTableau() const
{ return explicitTableau_; }

/// Set the explicit tableau from tableau
virtual void setExplicitTableau(
Teuchos::RCP<const RKButcherTableau<Scalar> > explicitTableau);

/// Return implicit tableau.
virtual Teuchos::RCP<const RKButcherTableau<Scalar> > getImplicitTableau() const
{ return implicitTableau_; }

/// Set the implicit tableau from tableau
virtual void setImplicitTableau(
Teuchos::RCP<const RKButcherTableau<Scalar> > implicitTableau);
Expand Down
Loading

0 comments on commit bd6bedc

Please sign in to comment.