Exemple #1
0
 def initialize_for_solve(self):
     if hasattr(self, 'f'):
         # If f is input in form of f(u,t), wrap f to f_f77 for Fortran code.
         f = self.f
         self.f_f77 = lambda t,u: np.asarray(f(u,t))
     elif hasattr(self, 'f_f77'):
         # If f is input in form of f(t,u) (usually in Fortran),
         # wrap f_f77 to the general form f(u,t) for switch_to()
         f_f77 = self.f_f77
         self.f = lambda u,t: np.asarray(f_f77(t,u))
     Solver.initialize_for_solve(self)
Exemple #2
0
    def initialize_for_solve(self):
        # INFO(4) is an integer array to specify how the problem
        # is to be solved
        self.info = np.zeros(4, int)

        self.info[0] = 1      # Compute solution at each time point
        if hasattr(self, 'spcrad_f77') or hasattr(self, 'spcrad'):
            self.info[1] = 1  # SPCRAD routine is supplied
        else:
            self.spcrad = lambda x,y: 0.0  # dummy function
        # Is the Jacobian constant?
        self.info[2] = self.jac_constant
        if (np.iterable(self.atol) and (len(self.atol) == self.neq)):
            self.info[3] = 1   # ATOL is a sequence of length NEQ

        if hasattr(self, 'f'):
            # If f is input in form of a Python function f(u,t),
            # let self.f_f77 wrap f and have arguments t, u.
            f = self.f
            self.f_f77 = lambda t,u: np.asarray(f(u,t))
        elif hasattr(self, 'f_f77'):
            # The right-hand side "f" is input as a Fortran function
            # taking the arguments t,u.
            # Set self.f to be f_f77 wrapped to the general form f(u,t)
            # for switch_to().
            f_f77 = self.f_f77
            self.f = lambda u,t: np.asarray(f_f77(t,u))
        # If spcrad is input in form of spcrad(u,t),
        # wrap spcrad to spcrad_f77 for Fortran code.
        if hasattr(self, 'spcrad'):
            # If spcrad is in form of spcrad(u,t), wrap for Fortran code.
            spcrad = self.spcrad
            self.spcrad_f77 = lambda t,u: np.asarray(spcrad(u,t))

        # We call Solver and not Adaptive below because Adaptive
        # just computes first_step, min_step and max_step, all of
        # which are non-used parameters for rkc.f
        Solver.initialize_for_solve(self)   # Common settings