def __init__(self,
              d,
              theta,
              A,
              b,
              Ahat=None,
              bhat=None,
              type='General',
              name='Two-step Runge-Kutta Method'):
     r"""
         Initialize a 2-step Runge-Kutta method."""
     d, A, b, Ahat, bhat = snp.normalize(d, A, b, Ahat, bhat)
     self.s = max(np.shape(b))
     self.d, self.theta, self.A, self.b = d, theta, A, b
     self.Ahat, self.bhat = Ahat, bhat
     #if type=='General': self.Ahat,self.bhat=Ahat,bhat
     #elif type=='Type I':
     #    self.Ahat = np.zeros([self.s,self.s])
     #    self.bhat = np.zeros([self.s,1])
     #elif type=='Type II':
     #    self.Ahat = np.zeros([self.s,self.s])
     #    self.Ahat[:,0]=Ahat
     #    self.bhat = np.zeros([self.s,1])
     #    self.bhat[0]=bhat
     #else: raise Exception('Unrecognized type')
     self.name = name
     self.type = type
Example #2
0
    def __init__(self,
                 A=None,
                 At=None,
                 b=None,
                 bt=None,
                 alpha=None,
                 beta=None,
                 alphat=None,
                 betat=None,
                 name='downwind Runge-Kutta Method',
                 description=''):
        r"""
            Initialize a downwind Runge-Kutta method.  The representation
            uses the form and notation of [Ketcheson2010]_.

            \\begin{align*}
            y^n_i = & u^{n-1} + \\Delta t \\sum_{j=1}^{s}
            (a_{ij} f(y_j^{n-1}) + \\tilde{a}_{ij} \\tilde{f}(y_j^n)) & (1\\le j \\le s) \\\\
            \\end{align*}

        """
        A, b, alpha, beta = snp.normalize(A, b, alpha, beta)

        butchform = [x is not None for x in [A, At, b, bt]]
        SOform = [x is not None for x in [alpha, alphat, beta, betat]]
        if not ((all(butchform) and not (True in SOform)) or
                ((not (True in butchform)) and all(SOform))):
            raise Exception("""To initialize a Runge-Kutta method,
                you must provide either Butcher arrays or Shu-Osher arrays,
                but not both.""")
        if A is not None:  #Initialize with Butcher arrays
            # Check that number of stages is consistent
            m = np.size(A, 0)  # Number of stages
            if m > 1:
                if not np.all([np.size(A, 1), np.size(b)] == [m, m]):
                    raise Exception(
                        'Inconsistent dimensions of Butcher arrays')
            else:
                if not np.size(b) == 1:
                    raise Exception(
                        'Inconsistent dimensions of Butcher arrays')
        elif alpha is not None:  #Initialize with Shu-Osher arrays
            A, At, b, bt = downwind_shu_osher_to_butcher(
                alpha, alphat, beta, betat)
        # Set Butcher arrays
        if len(np.shape(A)) == 2:
            self.A = A
            self.At = At
        else:
            self.A = snp.array([A])  #Fix for 1-stage methods
            self.At = snp.array([At])
        self.b = b
        self.bt = bt
        self.c = np.sum(self.A, 1) - np.sum(self.At, 1)
        self.name = name
        self.info = description
        self.underlying_method = rk.RungeKuttaMethod(self.A - self.At,
                                                     self.b - self.bt)
    def __init__(
        self,
        A=None,
        At=None,
        b=None,
        bt=None,
        alpha=None,
        beta=None,
        alphat=None,
        betat=None,
        name="downwind Runge-Kutta Method",
        description="",
    ):
        r"""
            Initialize a downwind Runge-Kutta method.  The representation
            uses the form and notation of [Ketcheson2010]_.

            \\begin{align*}
            y^n_i = & u^{n-1} + \\Delta t \\sum_{j=1}^{s}
            (a_{ij} f(y_j^{n-1}) + \\tilde{a}_{ij} \\tilde{f}(y_j^n)) & (1\\le j \\le s) \\\\
            \\end{align*}

        """
        A, b, alpha, beta = snp.normalize(A, b, alpha, beta)

        butchform = [x is not None for x in [A, At, b, bt]]
        SOform = [x is not None for x in [alpha, alphat, beta, betat]]
        if not ((all(butchform) and not (True in SOform)) or ((not (True in butchform)) and all(SOform))):
            raise Exception(
                """To initialize a Runge-Kutta method,
                you must provide either Butcher arrays or Shu-Osher arrays,
                but not both."""
            )
        if A is not None:  # Initialize with Butcher arrays
            # Check that number of stages is consistent
            m = np.size(A, 0)  # Number of stages
            if m > 1:
                if not np.all([np.size(A, 1), np.size(b)] == [m, m]):
                    raise Exception("Inconsistent dimensions of Butcher arrays")
            else:
                if not np.size(b) == 1:
                    raise Exception("Inconsistent dimensions of Butcher arrays")
        elif alpha is not None:  # Initialize with Shu-Osher arrays
            A, At, b, bt = downwind_shu_osher_to_butcher(alpha, alphat, beta, betat)
        # Set Butcher arrays
        if len(np.shape(A)) == 2:
            self.A = A
            self.At = At
        else:
            self.A = snp.array([A])  # Fix for 1-stage methods
            self.At = snp.array([At])
        self.b = b
        self.bt = bt
        self.c = np.sum(self.A, 1) - np.sum(self.At, 1)
        self.name = name
        self.info = description
        self.underlying_method = rk.RungeKuttaMethod(self.A - self.At, self.b - self.bt)
 def __init__(self,d,theta,A,b,Ahat=None,bhat=None,type='General',name='Two-step Runge-Kutta Method'):
     r"""
         Initialize a 2-step Runge-Kutta method."""
     d,A,b,Ahat,bhat=snp.normalize(d,A,b,Ahat,bhat)
     self.s = max(np.shape(b))
     self.d,self.theta,self.A,self.b = d,theta,A,b
     self.Ahat,self.bhat=Ahat,bhat
     #if type=='General': self.Ahat,self.bhat=Ahat,bhat
     #elif type=='Type I':
     #    self.Ahat = np.zeros([self.s,self.s])
     #    self.bhat = np.zeros([self.s,1])
     #elif type=='Type II':
     #    self.Ahat = np.zeros([self.s,self.s])
     #    self.Ahat[:,0]=Ahat
     #    self.bhat = np.zeros([self.s,1])
     #    self.bhat[0]=bhat
     #else: raise Exception('Unrecognized type')
     self.name=name
     self.type=type