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

140 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2025-11-29 01:35 +0000

1from pydantic import BaseModel, Field 

2from typing import List, Literal, Optional, Union 

3 

4 

5# ============= GEOMETRY ============= # 

6# -- Input/Output settings -- # 

7class HomogenizedConductorIOsettingsLoad(BaseModel): 

8 """ 

9 Level 3: Class for Input/Output settings for the cable geometry 

10 """ 

11 

12 load_from_yaml: Optional[bool] = Field( 

13 default=False, 

14 description="True to load the geometry from a YAML file, false to generate the geometry.", 

15 ) 

16 filename: Optional[str] = Field( 

17 default=None, 

18 description="Name of the YAML file from which to load the geometry.", 

19 ) 

20 

21class HomogenizedConductorIOsettingsSave(BaseModel): 

22 """ 

23 Level 3: Class for Input/Output settings for the cable geometry 

24 """ 

25 

26 save_to_yaml: Optional[bool] = Field( 

27 default=False, 

28 description="True to save the geometry to a YAML-file, false to not save the geometry.", 

29 ) 

30 filename: Optional[str] = Field( 

31 default=None, 

32 description="Name of the output geometry YAML file.", 

33 ) 

34 

35class HomogenizedConductorGeometryIOsettings(BaseModel): 

36 """ 

37 Level 2: Class for Input/Output settings for the cable geometry 

38 """ 

39 

40 load: HomogenizedConductorIOsettingsLoad = ( 

41 HomogenizedConductorIOsettingsLoad() 

42 ) 

43 save: HomogenizedConductorIOsettingsSave = ( 

44 HomogenizedConductorIOsettingsSave() 

45 ) 

46 

47class Rectangle(BaseModel): 

48 """ 

49 Level 2: Class for Input/Output settings for the cable geometry 

50 """ 

51 center_position: Optional[List[float]] = Field( 

52 default=None, description="Center position in two dimensional plane (x, y)." 

53 ) 

54 width: Optional[float] = Field( 

55 default=None, description="Width of the region (m)." 

56 ) 

57 height: Optional[float] = Field( 

58 default=None, description="Height of the region (m)." 

59 ) 

60 

61class Circle(BaseModel): 

62 """ 

63 Level 2: Class for Input/Output settings for the cable geometry 

64 """ 

65 center_position: Optional[List[float]] = Field( 

66 default=None, description="Center position in two dimensional plane (x, y)." 

67 ) 

68 radius: Optional[float] = Field( 

69 default=None, description="Radius of the circle (m)." 

70 ) 

71 

72# -- Strand geometry parameters -- # 

73class HomogenizedConductorGeometry(BaseModel): 

74 """ 

75 Level 2: Class for strand geometry parameters 

76 """ 

77 cables: List[Rectangle] = Rectangle() 

78 excitation_coils: Optional[List[Rectangle]] = Field(default=[], description="List of excitation coils") 

79 air: Circle = Circle() 

80 air_form: Literal['circle'] = Field( 

81 default='circle', 

82 description="Type of model geometry which will be generated. Supported options are only circle for now" 

83 ) 

84 io_settings: HomogenizedConductorGeometryIOsettings = HomogenizedConductorGeometryIOsettings() 

85 

86# ============= MESH ============= # 

87 

88# -- Strand mesh settings -- # 

89class HomogenizedConductorMesh(BaseModel): 

90 """ 

91 Level 2: Class for FiQuS ConductorAC 

92 """ 

93 

94 scaling_global: Optional[float] = Field( 

95 default=1, description="Global scaling factor for mesh size." 

96 ) 

97 air_boundary_mesh_size_ratio: Optional[float] = Field( 

98 default=1, description="Ratio within the air region from boundary to inner elements." 

99 ) 

100 cable_mesh_size_ratio: Optional[float] = Field( 

101 default=1, description="Scaling factor within the cable regions." 

102 ) 

103 

104 

105# ============= SOLVE ============= # 

106# -- General parameters -- # 

107class HomogenizedConductorSolveGeneralparameters(BaseModel): 

108 """ 

109 Level 3: Class for general parameters 

110 """ 

111 superconductor_linear: Optional[bool] = Field(default=False, description="For debugging: replace LTS by normal conductor.") 

112 

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

114 default=False, 

115 title="No. of tasks for MPI parallel run of GetDP", 

116 description=( 

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

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

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

120 ), 

121 ) 

122 rho_cables: Optional[float] = Field( 

123 default=1, 

124 description='Resistance for cables when modelled as linear conductors (no current sharing with power law) [Ohm*m].' 

125 ) 

