Coverage for pySDC/projects/parallelSDC/GeneralizedFisher_1D_FD_implicit_Jac.py: 100%

12 statements  

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

1import scipy.sparse as sp 

2import numpy as np 

3from scipy.sparse.linalg import spsolve 

4 

5from pySDC.implementations.problem_classes.GeneralizedFisher_1D_FD_implicit import generalized_fisher 

6 

7 

8# noinspection PyUnusedLocal 

9class generalized_fisher_jac(generalized_fisher): 

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 # noinspection PyTypeChecker 

22 dfdu = self.A[1:-1, 1:-1] + sp.diags(self.lambda0**2 - self.lambda0**2 * (self.nu + 1) * u**self.nu, offsets=0) 

23 

24 return dfdu 

25 

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

27 """ 

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

29 

30 Args: 

31 dfdu: the Jacobian of the RHS of the ODE 

32 rhs: right-hand side for the linear system 

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

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

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

36 

37 Returns: 

38 solution as mesh 

39 """ 

40 

41 me = self.dtype_u((self.init[0], self.init[1], np.dtype('complex128'))) 

42 me[:] = spsolve(sp.eye(self.nvars) - factor * dfdu, rhs) 

43 return me