Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge magnetomotive examples in one #246

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/aedt/maxwell_2d/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ These examples use PyAEDT to show Maxwell 2D capabilities
../../low_frequency/general/electrostatic.py
../../low_frequency/general/external_circuit.py
../../low_frequency/general/resistance.py
../../low_frequency/magnetic/magneto_motive_contour.py
../../low_frequency/magnetic/magneto_motive_line.py
../../low_frequency/magnetic/transient_winding.py
../../low_frequency/magnetic/lorentz_actuator.py
Expand Down
1 change: 0 additions & 1 deletion examples/low_frequency/magnetic/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ These examples use PyAEDT to show some magnetics applications.

transient_winding.py
choke.py
magneto_motive_contour.py
magneto_motive_line.py
lorentz_actuator.py
138 changes: 0 additions & 138 deletions examples/low_frequency/magnetic/magneto_motive_contour.py

This file was deleted.

140 changes: 100 additions & 40 deletions examples/low_frequency/magnetic/magneto_motive_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
# the magnetomotive force along a line that changes position.
# It shows how to leverage the PyAEDT advanced fields calculator
# to insert a custom formula, which in this case is the integral
# of the H field along a line. It computes the field for each position
# with a parametric sweep.
#
# of the H field along a line.
# The example shows two options to achieve the intent.
# The first one creates many lines as to simulate a contour that changes position.
# The integral of the H field is computed for each line.
# The second option creates one parametric polyline and then uses a parametric sweep to change its position.
# The integral of the H field is computed for each position.

# Keywords: **Maxwell 2D**, **magnetomotive force**.

# ## Perform imports and define constants
Expand Down Expand Up @@ -55,6 +59,67 @@
design="Maxwell2DDesign1",
)

# ## Plot model

model = m2d.plot(show=False)
model.plot(os.path.join(temp_folder.name, "Image.jpg"))

# # First option

# ## Create a polyline
#
# Create a polyline, specifying its ends.

poly = m2d.modeler.create_polyline(points=[[10, -10, 0], [10, 10, 0]], name="polyline")

# Duplicate the polyline along a vector.

polys = [poly.name]
polys.extend(poly.duplicate_along_line(vector=[-0.5, 0, 0], clones=10))

# ## Compute magnetomotive force along each line
#
# Create and add a new formula to add in the PyAEDT advanced fields calculator.
# Create the fields report object and get field data.
# Create a data table report for the H field along each line and export it to a .csv file.

my_expression = {
"name": None,
"description": "Magnetomotive force along a line",
"design_type": ["Maxwell 2D", "Maxwell 3D"],
"fields_type": ["Fields"],
"primary_sweep": "distance",
"assignment": None,
"assignment_type": ["Line"],
"operations": [
"Fundamental_Quantity('H')",
"Operation('Tangent')",
"Operation('Dot')",
"EnterLine('assignment')",
"Operation('LineValue')",
"Operation('Integrate')",
],
"report": ["Data Table"],
}

quantities = []
for p in polys:
quantity = "H_field_{}".format(p)
quantities.append(quantity)
my_expression["name"] = quantity
my_expression["assignment"] = quantity
m2d.post.fields_calculator.add_expression(my_expression, p)
report = m2d.post.create_report(
expressions=quantity,
context=p,
polyline_points=1,
report_category="Fields",
plot_type="Data Table",
plot_name=quantity,
)

# # Second option

# ## Create a design variable
#
# Parametrize the polyline x position.
Expand All @@ -63,17 +128,12 @@

# ## Create polyline
#
# Create a polyline, specifying its points.
# Create a parametrized polyline, specifying its ends.

poly = m2d.modeler.create_polyline(
points=[["xl", -10, 0], ["xl", 10, 0]], name="polyline"
points=[["xl", -10, 0], ["xl", 10, 0]], name="polyline_sweep"
)

# ## Plot model

model = m2d.plot(show=False)
model.plot(os.path.join(temp_folder.name, "Image.jpg"))

# ## Add parametric sweep
#
# Add a parametric sweep where the parameter to sweep is ``xl``.
Expand All @@ -91,52 +151,52 @@
#
# Create and add a new formula to add in the PyAEDT advanced fields calculator.

quantity = "H_field_{}".format(poly.name)
my_expression = {
"name": quantity,
"description": "Magnetomotive force along a line",
"design_type": ["Maxwell 2D", "Maxwell 3D"],
"fields_type": ["Fields"],
"primary_sweep": "distance",
"assignment": poly.name,
"assignment_type": ["Line"],
"operations": [
"Fundamental_Quantity('H')",
"Operation('Tangent')",
"Operation('Dot')",
"EnterLine('assignment')",
"Operation('LineValue')",
"Operation('Integrate')",
],
"report": ["Data Table"],
}
quantity_sweep = "H_field_{}".format(poly.name)
my_expression["name"] = quantity_sweep
my_expression["assignment"] = poly.name
m2d.post.fields_calculator.add_expression(my_expression, poly.name)

# ## Add parametric sweep calculation specifying the quantity (H).
# ## Add parametric sweep calculation specifying the quantity (H) and save fields.

param_sweep.add_calculation(calculation=quantity, report_type="Fields", ranges={})

# ## Analyze parametric sweep

param_sweep.analyze(cores=NUM_CORES)
param_sweep.add_calculation(calculation=quantity_sweep, report_type="Fields", ranges={})
param_sweep.props["ProdOptiSetupDataV2"]["SaveFields"] = True

# ## Create data table report
#
# Create a data table report to display H for each polyline position.
# Afterwards, export results to a CSV file.

report = m2d.post.create_report(
expressions=quantity,
report_sweep = m2d.post.create_report(
expressions=quantity_sweep,
report_category="Fields",
plot_type="Data Table",
plot_name=quantity,
plot_name=quantity_sweep,
primary_sweep_variable="xl",
variations={"xl": "All"},
)

# ## Analyze parametric sweep

param_sweep.analyze(cores=NUM_CORES)

# ## Export results
#
# Export results in a .csv file for the parametric sweep analysis (second option).

m2d.post.export_report_to_csv(
project_dir=temp_folder.name,
plot_name=quantity,
plot_name=quantity_sweep,
)

# Export results in a .csv file for each polyline (first option).

[
m2d.post.export_report_to_csv(
project_dir=temp_folder.name,
plot_name=q,
)
for q in quantities
]

# ## Release AEDT

m2d.save_project()
Expand Down
Loading