Skip to content

Commit 5e5ab9d

Browse files
Update Q3D (#183)
Make consistent with template. Co-authored-by: Samuel Lopez <85613111+Samuelopez-ansys@users.noreply.github.com>
1 parent 31f8dec commit 5e5ab9d

6 files changed

+269
-229
lines changed

examples/05-Q3D/Q2D_Armoured_Cable.py

+123-94
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,35 @@
22

33
# This example shows how you can use PyAEDT to perform these tasks:
44
#
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.
77
# - Link the solution to a Simplorer design.
88
#
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)
1113

1214
# ## Perform required imports
1315
#
1416

15-
# +
1617
import math
18+
import os
19+
import tempfile
1720

1821
import pyaedt
19-
# -
2022

21-
# Set constant values
23+
# ## Create temporary directory
24+
25+
temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
26+
27+
# Define constants.
2228

2329
AEDT_VERSION = "2024.1"
30+
NG_MODE = False # Open Electronics UI when the application is launched.
2431

2532

26-
# ## Initialize core strand dimensions and positions
33+
# ## Set up for model creation
2734
#
2835
# Initialize cable sizing - radii in mm.
2936

@@ -33,28 +40,39 @@
3340
core_xlpe_ins_thickness = 0.5
3441
core_xy_coord = math.ceil(3 * c_strand_radius + 2 * core_xlpe_ins_thickness)
3542

36-
# ## Initialize filling and sheath dimensions
37-
#
3843
# Initialize radii of further structures incrementally adding thicknesses.
3944

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+
)
4148
inner_sheath_radius = filling_radius + 0.75
4249
armour_thickness = 3
4350
armour_radius = inner_sheath_radius + armour_thickness
4451
outer_sheath_radius = armour_radius + 2
4552

46-
# ## Initialize armature strand dimensions
47-
#
4853
# Initialize radii.
4954

5055
armour_centre_pos = inner_sheath_radius + armour_thickness / 2.0
5156
arm_strand_rad = armour_thickness / 2.0 - 0.2
5257
n_arm_strands = 30
5358

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.
5876

5977
core_params = {
6078
"n_cores": str(cable_n_cores),
@@ -73,39 +91,13 @@
7391
"arm_strand_rad": str(arm_strand_rad) + "mm",
7492
"n_arm_strands": str(n_arm_strands),
7593
}
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-
9694
for k, v in core_params.items():
9795
q2d[k] = v
9896
for k, v in outer_params.items():
9997
q2d[k] = v
10098
for k, v in armour_params.items():
10199
q2d[k] = v
102100

103-
# ## Set model units
104-
105-
q2d.modeler.model_units = "mm"
106-
107-
# ## Initialize required material properties
108-
#
109101
# Cable insulators require the definition of specific materials since they are not
110102
# included in the Sys Library.
111103
# Plastic, PE (cross-linked, wire, and cable grade)
@@ -122,139 +114,176 @@
122114
mat_pp.conductivity = "0.0003161"
123115
mat_pp.update()
124116

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.
126120

127-
# +
128121
q2d.modeler.create_coordinate_system(
129122
origin=["c_strand_xy_coord", "c_strand_xy_coord", "0mm"], name="CS_c_strand_1"
130123
)
131124
q2d.modeler.set_working_coordinate_system("CS_c_strand_1")
132125
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",
134130
)
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)
137135
c_unite_name = q2d.modeler.unite(q2d.get_all_conductors_names())
138136

139137
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",
142140
name="c_strand_fill",
143-
matname="plastic_pp_carbon_fiber",
141+
material="plastic_pp_carbon_fiber",
144142
)
145143
fill_id.color = (255, 255, 0)
144+
146145
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",
149148
name="c_strand_xlpe",
150-
matname="plastic_pe_cable_grade",
149+
material="plastic_pe_cable_grade",
151150
)
152151
xlpe_id.color = (0, 128, 128)
153152

154153
q2d.modeler.set_working_coordinate_system("Global")
154+
155155
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+
)
157160
cond_names = q2d.get_all_conductors_names()
158-
# -
159161

160-
# ## Create geometry for filling object
162+
# Define the filling object.
161163

162164
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",
164169
)
165170
filling_id.color = (255, 255, 180)
166171

167-
# ## Create geometry for inner sheath object
172+
# Define the inner sheath.
168173

169174
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",
171179
)
172180
inner_sheath_id.color = (0, 0, 0)
173181

174-
# ## Create geometry for armature fill
182+
# Create the armature fill.
175183

176184
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",
178189
)
179190
arm_fill_id.color = (255, 255, 255)
180191

181-
# ## Create geometry for outer sheath
192+
# Create geometry for the outer sheath.
182193

183194
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",
185199
)
186200
outer_sheath_id.color = (0, 0, 0)
187201

188-
# ## Create geometry for armature steel strands
202+
# Create the geometry for armature steel strands.
189203

190204
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",
192209
)
193210
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+
)
195214
arm_strand_names = q2d.modeler.get_objects_w_string("arm_strand")
196215

197-
# ## Create region
216+
# Define the outer region that defines the solution domain.
198217

199218
region = q2d.modeler.create_region([500, 500, 500, 500])
200219
region.material_name = "vacuum"
201220

202-
# ## Assign conductors and reference ground
221+
# Assign conductors and reference ground.
203222

204223
obj = [q2d.modeler.get_object_from_name(i) for i in cond_names]
205224
[
206225
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"
208227
)
209228
for i in obj
210229
]
211230
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+
)
213234
q2d.modeler.fit_all()
214235

215-
# ## Assign design settings
236+
# Specify the design settings
216237

217238
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
223240

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
233244

234-
# ## Analyze setup
245+
q2d_setup = q2d.create_setup(name=setup_name)
246+
q2d_sweep = q2d_setup.add_sweep(name=sweep_name)
235247

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.
237256

238257
# +
239-
# q2d.analyze(setup_name=setup_name)
258+
# q2d.analyze()
240259
# -
241260

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
243264

244265
tb = pyaedt.TwinBuilder(design=tb_design_name)
245266

246-
# ## Add a Q3D dynamic component
267+
# Add a Q2D dynamic component.
247268

248269
tb.add_q3d_dynamic_component(
249270
project_name,
250271
q2d_design_name,
251-
setup_name,
252-
sweep_name,
272+
q2d_setup.name,
273+
q2d_sweep.name,
253274
model_depth=lumped_length,
254275
coupling_matrix_name="Original",
255276
)
256277

257278
# ## Save project and release desktop
258279

259280
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

Comments
 (0)