126 strand_transposition_length: Optional[float] = Field( 

127 default=0.1, 

128 description='Transposition length of the strands in the Rutherford cable (m).' 

129 ) 

130 n_strands: Optional[int] = Field( 

131 default=36, 

132 description='Number of strands in the cable (-).' 

133 ) 

134 strand_filling_factor: Optional[float] = Field( 

135 default=0.8617, 

136 description='Filling factor of the strands in the rectangular cable envelope (-).' 

137 ) 

138 

139 

140# -- Initial conditions -- # 

141class HomogenizedConductorSolveInitialconditions(BaseModel): 

142 """ 

143 Level 3: Class for initial conditions 

144 """ 

145 

146 init_from_pos_file: bool = Field( 

147 default=False, description="This field is used to initialize the solution from a non-zero field solution stored in a .pos file." 

148 ) 

149 pos_file_to_init_from: Optional[str] = Field( 

150 default=None, 

151 description="Name of .pos file for magnetic field (A/m) from which the solution should be initialized." 

152 " Should be in the Geometry_xxx/Mesh_xxx/ folder in which the Solution_xxx will be saved.", 

153 ) 

154 

155 

156# -- Source parameters -- # 

157class SolveExcitationCoils(BaseModel): 

158 """ 

159 Level 5: Class for superimposed DC field or current parameters for the sine source 

160 """ 

161 enable: Optional[bool] = Field(default=False, description='Solve with excitation coils acting as sources.') 

162 

163 

164class SolveSineSourceSuperimposedDC(BaseModel): 

165 """ 

166 Level 5: Class for superimposed DC field or current parameters for the sine source 

167 """ 

168 field_magnitude: Optional[float] = Field(default=0.0, description="DC field magnitude (T) (direction along y-axis). Solution must be initialized with a non-zero field solution stored in a .pos file if non-zero DC field is used.") 

169 current_magnitude: Optional[float] = Field(default=0.0, description="DC current magnitude (A). Solution must be initialized with a non-zero field solution stored in a .pos file if non-zero DC current is used.") 

170 

171 

172class SolveSineSource(BaseModel): 

173 """ 

174 Level 4: Class for Sine source parameters 

175 """ 

176 frequency: Optional[float] = Field(default=None, description="Frequency of the sine source (Hz).") 

177 field_amplitude: Optional[float] = Field(default=None, description="Amplitude of the sine field (T).") 

178 current_amplitude: Optional[float] = Field(default=None, description="Amplitude of the sine current (A).") 

179 superimposed_DC: SolveSineSourceSuperimposedDC = SolveSineSourceSuperimposedDC() 

180 

181 

182class SolvePiecewiseSource(BaseModel): 

183 """ 

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

185 """ 

186 source_csv_file: Optional[str] = Field(default=None, description="File name for the from_file source type defining the time evolution of current and field (in-phase). Multipliers are used for each of them. The file should contain two columns: 'time' (s) and 'value' (field/current (T/A)), with these headers. If this field is set, times, applied_fields_relative and transport_currents_relative are ignored.") 

187 times: Optional[List[float]] = Field(default=None, description="Time instants (s) defining the piecewise linear sources. Used only if source_csv_file is not set. Can be scaled by time_multiplier.") 

188 applied_fields_relative: Optional[List[float]] = Field(default=None, description="Applied fields relative to multiplier applied_field_multiplier at the time instants 'times'. Used only if source_csv_file is not set.") 

189 transport_currents_relative: Optional[List[float]] = Field(default=None, description="Transport currents relative to multiplier transport_current_multiplier at the time instants 'times'. Used only if source_csv_file is not set.") 

190 time_multiplier: Optional[float] = Field(default=None, description="Multiplier for the time values in times (scales the time values). Also used for the time values in the source_csv_file.") 

191 applied_field_multiplier: Optional[float] = Field(default=None, description="Multiplier for the applied fields in applied_fields_relative. Also used for the values in the source_csv_file.") 

192 transport_current_multiplier: Optional[float] = Field(default=None, description="Multiplier for the transport currents in transport_currents_relative. Also used for the values in the source_csv_file.") 

193 

194 

195class HomogenizedConductorSolveSourceparameters(BaseModel): 

196 """ 

197 Level 3: Class for material properties 

198 """ 

199 boundary_condition_type: Literal['Natural','Essential'] = Field( 

200 default='Natural', 

201 description="Type of boundary condition applied at the outer domain boundary.", 

202 ) 

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

204 default='sine', 

