Coverage for fiqus/mains/MainCCT.py: 93%
97 statements
« prev ^ index » next coverage.py v7.4.4, created at 2025-01-14 02:37 +0100
« prev ^ index » next coverage.py v7.4.4, created at 2025-01-14 02:37 +0100
1import os
2import sys
3import time
4if len(sys.argv) == 3:
5 sys.path.insert(0, os.path.join(os.getcwd(), 'steam-fiqus-dev'))
6from fiqus.geom_generators.GeometryCCT import Generate_BREPs
7from fiqus.geom_generators.GeometryCCT import Prepare_BREPs
8from fiqus.pre_processors.PreProcessCCT import Pre_Process
9from fiqus.mesh_generators.MeshCCT import Mesh
10from fiqus.getdp_runners.RunGetdpCCT import RunGetdpCCT
11from fiqus.post_processors.PostProcessCCT import Post_Process
12from fiqus.plotters.PlotPythonCCT import PlotPythonCCT
14class MainCCT:
15 def __init__(self, fdm, verbose=True):
16 """
17 Main class for working with simulations for CCT type magnets
18 :param fdm: FiQuS data model
19 :param verbose: if True, more info is printed in the console
20 """
21 # os.chdir(model_folder)
22 self.verbose = verbose
23 self.fdm = fdm
24 self.settings = None
25 self.geom_folder = None
26 self.mesh_folder = None
27 self.solution_folder = None
28 self.model_file = None
29 self.model_folder = None
31 def generate_geometry(self, gui=False):
32 os.chdir(self.geom_folder)
33 gb = Generate_BREPs(fdm=self.fdm, verbose=self.verbose)
34 gb.generate_windings_or_fqpls('windings')
35 gb.save_volume_info()
36 gb.generate_windings_or_fqpls('fqpls')
37 gb.generate_formers()
38 gb.generate_air()
39 gb.generate_regions_file()
41 pb = Prepare_BREPs(fdm=self.fdm, verbose=self.verbose)
42 pb.straighten_terminal(gui=False)
43 pb.extend_terms(operation='extend', gui=False) # use operation='add' for externally generated brep files for windings
44 pb.save_fqpl_vi()
45 pb.fragment(gui=gui)
46 self.model_file = pb.model_file
47 self.model_folder = pb.model_folder
49 def load_geometry(self, gui=False):
50 os.chdir(self.geom_folder)
51 pb = Prepare_BREPs(fdm=self.fdm, verbose=self.verbose)
52 pb.load_geometry(gui=gui)
53 self.model_file = pb.model_file
54 self.model_folder = pb.model_folder
56 def pre_process(self, gui=False):
57 os.chdir(self.geom_folder)
58 pp = Pre_Process(fdm=self.fdm)
59 pp.calculate_normals(gui=gui)
61 def mesh(self, gui=False):
62 os.chdir(self.geom_folder)
63 pb = Prepare_BREPs(fdm=self.fdm, verbose=self.verbose)
64 pb.load_geometry(gui=False)
65 os.chdir(self.mesh_folder)
66 m = Mesh(fdm=self.fdm)
67 m.generate_physical_groups()
68 m.generate_mesh(gui=False)
69 m.generate_cuts(gui=False)
70 m.save_mesh(gui=gui)
71 self.model_file = m.model_file
72 self.model_folder = m.model_folder
73 return {'gamma': 0} # to be modified with mesh_parameters (see multipole)
75 def load_mesh(self, gui=False):
76 os.chdir(self.mesh_folder)
77 m = Mesh(fdm=self.fdm)
78 m.load_mesh(gui=gui)
80 def solve_and_postprocess_getdp(self, gui=False):
81 os.chdir(self.solution_folder)
82 gb = Generate_BREPs(fdm=self.fdm, verbose=self.verbose)
83 gb.generate_regions_file()
84 rg = RunGetdpCCT(fdm=self.fdm, GetDP_path=self.GetDP_path)
85 rg.assemble_pro()
86 start_time = time.time()
87 rg.solve_and_postprocess(gui=gui)
88 self.model_file = rg.model_file
89 self.model_folder = rg.model_folder
90 return time.time() - start_time
92 def post_process_getdp(self, gui=False):
93 os.chdir(self.solution_folder)
94 gb = Generate_BREPs(fdm=self.fdm, verbose=self.verbose)
95 gb.generate_regions_file()
96 rg = RunGetdpCCT(fdm=self.fdm, GetDP_path=self.GetDP_path)
97 rg.assemble_pro()
98 rg.postprocess(gui=gui)
99 self.model_file = rg.model_file
100 self.model_folder = rg.model_folder
102 def post_process_python(self, gui=False):
103 os.chdir(self.solution_folder)
104 pp = Post_Process(self.fdm)
105 pp.postprocess_fields(gui=gui)
106 #pp.postprocess_thermal_connections()
107 pp.postporcess_inductance()
108 self.model_file = pp.model_file
109 self.model_folder = pp.model_folder
110 return {'overall_error': 0} # to be modified with postprocess_parameters (see multipole)
112 def plot_python(self):
113 os.chdir(self.solution_folder)
114 p = PlotPythonCCT(self.fdm)
115 p.plot_elements_file()