Skip to content

Commit 5161e62

Browse files
authored
Merge branch 'main' into example_maxwell_transient_fields
2 parents 7dfb643 + 4f3ee7b commit 5161e62

4 files changed

+386
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# # Maxwell 2D Eddy Current analysis - Reduced Matrix
2+
3+
# This example shows how to leverage PyAEDT to assign matrix
4+
# and perform series or parallel connections in a Maxwell 2D design.
5+
6+
# ## Perform required imports
7+
#
8+
# Perform required imports.
9+
10+
import tempfile
11+
import time
12+
13+
import pyaedt
14+
15+
# ## Define constants
16+
17+
AEDT_VERSION = "2024.2"
18+
NG_MODE = False
19+
20+
# ## Create temporary directory and download files
21+
#
22+
# Create a temporary directory where we store downloaded data or
23+
# dumped data.
24+
# If you'd like to retrieve the project data for subsequent use,
25+
# the temporary folder name is given by ``temp_folder.name``.
26+
27+
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")
28+
29+
# ## Download .aedt file
30+
#
31+
# Set local temporary folder to export the .aedt file to.
32+
33+
project_path = pyaedt.downloads.download_file(
34+
source="maxwell_ec_reduced_matrix",
35+
name="m2d_eddy_current.aedt",
36+
destination=temp_folder.name,
37+
)
38+
39+
# ## Launch AEDT and Maxwell 2D
40+
#
41+
# Launch AEDT and Maxwell 2D providing the version, path to the project and the graphical mode.
42+
43+
m2d = pyaedt.Maxwell2d(
44+
project=project_path,
45+
version=AEDT_VERSION,
46+
design="EC_Planar",
47+
non_graphical=NG_MODE,
48+
)
49+
50+
# ## Assign a matrix
51+
#
52+
# Assign a matrix given the list of sources to assign the matrix to and the return path.
53+
54+
matrix = m2d.assign_matrix(
55+
assignment=["pri", "sec", "terz"], matrix_name="Matrix1", return_path="infinite"
56+
)
57+
58+
# ## Assign reduced matrices
59+
#
60+
# Assign reduced matrices to the parent matrix previously created.
61+
# For 2D/3D Eddy Current Solvers, two or more excitations can be joined
62+
# either in series or parallel connection. The result is known as reduced matrix.
63+
64+
series = matrix.join_series(sources=["pri", "sec"], matrix_name="ReducedMatrix1")
65+
parallel = matrix.join_parallel(sources=["sec", "terz"], matrix_name="ReducedMatrix2")
66+
67+
# ## Analyze setup
68+
69+
m2d.analyze()
70+
71+
# ## Get expressions
72+
#
73+
# Get the available report quantities given the context
74+
# and the quantities category ``L``.
75+
76+
expressions = m2d.post.available_report_quantities(
77+
report_category="EddyCurrent",
78+
display_type="Data Table",
79+
context={"Matrix1": "ReducedMatrix1"},
80+
quantities_category="L",
81+
)
82+
83+
# ## Create report and get solution data
84+
#
85+
# Create a data table report and get report data given the matrix context.
86+
87+
report = m2d.post.create_report(
88+
expressions=expressions,
89+
context={"Matrix1": "ReducedMatrix1"},
90+
plot_type="Data Table",
91+
setup_sweep_name="Setup1 : LastAdaptive",
92+
plot_name="reduced_matrix",
93+
)
94+
data = m2d.post.get_solution_data(
95+
expressions=expressions,
96+
context={"Matrix1": "ReducedMatrix1"},
97+
report_category="EddyCurrent",
98+
setup_sweep_name="Setup1 : LastAdaptive",
99+
)
100+
101+
# ## Get matrix data
102+
#
103+
# Get inductance results for the join connections in ``nH``.
104+
105+
ind = pyaedt.generic.constants.unit_converter(
106+
data.data_magnitude()[0],
107+
unit_system="Inductance",
108+
input_units=data.units_data[expressions[0]],
109+
output_units="uH",
110+
)
111+
112+
# ## Release AEDT and clean up temporary directory
113+
#
114+
# Release AEDT and remove both the project and temporary directory.
115+
116+
m2d.release_desktop()
117+
118+
time.sleep(3)
119+
temp_folder.cleanup()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# # Maxwell 2D: Magnetomotive force calculation along a contour
2+
#
3+
# This example shows how to use PyAEDT to calculate
4+
# the magnetomotive force along several lines.
5+
# It shows how to leverage PyAEDT advanced fields calculator
6+
# to insert a custom formula, in this case the integral
7+
# of the H field along a line.
8+
9+
# ## Perform required imports
10+
#
11+
# Perform required imports.
12+
13+
import os
14+
import tempfile
15+
import time
16+
17+
import pyaedt
18+
19+
# ## Define constants
20+
21+
AEDT_VERSION = "2024.2"
22+
NG_MODE = False
23+
24+
# ## Create temporary directory and download files
25+
#
26+
# Create a temporary directory where we store downloaded data or
27+
# dumped data.
28+
# If you'd like to retrieve the project data for subsequent use,
29+
# the temporary folder name is given by ``temp_folder.name``.
30+
31+
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")
32+
33+
# ## Import project
34+
#
35+
# The files required to run this example will be downloaded into the temporary working folder.
36+
37+
project_path = pyaedt.downloads.download_file(
38+
source="maxwell_magnetic_force",
39+
name="Maxwell_Magnetic_Force.aedt",
40+
destination=temp_folder.name,
41+
)
42+
43+
# ## Initialize and launch Maxwell 2D
44+
#
45+
# Initialize and launch Maxwell 2D, providing the version and the path of the project.
46+
47+
m2d = pyaedt.Maxwell2d(
48+
version=AEDT_VERSION,
49+
non_graphical=NG_MODE,
50+
project=project_path,
51+
design="Maxwell2DDesign1",
52+
)
53+
54+
# ## Create a polyline
55+
#
56+
# Create a polyline specifying its points.
57+
58+
poly = m2d.modeler.create_polyline(points=[[10, -10, 0], [10, 10, 0]], name="polyline")
59+
60+
# Duplicate polyline along a vector
61+
62+
polys = [poly.name]
63+
polys.extend(poly.duplicate_along_line(vector=[-0.5, 0, 0], clones=10))
64+
65+
# ## Analyze setup
66+
#
67+
# Analyze setup specifying setup name
68+
69+
m2d.analyze_setup(name=m2d.setups[0].name)
70+
71+
# ## Compute magnetomotive force along each line
72+
#
73+
# Create and add a new formula to add in PyAEDT advanced fields calculator.
74+
# Create fields report object and get field data.
75+
# Create a Data Table report for H field along each line and export it in a .csv file.
76+
77+
for p in polys:
78+
quantity = "H_field_{}".format(p)
79+
my_expression = {
80+
"name": quantity,
81+
"description": "Magnetomotive force along a line",
82+
"design_type": ["Maxwell 2D", "Maxwell 3D"],
83+
"fields_type": ["Fields"],
84+
"primary_sweep": "distance",
85+
"assignment": p,
86+
"assignment_type": ["Line"],
87+
"operations": [
88+
"Fundamental_Quantity('H')",
89+
"Operation('Tangent')",
90+
"Operation('Dot')",
91+
"EnterLine('assignment')",
92+
"Operation('LineValue')",
93+
"Operation('Integrate')",
94+
],
95+
"report": ["Data Table"],
96+
}
97+
m2d.post.fields_calculator.add_expression(my_expression, p)
98+
report = m2d.post.reports_by_category.fields(
99+
expressions=quantity, setup=m2d.nominal_sweep, polyline=p
100+
)
101+
data = report.get_solution_data()
102+
h = data.data_magnitude()
103+
report = m2d.post.create_report(
104+
expressions=quantity,
105+
context=p,
106+
polyline_points=1,
107+
report_category="Fields",
108+
plot_type="Data Table",
109+
plot_name=quantity,
110+
)
111+
m2d.post.export_report_to_csv(
112+
project_dir=os.path.join(temp_folder.name, "{}.csv".format(quantity)),
113+
plot_name=quantity,
114+
)
115+
116+
# ## Release AEDT and clean up temporary directory
117+
#
118+
# Release AEDT and remove both the project and temporary directory.
119+
120+
m2d.release_desktop()
121+
122+
time.sleep(3)
123+
temp_folder.cleanup()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# # Maxwell 2D: Magnetomotive force calculation along a contour
2+
#
3+
# This example shows how to use PyAEDT to calculate
4+
# the magnetomotive force along a line that changes position.
5+
# It shows how to leverage PyAEDT advanced fields calculator
6+
# to insert a custom formula, in this case the integral
7+
# of the H field along a line
8+
# and compute the field for each position with a parametric sweep.
9+
10+
# ## Perform required imports
11+
#
12+
# Perform required imports.
13+
14+
import os
15+
import tempfile
16+
import time
17+
18+
import pyaedt
19+
20+
# ## Define constants
21+
22+
AEDT_VERSION = "2024.2"
23+
NG_MODE = False
24+
25+
# ## Create temporary directory and download files
26+
#
27+
# Create a temporary directory where we store downloaded data or
28+
# dumped data.
29+
# If you'd like to retrieve the project data for subsequent use,
30+
# the temporary folder name is given by ``temp_folder.name``.
31+
32+
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")
33+
34+
# ## Import project
35+
#
36+
# The files required to run this example will be downloaded into the temporary working folder.
37+
38+
project_path = pyaedt.downloads.download_file(
39+
source="maxwell_magnetic_force",
40+
name="Maxwell_Magnetic_Force.aedt",
41+
destination=temp_folder.name,
42+
)
43+
44+
# ## Initialize and launch Maxwell 2D
45+
#
46+
# Initialize and launch Maxwell 2D, providing the version and the path of the project.
47+
48+
m2d = pyaedt.Maxwell2d(
49+
version=AEDT_VERSION,
50+
non_graphical=NG_MODE,
51+
project=project_path,
52+
design="Maxwell2DDesign1",
53+
)
54+
55+
# ## Create a new design variable
56+
#
57+
# Parametrize polyline x position.
58+
59+
m2d["xl"] = "10mm"
60+
61+
# ## Create a polyline
62+
#
63+
# Create a polyline specifying its points.
64+
65+
poly = m2d.modeler.create_polyline(
66+
points=[["xl", -10, 0], ["xl", 10, 0]], name="polyline"
67+
)
68+
69+
# ## Add a parametric sweep
70+
#
71+
# Add a parametric sweep where the parameter to sweep is ``xl``.
72+
# Create a linear step sweep from ``10mm`` to ``15mm`` every ``1mm`` step.
73+
74+
param_sweep = m2d.parametrics.add(
75+
variable="xl",
76+
start_point="10mm",
77+
end_point="15mm",
78+
step=1,
79+
variation_type="LinearStep",
80+
)
81+
82+
# ## Compute magnetomotive force along the line
83+
#
84+
# Create and add a new formula to add in PyAEDT advanced fields calculator.
85+
86+
quantity = "H_field_{}".format(poly.name)
87+
my_expression = {
88+
"name": quantity,
89+
"description": "Magnetomotive force along a line",
90+
"design_type": ["Maxwell 2D", "Maxwell 3D"],
91+
"fields_type": ["Fields"],
92+
"primary_sweep": "distance",
93+
"assignment": poly.name,
94+
"assignment_type": ["Line"],
95+
"operations": [
96+
"Fundamental_Quantity('H')",
97+
"Operation('Tangent')",
98+
"Operation('Dot')",
99+
"EnterLine('assignment')",
100+
"Operation('LineValue')",
101+
"Operation('Integrate')",
102+
],
103+
"report": ["Data Table"],
104+
}
105+
m2d.post.fields_calculator.add_expression(my_expression, poly.name)
106+
107+
# ## Add parametric sweep calculation specifying the quantity (H).
108+
109+
param_sweep.add_calculation(calculation=quantity, report_type="Fields", ranges={})
110+
111+
# ## Analyze parametric sweep
112+
113+
param_sweep.analyze()
114+
115+
# ## Create a data table report
116+
#
117+
# Create a data table report to display H for each polyline position.
118+
# Afterward export results in a .csv file.
119+
120+
report = m2d.post.create_report(
121+
expressions=quantity,
122+
report_category="Fields",
123+
plot_type="Data Table",
124+
plot_name=quantity,
125+
primary_sweep_variable="xl",
126+
)
127+
m2d.post.export_report_to_csv(
128+
project_dir=os.path.join(temp_folder.name, "{}.csv".format(quantity)),
129+
plot_name=quantity,
130+
)
131+
132+
# ## Release AEDT and clean up temporary directory
133+
#
134+
# Release AEDT and remove both the project and temporary directory.
135+
136+
m2d.release_desktop()
137+
138+
time.sleep(3)
139+
temp_folder.cleanup()

examples/03-Maxwell/Maxwell3D_Segmentation.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
"""
2-
Maxwell 3D: magnet segmentation
3-
-------------------------------
4-
This example shows how you can use PyAEDT to segment magnets of an electric motor.
5-
The method is valid and usable for any object the user would like to segment.
6-
"""
1+
# # Maxwell 3D: magnet segmentation
2+
3+
# This example shows how you can use PyAEDT to segment magnets of an electric motor.
4+
# The method is valid and usable for any object the user would like to segment.
5+
76
# ## Perform required imports
87
#
98
# Perform required imports.

0 commit comments

Comments
 (0)