How to setup a Mode Superposition Modal, Harmonic and Response Spectrum analysis?
import json
import os
import logging
import ansys.mechanical.core as mech
from ansys.mechanical.core import App
app = App(version=242)
globals().update(mech.global_variables(app, True))
print(app)
part_file_path = r"\Path\to\sample_geom.agdb"
# No Automatic Contacts to be generated
connections = Model.AddConnections()
connections.GenerateAutomaticConnectionOnRefresh = AutomaticOrManual.Manual
# Section 1: Read geometry information
geometry_import = Model.GeometryImportGroup
geometry_import = geometry_import.AddGeometryImport()
geometry_import_format = Ansys.Mechanical.DataModel.Enums.GeometryImportPreference.Format.Automatic
geometry_import_preferences = Ansys.ACT.Mechanical.Utilities.GeometryImportPreferences()
geometry_import_preferences.ProcessNamedSelections = True
geometry_import_preferences.NamedSelectionKey = None
geometry_import_preferences.ProcessCoordinateSystems = True
geometry_import_preferences.ProcessLines = True
geometry_import.Import(
part_file_path, geometry_import_format, geometry_import_preferences)
# Assign all Shells some thickness
geometry = ExtAPI.DataModel.Project.Model.Geometry
listBodies = geometry.GetChildren(DataModelObjectCategory.Body, True)
for body in listBodies:
if body.ModelType == PrototypeModelType.Shell:
body.Thickness = Quantity(1, "mm")
# Add Point Mass
point_mass_1 = geometry.AddPointMass()
point_mass_1.Location = ExtAPI.DataModel.GetObjectsByName("pointmass1")[0]
point_mass_1.Mass = Quantity(15, "g")
# Add Connections
connection_group = connections.AddConnectionGroup()
# Bonded Contact
contact_region_1 = connection_group.AddContactRegion()
contact_region_1.SourceLocation = ExtAPI.DataModel.GetObjectsByName("box1_bot")[
0]
contact_region_1.TargetLocation = ExtAPI.DataModel.GetObjectsByName("box2_top")[
0]
connection_group.RenameBasedOnChildren()
# Beam 1 Top
contact_region_2 = connection_group.AddContactRegion()
contact_region_2.SourceLocation = ExtAPI.DataModel.GetObjectsByName(
"beam_top_vertex")[0]
contact_region_2.TargetLocation = ExtAPI.DataModel.GetObjectsByName("beam_top_face")[
0]
# Beam 1 Bot
contact_region_3 = connection_group.AddContactRegion()
contact_region_3.SourceLocation = ExtAPI.DataModel.GetObjectsByName(
"beam_bot_vertex")[0]
contact_region_3.TargetLocation = ExtAPI.DataModel.GetObjectsByName("beam_bot_face")[
0]
connection_group.RenameBasedOnChildren()
# Fixed Joint
connection_joints = connections.AddConnectionGroup()
joint = connection_joints.AddJoint()
joint.RenameBasedOnDefinition()
joint.MobileLocation = ExtAPI.DataModel.GetObjectsByName("joint_face1")[0]
joint.ReferenceLocation = ExtAPI.DataModel.GetObjectsByName("joint_face2")[0]
connection_joints.RenameBasedOnChildren()
# Add Beam Connection
beam = connections.AddBeam()
beam.RenameBasedOnDefinition()
beam.Radius = Quantity(1, "mm")
beam.MobileLocation = ExtAPI.DataModel.GetObjectsByName("beam_connection_top")[
0]
beam.ReferenceLocation = ExtAPI.DataModel.GetObjectsByName(
"beam_connection_bot")[0]
# Generate Mesh
Mesh = Model.Mesh
method = Mesh.AddAutomaticMethod()
method.Location = ExtAPI.DataModel.GetObjectsByName("face_mesh_body")[0]
Mesh.GenerateMesh()
# Add Analysis Systems
all_disp_bc = ["d1_bc", "d2_bc", "d3_bc"]
modal = Model.AddModalAnalysis()
project_directory = modal.WorkingDir
harmonic = Model.AddHarmonicResponseAnalysis()
static = Model.AddStaticStructuralAnalysis()
harmonic.InitialConditions[0].ModalICEnvironment = modal
harmonic.AnalysisSettings.RangeMinimum = Quantity(0.5, "kHz")
harmonic.AnalysisSettings.RangeMaximum = Quantity(2.5, "kHz")
for disp_bc in all_disp_bc:
disp_modal = modal.AddDisplacement()
disp_modal.Location = ExtAPI.DataModel.GetObjectsByName(disp_bc)[0]
disp_modal.XComponent.Output.DiscreteValues = [Quantity(0, "mm")]
disp_modal.YComponent.Output.DiscreteValues = [Quantity(0, "mm")]
disp_modal.ZComponent.Output.DiscreteValues = [Quantity(0, "mm")]
disp_static = static.AddDisplacement()
disp_static.Location = ExtAPI.DataModel.GetObjectsByName(disp_bc)[0]
disp_static.XComponent.Output.DiscreteValues = [Quantity(0, "mm")]
disp_static.YComponent.Output.DiscreteValues = [Quantity(0, "mm")]
disp_static.ZComponent.Output.DiscreteValues = [Quantity(0, "mm")]
for analysis in [harmonic, static]:
force = analysis.AddForce()
force.Location = ExtAPI.DataModel.GetObjectsByName("force_bc")[0]
force.DefineBy = LoadDefineBy.Components
force.XComponent.Output.DiscreteValues = [Quantity(100, "N")]
force.YComponent.Output.DiscreteValues = [Quantity(200, "N")]
force.ZComponent.Output.DiscreteValues = [Quantity(300, "N")]
# Response Spectrum
freqs = [Quantity(5.0e-004, "kHz"),
Quantity(1.0e-003, "kHz"),
Quantity(1.1e-003, "kHz"),
Quantity(1.2e-003, "kHz"),
Quantity(2.0e-003, "kHz"),
Quantity(8.0e-003, "kHz"),
Quantity(1.0e-002, "kHz"),
Quantity(1.2e-002, "kHz"),
Quantity(1.4e-002, "kHz"),
Quantity(1.6e-002, "kHz"),
Quantity(1.8e-002, "kHz"),
Quantity(2.0e-002, "kHz"),
Quantity(2.2e-002, "kHz"),
Quantity(2.4e-002, "kHz"),
Quantity(2.6e-002, "kHz"),
Quantity(2.8e-002, "kHz"),
Quantity(3.0e-002, "kHz"),
Quantity(3.2e-002, "kHz"),
Quantity(3.3e-002, "kHz"),
Quantity(6.0e-002, "kHz")]
acc = [Quantity(7.2639e-003, "mm msec^-1 msec^-1"),
Quantity(1.4528e-002, "mm msec^-1 msec^-1"),
Quantity(1.5874e-002, "mm msec^-1 msec^-1"),
Quantity(1.5874e-002, "mm msec^-1 msec^-1"),
Quantity(1.5874e-002, "mm msec^-1 msec^-1"),
Quantity(1.5874e-002, "mm msec^-1 msec^-1"),
Quantity(1.2978e-002, "mm msec^-1 msec^-1"),
Quantity(1.1048e-002, "mm msec^-1 msec^-1"),
Quantity(9.6686e-003, "mm msec^-1 msec^-1"),
Quantity(8.6344e-003, "mm msec^-1 msec^-1"),
Quantity(7.8300e-003, "mm msec^-1 msec^-1"),
Quantity(7.1865e-003, "mm msec^-1 msec^-1"),
Quantity(6.6600e-003, "mm msec^-1 msec^-1"),
Quantity(6.2213e-003, "mm msec^-1 msec^-1"),
Quantity(5.8500e-003, "mm msec^-1 msec^-1"),
Quantity(5.5318e-003, "mm msec^-1 msec^-1"),
Quantity(5.2560e-003, "mm msec^-1 msec^-1"),
Quantity(5.0147e-003, "mm msec^-1 msec^-1"),
Quantity(4.9050e-003, "mm msec^-1 msec^-1"),
Quantity(4.9050e-003, "mm msec^-1 msec^-1")]
rs = Model.AddResponseSpectrumAnalysis()
rs_an = rs.AnalysisSettings
rs_an.CalculateVelocity = True
rs.InitialConditions[0].ModalICEnvironment = Model.Analyses[0]
# X RS-Acceleration
rs_x = rs.AddRSAcceleration()
rs_x.BoundaryCondition = RSBoundaryConditionSelectionType.AllSupports
rs_x.Direction = NormalOrientationType.XAxis
rs_x.LoadData.Inputs[0].DiscreteValues = freqs
rs_x.LoadData.Output.DiscreteValues = acc
# Y RS-Acceleration
rs_y = rs.AddRSAcceleration()
rs_y.BoundaryCondition = RSBoundaryConditionSelectionType.AllSupports
rs_y.Direction = NormalOrientationType.YAxis
rs_y.LoadData.Inputs[0].DiscreteValues = freqs
rs_y.LoadData.Output.DiscreteValues = acc
# Z RS-Acceleration
rs_z = rs.AddRSAcceleration()
rs_z.BoundaryCondition = RSBoundaryConditionSelectionType.AllSupports
rs_z.Direction = NormalOrientationType.ZAxis
rs_z.LoadData.Inputs[0].DiscreteValues = freqs
rs_z.LoadData.Output.DiscreteValues = acc
modal.Solve()
harmonic.Solve()
static.Solve()
rs.Solve()
project_path = os.path.join(project_directory, "example_pymech_remote.mechdb")
print(project_path)
app.save_as(project_path, overwrite=True)
app.exit()
📝 Description of the example
How to setup a Mode Superposition Modal, Harmonic and Response Spectrum analysis?
📁 Files needed for running the example
💻 Which operating system are you using?
Windows
📀 Which ANSYS version are you using?
No response
🐍 Which Python version are you using?
3.12
📦 Installed packages