5#include <unordered_map>
32template<
class real_type>
47 std::vector<real_type>& a_v,
const std::vector<real_type>& b_v,
48 const std::vector<real_type>& c_v): m_steps(
steps), m_order(
order),
49 m_a(a_v), m_b(b_v), m_c(c_v){
51 m_c.assign(
steps+1, 0);
53 m_b.assign(
steps, 0);
61 real_type
a(
unsigned i){
return m_a[i];}
67 real_type
ex(
unsigned i){
return m_b[i];}
73 real_type
im(
unsigned i){
return m_c[i];}
84 for(
unsigned i=0; i<m_steps; i++)
91 for(
unsigned i=0; i<m_steps+1; i++)
97 unsigned m_steps, m_order;
98 std::vector<real_type> m_a, m_b, m_c;
104template<
class real_type>
105MultistepTableau<real_type> imex_euler_1_1()
107 unsigned steps = 1, order = 1;
108 std::vector<real_type> a(steps,0), b(steps, 0), c(steps+1,0);
109 a[0] = b[0] = c[0] = 1;
110 return MultistepTableau<real_type>( steps, order, a, b, c);
112template<
class real_type>
113MultistepTableau<real_type> imex_adams_2_2()
117 unsigned steps = 2, order = 2;
118 std::vector<real_type> a(steps,0), b(steps, 0), c(steps+1,0);
125 return MultistepTableau<real_type>( steps, order, a, b, c);
127template<
class real_type>
128MultistepTableau<real_type> imex_adams_3_3()
132 unsigned steps = 3, order = 3;
133 std::vector<real_type> a(steps,0), b(steps, 0), c(steps+1,0);
139 c[1] = 15551./30000.;
141 c[3] = -1483./30000.;
142 return MultistepTableau<real_type>( steps, order, a, b, c);
144template<
class real_type>
145MultistepTableau<real_type> imex_koto_2_2()
148 unsigned steps = 2, order = 2;
149 std::vector<real_type> am(steps,0), bm(steps, 0), cm(steps+1,0);
150 std::vector<real_type> ap(steps+1,0), bp(steps+1, 0), cp(steps+1,0);
152 real_type a = 20., b = 20.;
161 am[0] = -ap[1]/a, am[1] = -ap[2]/a;
162 bm[0] = bp[1]/a, bm[1] = bp[2]/a;
163 cm[0] = cp[0]/a, cm[1] = cp[1]/a, cm[2] = cp[2]/a;
164 return MultistepTableau<real_type>( steps, order, am, bm, cm);
167template<
class real_type>
168MultistepTableau<real_type> imex_bdf(
unsigned steps)
170 unsigned order = steps;
171 std::vector<real_type> a(steps,0), b(steps, 0), c(steps+1,0);
176 a[0] = 4./3.; b[0] = 4./3.;
177 a[1] = -1./3.; b[1] = -2./3.;
183 a[0] = 18./11.; b[0] = 18./11.;
184 a[1] = -9./11.; b[1] = -18./11.;
185 a[2] = 2./11.; b[2] = 6./11.;
190 a[0] = 48./25.; b[0] = 48./25.;
191 a[1] = -36./25.; b[1] = -72./25.;
192 a[2] = 16./25.; b[2] = 48./25.;
193 a[3] = - 3./25.; b[3] = -12./25.;
198 a[0] = 300./137.; b[0] = 300./137.;
199 a[1] = -300./137.; b[1] = -600./137.;
200 a[2] = 200./137.; b[2] = 600./137.;
201 a[3] = -75./137.; b[3] = -300./137.;
202 a[4] = 12./137.; b[4] = 60./137.;
206 a = {360./147.,-450./147.,400./147.,-225./147.,72./147.,-10./147.};
207 b = {360./147.,-900./147.,1200./147.,-900./147.,360./147.,-60./147.};
211 return MultistepTableau<real_type>( steps, order, a, b, c);
214template<
class real_type>
215MultistepTableau<real_type> imex_tvb(
unsigned steps)
217 unsigned order = steps;
218 std::vector<real_type> a(steps,0), b(steps, 0), c(steps+1,0);
223 a[0] = 3909./2048.; b[0] = 18463./12288.;
224 a[1] = -1367./1024.; b[1] = -1271./768.;
225 a[2] = 873./2048.; b[2] = 8233./12288.;
227 c[1] = -1139./12288.;
233 a[0] = 21531./8192.; b[0] = 13261./8192.;
234 a[1] = -22753./8192.; b[1] = -75029./24576.;
235 a[2] = 12245./8192.; b[2] = 54799./24576.;
236 a[3] = -2831./8192. ; b[3] = -15245./24576.;
245 a[0] = 13553./4096.; b[0] = 10306951./5898240.;
246 a[1] = -38121./8192.; b[1] = -13656497./2949120.;
247 a[2] = 7315./2048.; b[2] = 1249949./245760.;
248 a[3] = -6161/4096. ; b[3] = -7937687./2949120.;
249 a[4] = 2269./8192.; b[4] = 3387361./5898240.;
251 c[1] = -4118249./5898240.;
252 c[2] = 768703./2949120.;
253 c[3] = 47849./245760.;
254 c[4] = -725087./2949120.;
255 c[5] = 502321./5898240.;
258 return MultistepTableau<real_type>( steps, order, a, b, c);
261template<
class real_type>
262MultistepTableau<real_type> ab(
unsigned order)
264 unsigned steps = order;
265 std::vector<real_type> a(steps,0), b(steps, 0), c(steps+1,0);
268 case 1: b = {1};
break;
269 case 2: b = {1.5, -0.5};
break;
270 case 3: b = { 23./12., -4./3., 5./12.};
break;
271 case 4: b = {55./24., -59./24., 37./24., -3./8.};
break;
272 case 5: b = { 1901./720., -1387./360., 109./30., -637./360., 251./720.};
break;
273 default:
throw dg::Error(
dg::Message()<<
"Order "<<order<<
" not implemented in AdamsBashforth!");
275 return MultistepTableau<real_type>( steps, order, a, b, c);
278template<
class real_type>
279MultistepTableau<real_type> tvb(
unsigned steps)
281 unsigned order = steps;
282 std::vector<real_type> a(steps,0), b(steps, 0), c(steps+1,0);
289 b = {4./3., -2./3.};
break;
291 a[0] = 1.908535476882378; b[0] = 1.502575553858997;
292 a[1] = -1.334951446162515; b[1] = -1.654746338401493;
293 a[2] = 0.426415969280137; b[2] = 0.670051276940255;
296 a[0] = 2.628241000683208; b[0] = 1.618795874276609;
297 a[1] = -2.777506277494861; b[1] = -3.052866947601049;
298 a[2] = 1.494730011212510; b[2] = 2.229909318681302;
299 a[3] = -0.345464734400857; b[3] = -0.620278703629274;
302 a[0] = 3.308891758551210; b[0] = 1.747442076919292;
303 a[1] = -4.653490937946655; b[1] = -4.630745565661800;
304 a[2] = 3.571762873789854; b[2] = 5.086056171401077;
305 a[3] = -1.504199914126327; b[3] = -2.691494591660196;
306 a[4] = 0.277036219731918; b[4] = 0.574321855183372;
309 a[0] = 4.113382628475685; b[0] = 1.825457674048542;
310 a[1] = -7.345730559324184; b[1] = -6.414174588309508;
311 a[2] = 7.393648314992094; b[2] = 9.591671249204753;
312 a[3] = -4.455158576186636; b[3] = -7.583521888026967;
313 a[4] = 1.523638279938299; b[4] = 3.147082225022105;
314 a[5] = -0.229780087895259; b[5] = -0.544771649561925;
318 return MultistepTableau<real_type>( steps, order, a, b, c);
320template<
class real_type>
321MultistepTableau<real_type> ssp(
unsigned steps)
323 std::vector<real_type> a(steps,0), b(steps, 0), c(steps+1,0);
331 b = {8./5., -2./5.};
break;
333 a = { 3./4., 0., 1./4.};
334 b = { 3./2., 0., 0. };
break;
336 a = {8./9., 0., 0., 1./9.};
337 b = {4./3., 0., 0., 0.};
break;
339 a = {25./32., 0., 0., 0., 7./32.};
340 b = {25./16.,0.,0.,0.,5./16.};
break;
342 a = {108./125.,0.,0.,0.,0.,17./125.};
343 b = {36./25.,0.,0.,0.,0.,6./25.};
break;
346 return MultistepTableau<real_type>( steps, order, a, b, c);
413static std::unordered_map<std::string, enum multistep_identifier> str2lmsid{
463 if( str2lmsid.find(name) == str2lmsid.end())
466 return str2lmsid[name];
470 for(
auto name: str2lmsid)
472 if( name.second ==
id)
478template<
class real_type>
483 return dg::tableau::imex_euler_1_1<real_type>();
485 return dg::tableau::imex_adams_2_2<real_type>();
487 return dg::tableau::imex_adams_3_3<real_type>();
489 return dg::tableau::imex_koto_2_2<real_type>();
491 return dg::tableau::imex_bdf<real_type>(2);
493 return dg::tableau::imex_bdf<real_type>(3);
495 return dg::tableau::imex_bdf<real_type>(4);
497 return dg::tableau::imex_bdf<real_type>(5);
499 return dg::tableau::imex_bdf<real_type>(6);
501 return dg::tableau::imex_tvb<real_type>(3);
503 return dg::tableau::imex_tvb<real_type>(4);
505 return dg::tableau::imex_tvb<real_type>(5);
507 return dg::tableau::ab<real_type>(1);
509 return dg::tableau::ab<real_type>(2);
511 return dg::tableau::ab<real_type>(3);
513 return dg::tableau::ab<real_type>(4);
515 return dg::tableau::ab<real_type>(5);
517 return dg::tableau::imex_euler_1_1<real_type>();
519 return dg::tableau::imex_bdf<real_type>(2);
521 return dg::tableau::imex_bdf<real_type>(3);
523 return dg::tableau::imex_bdf<real_type>(4);
525 return dg::tableau::imex_bdf<real_type>(5);
527 return dg::tableau::imex_bdf<real_type>(6);
529 return dg::tableau::imex_euler_1_1<real_type>();
531 return dg::tableau::tvb<real_type>(2);
533 return dg::tableau::tvb<real_type>(3);
535 return dg::tableau::tvb<real_type>(4);
537 return dg::tableau::tvb<real_type>(5);
539 return dg::tableau::tvb<real_type>(6);
541 return dg::tableau::ssp<real_type>(1);
543 return dg::tableau::ssp<real_type>(2);
545 return dg::tableau::ssp<real_type>(3);
547 return dg::tableau::ssp<real_type>(4);
549 return dg::tableau::ssp<real_type>(5);
551 return dg::tableau::ssp<real_type>(6);
553 return dg::tableau::imex_euler_1_1<real_type>();
555 return dg::tableau::imex_bdf<real_type>(2);
557 return dg::tableau::imex_bdf<real_type>(3);
559 return dg::tableau::imex_bdf<real_type>(4);
561 return dg::tableau::imex_bdf<real_type>(5);
563 return dg::tableau::imex_bdf<real_type>(6);
565 return MultistepTableau<real_type>();
569template<
class real_type>
570MultistepTableau<real_type> lmstableau( std::string name)
572 return lmstableau<real_type>( str2lmstableau(name));
649template<
class real_type>
674 dg::create::lmstableau<real_type>(name)){}
678 dg::create::lmstableau<real_type>(std::string(name))){}
class intended for the use in throw statements
Definition: exceptions.h:83
small class holding a stringstream
Definition: exceptions.h:29
#define _ping_
Definition: exceptions.h:12
tableau_identifier
Identifiers for Butcher Tableaus.
Definition: tableau.h:1328
multistep_identifier
Identifiers for Multistep Tableaus.
Definition: multistep_tableau.h:363
@ AB_5_5
Definition: multistep_tableau.h:382
@ IMEX_BDF_6_6
Definition: multistep_tableau.h:373
@ IMEX_TVB_5_5
Definition: multistep_tableau.h:376
@ BDF_6_6
Definition: multistep_tableau.h:407
@ SSP_2_2
Definition: multistep_tableau.h:396
@ eBDF_4_4
Definition: multistep_tableau.h:386
@ BDF_2_2
Definition: multistep_tableau.h:403
@ BDF_5_5
Definition: multistep_tableau.h:406
@ SSP_3_2
Definition: multistep_tableau.h:397
@ TVB_4_4
Definition: multistep_tableau.h:392
@ IMEX_KOTO_2_2
Definition: multistep_tableau.h:368
@ SSP_4_2
Definition: multistep_tableau.h:398
@ eBDF_5_5
Definition: multistep_tableau.h:387
@ IMEX_ADAMS_3_3
Definition: multistep_tableau.h:367
@ TVB_1_1
Definition: multistep_tableau.h:389
@ eBDF_1_1
Definition: multistep_tableau.h:383
@ eBDF_3_3
Definition: multistep_tableau.h:385
@ TVB_3_3
Definition: multistep_tableau.h:391
@ SSP_1_1
Definition: multistep_tableau.h:395
@ IMEX_TVB_3_3
Definition: multistep_tableau.h:374
@ AB_4_4
Definition: multistep_tableau.h:381
@ eBDF_6_6
Definition: multistep_tableau.h:388
@ BDF_3_3
Definition: multistep_tableau.h:404
@ IMEX_EULER_1_1
Definition: multistep_tableau.h:365
@ AB_3_3
Definition: multistep_tableau.h:380
@ AB_2_2
Definition: multistep_tableau.h:379
@ IMEX_BDF_5_5
Definition: multistep_tableau.h:372
@ IMEX_ADAMS_2_2
Definition: multistep_tableau.h:366
@ BDF_4_4
Definition: multistep_tableau.h:405
@ IMEX_TVB_4_4
Definition: multistep_tableau.h:375
@ SSP_5_3
Definition: multistep_tableau.h:399
@ AB_1_1
Definition: multistep_tableau.h:378
@ eBDF_2_2
Definition: multistep_tableau.h:384
@ BDF_1_1
Definition: multistep_tableau.h:402
@ TVB_2_2
Definition: multistep_tableau.h:390
@ SSP_6_3
Definition: multistep_tableau.h:400
@ TVB_5_5
Definition: multistep_tableau.h:393
@ IMEX_BDF_2_2
Definition: multistep_tableau.h:369
@ TVB_6_6
Definition: multistep_tableau.h:394
@ IMEX_BDF_3_3
Definition: multistep_tableau.h:370
@ IMEX_BDF_4_4
Definition: multistep_tableau.h:371
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
Convert identifiers to their corresponding dg::MultistepTableau.
Definition: multistep_tableau.h:651
ConvertsToMultistepTableau(enum tableau_identifier id)
Create MultistepTableau from dg::tableau_identifier.
Definition: multistep_tableau.h:662
ConvertsToMultistepTableau(std::string name)
Create MultistepTableau from its name (very useful)
Definition: multistep_tableau.h:673
real_type value_type
Definition: multistep_tableau.h:652
ConvertsToMultistepTableau(const char *name)
Create MultistepTableau from its name (very useful)
Definition: multistep_tableau.h:677
ConvertsToMultistepTableau(MultistepTableau< real_type > tableau)
Definition: multistep_tableau.h:655
Manage coefficients of Multistep methods.
Definition: multistep_tableau.h:34
unsigned steps() const
The number of stages s.
Definition: multistep_tableau.h:75
bool isImplicit() const
True if any of the implicit coefficients c_i are non-zero.
Definition: multistep_tableau.h:90
real_type a(unsigned i)
Read the a_i coefficients.
Definition: multistep_tableau.h:61
real_type ex(unsigned i)
Read the explicit (b_i) coefficients.
Definition: multistep_tableau.h:67
unsigned order() const
global order of accuracy for the method
Definition: multistep_tableau.h:79
real_type im(unsigned i)
Read the implicit (c_i) coefficients.
Definition: multistep_tableau.h:73
MultistepTableau()
No memory allocation.
Definition: multistep_tableau.h:37
real_type value_type
Definition: multistep_tableau.h:35
MultistepTableau(unsigned steps, unsigned order, const std::vector< real_type > &a_v, const std::vector< real_type > &b_v, const std::vector< real_type > &c_v)
Construct a tableau.
Definition: multistep_tableau.h:46
bool isExplicit() const
True if any of the explicit coefficients b_i are non-zero.
Definition: multistep_tableau.h:83