Coverage for fiqus/data/DataFiQuSConductorAC_CC.py: 100%

85 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2026-01-09 01:49 +0000

1 

2"""DataFiQuSConductorAC_CC.py""" 

3 

4from pydantic import BaseModel, Field, field_validator 

5from typing import Literal, Optional, Union, List 

6 

7 

8 

9 

10class CACCCGeometry(BaseModel): 

11 """ 

12 Level 2: Geometry for CACCC. 

13 """ 

14 air_radius: Optional[float] = Field( 

15 default=None, 

16 description = "Radius of air region." 

17 ) 

18 

19 

20class CACCCGeneralparameters(BaseModel): 

21 """ 

22 Level 3: Class for general parameters 

23 """ 

24 temperature: float = Field( 

25 default=1.9, 

26 description = "Temperature (K)." 

27 ) 

28 noOfMPITasks: Optional[Union[bool, int]] = Field( 

29 default=False, title = "No. of tasks for MPI parallel run of GetDP", 

30 description = "If integer, GetDP will be run in parallel using MPI. This is only valid" 

31 " if MPI is installed on the system and an MPI-enabled GetDP is used." 

32 " If False, GetDP will be run in serial without invoking mpiexec." 

33 ) 

34 

35 

36 

37class CACCCSolveInitialconditions(BaseModel): 

38 """ 

39 Level 3: Class for initial conditions 

40 """ 

41 init_type: Optional[Literal['virgin', 'pos_file', 'uniform_field']] = Field( 

42 default='virgin', 

43 description = "Type of initialization for the simulation. (i) 'virgin' is the default type, the initial magnetic field is zero," 

44 "(ii) 'pos_file' is to initialize from the solution of another solution, given by the solution_to_init_from entry," 

45 " and (iii) 'uniform_field' is to initialize at a uniform field, which will be the applied field at the initial time of the simulation." 

46 " Note that the uniform_field option does not allow any non-zero transport current (initialization from pos_file is needed for this)." 

47 ) 

48 solution_to_init_from: Optional[Union[int, str]] = Field( 

49 default=None, 

50 description = "Name xxx of the solution from which the simulation should be initialized. " 

51 "The file last_magnetic_field.pos of folder Solution_xxx will be used for the initial solution." 

52 "It must be in the Geometry_.../Mesh_.../ folder in which the Solution_xxx will be saved.", 

53 ) 

54 

55 

56 

57class CACCCSolveSourceparametersSine(BaseModel): 

58 """ 

59 Level 4: Class for Sine source parameters 

60 """ 

61 frequency: Optional[float] = Field( 

62 default=None, 

63 description = "Frequency of the sine source (Hz)." 

64 ) 

65 field_amplitude: Optional[float] = Field( 

66 default=None, 

67 description = "Amplitude of the sine field (T)." 

68 ) 

69 current_amplitude: Optional[float] = Field( 

70 default=None, 

71 description = "Amplitude of the sine current (A)." 

72 ) 

73 

74 

75 

76class CACCCSolveSourceparametersPiecewise(BaseModel): 

77 """ 

78 Level 4: Class for piecewise (linear) source parameters 

79 """ 

80 source_csv_file: Optional[str] = Field( 

81 default=None, 

82 description = "File name for the from_file source type defining the time evolution of current and field (in-phase)." 

83 "Multipliers are used for each of them." 

84 "The file should contain two columns: 'time' (s) and 'value' (field/current (T/A)), with these headers." 

85 "If this field is set, times, applied_fields_relative and transport_currents_relative are ignored." 

86 ) 

87 times: Optional[List[float]] = Field( 

88 default=None, 

89 description = "Time instants (s) defining the piecewise linear sources." 

90 "Used only if source_csv_file is not set." 

91 "Can be scaled by time_multiplier." 

92 ) 

93 applied_fields_relative: Optional[List[float]] = Field( 

94 default=None, 

95 description = "Applied fields relative to multiplier applied_field_multiplier at the time instants 'times'." 

96 "Used only if source_csv_file is not set." 

97 ) 

98 transport_currents_relative: Optional[List[float]] = Field( 

99 default=None, 

100 description = "Transport currents relative to multiplier transport_current_multiplier at the time instants 'times'." 

101 "Used only if source_csv_file is not set." 

102 ) 

103 time_multiplier: Optional[float] = Field( 

104 default=None, 

105 description = "Multiplier for the time values in times (scales the time values)." 

106 "Also used for the time values in the source_csv_file." 

107 ) 

108 applied_field_multiplier: Optional[float] = Field( 

109 default=None, 

110 description = "Multiplier for the applied fields in applied_fields_relative." 

111 "Also used for the values in the source_csv_file." 

112 ) 

