Exemple #1
0
 def __init__(self, problem):
     """
     Initiates the solver.
     
         Parameters::
         
             problem     
                         - The problem to be solved. Should be an instance
                           of the 'Explicit_Problem' class.                       
     """
     Explicit_ODE.__init__(self, problem) #Calls the base class
     
     #Solver options
     self.options["atol"] = 1.0e-6
     self.options["rtol"] = 1.0e-6
     self.options["inith"] = 0.01
     self.options["maxsteps"] = 10000
     
     #Internal temporary result vector
     self.Y1 = N.array([0.0]*len(self.y0))
     self.Y2 = N.array([0.0]*len(self.y0))
     self.Y3 = N.array([0.0]*len(self.y0))
     self.Y4 = N.array([0.0]*len(self.y0))
     self.Z3 = N.array([0.0]*len(self.y0))
     
     #RHS-Function
     self.f = problem.rhs_internal
     
     #Solver support
     self.supports["one_step_mode"] = True
     
     #Internal values
     # - Statistic values
     self.statistics["nsteps"] = 0 #Number of steps
     self.statistics["nfcn"] = 0 #Number of function evaluations
Exemple #2
0
    def print_statistics(self, verbose=NORMAL):
        """
        Prints the run-time statistics for the problem.
        """
        Explicit_ODE.print_statistics(self, verbose)  #Calls the base class

        self.log_message('\nSolver options:\n', verbose)
        self.log_message(' Solver                  : LSODAR ', verbose)
        self.log_message(
            ' Absolute tolerances     : {}'.format(self.options["atol"]),
            verbose)
        self.log_message(
            ' Relative tolerances     : {}'.format(self.options["rtol"]),
            verbose)
        if self.rkstarter == 1:
            self.log_message(
                ' Starter                 : {}'.format('classical'), verbose)
        else:
            self.log_message(
                ' Starter                 : Runge-Kutta order {}'.format(
                    self.rkstarter), verbose)
        if self.maxordn < 12 or self.maxords < 5:
            self.log_message(
                ' Maximal order Adams     : {}'.format(self.maxordn), verbose)
            self.log_message(
                ' Maximal order BDF       : {}'.format(self.maxords), verbose)
        if self.maxh > 0.:
            self.log_message(' Maximal stepsize maxh   : {}'.format(self.maxh),
                             verbose)
        self.log_message('', verbose)
Exemple #3
0
    def __init__(self, problem):
        """
        Initiates the solver.
        
            Parameters::
            
                problem     
                            - The problem to be solved. Should be an instance
                              of the 'Explicit_Problem' class.                       
        """
        Explicit_ODE.__init__(self, problem)  #Calls the base class

        #Solver options
        self.options["atol"] = 1.0e-6
        self.options["rtol"] = 1.0e-6
        self.options["inith"] = 0.01
        self.options["maxsteps"] = 10000

        #Internal temporary result vector
        self.Y1 = N.array([0.0] * len(self.y0))
        self.Y2 = N.array([0.0] * len(self.y0))
        self.Y3 = N.array([0.0] * len(self.y0))
        self.Y4 = N.array([0.0] * len(self.y0))
        self.Z3 = N.array([0.0] * len(self.y0))

        #RHS-Function
        self.f = problem.rhs_internal

        #Solver support
        self.supports["one_step_mode"] = True

        #Internal values
        # - Statistic values
        self.statistics["nsteps"] = 0  #Number of steps
        self.statistics["nfcn"] = 0  #Number of function evaluations
    def __init__(self, problem):
        """
        Initiates the solver.
        
            Parameters::
            
                problem     
                            - The problem to be solved. Should be an instance
                              of the 'Explicit_Problem' class.
        """
        Explicit_ODE.__init__(self, problem)  #Calls the base class

        #Default values
        self.options["inith"] = 0.01
        self.options[
            "fac1"] = 0.2  #Parameters for step-size selection (lower bound)
        self.options[
            "fac2"] = 6.0  #Parameters for step-size selection (upper bound)
        self.options["maxh"] = N.inf  #Maximum step-size.
        self.options["safe"] = 0.9  #Safety factor
        self.options["atol"] = 1.0e-6 * N.ones(
            self.problem_info["dim"])  #Absolute tolerance
        self.options["rtol"] = 1.0e-6  #Relative tolerance
        self.options[
            "usejac"] = True if self.problem_info["jac_fcn"] else False
        self.options["maxsteps"] = 10000

        #Solver support
        self.supports["report_continuously"] = True
        self.supports["interpolated_output"] = True
        self.supports["state_events"] = True

        #Internal
        self._leny = len(self.y)  #Dimension of the problem
