In this example, using the attached files, you will insert a Harmonic 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.
Harmonic_Acoustics_Example.agdb
Harmonic_Acoustics_Example.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 Harmonic_Acoustics_Example.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 Harmonic_Acoustics_Example.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 Store all main tree nodes as variables GEOMETRY = Model.Geometry MESH = Model.Mesh NAMED_SELECTIONS = Model.NamedSelections CONNECTIONS = Model.Connections #Scenario 2 Suppress unneeded bodies and assign material ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardMKS SPEAKER_BOX = [i for i in GEOMETRY.GetChildren[Ansys.ACT.Automation.Mechanical.Body](True) if i.Name == 'speaker-box assy'][0] PLATE = [i for i in GEOMETRY.GetChildren[Ansys.ACT.Automation.Mechanical.Body](True) if i.Name == 'plate'][0] FEA_DOMAIN = [i for i in GEOMETRY.GetChildren[Ansys.ACT.Automation.Mechanical.Body](True) if i.Name == 'FEA_Domain'][0] PML_REGION = [i for i in GEOMETRY.GetChildren[Ansys.ACT.Automation.Mechanical.Body](True) if i.Name == 'PML_Region'][0] SPEAKER_BOX.Suppressed = 1 PLATE.Suppressed = 1 FEA_DOMAIN.Material = "Air" PML_REGION.Material= "Air" #Scenario 3 Store Named selections as variable FEA_BODY = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'FEA_Body'][0] PML_BODY = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'PML_Body'][0] MASS_SOURCE_FACE = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'Mass_Source_face'][0] PRESSURE_FACES = [i for i in NAMED_SELECTIONS.GetChildren[Ansys.ACT.Automation.Mechanical.NamedSelection](True) if i.Name == 'PRESSURE_FACES'][0] #Scenario 4 Add mesh sizing and method SIZING1 = MESH.AddSizing() SIZING1.Location = FEA_BODY SIZING1.ElementSize =Quantity('0.01 [m]') SIZING2 = MESH.AddSizing() SIZING2.Location = PML_BODY SIZING2.ElementSize =Quantity('0.01 [m]') MESH_METHOD1 = MESH.AddAutomaticMethod() MESH_METHOD1.Location = FEA_BODY.Location MESH_METHOD1.Method =MethodType.HexDominant MESH_METHOD2 = MESH.AddAutomaticMethod() MESH_METHOD2.Location = PML_BODY.Location MESH_METHOD2.Method =MethodType.HexDominant #Scenario 5 Insert automatic node merge MESH_EDIT = Model.AddMeshEdit() NODE_MERGE_GROUP = MESH_EDIT.AddNodeMergeGroup() NODE_MERGE_GROUP.ToleranceValue = Quantity('0.001 [m]') MESH_EDIT.Generate() #Scenario 6 Setup Harmonic Acoustics and defined Acoustic and PML regions ANALYSIS_SETTINGS = Model.Analyses[0].AnalysisSettings ANALYSIS_SETTINGS.RangeMaximum = Quantity('3000 [Hz]') ANALYSIS_SETTINGS.SolutionIntervals = 1 ANALYSIS_SETTINGS.CalculateVelocity = True ANALYSIS_SETTINGS.CalculateEnergy = True ANALYSIS_SETTINGS.GeneralMiscellaneous = True ANALYSIS_SETTINGS.FarFieldRadiationSurface =FarFieldRadiationSurfaceType.Manual HARMONIC_ACOUSTICS = Model.Analyses[0] ACOUSTIC_REGION1 = HARMONIC_ACOUSTICS.Children[2] ACOUSTIC_REGION1.Location = FEA_BODY ACOUSTIC_REGION2 = HARMONIC_ACOUSTICS.AddPhysicsRegion() ACOUSTIC_REGION2.Location = PML_BODY ACOUSTIC_REGION2.Acoustics = True ACOUSTIC_REGION2.ArtificiallyMatchedLayers = ArtificiallyMatchedLayers.PML MASS_SOURCE = HARMONIC_ACOUSTICS.AddAcousticMassSource() MASS_SOURCE.Location = MASS_SOURCE_FACE MASS_SOURCE.Magnitude.Output.DiscreteValues = [Quantity('0.01 [kg m-2 s-1]')] ACOUST_PRESSURE = HARMONIC_ACOUSTICS.AddAcousticPressure() ACOUST_PRESSURE.Location = PRESSURE_FACES FARFFIELD_RAD_SURFACE = HARMONIC_ACOUSTICS.CreateAutomaticFarFieldRadiationSurfaces() #Scenario 7 Insert Acoustic results and solve SOLUTION = Model.Analyses[0].Solution ACOUSTIC_PRESSURE_RESULT = SOLUTION.AddAcousticPressureResult() ACOUSTIC_PRESSURE_RESULT.Location = FEA_BODY SOUND_PRESSURE_LEVEL = SOLUTION.AddAcousticSoundPressureLevel() SOUND_PRESSURE_LEVEL.Location = FEA_BODY FAR_FIELD_SPL = SOLUTION.AddAcousticFarFieldSPL() FAR_FIELD_SPL.SphereRadius = Quantity('1 [m]') FAR_FIELD_SPL.ThetaAngleEnd = Quantity('90 [deg]') FAR_FIELD_SPL.ThetaAngleNoOfDivisions = 90 FAR_FIELD_AWEIGHTED_SPL = SOLUTION.AddAcousticFarFieldAWeightedSPL() FAR_FIELD_AWEIGHTED_SPL.SphereRadius = Quantity('1 [m]') FAR_FIELD_AWEIGHTED_SPL.ThetaAngleEnd = Quantity('90 [deg]') FAR_FIELD_AWEIGHTED_SPL.ThetaAngleNoOfDivisions = 90 #Scenario 8 Solve and store results SOLUTION.Solve(True) PRESSURE_MAX = ACOUSTIC_PRESSURE_RESULT.Minimum.Value PRESSURE_MIN = ACOUSTIC_PRESSURE_RESULT.Maximum.Value SPL_MIN = SOUND_PRESSURE_LEVEL.Minimum.Value SPL_MAX = SOUND_PRESSURE_LEVEL.Maximum.Value FF_SPL_MIN = FAR_FIELD_SPL.Minimum.Value FF_SPL_MAX = FAR_FIELD_SPL.Maximum.Value FF_A_SPL_MIN = FAR_FIELD_AWEIGHTED_SPL.Minimum.Value FF_A_SPL_MAX = FAR_FIELD_AWEIGHTED_SPL.Maximum.Value
Summary
This example demonstrates how scripting in Mechanical can be used to automate your actions.