|
2 | 2 |
|
3 | 3 | # This example shows how you can use PyAEDT to perform these tasks:
|
4 | 4 | #
|
5 |
| -# - Create a Q2D design using the Modeler primitives and importing part of the geometry. |
6 |
| -# - Set up the entire simulation. |
| 5 | +# - Create a Q2D design using modeler primitives and imported CAD. |
| 6 | +# - Set up the simulation. |
7 | 7 | # - Link the solution to a Simplorer design.
|
8 | 8 | #
|
9 |
| -# For cable information, see `4 Core Armoured Power Cable |
10 |
| -# <https://www.luxingcable.com/low-voltage-cables/4-core-armoured-power-cable.html>`_ |
| 9 | +# For information on the cable model used in this example please see the following link: |
| 10 | +# |
| 11 | +# - [4 Core Armoured Power Cable] |
| 12 | +# (https://www.luxingcable.com/low-voltage-cables/4-core-armoured-power-cable.html) |
11 | 13 |
|
12 | 14 | # ## Perform required imports
|
13 | 15 | #
|
14 | 16 |
|
15 |
| -# + |
16 | 17 | import math
|
| 18 | +import os |
| 19 | +import tempfile |
17 | 20 |
|
18 | 21 | import pyaedt
|
19 |
| -# - |
20 | 22 |
|
21 |
| -# Set constant values |
| 23 | +# ## Create temporary directory |
| 24 | + |
| 25 | +temp_dir = tempfile.TemporaryDirectory(suffix=".ansys") |
| 26 | + |
| 27 | +# Define constants. |
22 | 28 |
|
23 | 29 | AEDT_VERSION = "2024.1"
|
| 30 | +NG_MODE = False # Open Electronics UI when the application is launched. |
24 | 31 |
|
25 | 32 |
|
26 |
| -# ## Initialize core strand dimensions and positions |
| 33 | +# ## Set up for model creation |
27 | 34 | #
|
28 | 35 | # Initialize cable sizing - radii in mm.
|
29 | 36 |
|
|
33 | 40 | core_xlpe_ins_thickness = 0.5
|
34 | 41 | core_xy_coord = math.ceil(3 * c_strand_radius + 2 * core_xlpe_ins_thickness)
|
35 | 42 |
|
36 |
| -# ## Initialize filling and sheath dimensions |
37 |
| -# |
38 | 43 | # Initialize radii of further structures incrementally adding thicknesses.
|
39 | 44 |
|
40 |
| -filling_radius = 1.4142 * (core_xy_coord + 3 * c_strand_radius + core_xlpe_ins_thickness + 0.5) |
| 45 | +filling_radius = 1.4142 * ( |
| 46 | + core_xy_coord + 3 * c_strand_radius + core_xlpe_ins_thickness + 0.5 |
| 47 | +) |
41 | 48 | inner_sheath_radius = filling_radius + 0.75
|
42 | 49 | armour_thickness = 3
|
43 | 50 | armour_radius = inner_sheath_radius + armour_thickness
|
44 | 51 | outer_sheath_radius = armour_radius + 2
|
45 | 52 |
|
46 |
| -# ## Initialize armature strand dimensions |
47 |
| -# |
48 | 53 | # Initialize radii.
|
49 | 54 |
|
50 | 55 | armour_centre_pos = inner_sheath_radius + armour_thickness / 2.0
|
51 | 56 | arm_strand_rad = armour_thickness / 2.0 - 0.2
|
52 | 57 | n_arm_strands = 30
|
53 | 58 |
|
54 |
| -# ## Initialize dictionaries |
55 |
| -# |
56 |
| -# Initialize dictionaries that contain all the definitions for the design |
57 |
| -# variables and output variables. |
| 59 | +# Start an instance of the Q2D extractor, providing the version, project name, design |
| 60 | +# name and type. |
| 61 | + |
| 62 | +project_name = os.path.join(temp_dir.name, "Q2D_ArmouredCableExample.aedt") |
| 63 | +q2d_design_name = "2D_Extractor_Cable" |
| 64 | +setup_name = "AnalysisSeetup" |
| 65 | +sweep_name = "FreqSweep" |
| 66 | +tb_design_name = "CableSystem" |
| 67 | +q2d = pyaedt.Q2d( |
| 68 | + project=project_name, |
| 69 | + design=q2d_design_name, |
| 70 | + version=AEDT_VERSION, |
| 71 | + non_graphical=NG_MODE, |
| 72 | +) |
| 73 | +q2d.modeler.model_units = "mm" |
| 74 | + |
| 75 | +# Assign the variables to the Q3D design. |
58 | 76 |
|
59 | 77 | core_params = {
|
60 | 78 | "n_cores": str(cable_n_cores),
|
|
73 | 91 | "arm_strand_rad": str(arm_strand_rad) + "mm",
|
74 | 92 | "n_arm_strands": str(n_arm_strands),
|
75 | 93 | }
|
76 |
| - |
77 |
| -# ## Initialize Q2D |
78 |
| -# |
79 |
| -# Initialize Q2D, providing the version, path to the project, and the design |
80 |
| -# name and type. |
81 |
| - |
82 |
| -desktop_version = AEDT_VERSION |
83 |
| -project_name = "Q2D_ArmouredCableExample" |
84 |
| -q2d_design_name = "2D_Extractor_Cable" |
85 |
| -setup_name = "MySetupAuto" |
86 |
| -sweep_name = "sweep1" |
87 |
| -tb_design_name = "CableSystem" |
88 |
| -q2d = pyaedt.Q2d( |
89 |
| - project=project_name, design=q2d_design_name, version=desktop_version |
90 |
| -) |
91 |
| - |
92 |
| -# ## Define variables from dictionaries |
93 |
| -# |
94 |
| -# Define design variables from the created dictionaries. |
95 |
| - |
96 | 94 | for k, v in core_params.items():
|
97 | 95 | q2d[k] = v
|
98 | 96 | for k, v in outer_params.items():
|
99 | 97 | q2d[k] = v
|
100 | 98 | for k, v in armour_params.items():
|
101 | 99 | q2d[k] = v
|
102 | 100 |
|
103 |
| -# ## Set model units |
104 |
| - |
105 |
| -q2d.modeler.model_units = "mm" |
106 |
| - |
107 |
| -# ## Initialize required material properties |
108 |
| -# |
109 | 101 | # Cable insulators require the definition of specific materials since they are not
|
110 | 102 | # included in the Sys Library.
|
111 | 103 | # Plastic, PE (cross-linked, wire, and cable grade)
|
|
122 | 114 | mat_pp.conductivity = "0.0003161"
|
123 | 115 | mat_pp.update()
|
124 | 116 |
|
125 |
| -# ## Create geometry for core strands, filling, and XLPE insulation |
| 117 | +# ## Model Creation |
| 118 | +# |
| 119 | +# Create the geometry for core strands, fill, and XLPE insulation. |
126 | 120 |
|
127 |
| -# + |
128 | 121 | q2d.modeler.create_coordinate_system(
|
129 | 122 | origin=["c_strand_xy_coord", "c_strand_xy_coord", "0mm"], name="CS_c_strand_1"
|
130 | 123 | )
|
131 | 124 | q2d.modeler.set_working_coordinate_system("CS_c_strand_1")
|
132 | 125 | c1_id = q2d.modeler.create_circle(
|
133 |
| - ["0mm", "0mm", "0mm"], "c_strand_radius", name="c_strand_1", matname="copper" |
| 126 | + origin=["0mm", "0mm", "0mm"], |
| 127 | + radius="c_strand_radius", |
| 128 | + name="c_strand_1", |
| 129 | + material="copper", |
134 | 130 | )
|
135 |
| -c2_id = c1_id.duplicate_along_line(vector=["0mm", "2.0*c_strand_radius", "0mm"], nclones=2) |
136 |
| -q2d.modeler.duplicate_around_axis(c2_id, cs_axis="Z", angle=360 / core_n_strands, nclones=6) |
| 131 | +c2_id = c1_id.duplicate_along_line( |
| 132 | + vector=["0mm", "2.0*c_strand_radius", "0mm"], clones=2 |
| 133 | +) |
| 134 | +q2d.modeler.duplicate_around_axis(c2_id, axis="Z", angle=360 / core_n_strands, clones=6) |
137 | 135 | c_unite_name = q2d.modeler.unite(q2d.get_all_conductors_names())
|
138 | 136 |
|
139 | 137 | fill_id = q2d.modeler.create_circle(
|
140 |
| - ["0mm", "0mm", "0mm"], |
141 |
| - "3*c_strand_radius", |
| 138 | + origin=["0mm", "0mm", "0mm"], |
| 139 | + radius="3*c_strand_radius", |
142 | 140 | name="c_strand_fill",
|
143 |
| - matname="plastic_pp_carbon_fiber", |
| 141 | + material="plastic_pp_carbon_fiber", |
144 | 142 | )
|
145 | 143 | fill_id.color = (255, 255, 0)
|
| 144 | + |
146 | 145 | xlpe_id = q2d.modeler.create_circle(
|
147 |
| - ["0mm", "0mm", "0mm"], |
148 |
| - "3*c_strand_radius+" + str(core_xlpe_ins_thickness) + "mm", |
| 146 | + origin=["0mm", "0mm", "0mm"], |
| 147 | + radius="3*c_strand_radius+" + str(core_xlpe_ins_thickness) + "mm", |
149 | 148 | name="c_strand_xlpe",
|
150 |
| - matname="plastic_pe_cable_grade", |
| 149 | + material="plastic_pe_cable_grade", |
151 | 150 | )
|
152 | 151 | xlpe_id.color = (0, 128, 128)
|
153 | 152 |
|
154 | 153 | q2d.modeler.set_working_coordinate_system("Global")
|
| 154 | + |
155 | 155 | all_obj_names = q2d.get_all_conductors_names() + q2d.get_all_dielectrics_names()
|
156 |
| -q2d.modeler.duplicate_around_axis(all_obj_names, cs_axis="Z", angle=360 / cable_n_cores, nclones=4) |
| 156 | + |
| 157 | +q2d.modeler.duplicate_around_axis( |
| 158 | + all_obj_names, axis="Z", angle=360 / cable_n_cores, clones=4 |
| 159 | +) |
157 | 160 | cond_names = q2d.get_all_conductors_names()
|
158 |
| -# - |
159 | 161 |
|
160 |
| -# ## Create geometry for filling object |
| 162 | +# Define the filling object. |
161 | 163 |
|
162 | 164 | filling_id = q2d.modeler.create_circle(
|
163 |
| - ["0mm", "0mm", "0mm"], "filling_radius", name="Filling", matname="plastic_pp_carbon_fiber" |
| 165 | + origin=["0mm", "0mm", "0mm"], |
| 166 | + radius="filling_radius", |
| 167 | + name="Filling", |
| 168 | + material="plastic_pp_carbon_fiber", |
164 | 169 | )
|
165 | 170 | filling_id.color = (255, 255, 180)
|
166 | 171 |
|
167 |
| -# ## Create geometry for inner sheath object |
| 172 | +# Define the inner sheath. |
168 | 173 |
|
169 | 174 | inner_sheath_id = q2d.modeler.create_circle(
|
170 |
| - ["0mm", "0mm", "0mm"], "inner_sheath_radius", name="InnerSheath", matname="PVC plastic" |
| 175 | + origin=["0mm", "0mm", "0mm"], |
| 176 | + radius="inner_sheath_radius", |
| 177 | + name="InnerSheath", |
| 178 | + material="PVC plastic", |
171 | 179 | )
|
172 | 180 | inner_sheath_id.color = (0, 0, 0)
|
173 | 181 |
|
174 |
| -# ## Create geometry for armature fill |
| 182 | +# Create the armature fill. |
175 | 183 |
|
176 | 184 | arm_fill_id = q2d.modeler.create_circle(
|
177 |
| - ["0mm", "0mm", "0mm"], "armour_radius", name="ArmourFilling", matname="plastic_pp_carbon_fiber" |
| 185 | + origin=["0mm", "0mm", "0mm"], |
| 186 | + radius="armour_radius", |
| 187 | + name="ArmourFilling", |
| 188 | + material="plastic_pp_carbon_fiber", |
178 | 189 | )
|
179 | 190 | arm_fill_id.color = (255, 255, 255)
|
180 | 191 |
|
181 |
| -# ## Create geometry for outer sheath |
| 192 | +# Create geometry for the outer sheath. |
182 | 193 |
|
183 | 194 | outer_sheath_id = q2d.modeler.create_circle(
|
184 |
| - ["0mm", "0mm", "0mm"], "outer_sheath_radius", name="OuterSheath", matname="PVC plastic" |
| 195 | + origin=["0mm", "0mm", "0mm"], |
| 196 | + radius="outer_sheath_radius", |
| 197 | + name="OuterSheath", |
| 198 | + material="PVC plastic", |
185 | 199 | )
|
186 | 200 | outer_sheath_id.color = (0, 0, 0)
|
187 | 201 |
|
188 |
| -# ## Create geometry for armature steel strands |
| 202 | +# Create the geometry for armature steel strands. |
189 | 203 |
|
190 | 204 | arm_strand_1_id = q2d.modeler.create_circle(
|
191 |
| - ["0mm", "armour_centre_pos", "0mm"], "1.1mm", name="arm_strand_1", matname="steel_stainless" |
| 205 | + origin=["0mm", "armour_centre_pos", "0mm"], |
| 206 | + radius="1.1mm", |
| 207 | + name="arm_strand_1", |
| 208 | + material="steel_stainless", |
192 | 209 | )
|
193 | 210 | arm_strand_1_id.color = (128, 128, 64)
|
194 |
| -arm_strand_1_id.duplicate_around_axis("Z", "360deg/n_arm_strands", nclones="n_arm_strands") |
| 211 | +arm_strand_1_id.duplicate_around_axis( |
| 212 | + axis="Z", angle="360deg/n_arm_strands", clones="n_arm_strands" |
| 213 | +) |
195 | 214 | arm_strand_names = q2d.modeler.get_objects_w_string("arm_strand")
|
196 | 215 |
|
197 |
| -# ## Create region |
| 216 | +# Define the outer region that defines the solution domain. |
198 | 217 |
|
199 | 218 | region = q2d.modeler.create_region([500, 500, 500, 500])
|
200 | 219 | region.material_name = "vacuum"
|
201 | 220 |
|
202 |
| -# ## Assign conductors and reference ground |
| 221 | +# Assign conductors and reference ground. |
203 | 222 |
|
204 | 223 | obj = [q2d.modeler.get_object_from_name(i) for i in cond_names]
|
205 | 224 | [
|
206 | 225 | q2d.assign_single_conductor(
|
207 |
| - name="C1" + str(obj.index(i) + 1), target_objects=i, conductor_type="SignalLine" |
| 226 | + name="C1" + str(obj.index(i) + 1), assignment=i, conductor_type="SignalLine" |
208 | 227 | )
|
209 | 228 | for i in obj
|
210 | 229 | ]
|
211 | 230 | obj = [q2d.modeler.get_object_from_name(i) for i in arm_strand_names]
|
212 |
| -q2d.assign_single_conductor(name="gnd", target_objects=obj, conductor_type="ReferenceGround") |
| 231 | +q2d.assign_single_conductor( |
| 232 | + name="gnd", assignment=obj, conductor_type="ReferenceGround" |
| 233 | +) |
213 | 234 | q2d.modeler.fit_all()
|
214 | 235 |
|
215 |
| -# ## Assign design settings |
| 236 | +# Specify the design settings |
216 | 237 |
|
217 | 238 | lumped_length = "100m"
|
218 |
| -q2d_des_settings = q2d.design_settings |
219 |
| -q2d_des_settings["LumpedLength"] = lumped_length |
220 |
| -q2d.change_design_settings(q2d_des_settings) |
221 |
| - |
222 |
| -# ## Insert setup and frequency sweep |
| 239 | +q2d.design_settings["LumpedLength"] = lumped_length |
223 | 240 |
|
224 |
| -q2d_setup = q2d.create_setup(setupname=setup_name) |
225 |
| -q2d_sweep = q2d_setup.add_sweep(sweepname=sweep_name) |
226 |
| -q2d_sweep.add_subrange("LogScale", 0, 3, 10, "MHz") |
227 |
| -q2d_sweep.props["RangeType"] = "LogScale" |
228 |
| -q2d_sweep.props["RangeStart"] = "0Hz" |
229 |
| -q2d_sweep.props["RangeEnd"] = "3MHz" |
230 |
| -q2d_sweep.props["RangeCount"] = 10 |
231 |
| -q2d_sweep.props["RangeSamples"] = 1 |
232 |
| -q2d_sweep.update() |
| 241 | +# ## Solve the model |
| 242 | +# |
| 243 | +# Insert setup and frequency sweep |
233 | 244 |
|
234 |
| -# ## Analyze setup |
| 245 | +q2d_setup = q2d.create_setup(name=setup_name) |
| 246 | +q2d_sweep = q2d_setup.add_sweep(name=sweep_name) |
235 | 247 |
|
236 |
| -# Uncomment line to analyze the model |
| 248 | +# The cable model is generated by running two solution types: |
| 249 | +# 1. Capacitance and conductance per unit length (CG). |
| 250 | +# For this model, the CG solution runs in a few seconds. |
| 251 | +# 2. Series resistance and inductance (RL). |
| 252 | +# For this model the solution time can range from 15-20 minutes, |
| 253 | +# depending on the available hardware. |
| 254 | +# |
| 255 | +# Uncomment the following line to run the analysis. |
237 | 256 |
|
238 | 257 | # +
|
239 |
| -# q2d.analyze(setup_name=setup_name) |
| 258 | +# q2d.analyze() |
240 | 259 | # -
|
241 | 260 |
|
242 |
| -# ## Add a Simplorer/Twin Builder design and the Q3D dynamic component |
| 261 | +# ## Evaluate results |
| 262 | +# |
| 263 | +# Add a Simplorer/Twin Builder design and the Q3D dynamic component |
243 | 264 |
|
244 | 265 | tb = pyaedt.TwinBuilder(design=tb_design_name)
|
245 | 266 |
|
246 |
| -# ## Add a Q3D dynamic component |
| 267 | +# Add a Q2D dynamic component. |
247 | 268 |
|
248 | 269 | tb.add_q3d_dynamic_component(
|
249 | 270 | project_name,
|
250 | 271 | q2d_design_name,
|
251 |
| - setup_name, |
252 |
| - sweep_name, |
| 272 | + q2d_setup.name, |
| 273 | + q2d_sweep.name, |
253 | 274 | model_depth=lumped_length,
|
254 | 275 | coupling_matrix_name="Original",
|
255 | 276 | )
|
256 | 277 |
|
257 | 278 | # ## Save project and release desktop
|
258 | 279 |
|
259 | 280 | tb.save_project()
|
260 |
| -tb.release_desktop(True, True) |
| 281 | +tb.release_desktop() |
| 282 | + |
| 283 | +# ## Cleanup |
| 284 | +# |
| 285 | +# All project files are saved in the folder ``temp_dir.name``. |
| 286 | +# If you've run this example as a Jupyter notebook you can retrieve those project files. |
| 287 | +# The following cell removes all temporary files, including the project folder. |
| 288 | + |
| 289 | +temp_dir.cleanup() |
0 commit comments