9 #ifndef Tempus_RKButcherTableau_hpp 10 #define Tempus_RKButcherTableau_hpp 14 #pragma clang system_header 19 #include "Teuchos_Assert.hpp" 20 #include "Teuchos_as.hpp" 21 #include "Teuchos_Describable.hpp" 22 #include "Teuchos_VerboseObject.hpp" 23 #include "Teuchos_VerboseObjectParameterListHelpers.hpp" 24 #include "Teuchos_SerialDenseMatrix.hpp" 25 #include "Teuchos_SerialDenseVector.hpp" 26 #include "Thyra_MultiVectorStdOps.hpp" 49 template<
class Scalar>
51 virtual public Teuchos::Describable,
52 virtual public Teuchos::VerboseObject<RKButcherTableau<Scalar> >
57 std::string stepperType,
58 const Teuchos::SerialDenseMatrix<int,Scalar>&
A,
59 const Teuchos::SerialDenseVector<int,Scalar>&
b,
60 const Teuchos::SerialDenseVector<int,Scalar>&
c,
64 const Teuchos::SerialDenseVector<int,Scalar>&
65 bstar = Teuchos::SerialDenseVector<int,Scalar>(),
70 TEUCHOS_ASSERT_EQUALITY(
A.numCols(),
numStages );
71 TEUCHOS_ASSERT_EQUALITY(
b.length(),
numStages );
72 TEUCHOS_ASSERT_EQUALITY(
c.length(),
numStages );
73 TEUCHOS_ASSERT(
order > 0 );
84 typedef Teuchos::ScalarTraits<Scalar> ST;
85 Scalar sumb = ST::zero();
86 for (
size_t i = 0; i < this->
numStages(); i++) sumb +=
b_(i);
87 TEUCHOS_TEST_FOR_EXCEPTION( std::abs(ST::one()-sumb) > 1.0e-08,
89 "Error - Butcher Tableau b fails to satisfy Sum(b_i) = 1.\n" 90 <<
" Sum(b_i) = " << sumb <<
"\n");
94 for (
size_t i = 0; i < this->
numStages(); i++) {
95 Scalar sumai = ST::zero();
96 for (
size_t j = 0; j < this->
numStages(); j++) sumai +=
A_(i,j);
98 if (std::abs(sumai) > 1.0e-08)
99 failed = (std::abs((sumai-
c_(i))/sumai) > 1.0e-08);
101 failed = (std::abs(
c_(i)) > 1.0e-08);
103 TEUCHOS_TEST_FOR_EXCEPTION( failed, std::runtime_error,
104 "Error - Butcher Tableau fails to satisfy c_i = Sum_j(a_ij).\n" 105 <<
" Stage i = " << i <<
"\n" 106 <<
" c_i = " <<
c_(i) <<
"\n" 107 <<
" Sum_j(a_ij) = " << sumai <<
"\n" 108 <<
" This may be OK as some valid tableaus do not satisfy\n" 109 <<
" this condition. If so, construct this RKButcherTableau\n" 110 <<
" with checkC = false.\n");
114 if (
bstar.length() > 0 ) {
126 virtual const Teuchos::SerialDenseMatrix<int,Scalar>&
A()
const 129 virtual const Teuchos::SerialDenseVector<int,Scalar>&
b()
const 132 virtual const Teuchos::SerialDenseVector<int,Scalar>&
bstar()
const 135 virtual const Teuchos::SerialDenseVector<int,Scalar>&
c()
const 155 const Teuchos::EVerbosityLevel verbLevel)
const 157 if (verbLevel != Teuchos::VERB_NONE) {
159 out <<
"number of Stages = " << this->
numStages() << std::endl;
160 out <<
"A = " << printMat(this->
A()) << std::endl;
161 out <<
"b = " << printMat(this->
b()) << std::endl;
162 out <<
"c = " << printMat(this->
c()) << std::endl;
163 out <<
"bstar = " << printMat(this->
bstar()) << std::endl;
164 out <<
"order = " << this->
order() << std::endl;
165 out <<
"orderMin = " << this->
orderMin() << std::endl;
166 out <<
"orderMax = " << this->
orderMax() << std::endl;
167 out <<
"isImplicit = " << this->
isImplicit() << std::endl;
168 out <<
"isDIRK = " << this->
isDIRK() << std::endl;
169 out <<
"isEmbedded = " << this->
isEmbedded() << std::endl;
175 const Scalar relTol = 1.0e-15;
176 if (
A_->numRows() != t.
A_->numRows() ||
177 A_->numCols() != t.
A_->numCols() ) {
181 for(i = 0; i <
A_->numRows(); i++) {
182 for(j = 0; j <
A_->numCols(); j++) {
183 if(std::abs((t.
A_(i,j) -
A_(i,j))/
A_(i,j)) > relTol)
return false;
188 if (
b_->length() != t.
b_->length() ||
189 b_->length() != t.
c_->length() ||
190 b_->length() != t.
bstar_->length() ) {
194 for(i = 0; i <
A_->numRows(); i++) {
195 if(std::abs((t.
b_(i) -
b_(i))/
b_(i)) > relTol)
return false;
196 if(std::abs((t.
c_(i) -
c_(i))/
c_(i)) > relTol)
return false;
204 return !((*this) == t);
215 for (
size_t i = 0; i < this->
numStages(); i++)
216 for (
size_t j = i; j < this->
numStages(); j++)
223 bool nonZero =
false;
224 for (
size_t i = 0; i < this->
numStages(); i++) {
225 if (
A_(i,i) != 0.0) nonZero =
true;
226 for (
size_t j = i+1; j < this->
numStages(); j++)
229 if (nonZero ==
false)
isDIRK_ =
false;
234 Teuchos::SerialDenseMatrix<int,Scalar>
A_;
235 Teuchos::SerialDenseVector<int,Scalar>
b_;
236 Teuchos::SerialDenseVector<int,Scalar>
c_;
243 Teuchos::SerialDenseVector<int,Scalar>
bstar_;
250 #endif // Tempus_RKButcherTableau_hpp virtual const Teuchos::SerialDenseVector< int, Scalar > & b() const
Return the vector of quadrature weights.
Teuchos::SerialDenseMatrix< int, Scalar > A_
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
virtual bool isDIRK() const
Return true if the RK method is Diagonally Implicit.
virtual int orderMax() const
Return the maximum order.
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)
bool operator==(const RKButcherTableau &t) const
Teuchos::SerialDenseVector< int, Scalar > bstar_
virtual const Teuchos::SerialDenseVector< int, Scalar > & bstar() const
Return the vector of quadrature weights for embedded methods.
virtual bool isEmbedded() const
Return true if the RK method has embedded capabilities.
virtual const Teuchos::SerialDenseMatrix< int, Scalar > & A() const
Return the matrix coefficients.
virtual bool isImplicit() const
Return true if the RK method is implicit.
virtual std::string description() const
virtual const Teuchos::SerialDenseVector< int, Scalar > & c() const
Return the vector of stage positions.
void set_isDIRK()
DIRK is defined as if a_ij = 0 for j>i and a_ii != 0 for at least one i.
Teuchos::SerialDenseVector< int, Scalar > b_
virtual std::size_t numStages() const
Return the number of stages.
virtual int order() const
Return the order.
virtual int orderMin() const
Return the minimum order.
Teuchos::SerialDenseVector< int, Scalar > c_
bool operator!=(const RKButcherTableau &t) const