In this example, using the attached files, you will insert a Modal Acoustic analysis system and execute a sequence of python journal commands that will define and solve the analysis.
This example begins in the Mechanical application. It requires you to download the following Ansys DesignModeler and python files.
Mechanical_Modal_Acoustics_013_Geometry.agdb
Mechanical_Modal_Acoustics_013_Script.py
These files are available here.
Procedure
Open Mechanical directly without importing a geometry or specifying an analysis type. This can be done through Start Menu.
From the Analysis drop-down menu of the Insert group on the Home tab, insert a system into the tree.
Select the Geometry object and select the Attach Geometry option from the Geometry group on the Geometry Context tab. Navigate to the proper folder location and select Mechanical_Modal_Acoustics_013_Geometry.agdb.
Select the Automation tab and select the Scripting option to open the Mechanical Scripting pane.
Select the Open Script option (
) from the Editor toolbar. Navigate to the
proper folder location and select
Mechanical_Modal_Acoustics_013_Script.py.Select the Run Script option (
) from the Editor toolbar.
Scripts Illustrated
In this example, the python file automatically performs the following actions:
#Scenario 1 Define main Tree node objects
GEOMETRY = Model.Geometry
MESH = Model.Mesh
NS_GRP = Model.NamedSelections
#Scenario 2 Store Named selections as variables
NS_OUTER_FACE = [i for i in NS_GRP.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Acoustic_outer_face'][0]
NS_FSI_FACE = [i for i in NS_GRP.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'FSI_Face'][0]
NS_ACOUSTIC_BODY = [i for i in NS_GRP.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Acoustic_body'][0]
NS_SOLID_BODY = [i for i in NS_GRP.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Solid_body'][0]
NS_SOLID_FACE1 = [i for i in NS_GRP.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Solid_face1'][0]
NS_ACST_FACE1 = [i for i in NS_GRP.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Acst_face1'][0]
#Scenario 3 Assign Water to Acoustic parts
GEOM_WATER = [i for i in GEOMETRY.GetChildren[Ansys.ACT.Automation.Mechanical.Body](True) if i.Name == 'Water'][0]
GEOM_WATER.Material = 'Water Liquid'
#Scenario 4 Insert and setup mesh controls
MESH.ElementOrder = ElementOrder.Quadratic
FACE_MESH1 = MESH.AddFaceMeshing()
FACE_MESH1.Location = NS_SOLID_FACE1
FACE_MESH2 = MESH.AddFaceMeshing()
FACE_MESH2.Location = NS_ACST_FACE1
MESH_SIZE1 = MESH.AddSizing()
MESH_SIZE1.Location = NS_SOLID_BODY
MESH_SIZE1.ElementSize = Quantity('0.125 [in]')
MESH_SIZE2 = MESH.AddSizing()
MESH_SIZE2.Location = NS_ACOUSTIC_BODY
MESH_SIZE2.ElementSize = Quantity('5 [in]')
#Scenario 5 Define Physics Regions
MODAL_ACOUSTIC = Model.Analyses[0]
ANALYSIS_SETTINGS = Model.Analyses[0].AnalysisSettings
ANALYSIS_SETTINGS.IgnoreAcousticDamping = True
ACOUSTIC_REGION = MODAL_ACOUSTIC.Children[2]
ACOUSTIC_REGION.Location = NS_ACOUSTIC_BODY
ACOUSTIC_REGION.Acoustics = True
STRUCTURAL_REGION = MODAL_ACOUSTIC.AddPhysicsRegion()
STRUCTURAL_REGION.Location = NS_SOLID_BODY
STRUCTURAL_REGION.Structural = True
#Scenario 6 Insert Acoustic Pressure and FSI
ACOUSTIC_PRESSURE = MODAL_ACOUSTIC.AddAcousticPressure()
ACOUSTIC_PRESSURE.Location = NS_OUTER_FACE
ACOUSTIC_PRESSURE.Magnitude = Quantity('0.000001 [psi]')
FLUID_SOLID_INTERFACE = MODAL_ACOUSTIC.AddFluidSolidInterface()
FLUID_SOLID_INTERFACE.Location = NS_FSI_FACE
#Scenario 7 Insert results Total Deformation and Acoustic Pressure
SOLUTION = MODAL_ACOUSTIC.Solution
TOTAL_DEFORMATION_1 = SOLUTION.AddTotalDeformation()
ACOUSTIC_PRESSURE_RESULT_1 = SOLUTION.AddAcousticPressureResult()
ACOUSTIC_PRESSURE_RESULT_1.Location = NS_ACOUSTIC_BODY
ACOUSTIC_PRESSURE_RESULT_2 = SOLUTION.AddAcousticPressureResult()
ACOUSTIC_PRESSURE_RESULT_2.SetNumber = 2
#Scenario 8 Solve and store results
SOLUTION.Solve(True)
#Frequency for particular mode from details view
FREQ1 = TOTAL_DEFORMATION_1.ReportedFrequency.Value
#Frequency for all modes from tabular data
FREQ1 = TOTAL_DEFORMATION_1.TabularData["Frequency"][0]
FREQ2 = TOTAL_DEFORMATION_1.TabularData["Frequency"][1]
FREQ3 = TOTAL_DEFORMATION_1.TabularData["Frequency"][2]
FREQ4 = TOTAL_DEFORMATION_1.TabularData["Frequency"][3]
FREQ5 = TOTAL_DEFORMATION_1.TabularData["Frequency"][4]
FREQ6 = TOTAL_DEFORMATION_1.TabularData["Frequency"][5]
PRESSURE_MAX = ACOUSTIC_PRESSURE_RESULT_1.Maximum.Value
PRESSURE_MIN = ACOUSTIC_PRESSURE_RESULT_1.Minimum.ValueSummary
This example demonstrates how scripting in Mechanical can be used to automate your actions.