Coverage for pySDC/projects/parallelSDC/Van_der_Pol_implicit_Jac.py: 0%

14 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-20 14:51 +0000

1import numpy as np 

2import scipy.sparse as sp 

3from scipy.sparse.linalg import spsolve 

4 

5from pySDC.implementations.problem_classes.Van_der_Pol_implicit import vanderpol 

6 

7 

8# noinspection PyUnusedLocal 

9class vanderpol_jac(vanderpol): 

10 def eval_jacobian(self, u): 

11 """ 

12 Evaluation of the Jacobian of the right-hand side 

13 

14 Args: 

15 u: space values 

16 

17 Returns: 

18 Jacobian matrix 

19 """ 

20 

21 x1 = u[0] 

22 x2 = u[1] 

23 

24 dfdu = np.array([[0, 1], [-2 * self.params.mu * x1 * x2 - 1, self.params.mu * (1 - x1**2)]]) 

25 

26 return dfdu 

27 

28 def solve_system_jacobian(self, dfdu, rhs, factor, u0, t): 

29 """ 

30 Simple linear solver for (I-dtA)u = rhs 

31 

32 Args: 

33 dfdu: the Jacobian of the RHS of the ODE 

34 rhs: right-hand side for the linear system 

35 factor: abbrev. for the node-to-node stepsize (or any other factor required) 

36 u0: initial guess for the iterative solver (not used here so far) 

37 t: current time (e.g. for time-dependent BCs) 

38 

39 Returns: 

40 solution as mesh 

41 """ 

42 

43 me = self.dtype_u(2) 

44 me[:] = spsolve(sp.eye(2) - factor * dfdu, rhs) 

45 return me