Exemple #5
0
    def __init__(self, problem):
        """
        Initiates the solver.
        
            Parameters::
            
                problem     
                            - The problem to be solved. Should be an instance
                              of the 'Explicit_Problem' class.
        """
        Explicit_ODE.__init__(self, problem)  #Calls the base class
        if not isinstance(problem, SingPerturbed_Problem):
            raise Explicit_ODE_Exception(
                'The problem needs to be a subclass of a SingPerturbed_Problem.'
            )
        self.n = self.problem.n
        self.m = self.problem.m

        # Set initial values
        self.wsy = N.empty((10 * self.n, ))
        self.wsy[:self.n] = self.problem.yy0
        self.wsz = N.empty((max(9 * self.m,
                                1), ))  # array must be at least 1 element long
        self.wsz[:self.m] = self.problem.zz0

        # - Default values
        self.options["atol"] = 1.0e-6 * N.ones(
            self.problem_info["dim"])  #Absolute tolerance
        self.options["rtol"] = 1.0e-6  #Relative tolerance

        self.statistics.add_key("nyder",
                                "Number of slow function evaluations (Y)")
        self.statistics.add_key("nzder",
                                "Number of fast function evaluations (Z)")
Exemple #6
0
    def __init__(self, problem):
        """
        Initiates the solver.
        
            Parameters::
            
                problem     
                            - The problem to be solved. Should be an instance
                              of the 'Explicit_Problem' class.                       
        """
        Explicit_ODE.__init__(self, problem)  #Calls the base class

        #Solver options
        self.options["atol"] = 1.0e-6
        self.options["rtol"] = 1.0e-6
        self.options["inith"] = 0.01
        self.options["maxsteps"] = 10000

        #Internal temporary result vector
        self.Y1 = N.array([0.0] * len(self.y0))
        self.Y2 = N.array([0.0] * len(self.y0))
        self.Y3 = N.array([0.0] * len(self.y0))
        self.Y4 = N.array([0.0] * len(self.y0))
        self.Z3 = N.array([0.0] * len(self.y0))

        #Solver support
        self.supports["report_continuously"] = True
        self.supports["interpolated_output"] = True
        self.supports["state_events"] = True
Exemple #7
0
 def __init__(self, problem):
     Explicit_ODE.__init__(self, problem) #Calls the base class
     
     #Solver options
     self.options["h"] = 0.01
     
     #Statistics
     self.statistics["nsteps"] = 0
     self.statistics["nfcns"] = 0
 def print_statistics(self, verbose):
     """
     Should print the statistics.
     """
     Explicit_ODE.print_statistics(self, verbose) #Calls the base class
     
     self.log_message('\nSolver options:\n',                                              verbose)
     self.log_message(' Solver             : RungeKutta34',                               verbose)
     self.log_message(' Solver type        : Adaptive',                                   verbose)
     self.log_message(' Relative tolerance : ' + str(self.options["rtol"]),        verbose)
     self.log_message(' Absolute tolerance : ' + str(self._compact_atol()) + '\n', verbose)
 def print_statistics(self, verbose=NORMAL):
     """
     Prints the run-time statistics for the problem.
     """
     Explicit_ODE.print_statistics(self, verbose) #Calls the base class
     
     self.log_message('\nSolver options:\n',                                      verbose)
     self.log_message(' Solver                  : Dopri5 ',          verbose)
     self.log_message(' Tolerances (absolute)   : ' + str(self._compact_atol()),  verbose)
     self.log_message(' Tolerances (relative)   : ' + str(self.options["rtol"]),  verbose)
     self.log_message('',                                                         verbose)
Exemple #10
0
    def __init__(self, problem):

        Explicit_ODE.__init__(self, problem)  #Calls the base class

        #Solver options
        self.options["h"] = 0.001
        self.alpha = -1 / 3
        self.gamma = 1 / 2
        self.HHT = False

        #Statistics
        self.statistics["nsteps"] = 0
        self.statistics["nfcns"] = 0