205 description="Time evolution of applied current and magnetic field. Supported options are: sine, sine_with_DC, piecewise_linear, from_list.", 

206 ) 

207 parallel_resistor: Optional[Union[bool, float]] = Field( 

208 default=False, 

209 title="Resistor parallel to the cable(s)", 

210 description=( 

211 "If False, no parallel resistor and the current source directly and only feeds the cable." 

212 " If True, a resistor is placed in parallel with the cable, with a default resistance of 1 Ohm. If float (cannot be zero), this defines the value of the resistance." 

213 " If more than one cable is modelled, they are all connected in series (and carry the same current)." 

214 ), 

215 ) 

216 excitation_coils: SolveExcitationCoils = SolveExcitationCoils() 

217 

218 sine: SolveSineSource = SolveSineSource() 

219 piecewise: SolvePiecewiseSource = SolvePiecewiseSource() 

220 field_angle: Optional[float] = Field(default=90, description="Angle of the source magnetic field, with respect to the x-axis (degrees).") 

221 cable_current_multipliers: Optional[List[float]] = Field( 

222 default = None, 

223 description = "Individual multipliers applied to the transport current imposed in each cable. factors are applied according to the cable declarations in the geometry section of the yaml." 

224 ) 

225 

226 

227 

228# -- Numerical parameters -- # 

229class HomogenizedConductorNumericalparametersSine(BaseModel): 

230 """  

231 Level 4: Numerical parameters corresponding to the sine source 

232 """ 

233 timesteps_per_period: Optional[float] = Field(default=None, description="Initial value for number of time steps (-) per period for the sine source. Determines the initial time step size.") 

234 number_of_periods_to_simulate: Optional[float] = Field(default=None, description="Number of periods (-) to simulate for the sine source.") 

235 

236 

237class HomogenizedConductorNumericalparametersPiecewise(BaseModel): 

238 """ 

239 Level 4: Numerical parameters corresponding to the piecewise source 

240 """ 

241 time_to_simulate: Optional[float] = Field(default=None, description="Total time to simulate (s). Used for the piecewise source.") 

242 timesteps_per_time_to_simulate: Optional[float] = Field(default=None, description="If variable_max_timestep is False. Number of time steps (-) per period for the piecewise source.") 

243 force_stepping_at_times_piecewise_linear: bool = Field(default=False, description="If True, time-stepping will contain exactly the time instants that are in the times_source_piecewise_linear list (to avoid truncation maximum applied field/current values).") 

244 

245 variable_max_timestep: bool = Field(default=False, description="If False, the maximum time step is kept constant through the simulation. If True, it varies according to the piecewise definition.") 

246 times_max_timestep_piecewise_linear: Optional[List[float]] = Field(default=None, description="Time instants (s) defining the piecewise linear maximum time step.") 

247 max_timestep_piecewise_linear: Optional[List[float]] = Field(default=None, description="Maximum time steps (s) at the times_max_timestep_piecewise_linear. Above the limits, linear extrapolation of the last two values.") 

248 

249 

250class HomogenizedConductorSolveNumericalparameters(BaseModel): 

251 """ 

252 Level 3: Class for numerical parameters 

253 """ 

254 

255 sine: HomogenizedConductorNumericalparametersSine = HomogenizedConductorNumericalparametersSine() 

256 piecewise: HomogenizedConductorNumericalparametersPiecewise = HomogenizedConductorNumericalparametersPiecewise() 

257 

258 

259# -- FrequencyDomainSolver parameters -- # 

260class HomogenizedConductorSolveFrequencyDomainSweep(BaseModel): 

261 """  

262 Level 4: Class for the frequency sweep definition within a frequency domain solver. 

263 """ 

264 run_sweep: Optional[bool] = Field(default=False, description='Enabling a frequency sweep.') 

265 

266 start_frequency: Optional[float] = Field(default=1, description='Start frequency of the sweep in Hz.') 

267 end_frequency: Optional[float] = Field(default=100, description='End frequency of the sweep in Hz.') 

268 number_of_frequencies: Optional[int] = Field(default=3, description='Total number of frequencies in the sweep (logspaced)') 

269 

270 

271class HomogenizedConductorSolveFrequencyDomain(BaseModel): 

272 """ 

273 Level 3: Class for frequency domain solver parameters 

274 """ 

275 enable: Optional[bool] = Field(default=False, description='Enable frequency solver functionality in the solve step.') 

276 frequency_sweep: HomogenizedConductorSolveFrequencyDomainSweep = HomogenizedConductorSolveFrequencyDomainSweep() 

277 

278 

