Rythmos_RKButcherTableau.hpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef RYTHMOS_RK_BUTCHER_TABLEAU_HPP
00031 #define RYTHMOS_RK_BUTCHER_TABLEAU_HPP
00032
00033
00034 #include "Rythmos_Types.hpp"
00035 #include "Thyra_ProductVectorBase.hpp"
00036 #include "Thyra_VectorStdOps.hpp"
00037 #include "Teuchos_as.hpp"
00038 #include "Teuchos_SerialDenseMatrix.hpp"
00039 #include "Teuchos_SerialDenseVector.hpp"
00040 #include "Teuchos_Assert.hpp"
00041
00042
00043 namespace Rythmos {
00044
00045
00046
00047 template<class Scalar>
00048 class RKButcherTableau {
00049 public:
00051 RKButcherTableau()
00052 {}
00054 RKButcherTableau(
00055 const Teuchos::SerialDenseMatrix<int,Scalar>& A,
00056 const Teuchos::SerialDenseVector<int,Scalar>& b,
00057 const Teuchos::SerialDenseVector<int,Scalar>& c
00058 )
00059 : A_(A), b_(b), c_(c)
00060 {
00061 const int numStages = A.numRows();
00062 TEUCHOS_ASSERT_EQUALITY( A.numRows(), numStages );
00063 TEUCHOS_ASSERT_EQUALITY( A.numCols(), numStages );
00064 TEUCHOS_ASSERT_EQUALITY( b.length(), numStages );
00065 TEUCHOS_ASSERT_EQUALITY( c.length(), numStages );
00066 }
00068 int numStages() const { return A_.numRows(); }
00070 const Teuchos::SerialDenseMatrix<int,Scalar>& A() const { return A_; }
00072 const Teuchos::SerialDenseVector<int,Scalar> b() const { return b_; }
00074 const Teuchos::SerialDenseVector<int,Scalar> c() const { return c_; }
00075 private:
00076 Teuchos::SerialDenseMatrix<int,Scalar> A_;
00077 Teuchos::SerialDenseVector<int,Scalar> b_;
00078 Teuchos::SerialDenseVector<int,Scalar> c_;
00079 };
00080
00081
00082
00083 template<class Scalar>
00084 void assembleIRKState(
00085 const int stageIndex,
00086 const Teuchos::SerialDenseMatrix<int,Scalar> &A,
00087 const Scalar dt,
00088 const Thyra::VectorBase<Scalar> &x_base,
00089 const Thyra::ProductVectorBase<Scalar> &x_stage_bar,
00090 Teuchos::Ptr<Thyra::VectorBase<Scalar> > x_out_ptr
00091 )
00092 {
00093
00094 typedef ScalarTraits<Scalar> ST;
00095
00096 const int numStages = A.numRows();
00097 TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE( stageIndex, 0, numStages );
00098 TEUCHOS_ASSERT_EQUALITY( A.numRows(), numStages );
00099 TEUCHOS_ASSERT_EQUALITY( A.numCols(), numStages );
00100 TEUCHOS_ASSERT_EQUALITY( x_stage_bar.productSpace()->numBlocks(), numStages );
00101 Thyra::VectorBase<Scalar>& x_out = *x_out_ptr;
00102
00103 V_V( outArg(x_out), x_base );
00104 for ( int j = 0; j < numStages; ++j ) {
00105 Vp_StV( outArg(x_out), dt * A(stageIndex,j), *x_stage_bar.getVectorBlock(j) );
00106 }
00107
00108 }
00109
00110
00111
00112 template<class Scalar>
00113 void assembleIRKSolution(
00114 const Teuchos::SerialDenseVector<int,Scalar> &b,
00115 const Scalar dt,
00116 const Thyra::VectorBase<Scalar> &x_base,
00117 const Thyra::ProductVectorBase<Scalar> &x_stage_bar,
00118 Teuchos::Ptr<Thyra::VectorBase<Scalar> > x_out_ptr
00119 )
00120 {
00121
00122 typedef ScalarTraits<Scalar> ST;
00123
00124 const int numStages = b.length();
00125 TEUCHOS_ASSERT_EQUALITY( b.length(), numStages );
00126 TEUCHOS_ASSERT_EQUALITY( x_stage_bar.productSpace()->numBlocks(), numStages );
00127 Thyra::VectorBase<Scalar>& x_out = *x_out_ptr;
00128
00129 V_V( outArg(x_out), x_base );
00130 for ( int j = 0; j < numStages; ++j ) {
00131 Vp_StV( outArg(x_out), dt * b(j), *x_stage_bar.getVectorBlock(j) );
00132 }
00133
00134 }
00135
00136
00137
00138 }
00139
00140
00141 #endif // RYTHMOS_RK_BUTCHER_TABLEAU_HPP