Exemple #11
0
 def __init__(self, problem):
     Explicit_ODE.__init__(self, problem) #Calls the base class
     
     #Solver options
     self.options["h"] = 0.01
     
     #Internal temporary result vector
     self.Y1 = N.array([0.0]*len(self.y0))
     self.Y2 = N.array([0.0]*len(self.y0))
     self.Y3 = N.array([0.0]*len(self.y0))
     self.Y4 = N.array([0.0]*len(self.y0))
     
     #RHS-Function
     self.f = problem.rhs_internal
     
     #Solver support
     self.supports["one_step_mode"] = True
Exemple #12
0
    def __init__(self, problem):
        Explicit_ODE.__init__(self, problem)  #Calls the base class

        #Solver options
        self.options["h"] = 0.01

        #Internal temporary result vector
        self.Y1 = N.array([0.0] * len(self.y0))
        self.Y2 = N.array([0.0] * len(self.y0))
        self.Y3 = N.array([0.0] * len(self.y0))
        self.Y4 = N.array([0.0] * len(self.y0))

        #RHS-Function
        self.f = problem.rhs_internal

        #Solver support
        self.supports["one_step_mode"] = True
Exemple #13
0
    def __init__(self, problem):
        """
        Initiates the solver.
        
            Parameters::
            
                problem     
                            - The problem to be solved. Should be an instance
                              of the 'Implicit_Problem' class.
        """
        Explicit_ODE.__init__(self, problem)  #Calls the base class

        #Default values
        self.options["atol"] = 1.0e-6 * N.ones(
            self.problem_info["dim"])  #Absolute tolerance
        self.options["rtol"] = 1.0e-6  #Relative tolerance
        self.options["usejac"] = False
        self.options["maxsteps"] = 100000
        self.options["rkstarter"] = 1
        self.options["maxordn"] = 12
        self.options["maxords"] = 5
        self.options["maxh"] = 0.

        self._leny = len(self.y)  #Dimension of the problem
        self._nordsieck_array = []
        self._nordsieck_order = 0
        self._nordsieck_time = 0.0
        self._nordsieck_h = 0.0
        self._update_nordsieck = False

        # Solver support
        self.supports["state_events"] = True
        self.supports["report_continuously"] = True
        self.supports["interpolated_output"] = True

        self._RWORK = N.array(
            [0.0] *
            (22 +
             self.problem_info["dim"] * max(16, self.problem_info["dim"] + 9) +
             3 * self.problem_info["dimRoot"]))
        self._IWORK = N.array([0] * (20 + self.problem_info["dim"]))
Exemple #14
0
    def __init__(self, problem, alpha = 0.0):
        """
            problem: assimulo Explicit_Probelm
            alpha: optional value on the interval [-1/3,0]
        """
        Explicit_ODE.__init__(self, problem)

        self.options["a"] = alpha
        self.options["b"] = ((1.0 - self.options["a"]) / 2.0) ** 2
        self.options["g"] = 0.5 - self.options["a"]
        self.options["h"] = 0.05
        
        if self.options["a"] > 0 or self.options["a"] < -1.0 / 3.0:
            raise ValueError('alpha %s not in range [-1/3, 0]' % self.options["a"])

        self.a_old = None

        self.statistics['nfevals'] = 0
        self.statistics['nsteps'] = 0

        self.supports["one_step_mode"] = True

        self.rhs = problem.rhs
        self.n = len(self.y0) / 2
