This file is indexed.

/usr/include/deal.II/base/time_stepping.templates.h is in libdeal.ii-dev 8.4.2-2+b1.

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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
// ---------------------------------------------------------------------
//
// Copyright (C) 2014 - 2015 by the deal.II authors
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE at
// the top level of the deal.II distribution.
//
// ---------------------------------------------------------------------

#ifndef dealii__time_stepping_templates_h
#define dealii__time_stepping_templates_h

#include <deal.II/base/std_cxx11/bind.h>
#include <deal.II/base/exceptions.h>
#include <deal.II/base/time_stepping.h>

DEAL_II_NAMESPACE_OPEN

namespace TimeStepping
{
  // ----------------------------------------------------------------------
  // RungeKutta
  // ----------------------------------------------------------------------

  template <typename VectorType>
  double RungeKutta<VectorType>::evolve_one_time_step(
    std::vector<std_cxx11::function<VectorType (const double, const VectorType &)> > &F,
    std::vector<std_cxx11::function<VectorType (const double, const double, const VectorType &)> > &J_inverse,

    double t,
    double delta_t,
    VectorType &y)
  {
    AssertThrow(F.size()==0,
                ExcMessage("RungeKutta methods cannot handle more that one function to integate."));
    AssertThrow(J_inverse.size()==0,
                ExcMessage("RungeKutta methods cannot handle more that one function to integate."));

    return evolve_one_time_step(F[0],J_inverse[0],t,delta_t,y);
  }



  // ----------------------------------------------------------------------
  // ExplicitRungeKutta
  // ----------------------------------------------------------------------

  template <typename VectorType>
  ExplicitRungeKutta<VectorType>::ExplicitRungeKutta(runge_kutta_method method)
  {
    initialize(method);
  }



  template <typename VectorType>
  void ExplicitRungeKutta<VectorType>::initialize(runge_kutta_method method)
  {
    status.method = method;

    switch (method)
      {
      case (FORWARD_EULER) :
      {
        this->n_stages = 1;
        this->b.push_back(1.0);
        this->c.push_back(0.0);

        break;
      }
      case (RK_THIRD_ORDER) :
      {
        this->n_stages = 3;
        this->b.reserve(this->n_stages);
        this->c.reserve(this->n_stages);
        this->b.push_back(1.0/6.0);
        this->b.push_back(2.0/3.0);
        this->b.push_back(1.0/6.0);
        this->c.push_back(0.0);
        this->c.push_back(0.5);
        this->c.push_back(1.0);
        std::vector<double> tmp;
        this->a.push_back(tmp);
        tmp.resize(1);
        tmp[0] = 0.5;
        this->a.push_back(tmp);
        tmp.resize(2);
        tmp[0] = -1.0;
        tmp[1] = 2.0;
        this->a.push_back(tmp);

        break;
      }
      case (RK_CLASSIC_FOURTH_ORDER) :
      {
        this->n_stages = 4;
        this->b.reserve(this->n_stages);
        this->c.reserve(this->n_stages);
        std::vector<double> tmp;
        this->a.push_back(tmp);
        tmp.resize(1);
        tmp[0] = 0.5;
        this->a.push_back(tmp);
        tmp.resize(2);
        tmp[0] = 0.0;
        tmp[1] = 0.5;
        this->a.push_back(tmp);
        tmp.resize(3);
        tmp[1] = 0.0;
        tmp[2] = 1.0;
        this->a.push_back(tmp);
        this->b.push_back(1.0/6.0);
        this->b.push_back(1.0/3.0);
        this->b.push_back(1.0/3.0);
        this->b.push_back(1.0/6.0);
        this->c.push_back(0.0);
        this->c.push_back(0.5);
        this->c.push_back(0.5);
        this->c.push_back(1.0);

        break;
      }
      default :
      {
        AssertThrow(false,ExcMessage("Unimplemented explicit Runge-Kutta method."));
      }
      }
  }



  template <typename VectorType>
  double ExplicitRungeKutta<VectorType>::evolve_one_time_step
  (std_cxx11::function<VectorType (const double, const VectorType &)> f,
   std_cxx11::function<VectorType (const double, const double, const VectorType &)> /*id_minus_tau_J_inverse*/,
   double                                                             t,
   double                                                             delta_t,
   VectorType                                                         &y)
  {
    return evolve_one_time_step(f,t,delta_t,y);
  }



