10#ifndef Tempus_RKButcherTableau_hpp
11#define Tempus_RKButcherTableau_hpp
15#pragma clang system_header
18#include "Teuchos_SerialDenseMatrix.hpp"
19#include "Teuchos_SerialDenseVector.hpp"
21#include "Tempus_config.hpp"
43template <
class Scalar>
45 :
virtual public Teuchos::Describable,
46 virtual public Teuchos::VerboseObject<RKButcherTableau<Scalar> > {
49 const Teuchos::SerialDenseMatrix<int, Scalar>&
A,
50 const Teuchos::SerialDenseVector<int, Scalar>&
b,
51 const Teuchos::SerialDenseVector<int, Scalar>&
c,
53 const Teuchos::SerialDenseVector<int, Scalar>&
bstar =
54 Teuchos::SerialDenseVector<int, Scalar>(),
59 TEUCHOS_ASSERT_EQUALITY(
A.numCols(),
numStages);
60 TEUCHOS_ASSERT_EQUALITY(
b.length(),
numStages);
61 TEUCHOS_ASSERT_EQUALITY(
c.length(),
numStages);
62 TEUCHOS_ASSERT(
order > 0);
73 typedef Teuchos::ScalarTraits<Scalar> ST;
74 Scalar sumb = ST::zero();
75 for (
size_t i = 0; i < this->
numStages(); i++) sumb +=
b_(i);
76 TEUCHOS_TEST_FOR_EXCEPTION(
77 std::abs(ST::one() - sumb) > 1.0e-08, std::runtime_error,
78 "Error - Butcher Tableau b fails to satisfy Sum(b_i) = 1.\n"
79 <<
" Sum(b_i) = " << sumb <<
"\n");
83 for (
size_t i = 0; i < this->
numStages(); i++) {
84 Scalar sumai = ST::zero();
85 for (
size_t j = 0; j < this->
numStages(); j++) sumai +=
A_(i, j);
87 if (std::abs(sumai) > 1.0e-08)
88 failed = (std::abs((sumai -
c_(i)) / sumai) > 1.0e-08);
90 failed = (std::abs(
c_(i)) > 1.0e-08);
92 TEUCHOS_TEST_FOR_EXCEPTION(
93 failed, std::runtime_error,
94 "Error - Butcher Tableau fails to satisfy c_i = Sum_j(a_ij).\n"
95 <<
" Stage i = " << i <<
"\n"
96 <<
" c_i = " <<
c_(i) <<
"\n"
97 <<
" Sum_j(a_ij) = " << sumai <<
"\n"
98 <<
" This may be OK as some valid tableaus do not satisfy\n"
99 <<
" this condition. If so, construct this RKButcherTableau\n"
100 <<
" with checkC = false.\n");
104 if (
bstar.length() > 0) {
117 virtual const Teuchos::SerialDenseMatrix<int, Scalar>&
A()
const
122 virtual const Teuchos::SerialDenseVector<int, Scalar>&
b()
const
127 virtual const Teuchos::SerialDenseVector<int, Scalar>&
bstar()
const
132 virtual const Teuchos::SerialDenseVector<int, Scalar>&
c()
const
162 const Teuchos::EVerbosityLevel verbLevel)
const
164 out.setOutputToRootOnly(0);
166 if (verbLevel != Teuchos::VERB_NONE) {
168 out <<
"number of Stages = " << this->
numStages() << std::endl;
169 out <<
"A = " << printMat(this->
A()) << std::endl;
170 out <<
"b = " << printMat(this->
b()) << std::endl;
171 out <<
"c = " << printMat(this->
c()) << std::endl;
172 out <<
"bstar = " << printMat(this->
bstar()) << std::endl;
173 out <<
"order = " << this->
order() << std::endl;
174 out <<
"orderMin = " << this->
orderMin() << std::endl;
175 out <<
"orderMax = " << this->
orderMax() << std::endl;
176 out <<
"isImplicit = " << this->
isImplicit() << std::endl;
177 out <<
"isDIRK = " << this->
isDIRK() << std::endl;
178 out <<
"isEmbedded = " << this->
isEmbedded() << std::endl;
180 out <<
"TVD Coeff = " << this->
getTVDCoeff() << std::endl;
187 const Scalar relTol = 1.0e-15;
188 if (
A_->numRows() != t.
A_->numRows() ||
A_->numCols() != t.
A_->numCols()) {
193 for (i = 0; i <
A_->numRows(); i++) {
194 for (j = 0; j <
A_->numCols(); j++) {
195 if (std::abs((t.
A_(i, j) -
A_(i, j)) /
A_(i, j)) > relTol)
201 if (
b_->length() != t.
b_->length() ||
b_->length() != t.
c_->length() ||
202 b_->length() != t.
bstar_->length()) {
207 for (i = 0; i <
A_->numRows(); i++) {
208 if (std::abs((t.
b_(i) -
b_(i)) /
b_(i)) > relTol)
return false;
209 if (std::abs((t.
c_(i) -
c_(i)) /
c_(i)) > relTol)
return false;
226 for (
size_t i = 0; i < this->
numStages(); i++)
227 for (
size_t j = i; j < this->
numStages(); j++)
235 bool nonZero =
false;
236 for (
size_t i = 0; i < this->
numStages(); i++) {
237 if (
A_(i, i) != 0.0) nonZero =
true;
238 for (
size_t j = i + 1; j < this->
numStages(); j++)
241 if (nonZero ==
false)
isDIRK_ =
false;
246 Teuchos::SerialDenseMatrix<int, Scalar>
A_;
247 Teuchos::SerialDenseVector<int, Scalar>
b_;
248 Teuchos::SerialDenseVector<int, Scalar>
c_;
256 Teuchos::SerialDenseVector<int, Scalar>
bstar_;
bool operator!=(const RKButcherTableau &t) const
virtual bool isImplicit() const
Return true if the RK method is implicit.
virtual const Teuchos::SerialDenseMatrix< int, Scalar > & A() const
Return the matrix coefficients.
Teuchos::SerialDenseVector< int, Scalar > b_
Teuchos::SerialDenseVector< int, Scalar > bstar_
virtual int orderMin() const
Return the minimum order.
Teuchos::SerialDenseVector< int, Scalar > c_
virtual int orderMax() const
Return the maximum order.
virtual void setTVDCoeff(const Scalar a)
set TVD coefficient of RK method
virtual bool isTVD() const
Return true if the RK method is TVD.
bool operator==(const RKButcherTableau &t) const
virtual Scalar getTVDCoeff() const
Return TVD coefficient of RK method.
virtual const Teuchos::SerialDenseVector< int, Scalar > & c() const
Return the vector of stage positions.
virtual int order() const
Return the order.
virtual const Teuchos::SerialDenseVector< int, Scalar > & b() const
Return the vector of quadrature weights.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Teuchos::SerialDenseMatrix< int, Scalar > A_
virtual std::size_t numStages() const
Return the number of stages.
virtual void setTVD(bool a)
RKButcherTableau(std::string stepperType, const Teuchos::SerialDenseMatrix< int, Scalar > &A, const Teuchos::SerialDenseVector< int, Scalar > &b, const Teuchos::SerialDenseVector< int, Scalar > &c, const int order, const int orderMin, const int orderMax, const Teuchos::SerialDenseVector< int, Scalar > &bstar=Teuchos::SerialDenseVector< int, Scalar >(), bool checkC=true)
virtual bool isEmbedded() const
Return true if the RK method has embedded capabilities.
void set_isDIRK()
DIRK is defined as if a_ij = 0 for j>i and a_ii != 0 for at least one i.
virtual const Teuchos::SerialDenseVector< int, Scalar > & bstar() const
Return the vector of quadrature weights for embedded methods.
virtual bool isDIRK() const
Return true if the RK method is Diagonally Implicit.
virtual std::string description() const
virtual void setEmbedded(bool a)