Coverage for pygeodyn/generic/computer.py: 97%

30 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-12-22 13:43 +0000

1import numpy as np 

2from ..corestates import with_core_state_of_dimensions 

3import geodyn_fortran as fortran 

4from ..inout.config import ComputationConfig 

5 

6 

7class GenericComputer(object): 

8 """ 

9 Mother class of Forecaster and Analyser. Implements methods and members that are common to both. 

10 """ 

11 def __init__(self, algo): 

12 """ 

13 Constructor of GenericComputer. Sets the args as members. 

14 

15 :param algo: Algorithm object 

16 :type algo: Algo 

17 """ 

18 

19 if type(algo.config) is not ComputationConfig: 

20 raise TypeError('{} was initialised with a ComputationConfig argument ! Got an argument of type {} instead.'.format(type(self).__name__, type(algo.config))) 

21 

22 self.cfg = algo.config 

23 self.algo = algo 

24 

25 @with_core_state_of_dimensions(1) 

26 def compute_Ab(self, input_core_state, specfic_real=False): 

27 """ 

28 Compute A(b) the operator DivH(uBr) in the spectral domain. 

29 

30 :param input_core_state: 1D CoreState storing a minima the magnetic field coefficients. 

31 :type input_core_state: 1D CoreState 

32 :return: The computed A(b) 

33 :rtype: 2D numpy.ndarray (dim: Nsv x Nu2) 

34 """ 

35 

36 gauss_th = np.asfortranarray(self.algo.legendre_polys['thetas']) 

37 gauss_weights = np.asfortranarray(self.algo.legendre_polys['weights']) 

38 tmax = gauss_th.shape[0] 

39 

40 lpsv = np.asfortranarray(self.algo.legendre_polys['SV'][0]) 

41 dlpsv = np.asfortranarray(self.algo.legendre_polys['SV'][1]) 

42 d2lpsv = np.asfortranarray(self.algo.legendre_polys['SV'][2]) 

43 LLsv = d2lpsv.shape[0] 

44 

45 lpu = np.asfortranarray(self.algo.legendre_polys['U'][0]) 

46 dlpu = np.asfortranarray(self.algo.legendre_polys['U'][1]) 

47 d2lpu = np.asfortranarray(self.algo.legendre_polys['U'][2]) 

48 LLu = d2lpu.shape[0] 

49 

50 lpb = np.asfortranarray(self.algo.legendre_polys['MF'][0]) 

51 dlpb = np.asfortranarray(self.algo.legendre_polys['MF'][1]) 

52 d2lpb = np.asfortranarray(self.algo.legendre_polys['MF'][2]) 

53 LLb = d2lpb.shape[0] 

54 

55 # Function radmats computes A(b)^T 

56 AbT = np.zeros((input_core_state.Nu2, input_core_state.Nsv), order='F') 

57 fortran.integral.radmats(gauss_th, gauss_weights, lpsv, dlpsv, d2lpsv, 

58 lpu, dlpu, d2lpu, lpb, dlpb, d2lpb, 

59 AbT, input_core_state.B, 

60 input_core_state.Lsv, input_core_state.Lu, input_core_state.Lb, 

61 input_core_state.Nsv, input_core_state.Nu2 // 2, input_core_state.Nb, 

62 LLsv, LLu, LLb, tmax) 

63 

64 # Return A(b) 

65 return np.transpose(AbT)