  template <typename VectorType>
  double ExplicitRungeKutta<VectorType>::evolve_one_time_step
  (std_cxx11::function<VectorType (const double, const VectorType &)> f,
   double                                                             t,
   double                                                             delta_t,
   VectorType                                                         &y)
  {
    std::vector<VectorType> f_stages(this->n_stages,y);
    // Compute the different stages needed.
    compute_stages(f,t,delta_t,y,f_stages);

    // Linear combinations of the stages.
    for (unsigned int i=0; i<this->n_stages; ++i)
      y.sadd(1.,delta_t *this->b[i],f_stages[i]);

    return (t+delta_t);
  }



  template <typename VectorType>
  const typename ExplicitRungeKutta<VectorType>::Status &ExplicitRungeKutta<VectorType>::get_status() const
  {
    return status;
  }



  template <typename VectorType>
  void ExplicitRungeKutta<VectorType>::compute_stages
  (std_cxx11::function<VectorType (const double, const VectorType &)> f,
   const double                                                       t,
   const double                                                       delta_t,
   const VectorType                                                   &y,
   std::vector<VectorType>                                            &f_stages) const
  {
    for (unsigned int i=0; i<this->n_stages; ++i)
      {
        VectorType Y(y);
        for (unsigned int j=0; j<i; ++j)
          Y.sadd(1.,delta_t *this->a[i][j],f_stages[j]);
        // Evaluate the function f at the point (t+c[i]*delta_t,Y).
        f_stages[i] = f(t+this->c[i]*delta_t,Y);
      }
  }



  // ----------------------------------------------------------------------
  // ImplicitRungeKutta
  // ----------------------------------------------------------------------

  template <typename VectorType>
  ImplicitRungeKutta<VectorType>::ImplicitRungeKutta(runge_kutta_method method,
                                                     unsigned int max_it,
                                                     double tolerance)
    :
    RungeKutta<VectorType> (),
    skip_linear_combi(false),
    max_it(max_it),
    tolerance(tolerance)
  {
    initialize(method);
  }



  template <typename VectorType>
  void ImplicitRungeKutta<VectorType>::initialize(runge_kutta_method method)
  {
    status.method = method;

    switch (method)
      {
      case (BACKWARD_EULER) :
      {
        this->n_stages = 1;
        this->a.push_back(std::vector<double>(1, 1.0));
        this->b.push_back(1.0);
        this->c.push_back(1.0);

        break;
      }
      case (IMPLICIT_MIDPOINT) :
      {
        this->a.push_back(std::vector<double>(1, 0.5));
        this->b.push_back(1.0);
        this->c.push_back(0.5);
        this->n_stages = 1;

        break;
      }
      case (CRANK_NICOLSON) :
      {
        this->n_stages = 2;
        this->b.reserve(this->n_stages);
        this->c.reserve(this->n_stages);
        this->a.push_back(std::vector<double>(1, 0.0));
        this->a.push_back(std::vector<double>(2, 0.5));
        this->b.push_back(0.5);
        this->b.push_back(0.5);
        this->c.push_back(0.0);
        this->c.push_back(1.0);

        break;
      }
      case (SDIRK_TWO_STAGES) :
      {
        this->n_stages = 2;
        this->b.reserve(this->n_stages);
        this->c.reserve(this->n_stages);
        double const gamma = 1.0 - 1.0 / std::sqrt(2.0);
        this->b.push_back(1.0 - gamma);
        this->b.push_back(gamma);
        this->a.push_back(std::vector<double>(1, gamma));
        this->a.push_back(this->b);
        this->c.push_back(gamma);
        this->c.push_back(1.0);

        break;
      }
      default :
      {
        AssertThrow(false,ExcMessage("Unimplemented implicit Runge-Kutta method."));
      }
      }
  }



  template <typename VectorType>
  double ImplicitRungeKutta<VectorType>::evolve_one_time_step
  (std_cxx11::function<VectorType (const double, const VectorType &)> f,
   std_cxx11::function<VectorType (const double, const double, const VectorType &)> id_minus_tau_J_inverse,
   double                                                             t,
   double                                                             delta_t,
   VectorType                                                         &y)
  {
    VectorType old_y(y);
    std::vector<VectorType> f_stages(this->n_stages,y);
    // Compute the different stages needed.
    compute_stages(f,id_minus_tau_J_inverse,t,delta_t,y,f_stages);

    // If necessary, compute the linear combinations of the stages.
    if (skip_linear_combi==false)
      {
        y = old_y;
        for (unsigned int i=0; i<this->n_stages; ++i)
          y.sadd(1.,delta_t *this->b[i],f_stages[i]);
      }

    return (t+delta_t);
  }



