Coverage for fiqus/mains/MainConductorAC_Strand.py: 62%

74 statements  

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

1import os, cProfile 

2 

3from fiqus.geom_generators.GeometryConductorAC_Strand import Geometry 

4from fiqus.mesh_generators.MeshConductorAC_Strand import Mesh, StrandMesh 

5from fiqus.getdp_runners.RunGetdpConductorAC_Strand import Solve 

6from fiqus.post_processors.PostProcessConductorAC import PostProcess, BatchPostProcess 

7 

8 

9class MainConductorAC_Strand: 

10 def __init__(self, fdm, inputs_folder_path='', outputs_folder_path='', verbose=True): 

11 """ 

12 Main class for working with simulations for the Conductor AC model. 

13 :param fdm: FiQuS data model 

14 :param inputs_folder_path: full path to folder with input files 

15 :param verbose: if True, more info is printed in the console 

16 """ 

17 self.verbose = verbose 

18 self.fdm = fdm 

19 self.inputs_folder_path = inputs_folder_path 

20 self.outputs_folder_path = outputs_folder_path 

21 self.GetDP_path = None 

22 self.geom_folder = None 

23 self.mesh_folder = None 

24 self.solution_folder = None 

25 self.model_file = None 

26 self.model_folder = None 

27 

28 def generate_geometry(self, gui=False): 

29 """ 

30 Generates the strand geometry. 

31 """ 

32 os.chdir(self.geom_folder) 

33 g = Geometry(fdm=self.fdm, inputs_folder_path=self.inputs_folder_path, verbose=self.verbose) 

34 g.generate_strand_geometry(gui) 

35 

36 def load_geometry(self, gui: bool = False): 

37 """ 

38 Loads the previously generated geometry from the .brep file. 

39 """ 

40 os.chdir(self.geom_folder) 

41 g = Geometry(fdm=self.fdm, inputs_folder_path=self.inputs_folder_path, verbose=self.verbose) 

42 g.load_conductor_geometry(gui) 

43 # self.model_file = g.model_file 

44 

45 def pre_process(self, gui=False): 

46 pass 

47 

48 def mesh(self, gui: bool = False): 

49 """ 

50 Generates the mesh for the strand geometry. 

51 """ 

52 os.chdir(self.mesh_folder) 

53 

54 m = StrandMesh(fdm=self.fdm, verbose=self.verbose) 

55 m.generate_mesh(self.geom_folder) 

56 m.generate_cuts() 

57 m.generate_regions_file() 

58 m.save_mesh(gui) 

59 

60 return {"test": 0} 

61 

62 def load_mesh(self, gui=False): 

63 """ 

64 Loads the previously generated mesh from the MSH file. 

65 """ 

66 os.chdir(self.mesh_folder) 

67 m = Mesh(fdm=self.fdm, verbose=self.verbose) 

68 m.load_mesh(gui) 

69 

70 # self.model_file = m.mesh_file 

71 

72 def solve_and_postprocess_getdp(self, gui: bool = False): 

73 """ 

74 Assembles the .pro-file from the template, then runs the simulation and the post-processing steps using GetDP. 

75 """ 

76 os.chdir(self.solution_folder) 

77 

78 s = Solve(self.fdm, self.GetDP_path, self.geom_folder, self.mesh_folder, self.verbose) 

79 s.read_excitation(inputs_folder_path=self.inputs_folder_path) 

80 s.get_solution_parameters_from_yaml(inputs_folder_path=self.inputs_folder_path) 

81 s.assemble_pro() 

82 s.run_getdp(solve=True, postOperation=True, gui=gui) 

83 s.cleanup() 

84 

85 # def pre_process(self): 

86 # os.chdir(self.solution_folder) 

87 

88 # s = Solve(self.fdm, self.GetDP_path, self.mesh_folder, self.verbose) 

89 

90 def post_process_getdp(self, gui: bool = False): 

91 """ 

92 Runs the post-processing steps trough GetDP. 

93 """ 

94 os.chdir(self.solution_folder) 

95 

96 s = Solve(self.fdm, self.GetDP_path, self.geom_folder, self.mesh_folder, self.verbose) 

97 s.read_excitation(inputs_folder_path=self.inputs_folder_path) 

98 s.get_solution_parameters_from_yaml(inputs_folder_path=self.inputs_folder_path) 

99 s.assemble_pro() 

100 s.run_getdp(solve=False, postOperation=True, gui=gui) 

101 

102 # 

103 def post_process_python(self, gui: bool = False): 

104 # os.chdir(self.solution_folder) 

105 postProc = PostProcess(self.fdm, self.outputs_folder_path) 

106 

107 if self.fdm.magnet.postproc.plot_instantaneous_power: 

108 postProc.instantaneous_loss() 

109 

110 if self.fdm.magnet.postproc.plot_flux.show: 

111 postProc.internal_flux() 

112 

113 postProc.plotter.show() 

114 

115 return {'test': 0} 

116 

117 def batch_post_process_python(self, gui: bool = False): 

118 """ 

119 Runs batch post-processing steps using Python. 

120 Used for gathering, analysing, comparing and plotting data from multiple simulations. 

121 """ 

122 BatchPostProc = BatchPostProcess(self.fdm, lossMap_gridData_folder=None, inputs_folder_path=self.inputs_folder_path, outputs_folder_path=self.outputs_folder_path) 

123 

124 if self.fdm.magnet.postproc.batch_postproc.loss_map.produce_loss_map: 

125 # plotter.save_lossMap_gridData() 

126 # plotter.save_magnetization() 

127 BatchPostProc.plotter.create_lossMap() 

128 

129 if self.fdm.magnet.postproc.batch_postproc.loss_map.cross_section.plot_cross_section: 

130 BatchPostProc.plotter.plot_lossMap_crossSection() 

131 

132 if self.fdm.magnet.postproc.batch_postproc.loss_map.cross_section_sweep.animate_cross_section_sweep: 

133 BatchPostProc.plotter.animate_lossMap_crossSection() 

134 

135 if self.fdm.magnet.postproc.batch_postproc.plot2d.produce_plot2d: 

136 BatchPostProc.plotter.plot2d() 

137 

138 if self.fdm.magnet.postproc.batch_postproc.rohf_on_grid.fit_rohf or self.fdm.magnet.postproc.batch_postproc.rohf_on_grid.produce_error_map: 

139 BatchPostProc.rohf_on_grid() 

140 

141