|
| 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() |
0 commit comments