def __init__(self, fun, t0, y0, t_bound, max_step=np.inf, rtol=1e-7, atol=1e-12, safety_factor=0.9, min_step_change=0.333, max_step_change=6.0, beta_stabilizer=0.00, max_nsteps=100000, vectorized=False, **extraneous): warn_extraneous(extraneous) super().__init__(fun, t0, y0, t_bound, vectorized, support_complex=True) self.y_old = None self.max_step = validate_max_step(max_step) self.beta_stabilizer = validate_beta_stabilizer(beta_stabilizer) self.max_nsteps = validate_max_nsteps(max_nsteps) self.safety_factor = validate_safety_factor(safety_factor) self.rtol, self.atol = validate_tol(rtol, atol, self.n) self.min_step_change = min_step_change self.max_step_change = max_step_change self.order = 8 self.f = self.fun(self.t, self.y) self.h_abs = select_initial_step(self.fun, self.t, self.y, self.f, self.direction, self.order, self.rtol, self.atol) self.nfev += 2 self.n_steps = 0 self.n_accepted = 0 self.n_rejected = 0 self.factor_old = 1e-4 # Lund-stabilization factor self.K = np.zeros((16, self.n)) self.interpolation = np.zeros((8, self.n))
def __init__(self, fun, get_energy_gradient, t0, y0, t_bound, max_step=np.inf, rtol=1e-3, atol=1e-6, ls_ctol=1e-4, ls_max_iter=10, ls_dec_scale=0.5, vectorized=False, line_search_class=None, **extraneous): warn_extraneous(extraneous) super(RungeKutta_LS, self).__init__(fun, t0, y0, t_bound, vectorized, support_complex=True) self.y_old = None self.max_step = validate_max_step(max_step) self.rtol, self.atol = validate_tol(rtol, atol, self.n) self.f = self.fun(self.t, self.y) self.h_abs = select_initial_step(self.fun, self.t, self.y, self.f, self.direction, self.order, self.rtol, self.atol) self.K = np.empty((self.n_stages + 1, self.n), dtype=self.y.dtype) self.ls_ctol = ls_ctol self.ls_max_iter = ls_max_iter self.ls_dec_scale = ls_dec_scale self.get_energy_gradient = get_energy_gradient self.line_search_class = line_search_class
def __init__(self, fun, t0, y0, t_bound, max_step=np.inf, rtol=1e-7, atol=1e-12, safety_factor=0.9, min_step_change=0.333, max_step_change=6.0, beta_stabilizer=0.00, max_nsteps=100000, vectorized=False, **extraneous): warn_extraneous(extraneous) super().__init__(fun, t0, y0, t_bound, vectorized, support_complex=True) self.y_old = None self.max_step = validate_max_step(max_step) self.beta_stabilizer = validate_beta_stabilizer(beta_stabilizer) self.max_nsteps = validate_max_nsteps(max_nsteps) self.safety_factor = validate_safety_factor(safety_factor) self.rtol, self.atol = validate_tol(rtol, atol, self.n) self.min_step_change = min_step_change self.max_step_change = max_step_change self.order = 8 self.f = self.fun(self.t, self.y) self.h_abs = select_initial_step( self.fun, self.t, self.y, self.f, self.direction, self.order, self.rtol, self.atol, ) self.nfev += 2 self.n_steps = 0 self.n_accepted = 0 self.n_rejected = 0 self.factor_old = 1e-4 # Lund-stabilization factor self.K = np.zeros((16, self.n)) self.interpolation = np.zeros((8, self.n))
def __init__(self, fun, t0, y0, t_bound, max_step=np.inf, rtol=1e-3, atol=1e-6, min_step=0, vectorized=False, first_step=None, **extraneous): warn_extraneous(extraneous) super(RungeKutta, self).__init__(fun, t0, y0, t_bound, vectorized, support_complex=True) self.min_step_user = min_step self.y_old = None self.max_step = validate_max_step(max_step) self.rtol, self.atol = validate_tol(rtol, atol, self.n) self.f = self.fun(self.t, self.y) if first_step is None: self.h_abs = select_initial_step( self.fun, self.t, self.y, self.f, self.direction, self.order, self.rtol, self.atol) else: self.h_abs = validate_first_step(first_step, t0, t_bound) self.K = np.empty((self.n_stages + 1, self.n), dtype=self.y.dtype)
def __init__(self, *args, **kwargs): self.options = VariableStepOptions( **{k: kwargs.pop(k) for k in variable_step_options if k in kwargs}) h = kwargs.pop("first_step", None) super().__init__(*args, **kwargs) validate_max_step(self.options.max_step) validate_tol(self.options.rtol, self.options.atol, self.y.size) if h is None: h = select_initial_step( self.rhs, self.t, self.y, self.f, 1, self.error_estimator_order, self.options.rtol, self.options.atol, ) self.h = np.array(h, dtype=float)
def __init__(self, fun, t0, y0, t_bound, max_step=np.inf, rtol=1e-3, atol=1e-6, jac=None, jac_sparsity=None, vectorized=False, first_step=None, mass=None, bPrint=False, newton_tol=None, constant_dt=False, bPrintProgress=False, **extraneous): warn_extraneous(extraneous) super(RadauDAE, self).__init__(fun, t0, y0, t_bound, vectorized) self.y_old = None self.max_step = validate_max_step(max_step) self.rtol, self.atol = validate_tol(rtol, atol, self.n) self.f = self.fun(self.t, self.y) # Select initial step assuming the same order which is used to control # the error. if first_step is None: self.h_abs = select_initial_step(self.fun, self.t, self.y, self.f, self.direction, 3, self.rtol, self.atol) else: self.h_abs = validate_first_step(first_step, t0, t_bound) self.h_abs_old = None self.error_norm_old = None if newton_tol is None: self.newton_tol = max(10 * EPS / rtol, min(0.03, rtol**0.5)) else: self.newton_tol = newton_tol self.sol = None self.constant_dt = constant_dt self.jac_factor = None self.jac, self.J = self._validate_jac(jac, jac_sparsity) self.nlusove = 0 self.bPrintProgress = bPrintProgress global BPRINT BPRINT = bPrint if BPRINT: zzzjac = self.jac def debugJacprint(t, y, f): print('\tupdating jacobian') return zzzjac(t, y, f) self.jac = debugJacprint if issparse(self.J): def lu(A): self.nlu += 1 return splu(A) def solve_lu(LU, b): self.nlusove += 1 return LU.solve(b) I = eye(self.n, format='csc') else: def lu(A): self.nlu += 1 return lu_factor(A, overwrite_a=True) def solve_lu(LU, b): self.nlusove += 1 return lu_solve(LU, b, overwrite_b=True) I = np.identity(self.n) self.lu = lu self.solve_lu = solve_lu self.I = I if not (mass is None): if issparse(mass): self.mass_matrix = csc_matrix(mass) self.index_algebraic_vars = np.where( np.all(self.mass_matrix.toarray() == 0, axis=1))[0] # TODO: avoid the toarray() else: self.mass_matrix = mass self.index_algebraic_vars = np.where( np.all(self.mass_matrix == 0, axis=1))[0] self.nvars_algebraic = self.index_algebraic_vars.size else: self.mass_matrix = None self.index_algebraic_vars = None self.nvars_algebraic = 0 self.current_jac = True self.LU_real = None self.LU_complex = None self.Z = None self.info = { 'cond': { 'LU_real': [], 'LU_complex': [], 't': [], 'h': [] } }