  template <typename VectorType>
  void ImplicitRungeKutta<VectorType>::set_newton_solver_parameters(unsigned int max_it_, double tolerance_)
  {
    max_it = max_it_;
    tolerance = tolerance_;
  }



  template <typename VectorType>
  const typename ImplicitRungeKutta<VectorType>::Status &ImplicitRungeKutta<VectorType>::get_status() const
  {
    return status;
  }



  template <typename VectorType>
  void ImplicitRungeKutta<VectorType>::compute_stages(
    std_cxx11::function<VectorType (const double, const VectorType &)> f,
    std_cxx11::function<VectorType (const double, const double, const VectorType &)> id_minus_tau_J_inverse,
    double t,
    double delta_t,
    VectorType &y,
    std::vector<VectorType> &f_stages)
  {
    VectorType z(y);
    for (unsigned int i=0; i<this->n_stages; ++i)
      {
        VectorType old_y(z);
        for (unsigned int j=0; j<i; ++j)
          old_y.sadd(1.,delta_t *this->a[i][j],f_stages[j]);

        // Solve the nonlinear system using Newton's method
        const double new_t = t+this->c[i]*delta_t;
        const double new_delta_t = this->a[i][i]*delta_t;
        newton_solve(std_cxx11::bind(&ImplicitRungeKutta<VectorType>::compute_residual,this,f,new_t,new_delta_t,
                                     std_cxx11::cref(old_y),std_cxx11::_1,std_cxx11::ref(f_stages[i]),std_cxx11::_2),
                     std_cxx11::bind(id_minus_tau_J_inverse,new_t,new_delta_t,std_cxx11::_1),y);
      }
  }



  template <typename VectorType>
  void ImplicitRungeKutta<VectorType>::newton_solve(
    std_cxx11::function<void (const VectorType &,VectorType &)> get_residual,
    std_cxx11::function<VectorType (const VectorType &)> id_minus_tau_J_inverse,
    VectorType &y)
  {
    VectorType residual(y);
    get_residual(y,residual);
    unsigned int i=0;
    const double initial_residual_norm = residual.l2_norm();
    double norm_residual = initial_residual_norm;
    while (i<max_it)
      {
        y.sadd(1.0,-1.0,id_minus_tau_J_inverse(residual));
        get_residual(y,residual);
        norm_residual = residual.l2_norm();
        if (norm_residual < tolerance)
          break;
        ++i;
      }
    status.n_iterations = i+1;
    status.norm_residual = norm_residual;
  }



  template <typename VectorType>
  void ImplicitRungeKutta<VectorType>::compute_residual
  (std_cxx11::function<VectorType (const double, const VectorType &)> f,
   double                                                             t,
   double                                                             delta_t,
   const VectorType                                                   &old_y,
   const VectorType                                                   &y,
   VectorType                                                         &tendency,
   VectorType                                                         &residual) const
  {
    // The tendency is stored to save one evaluation of f.
    tendency = f(t,y);
    residual = tendency;
    residual.sadd(delta_t,1.0,old_y);
    residual.sadd(-1.0,1.,y);
  }



  // ----------------------------------------------------------------------
  // EmbeddedExplicitRungeKutta
  // ----------------------------------------------------------------------

  template <typename VectorType>
  EmbeddedExplicitRungeKutta<VectorType>::EmbeddedExplicitRungeKutta
  (runge_kutta_method method,
   double             coarsen_param,
   double             refine_param,
   double             min_delta,
   double             max_delta,
   double             refine_tol,
   double             coarsen_tol)
    :
    coarsen_param(coarsen_param),
    refine_param(refine_param),
    min_delta_t(min_delta),
    max_delta_t(max_delta),
    refine_tol(refine_tol),
    coarsen_tol(coarsen_tol),
    last_same_as_first(false),
    last_stage(NULL)
  {
    initialize(method);
  }



