/usr/include/CLHEP/GenericFunctions/ButcherTableau.icc is in libclhep-dev 2.1.4.1+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | namespace Genfun {
ButcherTableau::ButcherTableau(const std::string &xname, unsigned int xorder):_name(xname),_order(xorder){
}
const std::string & ButcherTableau::name() const {
return _name;
}
unsigned int ButcherTableau::order() const{
return _order;
}
unsigned int ButcherTableau::nSteps() const{
return _A.size();
}
// don't generate warnings about intentional shadowing
#if defined __GNUC__
#if __GNUC__ > 3 && __GNUC_MINOR__ > 6
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
#endif
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wshadow"
#endif
double & ButcherTableau::A(unsigned int i, unsigned int j) {
if (i>=_A.size()) {
unsigned int newSize=i+1; // (shadowed)
for (unsigned int ii=0;ii<_A.size();ii++) {
_A[ii].resize(newSize,0.0);
}
for (unsigned int ii=_A.size();ii<newSize;ii++) {
_A.push_back(std::vector<double>(newSize,0));
}
if (j>=_A[i].size()) {
unsigned int newSize=j+1; // (shadow)
for (unsigned int ii=0;ii<_A.size();ii++) {
_A[ii].resize(newSize,0.0);
}
}
}
return _A[i][j];
}
#if defined __GNUC__
#if __GNUC__ > 3 && __GNUC_MINOR__ > 6
#pragma GCC diagnostic pop
#endif
#endif
#ifdef __clang__
#pragma clang diagnostic pop
#endif
double & ButcherTableau::b(unsigned int i){
if (i>=_b.size()) _b.resize(i+1);
return _b[i];
}
double & ButcherTableau::c(unsigned int i){
if (i>=_c.size()) _c.resize(i+1);
return _c[i];
}
const double & ButcherTableau::A(unsigned int i, unsigned int j) const{
return _A[i][j];
}
const double & ButcherTableau::b(unsigned int i) const{
return _b[i];
}
const double & ButcherTableau::c(unsigned int i) const{
return _c[i];
}
}
std::ostream & operator << (std::ostream & o, const Genfun::ButcherTableau & b) {
o << "Name " << b.name() << " of order " << b.order() << std::endl;
o << "A" << std::endl;
for (unsigned int i=0;i<b.nSteps();i++) {
for (unsigned int j=0;j<b.nSteps();j++) {
o << b.A(i,j) << " ";
}
o << std::endl;
}
o<< std::endl;
o << "c" << std::endl;
for (unsigned int j=0;j<b.nSteps();j++) {
o << b.c(j) << std::endl;
}
o<< std::endl;
o << "b" << std::endl;
for (unsigned int j=0;j<b.nSteps();j++) {
o << b.b(j) << " ";
}
o << std::endl;
return o;
}
namespace Genfun {
EulerTableau::EulerTableau():
ButcherTableau("Euler Method", 1)
{
A(0,0)=0;
b(0)=1;
c(0)=1;
}
MidpointTableau::MidpointTableau():
ButcherTableau("Midpoint Method", 2)
{
A(1,0)=1/2.0;
c(0)=0;
c(1)=1/2.0;
b(0)=0;
b(1)=1;
}
TrapezoidTableau::TrapezoidTableau():
ButcherTableau("Trapezoid Method", 2)
{
A(1,0)=1;
c(0)=0;
c(1)=1;
b(0)=1/2.0;
b(1)=1/2.0;
}
RK31Tableau::RK31Tableau():
ButcherTableau("RK31 Method", 3)
{
A(0,0) ; A(0,1) ; A(0,2);
A(1,0)=2/3.0; A(1,1) ; A(1,2);
A(2,0)=1/3.0; A(2,1)=1/3.0; A(2,2);
c(0)=0;
c(1)=2/3.0;
c(2)=2/3.0;
b(0)=1/4.0;
b(1)=0;
b(2)=3/4.0;
}
RK32Tableau::RK32Tableau():
ButcherTableau("RK32 Method", 3)
{
A(0,0) ; A(0,1) ; A(0,2);
A(1,0)=1/2.0; A(1,1) ; A(1,2);
A(2,0)=-1 ; A(2,1)= 2 ; A(2,2);
c(0)=0;
c(1)=1/2.0;
c(2)=1;
b(0)=1/6.0;
b(1)=2/3.0;
b(2)=1/6.0;
}
ClassicalRungeKuttaTableau::ClassicalRungeKuttaTableau():
ButcherTableau("Classical Runge Kutta Method", 4)
{
A(0,0) ; A(0,1) ; A(0,2) ; A(0,3);
A(1,0)=1/2.0; A(1,1) ; A(1,2) ; A(1,3);
A(2,0)=0 ; A(2,1)=1/2.0 ; A(2,2) ; A(2,3);
A(3,0)=0 ; A(3,1)=0 ; A(3,2)=1 ; A(3,3);
c(0)=0;
c(1)=1/2.0;
c(2)=1/2.0;
c(3)=1;
b(0)=1/6.0;
b(1)=1/3.0;
b(2)=1/3.0;
b(3)=1/6.0;
}
ThreeEighthsRuleTableau::ThreeEighthsRuleTableau():
ButcherTableau("Three-Eighths Rule Method", 4)
{
A(0,0) ; A(0,1) ; A(0,2) ; A(0,3);
A(1,0)=1/3.0 ; A(1,1) ; A(1,2) ; A(1,3);
A(2,0)=-1/3.0 ; A(2,1)=1 ; A(2,2) ; A(2,3);
A(3,0)=1 ; A(3,1)=-1 ; A(3,2)=1 ; A(3,3);
c(0)=0;
c(1)=1/3.0;
c(2)=2/3.0;
c(3)=1;
b(0)=1/8.0;
b(1)=3/8.0;
b(2)=3/8.0;
b(3)=1/8.0;
}
}
|