Rythmos - Transient Integration for Differential Equations  Version of the Day
Rythmos_RKButcherTableauBase.hpp
1 //@HEADER
2 // ***********************************************************************
3 //
4 // Rythmos Package
5 // Copyright (2006) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23 // USA
24 // Questions? Contact Todd S. Coffey (tscoffe@sandia.gov)
25 //
26 // ***********************************************************************
27 //@HEADER
28 
29 
30 #ifndef RYTHMOS_RK_BUTCHER_TABLEAU_BASE_HPP
31 #define RYTHMOS_RK_BUTCHER_TABLEAU_BASE_HPP
32 
33 #include "Rythmos_Types.hpp"
34 #include "Teuchos_Describable.hpp"
35 #include "Teuchos_ParameterListAcceptor.hpp"
36 #include "Teuchos_VerboseObject.hpp"
37 #include "Teuchos_SerialDenseMatrix.hpp"
38 #include "Teuchos_SerialDenseVector.hpp"
39 
40 namespace Rythmos {
41 
42 /* \brief . */
43 template<class Scalar>
44 class RKButcherTableauBase :
45  virtual public Teuchos::Describable,
46  virtual public Teuchos::ParameterListAcceptor,
47  virtual public Teuchos::VerboseObject<RKButcherTableauBase<Scalar> >
48 {
49 public:
51  virtual int numStages() const = 0;
53  virtual const Teuchos::SerialDenseMatrix<int,Scalar>& A() const = 0;
55  virtual const Teuchos::SerialDenseVector<int,Scalar>& b() const = 0;
57  virtual const Teuchos::SerialDenseVector<int,Scalar>& c() const = 0;
59  virtual int order() const = 0;
61  virtual bool operator== (const RKButcherTableauBase<Scalar>& rkbt) const;
63  virtual void setDescription(std::string longDescription) = 0;
64 };
65 
66 
67 /* \brief . */
68 template<class Scalar>
69 bool RKButcherTableauBase<Scalar>::operator== (const RKButcherTableauBase<Scalar>& rkbt) const
70 {
71  if (this->numStages() != rkbt.numStages()) {
72  return false;
73  }
74  if (this->order() != rkbt.order()) {
75  return false;
76  }
77  int N = rkbt.numStages();
78  // Check b and c first:
79  const Teuchos::SerialDenseVector<int,Scalar> b_ = this->b();
80  const Teuchos::SerialDenseVector<int,Scalar> c_ = this->c();
81  const Teuchos::SerialDenseVector<int,Scalar> other_b = rkbt.b();
82  const Teuchos::SerialDenseVector<int,Scalar> other_c = rkbt.c();
83  for (int i=0 ; i<N ; ++i) {
84  if (b_(i) != other_b(i)) {
85  return false;
86  }
87  if (c_(i) != other_c(i)) {
88  return false;
89  }
90  }
91  // Then check A:
92  const Teuchos::SerialDenseMatrix<int,Scalar>& A_ = this->A();
93  const Teuchos::SerialDenseMatrix<int,Scalar>& other_A = rkbt.A();
94  for (int i=0 ; i<N ; ++i) {
95  for (int j=0 ; j<N ; ++j) {
96  if (A_(i,j) != other_A(i,j)) {
97  return false;
98  }
99  }
100  }
101  return true;
102 }
103 
104 } // namespace Rythmos
105 
106 
107 #endif // RYTHMOS_RK_BUTCHER_TABLEAU_BASE_HPP