  template <typename VectorType>
  void EmbeddedExplicitRungeKutta<VectorType>::initialize(runge_kutta_method method)
  {
    status.method = method;

    switch (method)
      {
      case (HEUN_EULER) :
      {
        this->n_stages = 2;
        this->a.push_back(std::vector<double>());
        this->a.push_back(std::vector<double>(1, 1.0));
        this->c.push_back(0.0);
        this->c.push_back(1.0);
        b1.push_back(0.5);
        b1.push_back(0.5);
        b2.push_back(1.0);
        b2.push_back(0.0);

        break;
      }
      case (BOGACKI_SHAMPINE) :
      {
        last_same_as_first = true;
        this->n_stages = 4;
        this->c.reserve(this->n_stages);
        this->b1.reserve(this->n_stages);
        this->b2.reserve(this->n_stages);
        std::vector<double> tmp;
        this->a.push_back(tmp);
        tmp.resize(1);
        tmp[0] = 0.5;
        this->a.push_back(tmp);
        tmp.resize(2);
        tmp[0] = 0.0;
        tmp[1] = 0.75;
        this->a.push_back(tmp);
        tmp.resize(3);
        tmp[0] = 2.0/9.0;
        tmp[1] = 1.0/3.0;
        tmp[2] = 4.0/9.0;
        this->a.push_back(tmp);
        this->c.push_back(0.0);
        this->c.push_back(0.5);
        this->c.push_back(0.75);
        this->c.push_back(1.0);
        this->b1.push_back(2.0/9.0);
        this->b1.push_back(1.0/3.0);
        this->b1.push_back(4.0/9.0);
        this->b1.push_back(0.0);
        this->b2.push_back(7.0/24.0);
        this->b2.push_back(0.25);
        this->b2.push_back(1.0/3.0);
        this->b2.push_back(0.125);

        break;
      }
      case (DOPRI) :
      {
        last_same_as_first = true;
        this->n_stages = 7;
        this->c.reserve(this->n_stages);
        this->b1.reserve(this->n_stages);
        this->b2.reserve(this->n_stages);
        std::vector<double> tmp;
        this->a.push_back(tmp);
        tmp.resize(1);
        tmp[0] = 1./5.;
        this->a.push_back(tmp);
        tmp.resize(2);
        tmp[0] = 3./40.;
        tmp[1] = 9./40.;
        this->a.push_back(tmp);
        tmp.resize(3);
        tmp[0] = 44./45.;
        tmp[1] = -56./15.;
        tmp[2] = 32./9.;
        this->a.push_back(tmp);
        tmp.resize(4);
        tmp[0] = 19372./6561.;
        tmp[1] = -25360./2187.;
        tmp[2] = 64448./6561.;
        tmp[3] = -212./729.;
        this->a.push_back(tmp);
        tmp.resize(5);
        tmp[0] = 9017./3168.;
        tmp[1] = -355./33.;
        tmp[2] = 46732./5247.;
        tmp[3] = 49./176.;
        tmp[4] = -5103./18656;
        this->a.push_back(tmp);
        tmp.resize(6);
        tmp[0] = 35./384.;
        tmp[1] = 0.;
        tmp[2] = 500./1113.;
        tmp[3] = 125./192.;
        tmp[4] = -2187./6784.;
        tmp[5] = 11./84.;
        this->a.push_back(tmp);
        this->c.push_back(0.);
        this->c.push_back(1./5.);
        this->c.push_back(3./10.);
        this->c.push_back(4./5.);
        this->c.push_back(8./9.);
        this->c.push_back(1.);
        this->c.push_back(1.);
        this->b1.push_back(35./384.);
        this->b1.push_back(0.);
        this->b1.push_back(500./1113.);
        this->b1.push_back(125./192.);
        this->b1.push_back(-2187./6784.);
        this->b1.push_back(11./84.);
        this->b1.push_back(0.);
        this->b2.push_back(5179./57600.);
        this->b2.push_back(0.);
        this->b2.push_back(7571./16695.);
        this->b2.push_back(393./640.);
        this->b2.push_back(-92097./339200.);
        this->b2.push_back(187./2100.);
        this->b2.push_back(1./40.);

        break;
      }
      case (FEHLBERG) :
      {
        this->n_stages = 6;
        this->c.reserve(this->n_stages);
        this->b1.reserve(this->n_stages);
        this->b2.reserve(this->n_stages);
        std::vector<double> tmp;
        this->a.push_back(tmp);
        tmp.resize(1);
        tmp[0] = 0.25;
        this->a.push_back(tmp);
        tmp.resize(2);
        tmp[0] = 0.09375;
        tmp[1] = 0.28125;
        this->a.push_back(tmp);
        tmp.resize(3);
        tmp[0] = 1932.0/2197.0;
        tmp[1] = -7200.0/2197.0;
        tmp[2] = 7296.0/2197.0;
        this->a.push_back(tmp);
        tmp.resize(4);
        tmp[0] = 439.0/216.0;
        tmp[1] = -8.0;
        tmp[2] = 3680.0/513.0;
        tmp[3] = -845.0/4104.0;
        this->a.push_back(tmp);
        tmp.resize(5);
        tmp[0] = -8.0/27.0;
        tmp[1] = 2.0;
        tmp[2] = -3544.0/2565.0;
        tmp[3] = 1859.0/4104.0;
        tmp[4] = -0.275;
        this->a.push_back(tmp);
        this->c.push_back(0.0);
        this->c.push_back(0.25);
        this->c.push_back(0.375);
        this->c.push_back(12.0/13.0);
        this->c.push_back(1.0);
        this->c.push_back(0.5);
        this->b1.push_back(16.0/135.0);
        this->b1.push_back(0.0);
        this->b1.push_back(6656.0/12825.0);
        this->b1.push_back(28561.0/56430.0);
        this->b1.push_back(-0.18);
        this->b1.push_back(2.0/55.0);
        this->b2.push_back(25.0/216.0);
        this->b2.push_back(0.0);
        this->b2.push_back(1408.0/2565.0);
        this->b2.push_back(2197.0/4104.0);
        this->b2.push_back(-0.2);
        this->b2.push_back(0.0);

        break;
      }
      case (CASH_KARP) :
      {
        this->n_stages = 6;
        this->c.reserve(this->n_stages);
        this->b1.reserve(this->n_stages);
        this->b2.reserve(this->n_stages);
        std::vector<double> tmp;
        this->a.push_back(tmp);
        tmp.resize(1);
        tmp[0] = 0.2;
        this->a.push_back(tmp);
        tmp.resize(2);
        tmp[0] = 0.075;
        tmp[1] = 0.225;
        this->a.push_back(tmp);
        tmp.resize(3);
        tmp[0] = 0.3;
        tmp[1] = -0.9;
        tmp[2] = 1.2;
        this->a.push_back(tmp);
        tmp.resize(4);
        tmp[0] = -11.0/54.0;
        tmp[1] = 2.5;
        tmp[2] = -70.0/27.0;
        tmp[3] = 35.0/27.0;
        this->a.push_back(tmp);
        tmp.resize(5);
        tmp[0] = 1631.0/55296.0;
        tmp[1] = 175.0/512.0;
        tmp[2] = 575.0/13824.0;
        tmp[3] = 44275.0/110592.0;
        tmp[4] = 253.0/4096.0;
        this->a.push_back(tmp);
        this->c.push_back(0.0);
        this->c.push_back(0.2);
        this->c.push_back(0.3);
        this->c.push_back(0.6);
        this->c.push_back(1.0);
        this->c.push_back(0.875);
        this->b1.push_back(37.0/378.0);
        this->b1.push_back(0.0);
        this->b1.push_back(250.0/621.0);
        this->b1.push_back(125.0/594.0);
        this->b1.push_back(0.0);
        this->b1.push_back(512.0/1771.0);
        this->b2.push_back(2825.0/27648.0);
        this->b2.push_back(0.0);
        this->b2.push_back(18575.0/48384.0);
        this->b2.push_back(13525.0/55296.0);
        this->b2.push_back(277.0/14336.0);
        this->b2.push_back(0.25);

        break;
      }
      default :
      {
        AssertThrow(false,ExcMessage("Unimplemented Embedded Runge-Kutta method."));
      }
      }
  }