113 transport_current_multiplier: Optional[float] = Field( 

114 default=None, 

115 description = "Multiplier for the transport currents in transport_currents_relative." 

116 "Also used for the values in the source_csv_file." 

117 ) 

118 

119 

120 

121class CACCCSolveSourceparameters(BaseModel): 

122 """ 

123 Level 3: Class for material properties 

124 """ 

125 source_type: Literal['sine', 'piecewise'] = Field( 

126 default='sine', 

127 description = "Time evolution of applied current and magnetic field. " 

128 "Supported options are: sine, piecewise." 

129 ) 

130 sine: CACCCSolveSourceparametersSine = CACCCSolveSourceparametersSine() 

131 piecewise: CACCCSolveSourceparametersPiecewise = CACCCSolveSourceparametersPiecewise() 

132 field_angle_with_respect_to_normal_direction: Optional[float] = Field( 

133 default=None, 

134 description = "Angle of the source magnetic field with respect to the y-axis (normal to the tape) (degrees)." 

135 ) 

136 

137 

138 

139class CACCCSolveNumericalparametersSine(BaseModel): 

140 """  

141 Level 4: Numerical parameters corresponding to the sine source 

142 """ 

143 timesteps_per_period: Optional[float] = Field( 

144 default=None, 

145 description = "Initial value for number of time steps (-) per period for the sine source." 

146 "Determines the initial time step size." 

147 ) 

148 number_of_periods_to_simulate: Optional[float] = Field( 

149 default=None, 

150 description = "Number of periods (-) to simulate for the sine source." 

151 ) 

152 

153 

154 

155class CACCCSolveNumericalparametersPiecewise(BaseModel): 

156 """ 

157 Level 4: Numerical parameters corresponding to the piecewise source 

158 """ 

159 time_to_simulate: Optional[float] = Field( 

160 default=None, 

161 description = "Total time to simulate (s). Used for the piecewise source." 

162 ) 

163 timesteps_per_time_to_simulate: Optional[float] = Field( 

164 default=None, 

165 description = "If variable_max_timestep is False. Number of time steps (-) per period for the piecewise source." 

166 ) 

167 force_stepping_at_times_piecewise_linear: bool = Field( 

168 default=False, 

169 description = "If True, time-stepping will contain exactly the time instants that are in" 

170 "the times_source_piecewise_linear list (to avoid truncation maximum applied field/current values)." 

171 ) 

172 variable_max_timestep: bool = Field( 

173 default=False, 

174 description = "If False, the maximum time step is kept constant through the simulation. " 

175 "If True, it varies according to the piecewise definition." 

176 ) 

177 times_max_timestep_piecewise_linear: Optional[List[float]] = Field( 

178 default=None, 

179 description = "Time instants (s) defining the piecewise linear maximum time step." 

180 ) 

181 max_timestep_piecewise_linear: Optional[List[float]] = Field( 

182 default=None, 

183 description = "Maximum time steps (s) at the times_max_timestep_piecewise_linear. " 

184 "Above the limits, linear extrapolation of the last two values." 

185 ) 

186 

187 

188 

189class CACCCSolveNumericalparameters(BaseModel): 

190 """ 

191 Level 3: Class for numerical parameters 

192 """ 

193 relative_tolerance: Optional[float] = Field(default=1e-6, description="Tolerance on the relative change of the power indicator for the convergence criterion (1e-6 is usually a safe choice).") 

194 voltage_per_meter_stopping_criterion: Optional[float] = Field(default=None, description="If a non-zero value is given, the simulation will stop if the transport voltage per meter reaches this value (in absolute value).") 

195 relaxation_factors: Optional[bool] = Field(default=True, description="Use of relaxation factors to help convergence (automatic selection based on the lowest residual).") 

196 sine: CACCCSolveNumericalparametersSine = CACCCSolveNumericalparametersSine() 

197 piecewise: CACCCSolveNumericalparametersPiecewise = CACCCSolveNumericalparametersPiecewise() 

198 

199 

200 

201class CACCCSolve(BaseModel): 

202 """ 

203 Level 2: Solve block for CACCC 

204 """ 

205 pro_template: Optional[str] = Field( 

206 default='CAC_CC_template.pro', 

207 description = "Name of the .pro template file." 

208 ) 

209 conductor_name: Optional[str] = Field( 

210 default=None, 

211 description = "Name of the conductor. Must match a conductor name in " 

212 "the conductors section of the input YAML-file." 

213 ) 

214 general_parameters: CACCCGeneralparameters = ( 

215 CACCCGeneralparameters() 

216 ) 

217 initial_conditions: CACCCSolveInitialconditions = ( 

218 CACCCSolveInitialconditions() 

219 ) 

