|
| 1 | +# # Transformer leakage inductance calculation in Maxwell 2D Magnetostatic |
| 2 | +# |
| 3 | +# This example shows how you can use pyAEDT to create a Maxwell 2D |
| 4 | +# magnetostatic analysis analysis to calculate transformer leakage |
| 5 | +# inductance and reactance. |
| 6 | +# The analysis based on this document form page 8 on: |
| 7 | +# https://www.ee.iitb.ac.in/~fclab/FEM/FEM1.pdf |
| 8 | + |
| 9 | +# ## Perform required imports |
| 10 | + |
| 11 | +# + |
| 12 | +import tempfile |
| 13 | + |
| 14 | +from ansys.pyaedt.examples.constants import AEDT_VERSION |
| 15 | +from pyaedt import Maxwell2d |
| 16 | + |
| 17 | +# - |
| 18 | + |
| 19 | +# ## Create temporary directory |
| 20 | +# |
| 21 | +# Create temporary directory. |
| 22 | + |
| 23 | +temp_dir = tempfile.TemporaryDirectory(suffix=".ansys") |
| 24 | + |
| 25 | +# ## Initialize and launch Maxwell 2D |
| 26 | +# |
| 27 | +# Initialize and launch Maxwell 2D, providing the version, path to the project, the design |
| 28 | +# name and type. |
| 29 | + |
| 30 | +# + |
| 31 | +non_graphical = False |
| 32 | + |
| 33 | +project_name = "Transformer_leakage_inductance" |
| 34 | +design_name = "1 Magnetostatic" |
| 35 | +solver = "MagnetostaticXY" |
| 36 | +desktop_version = AEDT_VERSION |
| 37 | + |
| 38 | +m2d = Maxwell2d( |
| 39 | + specified_version=desktop_version, |
| 40 | + new_desktop_session=False, |
| 41 | + designname=design_name, |
| 42 | + projectname=project_name, |
| 43 | + solution_type=solver, |
| 44 | + non_graphical=non_graphical, |
| 45 | +) |
| 46 | +# - |
| 47 | + |
| 48 | +# ## Initialize dictionaries |
| 49 | +# |
| 50 | +# Initialize dictionaries that contain all the definitions for the design variables. |
| 51 | + |
| 52 | +# + |
| 53 | +m2d.modeler.model_units = "mm" |
| 54 | + |
| 55 | +dimensions = { |
| 56 | + "core_width": "1097mm", |
| 57 | + "core_height": "2880mm", |
| 58 | + "core_opening_x1": "270mm", |
| 59 | + "core_opening_x2": "557mm", |
| 60 | + "core_opening_y1": "540mm", |
| 61 | + "core_opening_y2": "2340mm", |
| 62 | + "core_opening_width": "core_opening_x2-core_opening_x1", |
| 63 | + "core_opening_height": "core_opening_y2-core_opening_y1", |
| 64 | + "LV_x1": "293mm", |
| 65 | + "LV_x2": "345mm", |
| 66 | + "LV_width": "LV_x2-LV_x1", |
| 67 | + "LV_mean_radius": "LV_x1+LV_width/2", |
| 68 | + "LV_mean_turn_length": "pi*2*LV_mean_radius", |
| 69 | + "LV_y1": "620mm", |
| 70 | + "LV_y2": "2140mm", |
| 71 | + "LV_height": "LV_y2-LV_y1", |
| 72 | + "HV_x1": "394mm", |
| 73 | + "HV_x2": "459mm", |
| 74 | + "HV_width": "HV_x2-HV_x1", |
| 75 | + "HV_mean_radius": "HV_x1+HV_width/2", |
| 76 | + "HV_mean_turn_length": "pi*2*HV_mean_radius", |
| 77 | + "HV_y1": "620mm", |
| 78 | + "HV_y2": "2140mm", |
| 79 | + "HV_height": "HV_y2-HV_y1", |
| 80 | + "HV_LV_gap_radius": "(LV_x2 + HV_x1)/2", |
| 81 | + "HV_LV_gap_length": "pi*2*HV_LV_gap_radius", |
| 82 | +} |
| 83 | + |
| 84 | +specifications = { |
| 85 | + "Amp_turns": "135024A", |
| 86 | + "Frequency": "50Hz", |
| 87 | + "HV_turns": "980", |
| 88 | + "HV_current": "Amp_turns/HV_turns", |
| 89 | +} |
| 90 | +# - |
| 91 | + |
| 92 | +# ## Define variables from dictionaries |
| 93 | +# |
| 94 | +# Define design variables from the created dictionaries. |
| 95 | + |
| 96 | +# + |
| 97 | +m2d.variable_manager.set_variable(variable_name="Dimensions") |
| 98 | + |
| 99 | +for k, v in dimensions.items(): |
| 100 | + m2d[k] = v |
| 101 | + |
| 102 | +m2d.variable_manager.set_variable(variable_name="Windings") |
| 103 | + |
| 104 | +for k, v in specifications.items(): |
| 105 | + m2d[k] = v |
| 106 | +# - |
| 107 | + |
| 108 | +# ## Create design geometries |
| 109 | +# |
| 110 | +# Create transformer core, HV and LV windings, and the region. |
| 111 | + |
| 112 | +# + |
| 113 | +core = m2d.modeler.create_rectangle( |
| 114 | + position=[0, 0, 0], |
| 115 | + dimension_list=["core_width", "core_height", 0], |
| 116 | + name="core", |
| 117 | + matname="steel_1008", |
| 118 | +) |
| 119 | + |
| 120 | +core_hole = m2d.modeler.create_rectangle( |
| 121 | + position=["core_opening_x1", "core_opening_y1", 0], |
| 122 | + dimension_list=["core_opening_width", "core_opening_height", 0], |
| 123 | + name="core_hole", |
| 124 | +) |
| 125 | + |
| 126 | +m2d.modeler.subtract(blank_list=[core], tool_list=[core_hole], keep_originals=False) |
| 127 | + |
| 128 | +lv = m2d.modeler.create_rectangle( |
| 129 | + position=["LV_x1", "LV_y1", 0], |
| 130 | + dimension_list=["LV_width", "LV_height", 0], |
| 131 | + name="LV", |
| 132 | + matname="copper", |
| 133 | +) |
| 134 | + |
| 135 | +hv = m2d.modeler.create_rectangle( |
| 136 | + position=["HV_x1", "HV_y1", 0], |
| 137 | + dimension_list=["HV_width", "HV_height", 0], |
| 138 | + name="HV", |
| 139 | + matname="copper", |
| 140 | +) |
| 141 | + |
| 142 | +region = m2d.modeler.create_region(pad_percent=[20, 10, 0, 10]) |
| 143 | + |
| 144 | +# ## Assign boundary condition |
| 145 | +# |
| 146 | +# Assign vector potential to zero on all region boundaries. This makes x=0 edge a symmetry boundary. |
| 147 | + |
| 148 | +m2d.assign_vector_potential(input_edge=region.edges, bound_name="VectorPotential1") |
| 149 | +# - |
| 150 | + |
| 151 | +# ## Create initial mesh settings |
| 152 | +# |
| 153 | +# Assign a relatively dense mesh to all objects to ensure that the energy is calculated accurately. |
| 154 | + |
| 155 | +m2d.mesh.assign_length_mesh( |
| 156 | + names=["core", "Region", "LV", "HV"], maxlength=50, maxel=None, meshop_name="all_objects" |
| 157 | +) |
| 158 | + |
| 159 | +# ## Define excitations |
| 160 | +# |
| 161 | +# Assign the same current in amp-turns but in opposite directions to HV and LV windings. |
| 162 | + |
| 163 | +m2d.assign_current(object_list=lv, amplitude="Amp_turns", name="LV") |
| 164 | +m2d.assign_current(object_list=hv, amplitude="Amp_turns", name="HV", swap_direction=True) |
| 165 | + |
| 166 | +# ## Create and analyze the setup |
| 167 | +# |
| 168 | +# Create and analyze the setup. Setu no. of minimum passes to 3 to ensure accuracy. |
| 169 | + |
| 170 | +m2d.create_setup(setupname="Setup1", MinimumPasses=3) |
| 171 | +m2d.analyze_setup() |
| 172 | + |
| 173 | +# ## Calculate transformer leakage inductance and reactance |
| 174 | +# |
| 175 | +# Calculate transformer leakage inductance from the magnetic energy. |
| 176 | + |
| 177 | +# + |
| 178 | +field_calculator = m2d.ofieldsreporter |
| 179 | + |
| 180 | +field_calculator.EnterQty("Energy") |
| 181 | +field_calculator.EnterSurf("HV") |
| 182 | +field_calculator.CalcOp("Integrate") |
| 183 | +field_calculator.EnterScalarFunc("HV_mean_turn_length") |
| 184 | +field_calculator.CalcOp("*") |
| 185 | + |
| 186 | +field_calculator.EnterQty("Energy") |
| 187 | +field_calculator.EnterSurf("LV") |
| 188 | +field_calculator.CalcOp("Integrate") |
| 189 | +field_calculator.EnterScalarFunc("LV_mean_turn_length") |
| 190 | +field_calculator.CalcOp("*") |
| 191 | + |
| 192 | +field_calculator.EnterQty("Energy") |
| 193 | +field_calculator.EnterSurf("Region") |
| 194 | +field_calculator.CalcOp("Integrate") |
| 195 | +field_calculator.EnterScalarFunc("HV_LV_gap_length") |
| 196 | +field_calculator.CalcOp("*") |
| 197 | + |
| 198 | +field_calculator.CalcOp("+") |
| 199 | +field_calculator.CalcOp("+") |
| 200 | + |
| 201 | +field_calculator.EnterScalar(2) |
| 202 | +field_calculator.CalcOp("*") |
| 203 | +field_calculator.EnterScalarFunc("HV_current") |
| 204 | +field_calculator.EnterScalarFunc("HV_current") |
| 205 | +field_calculator.CalcOp("*") |
| 206 | +field_calculator.CalcOp("/") |
| 207 | +field_calculator.AddNamedExpression("Leakage_inductance", "Fields") |
| 208 | + |
| 209 | +field_calculator.CopyNamedExprToStack("Leakage_inductance") |
| 210 | +field_calculator.EnterScalar(2) |
| 211 | +field_calculator.EnterScalar(3.14159265358979) |
| 212 | +field_calculator.EnterScalarFunc("Frequency") |
| 213 | +field_calculator.CalcOp("*") |
| 214 | +field_calculator.CalcOp("*") |
| 215 | +field_calculator.CalcOp("*") |
| 216 | +field_calculator.AddNamedExpression("Leakage_reactance", "Fields") |
| 217 | + |
| 218 | +m2d.post.create_report( |
| 219 | + expressions=["Leakage_inductance", "Leakage_reactance"], |
| 220 | + report_category="Fields", |
| 221 | + primary_sweep_variable="core_width", |
| 222 | + plot_type="Data Table", |
| 223 | + plotname="Transformer Leakage Inductance", |
| 224 | +) |
| 225 | +# - |
| 226 | + |
| 227 | +# ## Print leakage inductance and reactance values in the Message Manager |
| 228 | + |
| 229 | +m2d.logger.clear_messages() |
| 230 | +m2d.logger.info( |
| 231 | + "Leakage_inductance = {:.4f}H".format( |
| 232 | + m2d.post.get_scalar_field_value(quantity_name="Leakage_inductance") |
| 233 | + ) |
| 234 | +) |
| 235 | +m2d.logger.info( |
| 236 | + "Leakage_reactance = {:.2f}Ohm".format( |
| 237 | + m2d.post.get_scalar_field_value(quantity_name="Leakage_reactance") |
| 238 | + ) |
| 239 | +) |
| 240 | + |
| 241 | +# ## Plot energy in the simulation domain |
| 242 | +# |
| 243 | +# Most of the energy is confined in the air between the HV and LV windings. |
| 244 | + |
| 245 | +energy_field_overlay = m2d.post.create_fieldplot_surface( |
| 246 | + objlist=m2d.modeler.object_names, |
| 247 | + quantityName="energy", |
| 248 | + plot_name="Energy", |
| 249 | +) |
| 250 | + |
| 251 | +# ## Release AEDT and clean up temporary directory |
| 252 | +# |
| 253 | +# Release AEDT and remove both the project and temporary directory. |
| 254 | + |
| 255 | +m2d.save_project() |
| 256 | +m2d.release_desktop() |
| 257 | +temp_dir.cleanup() |
0 commit comments