  template <typename VectorType>
  void EmbeddedExplicitRungeKutta<VectorType>::free_memory()
  {
    if (last_stage!=NULL)
      delete last_stage;

    last_stage = NULL;
  }



  template <typename VectorType>
  double EmbeddedExplicitRungeKutta<VectorType>::evolve_one_time_step(
    std_cxx11::function<VectorType (const double, const VectorType &)> f,
    std_cxx11::function<VectorType (const double, const double, const VectorType &)> /*id_minus_tau_J_inverse*/,
    double t,
    double delta_t,
    VectorType &y)
  {
    return evolve_one_time_step(f,t,delta_t,y);
  }



  template <typename VectorType>
  double EmbeddedExplicitRungeKutta<VectorType>::evolve_one_time_step(
    std_cxx11::function<VectorType (const double, const VectorType &)> f,
    double t, double delta_t, VectorType &y)
  {
    bool done = false;
    unsigned int count = 0;
    double error_norm = 0.;
    VectorType old_y(y);
    VectorType error(y);
    std::vector<VectorType> f_stages(this->n_stages,y);

    while (!done)
      {
        error = 0.;
        y = old_y;
        // Compute the different stages needed.
        compute_stages(f,t,delta_t,y,f_stages);

        for (unsigned int i=0; i<this->n_stages; ++i)
          {
            y.sadd(1.,delta_t *this->b1[i],f_stages[i]);
            error.sadd(1.,delta_t *(b2[i]-b1[i]),f_stages[i]);
          }

        error_norm = error.l2_norm();
        // Check if the norm of error is less than the coarsening tolerance
        if (error_norm<coarsen_tol)
          {
            done = true;
            // Increase the guessed time step
            double new_delta_t = delta_t *coarsen_param;
            // Check that the guessed time step is smaller than the maximum time
            // step allowed.
            if (new_delta_t>max_delta_t)
              {
                status.exit_delta_t = MAX_DELTA_T;
                status.delta_t_guess =  max_delta_t;
              }
            else
              {
                status.exit_delta_t = DELTA_T;
                status.delta_t_guess = delta_t;
              }
          }
        // Check if the norm of error is less than the refining tolerance
        else if (error_norm<refine_tol)
          {
            done = true;
            status.exit_delta_t = DELTA_T;
            status.delta_t_guess = delta_t;
          }
        else
          {
            // If the time step is already the smallest acceptable, exit.
            if (delta_t==min_delta_t)
              {
                done = true;
                status.exit_delta_t = MIN_DELTA_T;
                status.delta_t_guess = delta_t;
              }
            // Reduce the time step.
            else
              {
                delta_t *= refine_param;
                if (delta_t<min_delta_t)
                  delta_t = min_delta_t;
              }
          }

        ++count;
      }

    // Save the last stage if necessary
    if (last_same_as_first==true)
      {
        if (last_stage==NULL)
          last_stage = new VectorType(f_stages.back());
        else
          *last_stage = f_stages.back();
      }

    status.n_iterations = count;
    status.error_norm = error_norm;

    return (t+delta_t);
  }



