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

68 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-12-25 02:54 +0100

1import os 

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 

7from fiqus.plotters.PlotPythonConductorAC import PlotPython 

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 

29 def generate_geometry(self, gui=False): 

30 """  

31 Generates the strand geometry.  

32 """ 

33 os.chdir(self.geom_folder) 

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

35 g.generate_strand_geometry(gui) 

36 

37 

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

39 """ 

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

41 """ 

42 os.chdir(self.geom_folder) 

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

44 g.load_conductor_geometry(gui) 

45 # self.model_file = g.model_file 

46 

47 def pre_process(self, gui=False): 

48 pass 

49 

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

51 """  

52 Generates the mesh for the strand geometry. 

53 """ 

54 os.chdir(self.mesh_folder) 

55 

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

57 m.generate_mesh(self.geom_folder) 

58 m.generate_cuts() 

59 m.generate_regions_file() 

60 m.save_mesh(gui) 

61 

62 return {"test": 0} 

63 

64 def load_mesh(self, gui=False): 

65 """ 

66 Loads the previously generated mesh from the MSH file. 

67 """ 

68 os.chdir(self.mesh_folder) 

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

70 m.load_mesh(gui) 

71 

72 # self.model_file = m.mesh_file 

73 

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

75 """ 

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

77 """ 

78 os.chdir(self.solution_folder) 

79 

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

81 s.read_excitation(inputs_folder_path=self.inputs_folder_path) 

82 s.get_solution_parameters_from_yaml(inputs_folder_path=self.inputs_folder_path) 

83 s.assemble_pro() 

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

85 s.cleanup() 

86 

87 # def pre_process(self): 

88 # os.chdir(self.solution_folder) 

89 

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

91 

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

93 """  

94 Runs the post-processing steps trough GetDP. 

95 """ 

96 os.chdir(self.solution_folder) 

97 

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

99 s.read_excitation(inputs_folder_path=self.inputs_folder_path) 

100 s.assemble_pro() 

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

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 postProc.plot_instantaneous_loss() 

107 

108 return {'test': 0} 

109 

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

111 """  

112 Runs batch post-processing steps using Python.  

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

114 """ 

115 plotter = PlotPython(self.fdm, csv_filename=self.fdm.magnet.postproc.batch_postproc.postProc_csv, lossMap_gridData_folder=None, inputs_folder_path=self.inputs_folder_path, outputs_folder_path=self.outputs_folder_path) 

116 

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

118 # plotter.save_lossMap_gridData() 

119 # plotter.save_magnetization() 

120 plotter.create_lossMap() 

121 

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

123 plotter.plot_lossMap_crossSection() 

124 

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

126 plotter.animate_lossMap_crossSection() 

127 

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

129 plotter.plot2d() 

130 

131 

132 # def plot_python(self): 

133 # pass