220 source_parameters: CACCCSolveSourceparameters = ( 

221 CACCCSolveSourceparameters() 

222 ) 

223 numerical_parameters: CACCCSolveNumericalparameters = ( 

224 CACCCSolveNumericalparameters() 

225 ) 

226 

227 

228 

229class CACCCMesh(BaseModel): 

230 """ 

231 Level 2: Mesh parameters for CACCC. 

232 """ 

233 HTS_n_elem_width: Optional[int] = Field( 

234 default=None, 

235 description = "Number of elements along HTS width (x-direction)." 

236 ) 

237 HTS_n_elem_thickness: Optional[int] = Field( 

238 default=None, 

239 description = "Number of elements through HTS thickness (y-direction)." 

240 ) 

241 substrate_elem_scale: Optional[float] = Field( 

242 default=None, 

243 description = "Element-count scale factor for substrate layer." 

244 ) 

245 substrate_side_progression: Optional[float] = Field( 

246 default=None, 

247 description = "Progression factor for substrate vertical sides near the HTS side." 

248 ) 

249 silver_elem_scale: Optional[float] = Field( 

250 default=None, 

251 description = "Element-count scale factor for silver layers." 

252 ) 

253 copper_elem_scale: Optional[float] = Field( 

254 default=None, 

255 description = "Element-count scale factor for copper layers." 

256 ) 

257 air_boundary_mesh_size_ratio: Optional[float] = Field( 

258 default=None, 

259 description = "Ratio of air outer-boundary mesh size to the HTS base size." 

260 ) 

261 scaling_global: Optional[float] = Field( 

262 default=None, 

263 description = "Global refinement factor." 

264 ) 

265 bump_coef: Optional[float] = Field( 

266 default=None, 

267 description = "Unified bump coefficient for transfinite horizontal edges. " 

268 "Used for both HTS and SilverTop when applying 'Bump' distributions. " 

269 "Values < 1 cluster nodes toward the edges; values > 1 cluster toward the center." 

270 ) 

271 

272 

273 

274 

275class CACCCPostprocPosFiles(BaseModel): 

276 """ 

277 Level 3: Class for post-pro .pos file requests 

278 """ 

279 quantities: Optional[List[str]] = Field( 

280 default=None, description = "List of GetDP postprocessing quantities to write to .pos file. " 

281 "Examples of valid entry is: phi, h, b, j, jz, power" 

282 ) 

283 regions: Optional[List[str]] = Field( 

284 default=None, 

285 description = "List of GetDP regions to write to .pos file postprocessing for. " 

286 "Examples of a valid entry is: " 

287 "Matrix, Filaments, Omega (full domain), OmegaC (conducting domain), OmegaCC (non conducting domain)" 

288 ) 

289 

290 @field_validator("quantities", 'regions', mode="before") 

291 @classmethod 

292 def convert_none_to_empty_list(cls, v): 

293 pass 

294 if v is None: 

295 return [] # if None default to empty list. Jinja relies on list for looping in the pro template. The default is not a list to be consistent with SDK entries. 

296 return v 

297 

298 model_config = { 

299 "validate_default": True 

300 } 

301 

302 

303 

304class CWSStrandPostprocCleanup(BaseModel): 

305 """ 

306 Level 3: Class for cleanup settings 

307 """ 

308 remove_pre_file: bool = Field( 

309 default=False, 

310 description = "Set True to remove the .pre-file after post-processing, to save disk space." 

311 ) 

312 remove_res_file: bool = Field( 

313 default=False, 

314 description = "Set True to remove the .res-file after post-processing, to save disk space." 

315 ) 

316 remove_msh_file: bool = Field( 

317 default=False, 

318 description = "Set True to remove the .msh-file after post-processing, to save disk space." 

319 ) 

320 

321 

322 

323class CACCCPostproc(BaseModel): 

324 """ 

325 Post-processing options for CACCC 

326 """ 

327 pos_files: CACCCPostprocPosFiles = Field( 

328 default=CACCCPostprocPosFiles(), 

329 description = "Entries controlling output of .pos files." 

330 "If None or empty lists are given, no .pos files are written." 

331 "Note that not all combinations of quantities and regions make sense." 

332 ) 

333 cleanup: CWSStrandPostprocCleanup = CWSStrandPostprocCleanup() 

334 

335 

336class CACCC(BaseModel): 

337 """ 

338 Level 1: Class for FiQuS CACCC 

339 """ 

340 type: Literal["CACCC"] 

341 geometry: CACCCGeometry = CACCCGeometry() 

342 mesh: CACCCMesh = CACCCMesh() 

343 solve: CACCCSolve = CACCCSolve() 

344 postproc: CACCCPostproc = CACCCPostproc() 

345