Exemple #15
0
 def __init__(self, problem):
     """
     Initiates the solver.
     
         Parameters::
         
             problem     
                         - The problem to be solved. Should be an instance
                           of the 'Explicit_Problem' class.
     """
     Explicit_ODE.__init__(self, problem) #Calls the base class
     
     #Default values
     self.options["inith"] = 0.01
     self.options["newt"]     = 7 #Maximum number of newton iterations
     self.options["thet"]     = 1.e-3 #Boundary for re-calculation of jac
     self.options["fnewt"]    = 0 #Stopping critera for Newtons Method
     self.options["quot1"]    = 1.0 #Parameters for changing step-size (lower bound)
     self.options["quot2"]    = 1.2 #Parameters for changing step-size (upper bound)
     self.options["fac1"]     = 0.2 #Parameters for step-size selection (lower bound)
     self.options["fac2"]     = 8.0 #Parameters for step-size selection (upper bound)
     self.options["maxh"]     = N.inf #Maximum step-size.
     self.options["safe"]     = 0.9 #Safety factor
     self.options["atol"]     = 1.0e-6 #Absolute tolerance
     self.options["rtol"]     = 1.0e-6 #Relative tolerance
     self.options["usejac"]   = True if self.problem_info["jac_fcn"] else False
     self.options["maxsteps"] = 10000
     
     # - Statistic values
     self.statistics["nsteps"] = 0 #Number of steps
     self.statistics["nfcn"] = 0 #Number of function evaluations
     self.statistics["njac"] = 0 #Number of jacobian evaluations
     self.statistics["njacfcn"] = 0 #Number of function evaluations when evaluating the jacobian
     self.statistics["nniter"] = 0 #Number of nonlinear iterations
     self.statistics["nniterfail"] = 0 #Number of nonlinear failures
     self.statistics["errfail"] = 0 #Number of step rejections
     self.statistics["nlu"] = 0 #Number of LU decompositions
     
     #Internal values
     self._curjac = False #Current jacobian?
     self._itfail = False #Iteration failed?
     self._needjac = True #Need to update the jacobian?
     self._needLU = True #Need new LU-factorisation?
     self._first = True #First step?
     self._rejected = True #Is the last step rejected?
     self._leny = len(self.y) #Dimension of the problem
     self._oldh = 0.0 #Old stepsize
     self._olderr = 1.0 #Old error
     self._eps = N.finfo('double').eps
     self._col_poly = N.zeros(self._leny*3)
     self._type = '(explicit)'
     self._curiter = 0 #Number of current iterations
     
     #RHS-Function
     self.f = problem.rhs_internal
     
     #Internal temporary result vector
     self.Y1 = N.array([0.0]*len(self.y0))
     self.Y2 = N.array([0.0]*len(self.y0))
     self.Y3 = N.array([0.0]*len(self.y0))
     self._f0 = N.array([0.0]*len(self.y0))
     
     #Solver support
     self.supports["one_step_mode"] = True
     self.supports["interpolated_output"] = True
     
     # - Retrieve the Radau5 parameters
     self._load_parameters() #Set the Radau5 parameters
Exemple #16
0
    def __init__(self, problem):
        """
        Initiates the solver.
        
            Parameters::
            
                problem     
                            - The problem to be solved. Should be an instance
                              of the 'Delay_Explicit_Problem' class.
        """
        Explicit_ODE.__init__(self, problem)  #Calls the base class

        #Default values
        self.options["inith"] = 0.01
        self.options["newt"] = 7  #Maximum number of newton iterations
        self.options["thet"] = 1.e-3  #Boundary for re-calculation of jac
        #        self.options["fnewt"]    = 0.0 #Stopping critera for Newtons Method
        self.options["fnewt"] = 0.03  #Stopping critera for Newtons Method
        self.options[
            "quot1"] = 1.0  #Parameters for changing step-size (lower bound)
        self.options[
            "quot2"] = 1.2  #Parameters for changing step-size (upper bound)
        self.options[
            "fac1"] = 0.2  #Parameters for step-size selection (lower bound)
        self.options[
            "fac2"] = 8.0  #Parameters for step-size selection (upper bound)
        self.options["maxh"] = N.inf  #Maximum step-size.
        self.options["safe"] = 0.9  #Safety factor
        self.options["atol"] = 1.0e-6 * N.ones(
            self.problem_info["dim"])  #Absolute tolerance
        self.options["rtol"] = 1.0e-6  #Relative tolerance
        self.options[
            "usejac"] = True if self.problem_info["jac_fcn"] else False
        self.options["maxsteps"] = 10000

        self.options[
            "alpha"] = 0.0  # Parameter to tune the error control of dense output (smaller = stronger control)
        self.options[
            "tckbp"] = 5.0  # Parameter for controlling the search for breaking points
        self.options[
            "ieflag"] = 0  # Switch between different modes of error control
        self.options[
            "mxst"] = 100  # The maximum number of stored dense output points
        self.options[
            "usejaclag"] = True if self.problem_info["jaclag_fcn"] else False

        SQ6 = N.sqrt(6.0)
        C1 = (4.0 - SQ6) / 10.0
        C2 = (4.0 + SQ6) / 10.0
        self.C1M1 = C1 - 1.0
        self.C2M1 = C2 - 1.0

        # - Statistic values
        self.statistics["nsteps"] = 0  #Number of steps
        self.statistics["nfcn"] = 0  #Number of function evaluations
        self.statistics["njac"] = 0  #Number of Jacobian evaluations
        self.statistics[
            "njacfcn"] = 0  #Number of function evaluations when evaluating the jacobian
        self.statistics["errfail"] = 0  #Number of step rejections
        self.statistics["nlu"] = 0  #Number of LU decompositions
        self.statistics[
            "nstepstotal"] = 0  #Number of total computed steps (may NOT be equal to nsteps+nerrfail)

        #Internal values
        self._leny = len(self.y)  #Dimension of the problem
        self._type = '(explicit)'
        self._yDelayTemp = []
        self._ntimelags = len(self.problem.lagcompmap)
        for i in range(self._ntimelags):
            self._yDelayTemp.append(range(len(self.problem.lagcompmap[i])))
        flat_lagcompmap = []
        for comp in self.problem.lagcompmap:
            flat_lagcompmap.extend(comp)
        self._nrdens = len(N.unique(flat_lagcompmap))
        self._ipast = N.unique(flat_lagcompmap).tolist() + [0]
        self._grid = N.array([])
