Skip to content

Commit f9f7882

Browse files
authored
Merge pull request #164 from upb-lea/gmsh_improvement
Gmsh improvement
2 parents 636e282 + 7d60341 commit f9f7882

5 files changed

Lines changed: 191 additions & 59 deletions

File tree

femmt/component.py

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def __init__(self, simulation_type: SimulationType = SimulationType.FreqDomain,
6464
:type component_type: ComponentType
6565
:param working_directory: Sets the working directory
6666
:type working_directory: string
67-
:param visualization_mode: Sets the visualization mode. it is only used in the time domain simulation.
67+
:param visualization_mode: Sets the visualization mode. it is used in the time and frequency domain simulation.
6868
:type visualization_mode: VisualizationMode
6969
:param is_gui: Asks at first startup for onelab-path. Distinction between GUI and command line.
7070
Defaults to 'False' in command-line-mode.
@@ -1301,8 +1301,23 @@ def simulate(self):
13011301
# Run simulations as sub clients (non-blocking??)
13021302
getdp_filepath = os.path.join(self.file_data.onelab_folder_path, "getdp")
13031303
if self.simulation_type == SimulationType.FreqDomain:
1304-
self.onelab_client.runSubClient("myGetDP", getdp_filepath + " " + solver_freq + " -msh " + \
1305-
self.file_data.e_m_mesh_file + " -solve Analysis -v2 " + verbose + to_file_str)
1304+
if self.visualization_mode == VisualizationMode.Stream:
1305+
# It opens gmsh and runs live
1306+
# 1) Start GUI
1307+
if not gmsh.isInitialized():
1308+
gmsh.initialize()
1309+
if '-nopopup' not in sys.argv:
1310+
gmsh.fltk.initialize()
1311+
gmsh.onelab.run("myGetDP", getdp_filepath + " " + solver_freq + " -msh " + self.file_data.e_m_mesh_file + \
1312+
" -solve Analysis -v2" + verbose + to_file_str)
1313+
gmsh.fltk.run()
1314+
elif self.visualization_mode == VisualizationMode.Post:
1315+
gmsh.onelab.run("myGetDP", getdp_filepath + " " + solver_freq + " -msh " + self.file_data.e_m_mesh_file + \
1316+
" -solve Analysis -v2" + verbose + to_file_str)
1317+
gmsh.fltk.run()
1318+
else:
1319+
self.onelab_client.runSubClient("myGetDP", getdp_filepath + " " + solver_freq + " -msh " + \
1320+
self.file_data.e_m_mesh_file + " -solve Analysis -v2 " + verbose + to_file_str)
13061321
if self.simulation_type == SimulationType.TimeDomain:
13071322
if self.visualization_mode == VisualizationMode.Stream:
13081323
# 1) Start GUI
@@ -1430,8 +1445,9 @@ def single_simulation(self, freq: float, current: list[float], phi_deg: list[flo
14301445
self.calculate_and_write_freq_domain_log() # TODO: reuse center tapped
14311446
self.log_reluctance_and_inductance()
14321447
logging_time = time.time() - start_time
1433-
if show_fem_simulation_results:
1434-
self.visualize()
1448+
if self.visualization_mode == VisualizationMode.Final:
1449+
if show_fem_simulation_results:
1450+
self.visualize()
14351451

14361452
return generate_electro_magnetic_mesh_time, prepare_simulation_time, real_simulation_time, logging_time
14371453
else:
@@ -1444,8 +1460,9 @@ def single_simulation(self, freq: float, current: list[float], phi_deg: list[flo
14441460
self.simulate()
14451461
self.calculate_and_write_freq_domain_log() # TODO: reuse center tapped
14461462
self.log_reluctance_and_inductance()
1447-
if show_fem_simulation_results:
1448-
self.visualize()
1463+
if self.visualization_mode == VisualizationMode.Final:
1464+
if show_fem_simulation_results:
1465+
self.visualize()
14491466
logger.info(f"The electromagnetic results are stored here: {self.file_data.e_m_results_log_path}")
14501467

14511468
def time_domain_simulation(self, current_period_vec: list[list[float]], time_period_vec: list[float], number_of_periods: int,
@@ -3476,6 +3493,10 @@ def write_electro_magnetic_parameter_pro(self):
34763493
text_file.write("Flag_Freq_Domain = 1;\n")
34773494
text_file.write("Flag_Time_Domain = 0;\n")
34783495
text_file.write("Flag_Static = 0;\n")
3496+
if self.visualization_mode == VisualizationMode.Stream or self.visualization_mode == VisualizationMode.Post:
3497+
text_file.write("Flag_Stream_Visualization = 1;\n")
3498+
else:
3499+
text_file.write("Flag_Stream_Visualization = 0;\n")
34793500

34803501
if self.simulation_type == SimulationType.TimeDomain:
34813502
text_file.write("Flag_Time_Domain = 1;\n")
@@ -3658,7 +3679,8 @@ def write_electro_static_parameter_pro(self):
36583679
winding_number=winding_number)
36593680

36603681
if self.windings[winding_number].parallel:
3661-
raise Exception("Parallel winding are not considered yet for electrostatic simulation")
3682+
text_file.write(f"NbrCond_{winding_number + 1} = 1;\n")
3683+
text_file.write(f"AreaCell_{winding_number + 1} = {self.windings[winding_number].a_cell * turns};\n")
36623684
else:
36633685
text_file.write(f"NbrCond_{winding_number + 1} = {turns};\n")
36643686
text_file.write(f"AreaCell_{winding_number + 1} = {self.windings[winding_number].a_cell};\n")
@@ -4356,8 +4378,11 @@ def calculate_and_write_electrostatic_log(self):
43564378
log_dict["capacitances"] = {"within_winding": {}, "between_windings": {}, "between_turns_core": {}}
43574379

43584380
for winding_number in range(len(self.windings)):
4359-
turns = ff.get_number_of_turns_of_winding(winding_windows=self.winding_windows, windings=self.windings,
4360-
winding_number=winding_number)
4381+
if self.windings[winding_number].parallel:
4382+
turns = 1
4383+
else:
4384+
turns = ff.get_number_of_turns_of_winding(winding_windows=self.winding_windows, windings=self.windings,
4385+
winding_number=winding_number)
43614386
winding_name = f"Winding_{winding_number + 1}"
43624387
log_dict["capacitances"]["within_winding"][winding_name] = {}
43634388

@@ -4380,10 +4405,16 @@ def calculate_and_write_electrostatic_log(self):
43804405
for winding2 in range(len(self.windings)):
43814406
if winding1 == winding2:
43824407
continue
4383-
turns1 = ff.get_number_of_turns_of_winding(winding_windows=self.winding_windows, windings=self.windings,
4384-
winding_number=winding1)
4385-
turns2 = ff.get_number_of_turns_of_winding(winding_windows=self.winding_windows, windings=self.windings,
4386-
winding_number=winding2)
4408+
if self.windings[winding1].parallel:
4409+
turns1 = 1
4410+
else:
4411+
turns1 = ff.get_number_of_turns_of_winding(winding_windows=self.winding_windows, windings=self.windings,
4412+
winding_number=winding1)
4413+
if self.windings[winding2].parallel:
4414+
turns2 = 1
4415+
else:
4416+
turns2 = ff.get_number_of_turns_of_winding(winding_windows=self.winding_windows, windings=self.windings,
4417+
winding_number=winding2)
43874418
winding2_name = f"Winding_{winding2 + 1}"
43884419
log_dict["capacitances"]["between_windings"][winding1_name][winding2_name] = {}
43894420

@@ -4410,9 +4441,11 @@ def calculate_and_write_electrostatic_log(self):
44104441
for winding_number in range(len(self.windings)):
44114442
winding_name = f"Winding_{winding_number + 1}"
44124443
log_dict["capacitances"]["between_turns_core"][winding_name] = {}
4413-
4414-
turns = ff.get_number_of_turns_of_winding(winding_windows=self.winding_windows, windings=self.windings,
4415-
winding_number=winding_number)
4444+
if self.windings[winding_number].parallel:
4445+
turns = 1
4446+
else:
4447+
turns = ff.get_number_of_turns_of_winding(winding_windows=self.winding_windows, windings=self.windings,
4448+
winding_number=winding_number)
44164449
for turn in range(1, turns + 1):
44174450
turn_key = f"Turn_{turn}"
44184451
capacitance_key = f"C_{winding_number + 1}_{turn}_Core"

femmt/electro_magnetic/fields.pro

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,67 @@ PostOperation Map_local UsingPost MagDyn_a {
5151
//Print[ ir_norm, OnElementsOf Region[{Domain}], File StrCat[DirResFields, "ir_norm", ExtGmsh], LastTimeStepOnly ] ;
5252

5353
// Ohmic Loss
54-
If(Flag_show_standard_fields)
55-
//Print[ j2F, OnElementsOf Region[{DomainC}], Name "Solid wire and core eddy current losses / W", File StrCat[DirResFields, "j2F", ExtGmsh], LastTimeStepOnly ] ;
56-
Print[ j2F_density, OnElementsOf Region[{DomainC}], Name "Solid wire and core eddy current loss density / W/m^3", File StrCat[DirResFields, "j2F_density", ExtGmsh], LastTimeStepOnly ] ;
57-
EndIf
58-
If(Flag_show_standard_fields)
59-
//Print[ j2H, OnElementsOf DomainS, Name "Litz wire losses / W" , File StrCat[DirResFields,"jH",ExtGmsh] ] ;
60-
Print[ j2H_density, OnElementsOf DomainS, Name "Litz wire loss density / W/m^3", File StrCat[DirResFields,"jH_density",ExtGmsh] ] ;
61-
EndIf
62-
//Print[ j2Hprox, OnElementsOf DomainS, File StrCat[DirResFields,"jHprox",ExtGmsh] ] ;
63-
//Print[ j2Hskin, OnElementsOf DomainS, File StrCat[DirResFields,"jHskin",ExtGmsh] ] ;
54+
// This code is written to avoid the duplication of the printed losses, and also to avoid printing both losses where do we have just solid losses
55+
// This is just in stream visualization
56+
If (Flag_Stream_Visualization)
57+
// initialize
58+
solid_exist = 0;
59+
litz_exist = 0;
60+
61+
For n In {1:n_windings}
62+
If(!Flag_HomogenisedModel~{n})
63+
solid_exist = 1; // found a solid conductor
64+
Else
65+
litz_exist = 1; // found a litz conductor
66+
EndIf
67+
EndFor
6468

69+
If(Flag_show_standard_fields)
70+
If(solid_exist)
71+
Print[ j2F_density, OnElementsOf Region[{DomainC}], Name "Solid wire and core eddy current loss density / W/m^3",
72+
File StrCat[DirResFields, "j2F_density", ExtGmsh], LastTimeStepOnly] ;
73+
EndIf
74+
If(litz_exist)
75+
Print[ j2H_density, OnElementsOf DomainS, Name "Litz wire loss density / W/m^3", File StrCat[DirResFields,"j2H_density",ExtGmsh], LastTimeStepOnly] ;
76+
EndIf
77+
EndIf
78+
Else
79+
If(Flag_show_standard_fields)
80+
Print[ j2F_density, OnElementsOf Region[{DomainC}], Name "Solid wire and core eddy current loss density / W/m^3", File StrCat[DirResFields, "j2F_density", ExtGmsh]] ;
81+
Print[ j2H_density, OnElementsOf DomainS, Name "Litz wire loss density / W/m^3", File StrCat[DirResFields,"j2H_density",ExtGmsh]] ;
82+
EndIf
83+
EndIf
6584

6685
// Settings
86+
/*
6787
Echo[ Str["View[PostProcessing.NbViews-1].Light=0;
6888
View[PostProcessing.NbViews-1].LineWidth = 2;
6989
View[PostProcessing.NbViews-1].RangeType=3;
7090
View[PostProcessing.NbViews-1].IntervalsType=1;
91+
View[PostProcessing.NbViews-1].ScaleType=1;
7192
View[PostProcessing.NbViews-1].NbIso = 25;"],
72-
File OptionPos];
93+
File "Option.pos"]; */
94+
// Settings
95+
If (Flag_Stream_Visualization)
96+
Echo[ Str[
97+
"For k In {0:PostProcessing.NbViews-1}",
98+
" View[k].RangeType = 3;", // per timestep
99+
" View[k].NbIso = 25;",
100+
" View[k].IntervalsType= 3;",
101+
" View[k].AutoPosition = 3;",
102+
" If (!StrCmp(View[k].Name, 'Solid wire and core eddy current loss density / W/m^3'))",
103+
" View[k].ScaleType = 2;",
104+
" View[k].SaturateValues = 1;",
105+
" EndIf",
106+
" If (!StrCmp(View[k].Name, 'Litz wire loss density / W/m^3'))",
107+
" View[k].ScaleType = 2;",
108+
" EndIf",
109+
" If (!StrCmp(View[k].Name, 'Litz wire loss density / W/m^3'))",
110+
" View[k].ScaleType = 2;",
111+
" EndIf",
112+
"EndFor"
113+
], File "option.pos"];
114+
EndIf
73115
// RangeType = 1; // Value scale range type (1=default, 2=custom, 3=per time step)
74116
// IntervalsType = 2; // Type of interval display (1=iso, 2=continuous, 3=discrete, 4=numeric)
75117

femmt/electro_magnetic/ind_axi_python_controlled.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ If(Flag_Permeability_From_Data)
77
Include "core_materials_temp.pro";
88
EndIf
99
ExtGmsh = ".pos";
10+
po = "Output 2D (Magnetic Simulation)/";
1011

1112

1213
// ----------------------

femmt/electro_magnetic/values.pro

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ PostOperation Get_global UsingPost MagDyn_a {
1010
//Print[ SoF[ DomainC ], OnGlobal, Format TimeTable, File > Sprintf("results/SF_Core.dat")] ; // TODO: Complex power
1111
//Print[ j2F[ Winding~{1} ], OnGlobal, Format TimeTable, File > StrCat[DirResVals, "j2F_1.dat"]] ;
1212

13-
For n In {1:n_windings}
14-
Print[ j2F[ Winding~{n} ], OnGlobal, Format TimeTable, File > Sprintf[StrCat[DirResVals, "j2F_%g.dat"], n]] ;
15-
EndFor
16-
17-
1813

1914
//Print[ j2F[ Winding3 ], OnGlobal, Format TimeTable, File > StrCat[DirResVals,"j2F_3.dat"]] ;
2015
// Stranded
@@ -24,10 +19,41 @@ PostOperation Get_global UsingPost MagDyn_a {
2419
//Print[ j2H[ StrandedWinding~{1} ], OnGlobal, Format TimeTable, File > StrCat[DirResVals,"j2H_1.dat"] ] ;
2520
//Print[ j2H[ StrandedWinding1 ], OnGlobal, Format Table];
2621

27-
For n In {1:n_windings}
28-
Print[ j2H[ StrandedWinding~{n} ], OnGlobal, Format TimeTable, File > Sprintf[StrCat[DirResVals,"j2H_%g.dat"], n]] ;
29-
EndFor
30-
22+
// This code is to prevent printing both if one of them is not exist
23+
If (Flag_Stream_Visualization)
24+
// initialize
25+
solid_exist = 0;
26+
litz_exist = 0;
27+
28+
For n In {1:n_windings}
29+
If(!Flag_HomogenisedModel~{n})
30+
solid_exist = 1; // found a solid conductor
31+
Else
32+
litz_exist = 1; // found a litz conductor
33+
EndIf
34+
EndFor
35+
If (solid_exist)
36+
For n In {1:n_windings}
37+
Print[ j2F[ Winding~{n} ], OnGlobal, Format TimeTable, File > Sprintf[StrCat[DirResVals, "j2F_%g.dat"], n],
38+
SendToServer Sprintf[StrCat[po,"12winding_%g_losses [J]"], n], Color "LightYellow" ] ;
39+
EndFor
40+
EndIf
41+
If(litz_exist)
42+
For n In {1:n_windings}
43+
Print[ j2H[ StrandedWinding~{n} ], OnGlobal, Format TimeTable, File > Sprintf[StrCat[DirResVals,"j2H_%g.dat"], n],
44+
SendToServer Sprintf[StrCat[po,"13winding_%g_losses [J]"], n], Color "LightYellow"] ;
45+
EndFor
46+
EndIf
47+
Else
48+
For n In {1:n_windings}
49+
Print[ j2F[ Winding~{n} ], OnGlobal, Format TimeTable, File > Sprintf[StrCat[DirResVals, "j2F_%g.dat"], n],
50+
SendToServer Sprintf[StrCat[po,"12winding_%g_losses [J]"], n], Color "LightYellow" ] ;
51+
EndFor
52+
For n In {1:n_windings}
53+
Print[ j2H[ StrandedWinding~{n} ], OnGlobal, Format TimeTable, File > Sprintf[StrCat[DirResVals,"j2H_%g.dat"], n],
54+
SendToServer Sprintf[StrCat[po,"13winding_%g_losses [J]"], n], Color "LightYellow"] ;
55+
EndFor
56+
EndIf
3157

3258
//Print[ j2H[ StrandedWinding2 ], OnGlobal, Format TimeTable, File > StrCat[DirResVals,"j2H_2.dat"] ] ;
3359
//Print[ j2H[ StrandedWinding3 ], OnGlobal, Format TimeTable, File > StrCat[DirResVals,"j2H_3.dat"] ] ;
@@ -54,13 +80,15 @@ PostOperation Get_global UsingPost MagDyn_a {
5480
// Core
5581

5682
// Eddy Current Losses according to sigma in Core
57-
Print[ j2F[ Core ], OnGlobal, Format TimeTable, File > StrCat[DirResVals,"CoreEddyCurrentLosses.dat"]] ;
83+
Print[ j2F[ Core ], OnGlobal, Format TimeTable, File > StrCat[DirResVals,"CoreEddyCurrentLosses.dat"], SendToServer StrCat[po,"15core_eddy_losses[J]"], Color "LightYellow" ] ;
5884

5985
// Hysteresis Losses according to complex permeability in Core
6086
Print[ p_hyst[ Core ], OnGlobal, Format TimeTable, File > StrCat[DirResVals,"p_hyst.dat"]] ;// Core losses
6187
For n In {1:nCoreParts}
62-
Print[ p_hyst[ CorePart~{n} ], OnGlobal , Format TimeTable, File > Sprintf[StrCat[DirResValsCore, "p_hyst_%g.dat"], n]] ;
63-
Print[ j2F[ CorePart~{n} ], OnGlobal , Format TimeTable, File > Sprintf[StrCat[DirResValsCore, "CoreEddyCurrentLosses_%g.dat"], n]] ;
88+
Print[ p_hyst[ CorePart~{n} ], OnGlobal , Format TimeTable, File > Sprintf[StrCat[DirResValsCore, "p_hyst_%g.dat"], n],
89+
SendToServer StrCat[po,"16hyst_losses[J]"], Color "LightYellow"] ;
90+
Print[ j2F[ CorePart~{n} ], OnGlobal , Format TimeTable, File > Sprintf[StrCat[DirResValsCore, "CoreEddyCurrentLosses_%g.dat"], n],
91+
SendToServer Sprintf[StrCat[po,"17core_part_%g_eddy_losses [J]"], n], Color "LightYellow"] ;
6492
EndFor
6593

6694

@@ -76,14 +104,16 @@ PostOperation Get_global UsingPost MagDyn_a {
76104
// Print[ Flux_Linkage_1[DomainCond1], OnGlobal, Format Table];
77105

78106
For n In {1:n_windings}
79-
Print[ Flux_Linkage~{n}[DomainCond~{n}], OnGlobal, Format Table, File > Sprintf[StrCat[DirResVals,"Flux_Linkage_%g.dat"], n]];
107+
Print[ Flux_Linkage~{n}[DomainCond~{n}], OnGlobal, Format Table, File > Sprintf[StrCat[DirResVals,"Flux_Linkage_%g.dat"], n],
108+
SendToServer Sprintf[StrCat[po,"18Flux_%g [Wb]"], n], Color "LightYellow"];
80109
//Print[ Flux_Linkage~{n}[DomainCond~{n}], OnGlobal, Format Table];
81110
EndFor
82111

83112
// Inductances
84113
For n In {1:n_windings}
85114
If(Val_EE~{n}!=0)
86-
Print[ L~{n}~{n}[DomainCond~{n}], OnGlobal, Format TimeTable, File > Sprintf[StrCat[DirResVals,"L_%g_%g.dat"], n, n]] ;
115+
Print[ L~{n}~{n}[DomainCond~{n}], OnGlobal, Format TimeTable, File > Sprintf[StrCat[DirResVals,"L_%g_%g.dat"], n, n],
116+
SendToServer Sprintf[StrCat[po,"19L_%g_%g [Wb]"], n, n], Color "LightYellow"] ;
87117
Print[ LFromMagEnergy~{n}~{n}[Domain], OnGlobal, Format TimeTable, File > Sprintf[StrCat[DirResVals,"LFromMagEnergy_%g_%g.dat"], n, n]] ;
88118
EndIf
89119
EndFor
@@ -100,16 +130,20 @@ PostOperation Get_global UsingPost MagDyn_a {
100130
If(!Flag_Circuit)
101131
For n In {1:n_windings}
102132
If(!Flag_HomogenisedModel~{n})
103-
Print[ I, OnRegion Winding~{n}, Format TimeTable, File > Sprintf[StrCat[DirResCirc,"I_%g_f%g.dat"], n, Freq] , LastTimeStepOnly];
104-
Print[ U, OnRegion Winding~{n}, Format TimeTable, File > Sprintf[StrCat[DirResCirc,"U_%g_f%g.dat"], n, Freq] , LastTimeStepOnly];
133+
Print[ I, OnRegion Winding~{n}, Format TimeTable, File > Sprintf[StrCat[DirResCirc,"I_%g_f%g.dat"], n, Freq] , LastTimeStepOnly,
134+
SendToServer Sprintf[StrCat[po,"10I_%g [A]"], n], Color "LightYellow"];
135+
Print[ U, OnRegion Winding~{n}, Format TimeTable, File > Sprintf[StrCat[DirResCirc,"U_%g_f%g.dat"], n, Freq] , LastTimeStepOnly,
136+
SendToServer Sprintf[StrCat[po,"11V_%g [V]"], n], Color "LightYellow"];
105137
Else
106-
Print[ I, OnRegion StrandedWinding~{n}, Format TimeTable, File > Sprintf[StrCat[DirResCirc,"I_%g_f%g.dat"], n, Freq] , LastTimeStepOnly];
107-
Print[ U, OnRegion StrandedWinding~{n}, Format TimeTable, File > Sprintf[StrCat[DirResCirc,"U_%g_f%g.dat"], n, Freq] , LastTimeStepOnly];
138+
Print[ I, OnRegion StrandedWinding~{n}, Format TimeTable, File > Sprintf[StrCat[DirResCirc,"I_%g_f%g.dat"], n, Freq] , LastTimeStepOnly,
139+
SendToServer Sprintf[StrCat[po,"10I_%g [A]"], n], Color "LightYellow"];
140+
Print[ U, OnRegion StrandedWinding~{n}, Format TimeTable, File > Sprintf[StrCat[DirResCirc,"U_%g_f%g.dat"], n, Freq] , LastTimeStepOnly,
141+
SendToServer Sprintf[StrCat[po,"11V_%g [V]"], n], Color "LightYellow"];
108142
EndIf
109143
EndFor
110144
Else
111-
Print[ I, OnRegion Input, Format TimeTable, File >Sprintf("results/I_f%g.dat", Freq), LastTimeStepOnly];
112-
Print[ U, OnRegion Input, Format TimeTable, File >Sprintf("results/U_f%g.dat", Freq), LastTimeStepOnly];
145+
Print[ I, OnRegion Input, Format TimeTable, File >Sprintf("results/I_f%g.dat", Freq), LastTimeStepOnly, SendToServer Sprintf[StrCat[po,"20I_%g [A]"], n], Color "LightYellow"];
146+
Print[ U, OnRegion Input, Format TimeTable, File >Sprintf("results/U_f%g.dat", Freq), LastTimeStepOnly, SendToServer Sprintf[StrCat[po,"21V_%g [V]"], n], Color "LightYellow"];
113147
EndIf
114148

115149
}

0 commit comments

Comments
 (0)