279# -- Formulation parameters -- # 

280 

281class HomogenizedConductorFormulationparametersROHM(BaseModel): 

282 """ 

283 Level 4: Class for ROHM model parameters 

284 """ 

285 enable: Optional[bool] = Field( 

286 default=False, 

287 description='Use ROHM to homogenize the magnetization hysteresis in the cables.' 

288 ) 

289 parameter_csv_file: Optional[str] = Field( 

290 default=None, 

291 description='Name of the csv file containing the ROHM parameters within the inputs folder with expected row structure: [alpha,kappa,chi,gamma,lambda].' 

292 ) 

293 weight_scaling: Optional[float] = Field( 

294 default=1.0, 

295 description='Downscaling factor (s<1.0) which is applied to all weights except the first, which is scaled up to compensate.' 

296 ) 

297 tau_scaling: Optional[float] = Field( 

298 default=1.0, 

299 description='Scaling factor which is applied uniformly to all coupling time constants.' 

300 ) 

301 

302class HomogenizedConductorFormulationparametersDISCC(BaseModel): 

303 """ 

304 Level 4: Class for DISCC model parameters 

305 """ 

306 gamma_c: Optional[float] = Field( 

307 default=0.43, 

308 description='Main crossing scaling parameter (-) that quantifies crossing coupling due to field perpendicular to cable wide face.' 

309 ) 

310 gamma_a: Optional[float] = Field( 

311 default=0.53, 

312 description='Main adjacent scaling parameter (-) that quantifies adjacent coupling due to field parallel to cable wide face.' 

313 ) 

314 lambda_a: Optional[float] = Field( 

315 default=0.006, 

316 description='Mixing scaling parameter (-) that quantifies adjacent coupling due to field perpendicular to cable wide face.' 

317 ) 

318 crossing_coupling_resistance: Optional[float] = Field( 

319 default=20e-6, 

320 description='Resistance (Ohm) of the contact between crossing strands.' 

321 ) 

322 adjacent_coupling_resistance: Optional[float] = Field( 

323 default=10e-6, 

324 description='Resistance (Ohm) of the contact between adjacent strands over one periodicity length (strand twist pitch divided by the number of strands).' 

325 ) 

326class HomogenizedConductorFormulationparametersROHF(BaseModel): 

327 """ 

328 Level 4: Class for ROHF model parameters 

329 """ 

330 enable: Optional[bool] = Field( 

331 default=False, 

332 description='Use ROHF to homogenize the internal flux hysteresis in the cables.' 

333 ) 

334 parameter_csv_file: Optional[str] = Field( 

335 default=None, 

336 description='Name of the csv file containing the ROHF parameters within the inputs folder with expected row structure: [alpha,kappa,tau].' 

337 ) 

338class HomogenizedConductorFormulationparametersCS(BaseModel): 

339 """ 

340 Level 4: Class for Current Sharing (CS) model parameters 

341 """ 

342 superconductor_n_value: Optional[float] = Field(default=30, description="n value for the power law (-), used in current sharing law.") 

343 superconductor_Ic: Optional[float] = Field(default=350, description="Critical current of the strands (A) (e.g., typical value at T=1.9K and B=10T). Will be taken as a constant as in this model the field dependence is not included" 

344 " (the main purpose of the model is to verify the more efficient Homogenized Conductor model)." 

345 " Including field-dependence could be done but is not trivial because is mixes global and local quantities in this Rutherford model with strand discretized individually as stranded conductors.") 

346 matrix_resistance: Optional[float] = Field(default=6.536208e-04, description="Resistance of the matrix (per unit length) (Ohm/m) for the current sharing law. Kept constant in this model (for simplicity).") 

347 

348 

349class HomogenizedConductorFormulationparameters(BaseModel): 

350 """ 

351 Level 3: Class for finite element formulation parameters 

352 """ 

353 hphia: Optional[bool] = Field(default=False, description='Use hphia formulation.') 

354 

355 

356 

357class HomogenizedConductorSolve(BaseModel): 

358 """ 

359 Level 2: Class for FiQuS HomogenizedConductor solver settings 

360 """ 

361 pro_template: Optional[Literal['HomogenizedConductor_template.pro']] = Field( 

362 default='HomogenizedConductor_template.pro', 

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

364 ) 

365 general_parameters: HomogenizedConductorSolveGeneralparameters = ( 

366 HomogenizedConductorSolveGeneralparameters() 

367 ) 

368 formulation_parameters: HomogenizedConductorFormulationparameters = ( 

369 HomogenizedConductorFormulationparameters() 

370 ) 