Exemple #17
0
    def __init__(self, problem):
        """
        Initiates the solver.
        
            Parameters::
            
                problem     
                            - The problem to be solved. Should be an instance
                              of the 'Explicit_Problem' class.
        """
        Explicit_ODE.__init__(self, problem)  #Calls the base class

        #Default values
        self.options["inith"] = 0.01
        self.options["newt"] = 7  #Maximum number of newton iterations
        self.options["thet"] = 1.e-3  #Boundary for re-calculation of jac
        self.options["fnewt"] = 0  #Stopping critera for Newtons Method
        self.options[
            "quot1"] = 1.0  #Parameters for changing step-size (lower bound)
        self.options[
            "quot2"] = 1.2  #Parameters for changing step-size (upper bound)
        self.options[
            "fac1"] = 0.2  #Parameters for step-size selection (lower bound)
        self.options[
            "fac2"] = 8.0  #Parameters for step-size selection (upper bound)
        self.options["maxh"] = N.inf  #Maximum step-size.
        self.options["safe"] = 0.9  #Safety factor
        self.options["atol"] = 1.0e-6  #Absolute tolerance
        self.options["rtol"] = 1.0e-6  #Relative tolerance
        self.options[
            "usejac"] = True if self.problem_info["jac_fcn"] else False
        self.options["maxsteps"] = 10000

        # - Statistic values
        self.statistics["nsteps"] = 0  #Number of steps
        self.statistics["nfcn"] = 0  #Number of function evaluations
        self.statistics["njac"] = 0  #Number of jacobian evaluations
        self.statistics[
            "njacfcn"] = 0  #Number of function evaluations when evaluating the jacobian
        self.statistics["nniter"] = 0  #Number of nonlinear iterations
        self.statistics["nniterfail"] = 0  #Number of nonlinear failures
        self.statistics["errfail"] = 0  #Number of step rejections
        self.statistics["nlu"] = 0  #Number of LU decompositions

        #Internal values
        self._curjac = False  #Current jacobian?
        self._itfail = False  #Iteration failed?
        self._needjac = True  #Need to update the jacobian?
        self._needLU = True  #Need new LU-factorisation?
        self._first = True  #First step?
        self._rejected = True  #Is the last step rejected?
        self._leny = len(self.y)  #Dimension of the problem
        self._oldh = 0.0  #Old stepsize
        self._olderr = 1.0  #Old error
        self._eps = N.finfo('double').eps
        self._col_poly = N.zeros(self._leny * 3)
        self._type = '(explicit)'
        self._curiter = 0  #Number of current iterations

        #RHS-Function
        self.f = problem.rhs_internal

        #Internal temporary result vector
        self.Y1 = N.array([0.0] * len(self.y0))
        self.Y2 = N.array([0.0] * len(self.y0))
        self.Y3 = N.array([0.0] * len(self.y0))
        self._f0 = N.array([0.0] * len(self.y0))

        #Solver support
        self.supports["one_step_mode"] = True
        self.supports["interpolated_output"] = True

        # - Retrieve the Radau5 parameters
        self._load_parameters()  #Set the Radau5 parameters