示例#1
0
    def validate_data(self):
        if not Adaptive.validate_data(self):
            return False

        # Check for dimension of user-defined butcher table.
        array_shape = self.butcher_tableau.shape
        if len(array_shape) is not 2:
            raise ValueError,'''
        Illegal input! Your input butcher_tableau should be a 2d-array!'''
        else:
            m,n = array_shape
            if m not in (n, n + 1):
                raise ValueError, '''\
        The dimension of 2d-array <method_yours_array> should be:
        1. Either (n, n), --> For 1-level RungeKutta methods
        2. Or (n+1, n),   --> For 2-levels RungeKutta methods
        The shape of your input array is (%d, %d).''' % (m,n)
        self._butcher_tableau = self.butcher_tableau

        # Check for user-defined order,
        # which should be an integer or a pair of adjacent integers
        if hasattr(self,'method_order'):
            error_1level = '''
        method_order should be a single integer, with a square butcher
        table, which implies a single-level RungeKutta method.
        Your input is %s .''' % str(self.method_order)
            error_2level = '''
        method order should be a pair of adjacent positive integers,
        with a supplied non-square butch table, which implies a
        2-level method. Your input is %s.''' % str(self.method_order)
            if array_shape[0] == array_shape[1] + 1:
                # 2-level RungeKutta methods
                if type(self.method_order) is int:
                    raise ValueError, error_2level
                try:
                    order1, order2 = self.method_order
                    if abs(order1-order2) != 1 or \
                            order1 < 1 or order2 < 1:
                        raise ValueError, error_2level
                except:
                    raise ValueError,error_2level
            else:
                # 1-level RungeKutta methods
                if type(self.method_order) is not int or \
                        self.method_order < 1:
                    raise ValueError,error_1level
            self._method_order = self.method_order

        else:   # method_order is not specified
            if array_shape[0] == array_shape[1] + 1:
                # Calculate order for 2-level-methods
                # Method_order is required for computation
                self._method_order = self.get_order()

        # check for consistency requirement of Butcher Tableau
        for i in range(1,array_shape[1] - 1):
            if not np.allclose(self.butcher_tableau[i][0],\
                               sum(self.butcher_tableau[i][1:])):
                raise ValueError, '''
        Inconsistent data in Butcher_Tableau!
        In each lines of stage-coefficients, first number should be
        equal to the sum of other numbers.
        That is, for a butcher_table with K columns,
            a[i][0] == a[i][1] + a[i][2] + ... + a[i][K - 1]
            where 1 <= i <= K - 1
        Your input for line %d is :%s
        ''' % (i,str(self.butcher_tableau[i]))

        return True
示例#2
0
 def initialize_for_solve(self):
     Adaptive.initialize_for_solve(self)
     self.info = {'rejected' : 0}
示例#3
0
文件: rkc.py 项目: zcemycl/odespy
 def validate_data(self):
     self.check_atol()
     return Adaptive.validate_data(self)