From f971f37d8b553ccad2a26d6f7215194b6684ec52 Mon Sep 17 00:00:00 2001 From: Devin Date: Thu, 31 Oct 2024 12:31:28 -0500 Subject: [PATCH 1/6] Update Template file - Use consistent headers. - Add some more descriptive text. --- examples/template.py | 71 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 16 deletions(-) diff --git a/examples/template.py b/examples/template.py index 7cbf473b..de9e045f 100644 --- a/examples/template.py +++ b/examples/template.py @@ -1,11 +1,14 @@ -# # Short, Descriptive Title (do not specify the application name here, i.e.: Maxwell2D, Maxwell3D etc) +# # Short, Descriptive Title # -# Description: +# (do not specify the solver type in the title, i.e.: Maxwell2D, Maxwell3D etc) +# +# ## Description: # # Most examples can be described as a series of steps that comprise a workflow. # 1. Import packages and instantiate the application. -# 2. Do something useful and interesting. -# 3. View the results. +# 2. Do something useful and interesting like creating the geometric model, assing materials and boundary conditions, etc. +# 3. Run one or more analyses. +# 4. View the results. # # Keywords: **Template**, **Jupyter** @@ -13,11 +16,13 @@ # # Perform required imports. +# + import os import tempfile import time import ansys.aedt.core +# - # Define constants. @@ -25,20 +30,27 @@ NUM_CORES = 4 NG_MODE = False # Open AEDT UI when it is launched. + # ## Create temporary directory # -# Create a temporary directory where downloaded data or -# dumped data can be stored. -# If you'd like to retrieve the project data for subsequent use, -# the temporary folder name is given by ``temp_folder.name``. +# Create a temporary working directory. +# The name of the working folder is stored in ``temp_folder.name``. +# +# > **Note:** The final cell in the notebook cleans up the temporary folder. If you want to +# > retrieve the AEDT project and data, do so before executing the final cell in the notebook. temp_folder = tempfile.TemporaryDirectory(suffix=".ansys") -# ## Launch AEDT and application +# ## Launch application +# +# The syntax for different applications in AEDT differs +# only in the name of the class. This example demonstrates the use of the +# ``Maxwell3d`` class. # -# Create an instance of the application (such as ``Maxwell3d`` or``Hfss``) -# with a class (such as ``m3d`` or``hfss``) by providing -# the project and design names, the solver, and the version. +# > **Note:** Some examples use multiple solver types. When the first solver is +# > instantiated, an AEDT _Project_ is created. In this case, it is the instance of +# > ``Maxwell3d``. When another instance of is created, for example an instance of +# > the ``Icepak`` class, an Icepak design will be inserted into the project. project_name = os.path.join(temp_folder.name, "my_project.aedt") m3d = ansys.aedt.core.Maxwell3d( @@ -49,18 +61,45 @@ non_graphical=NG_MODE, new_desktop=True, ) + +# ### Units +# +# The default units are "mm". Model units can be queried or changed using the +# property ``m3d.modeler.model_units``. + m3d.modeler.model_units = "mm" +print(f'Model units are "{m3d.modeler.model_units}"') -# ## Preprocess +# ## Model Preparation +# +# Description of steps used to create and prepare the model for simulation. +# Add as many sections as needed for preprocessing tasks. Use level 3 headers +# for subsequent headers in this section. # -# Description of preprocessing task. -# Add as many sections as needed for preprocessing tasks. +# ### Create 3D model +# +# > Insert code to generate a 3D model or import a model. +# +# ### Assign boundary conditions +# +# > Insert code to assign boundaries here. +# +# ### Define solution setup +# +# > Insert code to specify solver settings here. +# +# ### Run analysis +# +# > Run the simulation. +m3d.analyze_setup("Setup1") +# # ## Postprocess # # Description of postprocessing task. -# Add as many sections as needed for postprocessing tasks. +# Add as many sections as needed for postprocessing tasks. Again use +# level 3 headers: `### Level 3 header`. # ## Release AEDT From ce8a299db6f3e392558f7b741ea6bf3f6edee9ba Mon Sep 17 00:00:00 2001 From: Devin Date: Thu, 12 Dec 2024 07:34:00 -0800 Subject: [PATCH 2/6] Update Template - Use consistent headers. - Add some more descriptive text. - Update maxwell_icepak.py --- .../multiphysics/maxwell_icepak.py | 71 +++++++++-------- examples/template.py | 77 +++++++++++-------- 2 files changed, 85 insertions(+), 63 deletions(-) diff --git a/examples/low_frequency/multiphysics/maxwell_icepak.py b/examples/low_frequency/multiphysics/maxwell_icepak.py index 8211eab6..15b5af07 100644 --- a/examples/low_frequency/multiphysics/maxwell_icepak.py +++ b/examples/low_frequency/multiphysics/maxwell_icepak.py @@ -7,27 +7,26 @@ # Coil resistance and ohmic loss are analyzed again in Maxwell. Results are printed in AEDT Message Manager. # # Keywords: **Multiphysics**, **Maxwell**, **Icepak**, **Wireless Charging**. + +# ## Prerequisites # -# ## Perform imports and define constants -# -# Perform required imports. +# ### Perform imports -# + import os import tempfile import time - -import ansys.aedt.core +import ansys.aedt.core # Interface to Ansys Electronics Desktop from ansys.aedt.core.generic.constants import AXIS -# - - -# Define constants. +# ### Define constants +# +# Set the version of AEDT and define whether or not this example +# runs in _non-graphical_ mode. AEDT_VERSION = "2024.2" NG_MODE = False # Open AEDT UI when it is launched. -# ## Create temporary directory +# ### Create temporary directory # # Create a temporary working directory. # The name of the working folder is stored in ``temp_folder.name``. @@ -37,21 +36,23 @@ temp_folder = tempfile.TemporaryDirectory(suffix=".ansys") -# ## Launch application +# ### Launch application # # The syntax for different applications in AEDT differ # only in the name of the class. This example demonstrates the use of the -# ``Maxwell3d`` class. +# ``Maxwell3d`` and ``Icepak`` classes. # # > **Note:** An AEDT _Project_ is created when the ``Maxwell3d`` class is instantiated. An instance of -# > the ``Icepak`` class will be used to insert and simulate an Icepak design and demonstrate +# > the ``Icepak`` class will be used later to insert and simulate an +# > Icepak design to demonstrate # > the coupled electrical-thermal workflow. # + -project_name = os.path.join(temp_folder.name, "Maxwell-Icepak-2way-Coupling") maxwell_design_name = "1 Maxwell" icepak_design_name = "2 Icepak" +project_name = os.path.join(temp_folder.name, "Maxwell-Icepak-2way-Coupling") + m3d = ansys.aedt.core.Maxwell3d( project=project_name, design=maxwell_design_name, @@ -61,13 +62,9 @@ ) # - -# ### Units -# The default units are "mm". Model units can be queried or changed using the -# property ``m3d.modeler.model_units``. - -print(f'Model units are "{m3d.modeler.model_units}"') - -# ## Set up model +# ## Model Preparation +# +# ### Build the model # # Create the coil, coil terminal, core, and surrounding air region. The coil and core # are created by drawing a rectangle and sweeping it about the z-axis. @@ -97,13 +94,17 @@ region = m3d.modeler.create_region(pad_percent=[20, 20, 20, 20, 500, 100]) # - -# ### Restore view +# #### Restore view # # If you are using PyAEDT with an interactive desktop, you may want to fit the visible view to fit the model. -# PyAEDT uses the direct access to the native API for this command using the property `m3d.odesktop`. +# PyAEDT allows direct access to the native API for this command using the property `m3d.odesktop`. # # Uncomment and run the following cell if you are running PyAEDT interactively and would like to automatically fit the # window to the model. +# +# > **Note:** Native API calls do not allow for introspection or follow PIP +# > syntax guidelines. Full documentation for the native API is available in +# > the built-in AEDT [help](https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/Electronics/v242/en//Subsystems/Maxwell/Subsystems/Maxwell%20Scripting/Maxwell%20Scripting.htm). # + # desktop=m3d.odesktop.RestoreWindow() # Fit the active view @@ -137,6 +138,8 @@ m3d.assign_material(core.name, "ferrite") # - +# ### Define the source +# # The coil carries 0.5 A and 20 turns. # + @@ -150,7 +153,7 @@ # ### Assign mesh operations # -# Mesh "seeding" is used to retain solution accuracy and accelerate the auto-adaptive mesh refinement. +# Mesh "seeding" is used to accelerate the auto-adaptive mesh refinement. m3d.mesh.assign_length_mesh( ["Core"], maximum_length=15, maximum_elements=None, name="Inside_Core" @@ -163,7 +166,7 @@ # # The impact of Joule heating on conductivity can be considered # by adding a "thermal modifier" to the ``cu_litz`` material definition. -# In this example, conductivity increases by 0.393% per $\Delta$K. The temperature of the objects is set to the default value ($22^0$ C). +# In this example, conductivity increases by 0.393% per $\Delta^o$C. The temperature of the objects is set to the default value ($22^o$C). cu_resistivity_temp_coefficient = 0.00393 cu_litz.conductivity.add_thermal_modifier_free_form( @@ -171,10 +174,10 @@ ) m3d.modeler.set_objects_temperature(["Coil"], ambient_temperature=22) -# ### Assign matrix +# ### Assign the matrix calculation to the winding # # The resistance and inductance calculations for the coil are enabled by -# adding the matrix assignment. +# adding the matrix assignment to the winding. m3d.assign_matrix(["Winding1"], matrix_name="Matrix1") @@ -188,12 +191,16 @@ setup.props["PercentError"] = 0.5 setup.props["MinimumConvergedPasses"] = 2 -# ## Run the Maxwell 3D analysis +# ### Run the Maxwell 3D analysis +# +# The following command runs the 3D finite element analysis in Maxwell. m3d.analyze_setup("Setup1") # ## Postprocessing # +# ### DC resistance +# # The DC resistance of the coil can be calculated analyticially. The following cell compares the known # DC resistance with the simulated coil # resistance. @@ -210,9 +217,11 @@ report_loss = m3d.post.create_report(expressions="StrandedLossAC") solution_loss = report_loss.get_solution_data() em_loss = solution_loss.data_magnitude()[0] +# - + +# ### Analyitic calculation of DC resistance # + -# Analytical calculation of the DC resistance of the coil cu_cond = float(cu_litz.conductivity.value) # Average radius of a coil turn = 125 mm @@ -239,7 +248,7 @@ ) # - -# ## Insert Icepak design +# ## Create the thermal model # # The following commands insert an Icepak design into the AEDT project, copies the solid objects from Maxwell 3D, and modifies the region dimensions so they're suitable # for thermal convection analysis. @@ -377,4 +386,6 @@ # can retrieve those project files. The following cell removes # all temporary files, including the project folder. +m3d.release_desktop() + temp_folder.cleanup() diff --git a/examples/template.py b/examples/template.py index de9e045f..267ab1e6 100644 --- a/examples/template.py +++ b/examples/template.py @@ -2,8 +2,6 @@ # # (do not specify the solver type in the title, i.e.: Maxwell2D, Maxwell3D etc) # -# ## Description: -# # Most examples can be described as a series of steps that comprise a workflow. # 1. Import packages and instantiate the application. # 2. Do something useful and interesting like creating the geometric model, assing materials and boundary conditions, etc. @@ -12,26 +10,24 @@ # # Keywords: **Template**, **Jupyter** -# ## Perform imports and define constants +# ## Prerequisites # -# Perform required imports. +# ### Perform imports -# + import os import tempfile import time +import ansys.aedt.core # Interface to Ansys Electronics Desktop -import ansys.aedt.core -# - - -# Define constants. +# ### Define constants +# Constants defined here help ensure consistency and avoid repetition throughout the example. AEDT_VERSION = "2024.2" NUM_CORES = 4 NG_MODE = False # Open AEDT UI when it is launched. -# ## Create temporary directory +# ### Create temporary directory # # Create a temporary working directory. # The name of the working folder is stored in ``temp_folder.name``. @@ -41,16 +37,23 @@ temp_folder = tempfile.TemporaryDirectory(suffix=".ansys") -# ## Launch application +# ### Launch application # -# The syntax for different applications in AEDT differs -# only in the name of the class. This example demonstrates the use of the -# ``Maxwell3d`` class. +# AEDT applications are accessed through Python classes. +# Each application has it's own class, for example: +# - ``Maxwell3d`` +# - ``Hfss`` +# - ``Maxwell2d`` +# - ``Icepak`` +# - ``Emit`` +# - ``QExtractor`` # -# > **Note:** Some examples use multiple solver types. When the first solver is -# > instantiated, an AEDT _Project_ is created. In this case, it is the instance of -# > ``Maxwell3d``. When another instance of is created, for example an instance of -# > the ``Icepak`` class, an Icepak design will be inserted into the project. +# > **Note:** Some examples access multiple applications. When the first +# > application is +# > instantiated, an AEDT _Project_ is created. +# > When a 2nd application instance for a different AET +# > application is created, the corresponding design +# > type will be inserted into the project. project_name = os.path.join(temp_folder.name, "my_project.aedt") m3d = ansys.aedt.core.Maxwell3d( @@ -62,23 +65,23 @@ new_desktop=True, ) -# ### Units -# -# The default units are "mm". Model units can be queried or changed using the -# property ``m3d.modeler.model_units``. - -m3d.modeler.model_units = "mm" -print(f'Model units are "{m3d.modeler.model_units}"') - # ## Model Preparation # # Description of steps used to create and prepare the model for simulation. # Add as many sections as needed for preprocessing tasks. Use level 3 headers # for subsequent headers in this section. + +# #### Units # +# Model units can be queried or changed using the +# property ``m3d.modeler.model_units``. + +m3d.modeler.model_units = "mm" +print(f'Model units are "{m3d.modeler.model_units}"') + # ### Create 3D model # -# > Insert code to generate a 3D model or import a model. +# > Insert code to build the model from scratch or import a model. # # ### Assign boundary conditions # @@ -94,22 +97,30 @@ m3d.analyze_setup("Setup1") -# # ## Postprocess # -# Description of postprocessing task. -# Add as many sections as needed for postprocessing tasks. Again use -# level 3 headers: `### Level 3 header`. +# After generating results demonstrate how to visualize and evaluate results +# in this section. +# Level 3 headers can be used to identify various post-processing +# steps. +# +# ### Evaluate loss +# > For example, in this section you may use code to demonstrate how to evaluate loss. +# +# ### Visualize fields +# > PyAEDT provides access to field solution data via the -# ## Release AEDT +# ## Finish +# +# ### Save the project m3d.save_project() m3d.release_desktop() # Wait 3 seconds to allow AEDT to shut down before cleaning the temporary directory. time.sleep(3) -# ## Clean up +# ### Clean up # # All project files are saved in the folder ``temp_folder.name``. # If you've run this example as a Jupyter notebook, you From c96632abd85fe6c3eca35da35d550233ab18abfa Mon Sep 17 00:00:00 2001 From: Devin Date: Thu, 12 Dec 2024 07:34:49 -0800 Subject: [PATCH 3/6] Update Formatting - Insert Jupytext seperator --- examples/aedt_general/report/automatic_report.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/aedt_general/report/automatic_report.py b/examples/aedt_general/report/automatic_report.py index 46ee6298..a5274824 100644 --- a/examples/aedt_general/report/automatic_report.py +++ b/examples/aedt_general/report/automatic_report.py @@ -18,6 +18,7 @@ import ansys.aedt.core from IPython.display import Image +# - # Define constants. From 5924a2815ea883164682cf0a17a37c63a86ca360 Mon Sep 17 00:00:00 2001 From: Devin Date: Thu, 12 Dec 2024 07:36:39 -0800 Subject: [PATCH 4/6] Update .gitignore - Ignore "venv*/" instead of "venv/" in order to allow multiple venvs for Python version testing. --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 66951207..6567db02 100644 --- a/.gitignore +++ b/.gitignore @@ -106,7 +106,7 @@ test_results-*.xml .env .venv env/ -venv/ +venv*/ /venv/ ENV/ env.bak/ From 499f1e6103278f19f3d0420ef457595401211d57 Mon Sep 17 00:00:00 2001 From: Devin Date: Mon, 16 Dec 2024 20:00:51 -0600 Subject: [PATCH 5/6] Update Template - Update template file. --- .../multiphysics/maxwell_icepak.py | 17 +++---- examples/template.py | 46 +++++++++++++------ 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/examples/low_frequency/multiphysics/maxwell_icepak.py b/examples/low_frequency/multiphysics/maxwell_icepak.py index 8211eab6..b83c5575 100644 --- a/examples/low_frequency/multiphysics/maxwell_icepak.py +++ b/examples/low_frequency/multiphysics/maxwell_icepak.py @@ -12,16 +12,12 @@ # # Perform required imports. -# + import os import tempfile import time - import ansys.aedt.core from ansys.aedt.core.generic.constants import AXIS -# - - # Define constants. AEDT_VERSION = "2024.2" @@ -32,7 +28,8 @@ # Create a temporary working directory. # The name of the working folder is stored in ``temp_folder.name``. # -# > **Note:** The final cell in the notebook cleans up the temporary folder. If you want to +# > **Note:** The final cell in this example removes the temporary folder and +# > all contents. If you want to # > retrieve the AEDT project and data, do so before executing the final cell in the notebook. temp_folder = tempfile.TemporaryDirectory(suffix=".ansys") @@ -257,7 +254,8 @@ ) # - -# ## Map coil losses +# ## Setup Icepak model +# ### Map coil losses # # Map ohmic losses from Maxwell 3D to the Icepak design. @@ -295,7 +293,7 @@ solution_setup.props["Convergence Criteria - Flow"] = 0.0005 solution_setup.props["Flow Iteration Per Radiation Iteration"] = "5" -# ## Add two-way coupling and solve the project +# ### Add two-way coupling # # The temperature update from Icepak to Maxwell 3D is activated using the method ``assign_2way_coupling()``. The Ohmic # loss in Maxwell will change due to the temperature increase, which in turn will change the results @@ -305,6 +303,9 @@ # The full electro-thermal analysis is run by calling the ``analyze_setup()`` method. ipk.assign_2way_coupling() + +# ## Run Icepak analysis + ipk.analyze_setup(name=solution_setup.name) # ## Postprocess @@ -335,7 +336,7 @@ m3d.logger.info("*******Coil temperature = {:.2f}deg C".format(temp)) # - -# ### Get new resistance from Maxwell 3D +# ### Get updated resistance from Maxwell 3D # # The temperature of the coil increases, and consequently the coil resistance increases. diff --git a/examples/template.py b/examples/template.py index 7cbf473b..4d08ae44 100644 --- a/examples/template.py +++ b/examples/template.py @@ -16,7 +16,6 @@ import os import tempfile import time - import ansys.aedt.core # Define constants. @@ -27,18 +26,20 @@ # ## Create temporary directory # -# Create a temporary directory where downloaded data or -# dumped data can be stored. -# If you'd like to retrieve the project data for subsequent use, -# the temporary folder name is given by ``temp_folder.name``. +# Create a temporary working directory. +# The name of the working folder is stored in ``temp_folder.name``. +# +# > **Note:** The final cell in this example removes the temporary folder and +# > all contents. If you want to +# > retrieve the AEDT project and data, do so before executing the final cell in the notebook. temp_folder = tempfile.TemporaryDirectory(suffix=".ansys") -# ## Launch AEDT and application +# ## Launch application # -# Create an instance of the application (such as ``Maxwell3d`` or``Hfss``) -# with a class (such as ``m3d`` or``hfss``) by providing -# the project and design names, the solver, and the version. +# The syntax for different applications in AEDT differ +# only in the name of the class that instantiates the +# application. For example ``Maxwell3d``, ``Hfss`` or ``Icepak``. project_name = os.path.join(temp_folder.name, "my_project.aedt") m3d = ansys.aedt.core.Maxwell3d( @@ -51,19 +52,38 @@ ) m3d.modeler.model_units = "mm" -# ## Preprocess +# ## Set up model # # Description of preprocessing task. # Add as many sections as needed for preprocessing tasks. +# +# Subsequent steps in the model creation process should be labled with a +# H3 title. +# ### This is a H3 title +# +# Markdown syntax: +# ``` markdown +# ### This is a H3 title +# ``` + +# ## Run the analysis +# +# The analysis is generally run with a single call that launches the solve +# process: +# ``` python +# app.analyze_setup() +# ``` -# ## Postprocess +# ## Postprocessing # # Description of postprocessing task. -# Add as many sections as needed for postprocessing tasks. +# Add subsections with H3 titles as needed to +# describe postprocessing steps such as +# visualizing or analyzing simulation results. -# ## Release AEDT +# ### Save project m3d.save_project() m3d.release_desktop() From c6036263df9c459d5a6e15605a360e69025506ad Mon Sep 17 00:00:00 2001 From: Devin Date: Fri, 20 Dec 2024 09:24:33 +0100 Subject: [PATCH 6/6] Update Template - Update template file. --- .../multiphysics/maxwell_icepak.py | 19 ++--- .../team_problem/asymmetric_conductor.py | 81 ++++++++++--------- .../low_frequency/team_problem/bath_plate.py | 71 ++++++++-------- examples/template.py | 19 ++--- 4 files changed, 98 insertions(+), 92 deletions(-) diff --git a/examples/low_frequency/multiphysics/maxwell_icepak.py b/examples/low_frequency/multiphysics/maxwell_icepak.py index f533a168..a629fb61 100644 --- a/examples/low_frequency/multiphysics/maxwell_icepak.py +++ b/examples/low_frequency/multiphysics/maxwell_icepak.py @@ -20,8 +20,7 @@ # ### Define constants # -# Set the version of AEDT and define whether or not this example -# runs in _non-graphical_ mode. +# Constants help ensure consistency and avoid repetition throughout the example. AEDT_VERSION = "2024.2" NG_MODE = False # Open AEDT UI when it is launched. @@ -109,6 +108,7 @@ # + # desktop=m3d.odesktop.RestoreWindow() # Fit the active view +# desktop = m3d.post.still_focus_oneditor() # - # ### Create and assign material @@ -267,7 +267,6 @@ ) # - -# ## Setup Icepak model # ### Map coil losses # # Map ohmic losses from Maxwell 3D to the Icepak design. @@ -293,7 +292,9 @@ temp_monitor = ipk.assign_point_monitor([70, 0, 0], monitor_name="PointMonitor1") -# Set up Icepak solution +# ### Set up Icepak solution +# +# Icepak solution settings are modified by updating the ``props`` associated with the solution setup. solution_setup = ipk.create_setup() solution_setup.props["Convergence Criteria - Max Iterations"] = 50 @@ -317,7 +318,7 @@ ipk.assign_2way_coupling() -# ## Run Icepak analysis +# ### Run Icepak analysis ipk.analyze_setup(name=solution_setup.name) @@ -378,17 +379,17 @@ ) # - -# ### Save project +# ### Save the project ipk.save_project() ipk.release_desktop() time.sleep(3) # Allow AEDT to shut down before cleaning the temporary project folder. -# ## Clean up +# ### Clean up # # All project files are saved in the folder ``temp_folder.name``. # If you've run this example as a Jupyter notebook, you -# can retrieve those project files. The following cell removes -# all temporary files, including the project folder. +# can retrieve those project files. The following cell +# removes all temporary files, including the project folder. temp_folder.cleanup() diff --git a/examples/low_frequency/team_problem/asymmetric_conductor.py b/examples/low_frequency/team_problem/asymmetric_conductor.py index aa86bd64..b14437e9 100644 --- a/examples/low_frequency/team_problem/asymmetric_conductor.py +++ b/examples/low_frequency/team_problem/asymmetric_conductor.py @@ -7,10 +7,11 @@ # # Keywords: **Maxwell 3D**, **Asymmetric conductor**. -# ## Perform imports and define constants +# ## Prerequisites # -# Perform required imports. +# ### Perform imports +# + import os import tempfile import time @@ -18,28 +19,30 @@ import numpy as np from ansys.aedt.core import Maxwell3d from ansys.aedt.core.generic.general_methods import write_csv +# - -# Define constants. +# ### Define constants +# Constants help ensure consistency and avoid repetition throughout the example. AEDT_VERSION = "2024.2" NUM_CORES = 4 NG_MODE = False # Open AEDT UI when it is launched. -# ## Create temporary directory +# ### Create temporary directory +# +# Create a temporary working directory. +# The name of the working folder is stored in ``temp_folder.name``. # -# Create a temporary directory where downloaded data or -# dumped data can be stored. -# If you'd like to retrieve the project data for subsequent use, -# the temporary folder name is given by ``temp_folder.name``. +# > **Note:** The final cell in the notebook cleans up the temporary folder. If you want to +# > retrieve the AEDT project and data, do so before executing the final cell in the notebook. temp_folder = tempfile.TemporaryDirectory(suffix=".ansys") -# ## Launch AEDT and Maxwell 3D +# ### Launch Maxwell 3D # # Create an instance of the ``Maxwell3d`` class named ``m3d`` by providing # the project and design names, the solver, and the version. -# + project_name = os.path.join(temp_folder.name, "COMPUMAG2.aedt") m3d = Maxwell3d( project=project_name, @@ -50,9 +53,10 @@ new_desktop=True, ) m3d.modeler.model_units = "mm" -# - -# ## Add Maxwell 3D setup +# ## Model Preparation +# +# ### Define the Maxwell 3D analysis setup # # Add a Maxwell 3D setup with frequency points at DC, 50 Hz, and 200Hz. # Otherwise, the default PyAEDT setup values are used. To approximate a DC field in the @@ -77,7 +81,7 @@ setup.props["PercentError"] = 0.4 # - -# ## Define coil dimensions +# ### Define coil dimensions # # Define coil dimensions as shown on the TEAM7 drawing of the coil. @@ -89,6 +93,7 @@ coil_height = 100 coil_centre = [294 - 25 - 150 / 2, 25 + 150 / 2, 19 + 30 + 100 / 2] +# ### Define expressions to evaluate solution data # Use expressions to construct the three dimensions needed to describe the midpoints of # the coil. @@ -96,6 +101,7 @@ dim2 = coil_internal / 2 - coil_r1 dim3 = dim2 + np.sqrt(((coil_r1 + (coil_r2 - coil_r1) / 2) ** 2) / 2) +# ### Draw the coil # Use coordinates to draw a polyline along which to sweep the coil cross sections. P1 = [dim1, -dim2, 0] @@ -103,14 +109,12 @@ P3 = [dim3, dim3, 0] P4 = [dim2, dim1, 0] -# ## Create coordinate system for positioning coil +# Create a coordinate system to use as a reference for the coil. m3d.modeler.create_coordinate_system( origin=coil_centre, mode="view", view="XY", name="Coil_CS" ) -# ## Create polyline -# # Create a polyline. One quarter of the coil is modeled by sweeping a 2D sheet along a polyline. test = m3d.modeler.create_polyline( @@ -118,7 +122,7 @@ ) test.set_crosssection_properties(type="Rectangle", width=coil_thk, height=coil_height) -# ## Duplicate and unite polyline to create full coil +# Duplicate and unite the polyline to create the full coil. m3d.modeler.duplicate_around_axis( assignment="Coil", @@ -132,7 +136,7 @@ m3d.modeler.unite("Coil, Coil_3") m3d.modeler.fit_all() -# ## Assign material and if solution is allowed inside coil +# ### Assign material and enable the field solution inside the copper coil # # Assign the material ``Cooper`` from the Maxwell internal library to the coil and # allow a solution inside the coil. @@ -140,7 +144,7 @@ m3d.assign_material(assignment="Coil", material="Copper") m3d.solve_inside("Coil") -# ## Create terminal +# ### Create terminal # # Create a terminal for the coil from a cross-section that is split and one half deleted. @@ -148,25 +152,26 @@ m3d.modeler.separate_bodies(assignment="Coil_Section1") m3d.modeler.delete(assignment="Coil_Section1_Separate1") -# ## Add variable for coil excitation +# ### Add variable for coil excitation # -# Add a design variable for coil excitation. The NB units here are AmpereTurns. +# Use a parameter to define the coil current. +# The units in this case are Ampere$\times$Turns. Coil_Excitation = 2742 m3d["Coil_Excitation"] = str(Coil_Excitation) + "A" m3d.assign_current(assignment="Coil_Section1", amplitude="Coil_Excitation", solid=False) m3d.modeler.set_working_coordinate_system("Global") -# ## Add material +# ### Add material # # Add a material named ``team3_aluminium``. mat = m3d.materials.add_material("team7_aluminium") mat.conductivity = 3.526e7 -# ## Model aluminium plate with a hole +# ### Create the aluminium plate with a hole # -# Model the aluminium plate with a hole by subtracting two rectangular cuboids. +# Draw the aluminium plate with a hole by subtracting two cuboids. plate = m3d.modeler.create_box( origin=[0, 0, 0], sizes=[294, 294, 19], name="Plate", material="team7_aluminium" @@ -175,19 +180,17 @@ hole = m3d.modeler.create_box(origin=[18, 18, 0], sizes=[108, 108, 19], name="Hole") m3d.modeler.subtract(blank_list="Plate", tool_list=["Hole"], keep_originals=False) -# ## Draw background region +# ### Draw background region # -# Draw a background region that uses the default properties for an air region. +# The background air region defines the full volumetric solution domain. m3d.modeler.create_air_region( x_pos=100, y_pos=100, z_pos=100, x_neg=100, y_neg=100, z_neg=100 ) -# ## Adjust eddy effects for plate and coil +# ### Adjust eddy effects for plate and coil # -# Adjust the eddy effects for the plate and coil by turning off displacement currents -# for all parts. The setting for the eddy effect is ignored for the stranded conductor type -# used in the coil. +# Disable the eddy effects for the plate and coil. This forces the current to flow uniformly through the coils cross-section as would be the case for stranded wires. m3d.eddy_effects_on(assignment="Plate") m3d.eddy_effects_on( @@ -196,9 +199,9 @@ enable_displacement_current=False, ) -# ## Create expression for Z component of B in Gauss +# ### Create expression for $B_z$ in Gauss # -# Create an expression for the Z component of B in Gauss using PyAEDT advanced fields calculator. +# Create an expression for the $z$-component of $\bf{B}$ in Gauss using PyAEDT advanced fields calculator. bz = { "name": "Bz", @@ -221,7 +224,7 @@ } m3d.post.fields_calculator.add_expression(bz, None) -# ## Draw two lines along which to plot Bz +# ### Draw two lines along which to plot $B_z$ # # Draw two lines along which to plot Bz. The following code also adds a small cylinder # to refine the mesh locally around each line. @@ -454,22 +457,20 @@ ] # - -# ## Write dataset values to a CSV file +# ### Write dataset values to a CSV file # # Dataset details are used to encode test parameters in the text files. # For example, ``Bz A1_B1 050 0`` is the Z component of flux density ``B`` # along line ``A1_B1`` at 50 Hz and 0 deg. -# + line_length.insert(0, header[0]) for i in range(len(dataset)): data[i].insert(0, header[1]) ziplist = zip(line_length, data[i]) file_path = os.path.join(temp_folder.name, str(dataset[i]) + ".csv") write_csv(output_file=file_path, list_data=ziplist) -# - -# ## Create rectangular plots and import test data into report +# ### Create rectangular plots and import test data into report # # Create rectangular plots, using text file encoding to control their formatting. # Import test data into the correct plot and overlay with the simulation results. @@ -508,7 +509,7 @@ m3d.analyze(cores=NUM_CORES) -# ## Create plots of induced current and flux density on surface of plate +# ### Create plots of induced current and flux density on surface of plate # # Create two plots of the induced current (``Mag_J``) and the flux density (``Mag_B``) on the # surface of the plate. @@ -531,7 +532,9 @@ assignment=surf_list, quantity="Mesh", intrinsics=intrinsic_dict, plot_name="Mesh" ) -# ## Release AEDT +# ## Finish +# +# ### Save the project m3d.save_project() m3d.release_desktop() diff --git a/examples/low_frequency/team_problem/bath_plate.py b/examples/low_frequency/team_problem/bath_plate.py index b0bb16d0..1549b492 100644 --- a/examples/low_frequency/team_problem/bath_plate.py +++ b/examples/low_frequency/team_problem/bath_plate.py @@ -2,42 +2,46 @@ # # This example uses PyAEDT to set up the TEAM 3 bath plate problem and # solve it using the Maxwell 3D eddy current solver. -# # For more information on this problem, see this +# +# For more information on this problem, see this # [paper](https://www.compumag.org/wp/wp-content/uploads/2018/06/problem3.pdf). # # Keywords: **Maxwell 3D**, **TEAM 3 bath plate** -# ## Perform imports and define constants +# ## Prerequisites # -# Perform required imports. +# ### Perform imports +# + import os import tempfile import time import ansys.aedt.core +# - -# Define constants. +# ### Define constants +# Constants help ensure consistency and avoid repetition throughout the example. AEDT_VERSION = "2024.2" NUM_CORES = 4 NG_MODE = False # Open AEDT UI when it is launched. -# ## Create temporary directory +# ### Create temporary directory +# +# Create a temporary working directory. +# The name of the working folder is stored in ``temp_folder.name``. # -# Create a temporary directory where downloaded data or -# dumped data can be stored. -# If you'd like to retrieve the project data for subsequent use, -# the temporary folder name is given by ``temp_folder.name``. +# > **Note:** The final cell in the notebook cleans up the temporary folder. If you want to +# > retrieve the AEDT project and data, do so before executing the final cell in the notebook. temp_folder = tempfile.TemporaryDirectory(suffix=".ansys") -# ## Launch AEDT and Maxwell 3D +# ### Launch Maxwell 3D # # Create an instance of the ``Maxwell3d`` class named ``m3d`` by providing # the project and design names, the solver, and the version. -# + m3d = ansys.aedt.core.Maxwell3d( project=os.path.join(temp_folder.name, "COMPUMAG.aedt"), design="TEAM_3_Bath_Plate", @@ -47,9 +51,8 @@ new_desktop=True, ) uom = m3d.modeler.model_units = "mm" -# - -# ## Add variable +# ### Add variable # # Add a design variable named ``Coil_Position`` to use later to adjust the # position of the coil. @@ -57,14 +60,14 @@ Coil_Position = -20 m3d["Coil_Position"] = str(Coil_Position) + m3d.modeler.model_units -# ## Add material +# ### Add material # # Add a material named ``team3_aluminium`` for the ladder plate. mat = m3d.materials.add_material(name="team3_aluminium") mat.conductivity = 32780000 -# ## Draw background region +# ### Draw background region # # Draw a background region that uses the default properties for an air region. @@ -72,7 +75,7 @@ x_pos=100, y_pos=100, z_pos=100, x_neg=100, y_neg=100, z_neg=100 ) -# ## Draw ladder plate and assign material +# ### Draw ladder plate and assign material # # Draw a ladder plate and assign it the newly created material ``team3_aluminium``. @@ -90,7 +93,7 @@ keep_originals=False, ) -# ## Add mesh refinement to ladder plate +# ### Add mesh refinement to ladder plate # > **Note:** You can uncomment the following code. @@ -101,7 +104,7 @@ # name="Ladder_Mesh", # ) -# ## Draw search coil and assign excitation +# ### Draw search coil and assign excitation # # Draw a search coil and assign it a ``stranded`` current excitation. # The stranded type forces the current density to be constant in the coil. @@ -133,7 +136,7 @@ name="SearchCoil_Excitation", ) -# ## Draw a line for plotting Bz +# ### Draw a line for plotting $B_z$ # # Draw a line for plotting Bz later. Bz is the Z component of the flux # density. The following code also adds a small diameter cylinder to refine the @@ -144,7 +147,7 @@ poly = m3d.modeler.create_polyline(points=line_points, name="Line_AB_MeshRefinement") poly.set_crosssection_properties(type="Circle", width="0.5mm") -# ## Add Maxwell 3D setup +# ### Add Maxwell 3D setup # # Add a Maxwell 3D setup with frequency points at 50 Hz and 200 Hz. @@ -156,7 +159,7 @@ range_type="LinearStep", start=50, end=200, count=150, clear=True ) -# ## Adjust eddy effects +# ### Adjust eddy effects # # Adjust eddy effects for the ladder plate and the search coil. The setting for # eddy effect is ignored for the stranded conductor type used in the search coil. @@ -172,7 +175,7 @@ enable_displacement_current=True, ) -# ## Add linear parametric sweep +# ### Add linear parametric sweep # # Add a linear parametric sweep for the two coil positions. @@ -189,14 +192,16 @@ param["CopyMesh"] = False param["SolveWithCopiedMeshOnly"] = True -# ## Solve parametric sweep +# ### Solve parametric sweep # # Solve the parametric sweep directly so that results of all variations are available. m3d.save_project() param.analyze(cores=NUM_CORES) -# ## Create expression for Bz +# ## Postprocess +# +# ### Create expression for Bz # # Create an expression for Bz using PyAEDT advanced fields calculator. @@ -219,9 +224,9 @@ } m3d.post.fields_calculator.add_expression(bz, None) -# ## Plot mag(Bz) as a function of frequency +# ### Plot $|B_z|$ as a function of frequency # -# Plot mag(Bz) as a function of frequency for both coil positions. +# Plot $|B_z|$ as a function of frequency for both coil positions. # + variations = { @@ -241,7 +246,7 @@ ) # - -# ## Get simulation results from a solved setup +# ### Get simulation results from a solved setup # # Get simulation results from a solved setup as a ``SolutionData`` object. @@ -256,12 +261,12 @@ ) # - -# ## Set up sweep value and plot solution +# ### Set up sweep value and plot solution solutions.active_variation["Coil_Position"] = -0.02 solutions.plot() -# ## Change sweep value and plot solution +# ### Change sweep value and plot solution # # Change the sweep value and plot the solution again. # Uncomment to show plots. @@ -269,7 +274,7 @@ solutions.active_variation["Coil_Position"] = 0 # solutions.plot() -# ## Plot induced current density on surface of ladder plate +# ### Plot induced current density on surface of ladder plate # # Plot the induced current density, ``"Mag_J"``, on the surface of the ladder plate. @@ -282,14 +287,16 @@ plot_name="Mag_J", ) -# ## Release AEDT +# ## Finish +# +# ### Save the project m3d.save_project() m3d.release_desktop() # Wait 3 seconds to allow AEDT to shut down before cleaning the temporary directory. time.sleep(3) -# ## Clean up +# ### Clean up # # All project files are saved in the folder ``temp_folder.name``. # If you've run this example as a Jupyter notebook, you diff --git a/examples/template.py b/examples/template.py index 267ab1e6..3f25c082 100644 --- a/examples/template.py +++ b/examples/template.py @@ -4,7 +4,7 @@ # # Most examples can be described as a series of steps that comprise a workflow. # 1. Import packages and instantiate the application. -# 2. Do something useful and interesting like creating the geometric model, assing materials and boundary conditions, etc. +# 2. Do something useful and interesting like creating the model, assing materials and boundary conditions, etc. # 3. Run one or more analyses. # 4. View the results. # @@ -14,13 +14,16 @@ # # ### Perform imports +# + import os import tempfile import time + import ansys.aedt.core # Interface to Ansys Electronics Desktop +# - # ### Define constants -# Constants defined here help ensure consistency and avoid repetition throughout the example. +# Constants help ensure consistency and avoid repetition throughout the example. AEDT_VERSION = "2024.2" NUM_CORES = 4 @@ -50,8 +53,8 @@ # # > **Note:** Some examples access multiple applications. When the first # > application is -# > instantiated, an AEDT _Project_ is created. -# > When a 2nd application instance for a different AET +# > started, an AEDT _Project_ is created. +# > When a 2nd application instance for a different AEDT # > application is created, the corresponding design # > type will be inserted into the project. @@ -71,14 +74,6 @@ # Add as many sections as needed for preprocessing tasks. Use level 3 headers # for subsequent headers in this section. -# #### Units -# -# Model units can be queried or changed using the -# property ``m3d.modeler.model_units``. - -m3d.modeler.model_units = "mm" -print(f'Model units are "{m3d.modeler.model_units}"') - # ### Create 3D model # # > Insert code to build the model from scratch or import a model.