371 discc: HomogenizedConductorFormulationparametersDISCC = ( 

372 HomogenizedConductorFormulationparametersDISCC() 

373 ) 

374 rohf: HomogenizedConductorFormulationparametersROHF = ( 

375 HomogenizedConductorFormulationparametersROHF() 

376 ) 

377 rohm: HomogenizedConductorFormulationparametersROHM = ( 

378 HomogenizedConductorFormulationparametersROHM() 

379 ) 

380 current_sharing: HomogenizedConductorFormulationparametersCS = ( 

381 HomogenizedConductorFormulationparametersCS() 

382 ) 

383 initial_conditions: HomogenizedConductorSolveInitialconditions = ( 

384 HomogenizedConductorSolveInitialconditions() 

385 ) 

386 source_parameters: HomogenizedConductorSolveSourceparameters = ( 

387 HomogenizedConductorSolveSourceparameters() 

388 ) 

389 numerical_parameters: HomogenizedConductorSolveNumericalparameters = ( 

390 HomogenizedConductorSolveNumericalparameters() 

391 ) 

392 frequency_domain_solver: HomogenizedConductorSolveFrequencyDomain = ( 

393 HomogenizedConductorSolveFrequencyDomain() 

394 ) 

395 

396 

397# ============= POSTPROC ============= # 

398class HomogenizedConductorFormulationparametersSampleLine(BaseModel): 

399 """ 

400 Level 3: Class for sampling along a predefined line within the model 

401 """ 

402 start_point: Optional[List[float]] = Field( 

403 default=None, 

404 description='Start point of the line in cartesian coordinates: [x,y,z].' 

405 ) 

406 end_point: Optional[List[float]] = Field( 

407 default=None, 

408 description='End point of the line in cartesian coordinates: [x,y,z].' 

409 ) 

410 samples: Optional[int] = Field( 

411 default=None, 

412 description='Integer number of evenly spaced sample points along the line including start and end point.' 

413 ) 

414 

415class HomogenizedConductorPostprocCleanup(BaseModel): 

416 """ 

417 Level 3: Class for cleanup settings 

418 """ 

419 remove_pre_file: bool = Field( 

420 default=False, 

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

422 ) 

423 remove_res_file: bool = Field( 

424 default=False, 

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

426 ) 

427 remove_msh_file: bool = Field( 

428 default=False, 

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

430 ) 

431 

432 

433class HomogenizedConductorPostproc(BaseModel): 

434 """ 

435 Level 2: Class for FiQuS ConductorAC 

436 """ 

437 generate_pos_files: bool = Field( 

438 default=True, 

439 description="Set True to generate .pos-files during post-processing", 

440 ) 

441 output_folder: Optional[str] = Field( 

442 default=None, 

443 description="Batch post-processing creates a folder with the given name in the output directory, where all the plots are saved.", 

444 ) 

445 generate_report: Optional[bool] = Field( 

446 default=False, 

447 description="Generates a PDF report including all postprocessing graphs. File is saved in the output_folder." 

448 ) 

449 save_last_current_density: Optional[str] = Field( 

450 default=None, 

451 description="Saves the last current density field solution (out-of-plane) in the file given as a string." 

452 " The '.pos' extension will be appended to it. Nothing is done if None." 

453 " This can be for using the current density as an initial condition (but not implemented yet).", 

454 ) 

455 save_last_magnetic_field: Optional[str] = Field( 

456 default=None, 

457 description="Saves the last magnetic field solution (in-plane) in the file given as a string." 

458 " The '.pos' extension will be appended to it. Nothing is done if None." 

459 " This is for using the magnetic field as an initial condition for another resolution.", 

460 ) 

461 cleanup: HomogenizedConductorPostprocCleanup = HomogenizedConductorPostprocCleanup() 

462 sample_line: HomogenizedConductorFormulationparametersSampleLine = ( 

463 HomogenizedConductorFormulationparametersSampleLine() 

464 ) 

465 

466 

467# ============= BASE ============= # 

468class HomogenizedConductor(BaseModel): 

469 """ 

470 Level 1: Class for FiQuS ConductorAC 

471 """ 

472 

473 type: Literal["HomogenizedConductor"] 

474 geometry: HomogenizedConductorGeometry = HomogenizedConductorGeometry() 

475 mesh: HomogenizedConductorMesh = HomogenizedConductorMesh() 

476 solve: HomogenizedConductorSolve = HomogenizedConductorSolve() 

477 postproc: HomogenizedConductorPostproc = HomogenizedConductorPostproc() 

478