Rythmos_RKButcherTableau.hpp

00001 //@HEADER
00002 // ***********************************************************************
00003 //
00004 //                           Rythmos Package
00005 //                 Copyright (2006) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Todd S. Coffey (tscoffe@sandia.gov)
00025 //
00026 // ***********************************************************************
00027 //@HEADER
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 /* \brief . */
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 /* \brief . */
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 /* \brief . */
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 } // namespace Rythmos
00139 
00140 
00141 #endif // RYTHMOS_RK_BUTCHER_TABLEAU_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends

Generated on Tue Oct 20 10:24:09 2009 for Rythmos - Transient Integration for Differential Equations by  doxygen 1.6.1