Coverage for python/gsfit/database_readers/st40_astra_mdsplus/setup_passives.py: 0%

38 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 numpy as np 

5import numpy.typing as npt 

6from gsfit_rs import Passives 

7 

8from .astra_passives_reader import astra_passives_reader 

9 

10if TYPE_CHECKING: 

11 from . import DatabaseReader 

12 

13 

14def setup_passives( 

15 self: "DatabaseReader", 

16 pulseNo: int, 

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

18) -> Passives: 

19 """ 

20 This method initialises the Rust `Passives` class. 

21 

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

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

24 

25 **This method is specific to ASTRA simulations using fires.dat.** 

26 

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

28 """ 

29 

30 # Initialise the Passives Rust class 

31 passives = Passives() 

32 

33 # Read passive data from fires.dat 

34 passives_data = astra_passives_reader() 

35 

36 for passive_name, data in passives_data.items(): 

37 if passive_name == "ERINGT" or passive_name == "ERINGB": # or passive_name == "MCTCASE" or passive_name == "MCBCASE" 

38 continue # skip to the next passive 

39 

40 if passive_name == "GASBFLB" or passive_name == "GASBFLT": 

41 # In our set-up we have the GASBFL's as part of the IVC 

42 continue 

43 

44 if passive_name == "IVC": 

45 current_distribution_type = "eig" 

46 n_dof = settings["passive_dof_regularisation.json"]["IVC"]["n_dof"] 

47 regularisations = np.array(settings["passive_dof_regularisation.json"]["IVC"]["regularisations"]) 

48 regularisations_weight = np.array(settings["passive_dof_regularisation.json"]["IVC"]["regularisations_weight"]) 

49 

50 # Add the GASBFL's to the IVC 

51 r = np.concatenate((data["r"], passives_data["GASBFLB"]["r"], passives_data["GASBFLT"]["r"])) 

52 z = np.concatenate((data["z"], passives_data["GASBFLB"]["z"], passives_data["GASBFLT"]["z"])) 

53 d_r = np.concatenate((data["d_r"], passives_data["GASBFLB"]["d_r"], passives_data["GASBFLT"]["d_r"])) 

54 d_z = np.concatenate((data["d_z"], passives_data["GASBFLB"]["d_z"], passives_data["GASBFLT"]["d_z"])) 

55 angle_1 = np.concatenate((data["angle_1"], passives_data["GASBFLB"]["angle_1"], passives_data["GASBFLT"]["angle_1"])) 

56 angle_2 = np.concatenate((data["angle_2"], passives_data["GASBFLB"]["angle_2"], passives_data["GASBFLT"]["angle_2"])) 

57 

58 passives.add_passive( 

59 name=passive_name, 

60 r=r, 

61 z=z, 

62 d_r=d_r, 

63 d_z=d_z, 

64 angle_1=angle_1, 

65 angle_2=angle_2, 

66 resistivity=data["resistivity"], 

67 current_distribution_type=current_distribution_type, 

68 n_dof=n_dof, 

69 regularisations=regularisations, 

70 regularisations_weight=regularisations_weight, 

71 ) 

72 elif passive_name == "OVC": 

73 current_distribution_type = "constant_current_density" 

74 n_dof = 1 

75 regularisations = np.array([[1.0]]) 

76 regularisations_weight = np.array([0.001]) # original: 0.1 

77 

78 passives.add_passive( 

79 name=passive_name, 

80 r=data["r"], 

81 z=data["z"], 

82 d_r=data["d_r"], 

83 d_z=data["d_z"], 

84 angle_1=data["angle_1"], 

85 angle_2=data["angle_2"], 

86 resistivity=data["resistivity"], 

87 current_distribution_type=current_distribution_type, 

88 n_dof=n_dof, 

89 regularisations=regularisations, 

90 regularisations_weight=regularisations_weight, 

91 ) 

92 else: 

93 current_distribution_type = "constant_current_density" 

94 n_dof = 1 

95 regularisations = np.empty((0, 0)) 

96 regularisations_weight = np.empty(0) 

97 

98 passives.add_passive( 

99 name=passive_name, 

100 r=data["r"], 

101 z=data["z"], 

102 d_r=data["d_r"], 

103 d_z=data["d_z"], 

104 angle_1=data["angle_1"], 

105 angle_2=data["angle_2"], 

106 resistivity=data["resistivity"], 

107 current_distribution_type=current_distribution_type, 

108 n_dof=n_dof, 

109 regularisations=regularisations, 

110 regularisations_weight=regularisations_weight, 

111 ) 

112 

113 return passives