  template <typename VectorType>
  void EmbeddedExplicitRungeKutta<VectorType>::set_time_adaptation_parameters(double coarsen_param_,
      double refine_param_,
      double min_delta_,
      double max_delta_,
      double refine_tol_,
      double coarsen_tol_)
  {
    coarsen_param = coarsen_param_;
    refine_param = refine_param_;
    min_delta_t = min_delta_;
    max_delta_t = max_delta_;
    refine_tol = refine_tol_;
    coarsen_tol = coarsen_tol_;
  }



  template <typename VectorType>
  const typename EmbeddedExplicitRungeKutta<VectorType>::Status &EmbeddedExplicitRungeKutta<VectorType>::get_status() const
  {
    return status;
  }


  template <typename VectorType>
  void EmbeddedExplicitRungeKutta<VectorType>::compute_stages(
    std_cxx11::function<VectorType (const double, const VectorType &)> f,
    const double t,
    const double delta_t,
    const VectorType &y,
    std::vector<VectorType> &f_stages)
  {
    VectorType Y(y);
    unsigned int i = 0;

    // If the last stage is the same as the first, we can skip the evaluation
    // of the first stage.
    if (last_same_as_first==true)
      {
        if (last_stage!=NULL)
          {
            f_stages[0] = *last_stage;
            i = 1;
          }
      }

    for (; i<this->n_stages; ++i)
      {
        Y = y;
        for (unsigned int j = 0; j < i; ++j)
          Y.sadd(1.0,delta_t *this->a[i][j],f_stages[j]);
        f_stages[i] = f(t+this->c[i]*delta_t,Y);
      }
  }
}

DEAL_II_NAMESPACE_CLOSE

#endif