Coupled Field Harmonic Analysis

In this example, using the support files, you will insert a Coupled Field Harmonic analysis object into an undefined Mechanical session 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.

  • Coupled_Field_Harmonic_Example.agdb

  • Coupled_Field_Harmonic_Example.py

  • Coupled_Field_Harmonic_Example_PZT.xml

  • Coupled_Field_Harmonic_Example_Substrate.xml

These files are available here.

Procedure

  1. Open Workbench and insert a Coupled Field Harmonic system into the Project Schematic.

  2. Double-click the Engineering Data cell to open the workspace.

  3. Select File > Import Engineering Data, navigate to the proper folder location and select Coupled_Field_Harmonic_Example_PZT.xml. Repeat this for Coupled_Field_Harmonic_Example_Substrate.xml.

  4. Return to the Project tab.

  5. Right-click the Geometry cell and select Import Geometry > Browse and then navigate to the proper folder location and select Coupled_Field_Harmonic_Example.agdb.

  6. Open Mechanical: right-click the Model cell and select Edit.

  7. Select the Automation tab and select the Scripting option to open the Mechanical Scripting pane.

  8. Select the Open Script option ( ) from the Editor toolbar. Navigate to the proper folder location and select Coupled_Field_Harmonic_Example.py.

  9. Select the Run Script option ( ) from the Editor toolbar.

Scripts Illustrated

In this example, the python file automatically performs the following actions:

# Scenario 1 Set up the Tree Object Items
GEOMETRY = Model.Geometry
COORDINATE_SYSTEM = Model.CoordinateSystems
CONNECTIONS = Model.Connections
MESH = Model.Mesh
COUPLED_FIELD_HARMONIC = ExtAPI.DataModel.AnalysisByName("Coupled Field Harmonic")
ANALYSIS_SETTINGS = COUPLED_FIELD_HARMONIC.AnalysisSettings
SOLUTION = COUPLED_FIELD_HARMONIC.Solution

# Scenario 2 Set up the Unit Systems
ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardMKS

# Scenario 3 Assign Material Properties
SUBSTRATE = GEOMETRY.Children[0].Children[0]
PIEZO = GEOMETRY.Children[1].Children[0]
SUBSTRATE.Assignment='substrate_mat'
PIEZO.Assignment='PZT-5A'

# Scenario 4 Define Named Selections
PIEZO_PART = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == 'piezo_body'][0]
STRUCT_PART = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == 'struct_body'][0]
VERTEX = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == 'tip'][0]
DISP_BC = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == 'disp_constraints'][0]
PIEZO_TOP = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == 'piezo_top_surface'][0]
PIEZO_BOTTOM= [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == 'piezo_bottom_surface'][0]

# Scenario 5 Define Contact
CONTACTS = CONNECTIONS.Children[0]
CONTACTS_REGION = CONTACTS.Children[0]
CONTACTS_REGION.ContactFormulation=ContactFormulation.MPC

# Scenario 6 Define Mesh Settings
MESH.ElementSize = Quantity(' 0.005 [m]')
MESH.GenerateMesh()

# Scenario 7 Define Physics Region
PHY_REG01 = COUPLED_FIELD_HARMONIC.Children[2]
PHY_REG01.Location = PIEZO_PART
PHY_REG02 = COUPLED_FIELD_HARMONIC.AddPhysicsRegion()
PHY_REG02.Structural = True
PHY_REG02.Electric=ElectricType.No

# Scenario 8 Define Analysis Settings
ANALYSIS_SETTINGS.RangeMaximum = Quantity('125[Hz]')
ANALYSIS_SETTINGS.SolutionIntervals = 25

# Scenario 9 Insert Load and Boundary Conditions
DISPLACEMENT = COUPLED_FIELD_HARMONIC.AddDisplacement()
DISPLACEMENT.Location = DISP_BC
DISPLACEMENT.XComponent.Output.DiscreteValues=[Quantity('0 [m]')]
DISPLACEMENT.YComponent.Output.DiscreteValues=[Quantity('0 [m]')]
DISPLACEMENT.ZComponent.Output.DiscreteValues=[Quantity('0 [m]')]

VOLTAGE_COUPLING = COUPLED_FIELD_HARMONIC.AddVoltageCoupling()
VOLTAGE_COUPLING.Location = PIEZO_TOP

VOLTAGE_GROUND = COUPLED_FIELD_HARMONIC.AddVoltageGround()
VOLTAGE_GROUND.Location = PIEZO_BOTTOM

VOLTAGE = COUPLED_FIELD_HARMONIC.AddVoltage()
VOLTAGE.Location = VOLTAGE_COUPLING
VOLTAGE.Magnitude.Output.DiscreteValues = [Quantity('1 [V]')]

# Scenario 10 Insert Results
FRQUENCY_RESPONSE_DEFORMATION = SOLUTION.AddDeformationFrequencyResponse()
FRQUENCY_RESPONSE_DEFORMATION.Location = VERTEX
FRQUENCY_RESPONSE_DEFORMATION.NormalOrientation = NormalOrientationType.ZAxis

FREQUENCY_RESPONSE_VOLTAGE = SOLUTION.AddVoltageFrequencyResponse()
FREQUENCY_RESPONSE_VOLTAGE.Location = PIEZO_TOP

FREQUENCY_RESPONSE_CHARGE_REACTION = SOLUTION.AddChargeReactionFrequencyResponse()
FREQUENCY_RESPONSE_CHARGE_REACTION.BoundaryCondition = VOLTAGE

FREQUENCY_RESPONSE_IMPEDANCE = SOLUTION.AddImpedanceFrequencyResponse()
FREQUENCY_RESPONSE_IMPEDANCE.BoundaryCondition = VOLTAGE

# Scenario 11 Solve and review the Result
SOLUTION.Solve(True)
FRQUENCY_RESPONSE_DEFORMATION.MaximumAmplitude.Value
FRQUENCY_RESPONSE_DEFORMATION.FrequencyAtMaximumAmplitude.Value

FREQUENCY_RESPONSE_VOLTAGE.MaximumAmplitude.Value
FREQUENCY_RESPONSE_VOLTAGE.FrequencyAtMaximumAmplitude.Value
FREQUENCY_RESPONSE_VOLTAGE.PhaseAngle.Value
FREQUENCY_RESPONSE_VOLTAGE.RealAtMaximumAmplitude.Value
FREQUENCY_RESPONSE_VOLTAGE.ImaginaryAtMaximumAmplitude.Value

FREQUENCY_RESPONSE_CHARGE_REACTION.MaximumAmplitude.Value
FREQUENCY_RESPONSE_CHARGE_REACTION.FrequencyAtMaximumAmplitude.Value
FREQUENCY_RESPONSE_CHARGE_REACTION.PhaseAngle.Value
FREQUENCY_RESPONSE_CHARGE_REACTION.RealAtMaximumAmplitude.Value
FREQUENCY_RESPONSE_CHARGE_REACTION.ImaginaryAtMaximumAmplitude.Value

FREQUENCY_RESPONSE_IMPEDANCE.MaximumAmplitude.Value
FREQUENCY_RESPONSE_IMPEDANCE.FrequencyAtMaximumAmplitude.Value
FREQUENCY_RESPONSE_IMPEDANCE.PhaseAngle.Value
FREQUENCY_RESPONSE_IMPEDANCE.RealAtMaximumAmplitude.Value
FREQUENCY_RESPONSE_IMPEDANCE.ImaginaryAtMaximumAmplitude.Value

Summary

This example demonstrates how scripting in Mechanical can be used to automate your actions.