-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathMaxwell2D_Electrostatic.py
221 lines (179 loc) · 7.73 KB
/
Maxwell2D_Electrostatic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
"""
Maxwell 2D Electrostatic analysis
---------------------------------
This example shows how you can use PyAEDT to create a Maxwell 2D electrostatic analysis.
It shows how to create the geometry, load material properties from an Excel file and
set up the mesh settings. Moreover, it focuses on post-processing operations, in particular how to
plot field line traces, relevant for an electrostatic analysis.
"""
#################################################################################
# Perform required imports
# ~~~~~~~~~~~~~~~~~~~~~~~~
# Perform required imports.
import pyaedt
##########################################################
# Set AEDT version
# ~~~~~~~~~~~~~~~~
# Set AEDT version.
aedt_version = "2024.1"
#################################################################################
# Initialize Maxwell 2D
# ~~~~~~~~~~~~~~~~~~~~~
# Initialize Maxwell 2D, providing the version, path to the project, and the design
# name and type.
setup_name = 'MySetupAuto'
solver = 'Electrostatic'
design_name = 'Design1'
project_name = pyaedt.generate_unique_project_name()
non_graphical = False
#################################################################################
# Download .xlsx file
# ~~~~~~~~~~~~~~~~~~~
# Set local temporary folder to export the .xlsx file to.
file_name_xlsx = pyaedt.downloads.download_file("field_line_traces", "my_copper.xlsx")
#################################################################################
# Initialize dictionaries
# ~~~~~~~~~~~~~~~~~~~~~~~
# Initialize dictionaries that contain all the definitions for the design variables.
geom_params_circle = {
'circle_x0': '-10mm',
'circle_y0': '0mm',
'circle_z0': '0mm',
'circle_axis': 'Z',
'circle_radius': '1mm'
}
geom_params_rectangle = {
'r_x0': '1mm',
'r_y0': '5mm',
'r_z0': '0mm',
'r_axis': 'Z',
'r_dx': '-1mm',
'r_dy': '-10mm'
}
##################################################################################
# Launch Maxwell 2D
# ~~~~~~~~~~~~~~~~~
# Launch Maxwell 2D and save the project.
M2D = pyaedt.Maxwell2d(projectname=project_name,
specified_version=aedt_version,
designname=design_name,
solution_type=solver,
new_desktop_session=True,
non_graphical=non_graphical
)
##################################################################################
# Create object to access 2D modeler
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Create the object ``mod2D`` to access the 2D modeler easily.
mod2D = M2D.modeler
mod2D.delete()
mod2D.model_units = "mm"
##################################################################################
# Define variables from dictionaries
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Define design variables from the created dictionaries.
for k, v in geom_params_circle.items():
M2D[k] = v
for k, v in geom_params_rectangle.items():
M2D[k] = v
##################################################################################
# Read materials from .xslx file
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Read materials from .xslx file into and set into design.
mats = M2D.materials.import_materials_from_excel(file_name_xlsx)
##################################################################################
# Create design geometries
# ~~~~~~~~~~~~~~~~~~~~~~~~
# Create rectangle and a circle and assign the material read from the .xlsx file.
# Create two new polylines and a region.
rect = mod2D.create_rectangle(position=['r_x0', 'r_y0', 'r_z0'],
dimension_list=['r_dx', 'r_dy', 0],
name='Ground', matname=mats[0])
rect.color = (0, 0, 255) # rgb
rect.solve_inside = False
circle = mod2D.create_circle(position=['circle_x0', 'circle_y0', 'circle_z0'], radius='circle_radius',
num_sides='0', is_covered=True, name='Electrode', matname=mats[0])
circle.color = (0, 0, 255) # rgb
circle.solve_inside = False
poly1_points = [[-9, 2, 0], [-4, 2, 0], [2, -2, 0],[8, 2, 0]]
poly2_points = [[-9, 0, 0], [9, 0, 0]]
poly1_id = mod2D.create_polyline(position_list=poly1_points,segment_type='Spline', name='Poly1')
poly2_id = mod2D.create_polyline(position_list=poly2_points, name='Poly2')
mod2D.split([poly1_id, poly2_id], 'YZ', sides='NegativeOnly')
mod2D.create_region([20, 100, 20, 100])
##################################################################################
# Define excitations
# ~~~~~~~~~~~~~~~~~~
# Assign voltage excitations to rectangle and circle.
M2D.assign_voltage(rect.id, amplitude=0, name='Ground')
M2D.assign_voltage(circle.id, amplitude=50e6, name='50kV')
##################################################################################
# Create initial mesh settings
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Assign a surface mesh to the rectangle.
M2D.mesh.assign_surface_mesh_manual(names=['Ground'], surf_dev=0.001)
##################################################################################
# Create, validate and analyze the setup
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Create, update, validate and analyze the setup.
setup = M2D.create_setup(setupname=setup_name)
setup.props['PercentError'] = 0.5
setup.update()
M2D.validate_simple()
M2D.analyze_setup(setup_name)
##################################################################################
# Evaluate the E Field tangential component
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Evaluate the E Field tangential component along the given polylines.
# Add these operations to the Named Expression list in Field Calculator.
fields = M2D.ofieldsreporter
fields.CalcStack("clear")
fields.EnterQty("E")
fields.EnterEdge("Poly1")
fields.CalcOp("Tangent")
fields.CalcOp("Dot")
fields.AddNamedExpression("e_tan_poly1", "Fields")
fields.EnterQty("E")
fields.EnterEdge("Poly2")
fields.CalcOp("Tangent")
fields.CalcOp("Dot")
fields.AddNamedExpression("e_tan_poly2", "Fields")
##################################################################################
# Create Field Line Traces Plot
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Create Field Line Traces Plot specifying as seeding faces
# the ground, the electrode and the region
# and as ``In surface objects`` only the region.
plot = M2D.post.create_fieldplot_line_traces(seeding_faces=["Ground", "Electrode", "Region"],
in_volume_tracing_objs="Region", plot_name="LineTracesTest")
###################################################################################
# Update Field Line Traces Plot
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Update field line traces plot.
# Update seeding points number, line style and line width.
plot.SeedingPointsNumber = 20
plot.LineStyle = "Cylinder"
plot.LineWidth = 3
plot.update()
###################################################################################
# Export field line traces plot
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Export field line traces plot.
# For field lint traces plot, the export file format is ``.fldplt``.
M2D.post.export_field_plot(plotname="LineTracesTest", filepath=M2D.toolkit_directory, file_format="fldplt")
##########################################################
# Export a field plot to an image file
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Export the flux lines plot to an image file using PyVista Python package.
M2D.post.plot_field_from_fieldplot(plot.name, show=False)
##########################################################
# Export the mesh field plot
# ~~~~~~~~~~~~~~~~~~~~~~~~~~
# Export the mesh in ``aedtplt`` format.
M2D.post.export_mesh_obj(setup_name=M2D.nominal_adaptive)
###################################################################################
# Save project and close AEDT
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Save the project and close AEDT.
M2D.save_project()
M2D.release_desktop()