bubble-dynamics

Spherical bubble dynamics simulator
git clone https://git.0xfab.ch/bubble-dynamics.git
Log | Files | Refs | README | LICENSE

Dahlquist.h (1572B)


      1 /* File:   Dahlquist.h */
      2 /* Date:   Fri Feb  5 19:31:02 2016 */
      3 /* Author: Fabian Wermelinger */
      4 /* Tag:    Dahlquist equation (Test kernel) */
      5 /* Copyright 2016 ETH Zurich. All Rights Reserved. */
      6 #ifndef DAHLQUIST_H_SQ60WZPY
      7 #define DAHLQUIST_H_SQ60WZPY
      8 
      9 #include <ODETB/GnuplotDump.h>
     10 #include <ODETB/TimeStepper/KernelBase.h>
     11 #include <ODETB/common.h>
     12 
     13 #include <cassert>
     14 
     15 template <typename Tinput, typename Trhs=Tinput>
     16 class Dahlquist : public KernelBase<Tinput,Trhs>
     17 {
     18     GnuplotDump m_gp;
     19 
     20 protected:
     21     const Real m_a;
     22 
     23 public:
     24     Dahlquist(const Real a=1.0) : m_gp("out", GnuplotDump::ASCII), m_a(a) {}
     25     ~Dahlquist() {}
     26 
     27     void compute(const Tinput& U, Trhs& rhs, const Real t, void const* const data=nullptr)
     28     {
     29         rhs = m_a*U;
     30     }
     31 
     32     void write(const size_t step, const Real t, const Real dt, const Tinput& U, const void * const data=nullptr)
     33     {
     34         m_gp.write(step, t, dt, U.data(), U.size()*Tinput::DataType::SIZE);
     35     }
     36 };
     37 
     38 template <typename Tinput, typename Trhs=Tinput>
     39 class DahlquistLSRK3 : public Dahlquist<Tinput,Trhs>
     40 {
     41     using Dahlquist<Tinput, Trhs>::m_a;
     42 
     43 public:
     44     DahlquistLSRK3(const Real a=1.0) : Dahlquist<Tinput,Trhs>(a) {}
     45     ~DahlquistLSRK3() {}
     46 
     47     void compute(const Tinput& U, Trhs& rhs, const Real t, void const* const data=nullptr)
     48     {
     49         assert(data != nullptr);
     50         const Real * const LSRKData = static_cast<const Real* const>(data);
     51         const Real dt = LSRKData[0];
     52         const Real A  = LSRKData[1];
     53         rhs = A*rhs + dt*m_a*U;
     54     }
     55 };
     56 
     57 #endif /* DAHLQUIST_H_SQ60WZPY */