Coverage for python/gsfit/database_readers/freegs/setup_coils.py: 0%

18 statements  

« prev     ^ index     » next       coverage.py v7.15.0, created at 2026-07-07 13:12 +0000

1import typing 

2from typing import TYPE_CHECKING 

3 

4import freegs 

5import numpy as np 

6import numpy.typing as npt 

7from gsfit_rs import Coils 

8 

9if TYPE_CHECKING: 

10 from . import DatabaseReader 

11 

12 

13def setup_coils( 

14 self: "DatabaseReader", 

15 pulseNo: int, 

16 settings: dict[str, typing.Any], 

17 time: npt.NDArray[np.float64], 

18 freegs_eqs: list[freegs.equilibrium.Equilibrium], 

19) -> Coils: 

20 """ 

21 This method initialises the Rust `Coils` class. 

22 

23 :param pulseNo: Pulse number, used to read from the database 

24 :param settings: Dictionary containing the JSON settings read from the `settings` directory 

25 

26 **This method is specific to FreeGS.** 

27 

28 See `python/gsfit/database_readers/interface.py` for more details on how a new database_reader should be implemented. 

29 """ 

30 

31 # Initialise the coils class 

32 coils = Coils() 

33 

34 for pf_coil in freegs_eqs[0].tokamak.coils: 

35 # if isinstance(pf_coil, freegs.multi_coil.MultiCoil): 

36 coil_name = pf_coil[0] 

37 coil_r = pf_coil[1].Rfil 

38 coil_z = pf_coil[1].Zfil 

39 coil_d_r = pf_coil[1].Rfil * 0.0 + 1e-3 

40 coil_d_z = pf_coil[1].Zfil * 0.0 + 1e-3 

41 current = pf_coil[1].current 

42 # elif isinstance(pf_coil[1], freegs.machine.Coil): 

43 # coil_name = pf_coil[0] 

44 # coil_r = np.array([pf_coil[1].R]) 

45 # coil_z = np.array([pf_coil[1].Z]) 

46 # coil_d_r = np.array([1e-3]) 

47 # coil_d_z = np.array([1e-3]) 

48 # current = pf_coil[1].current * pf_coil[1].turns 

49 # elif isinstance(pf_coil[1], freegs.machine.Solenoid): 

50 # coil_name = pf_coil[0] 

51 # Rs = pf_coil[1].Rs 

52 # Zsmin = pf_coil[1].Zsmin 

53 # Zsmax = pf_coil[1].Zsmax 

54 # n_turns = pf_coil[1].Ns 

55 # coil_r = np.full(n_turns, Rs) 

56 # coil_z = np.linspace(Zsmin, Zsmax, n_turns) 

57 # coil_d_r = np.full(n_turns, 1e-3) 

58 # coil_d_z = np.full(n_turns, 1e-3) 

59 # current = pf_coil[1].current 

60 # else: 

61 # raise ValueError(f"Unknown coil type: {pf_coil[1]}") 

62 

63 coils.add_pf_coil( 

64 name=coil_name, 

65 r=coil_r, 

66 z=coil_z, 

67 d_r=coil_d_r, 

68 d_z=coil_d_z, 

69 time=np.array([0.0, 1.0]), 

70 measured=np.array([current, current]), 

71 ) 

72 

73 # Add TF coil 

74 coils.add_tf_coil( 

75 time=np.array([0.0, 1.0]), 

76 measured=np.array([1.0e6, 1.0e6]), 

77 ) 

78 

79 return coils