Skip to content

How to setup a Mode Superposition Modal, Harmonic and Response Spectrum analysis? #249

Open
@ayush-kumar-423

Description

@ayush-kumar-423

📝 Description of the example

How to setup a Mode Superposition Modal, Harmonic and Response Spectrum analysis?

📁 Files needed for running the example

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()

💻 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

aiohappyeyeballs==2.5.0
aiohttp==3.11.13
aiosignal==1.3.2
ansys-api-mechanical==0.1.2
ansys-dpf-core==0.13.6
ansys-mechanical-core==0.11.14
ansys-mechanical-env==0.1.9
ansys-mechanical-stubs==0.1.6
ansys-pythonnet==3.1.0rc6
ansys-tools-path==0.7.1
anyio==4.8.0
appdirs==1.4.4
argon2-cffi==23.1.0
argon2-cffi-bindings==21.2.0
arrow==1.3.0
asttokens==3.0.0
async-lru==2.0.4
attrs==25.1.0
babel==2.17.0
beautifulsoup4==4.13.3
bleach==6.2.0
certifi==2025.1.31
cffi==1.17.1
charset-normalizer==3.4.1
click==8.1.8
clr_loader==0.2.7.post0
cmocean==4.0.3
colorama==0.4.6
colorcet==3.1.0
comm==0.2.2
contourpy==1.3.1
cycler==0.12.1
debugpy==1.8.13
decorator==5.2.1
defusedxml==0.7.1
executing==2.2.0
fastjsonschema==2.21.1
fonttools==4.56.0
fqdn==1.5.1
frozenlist==1.5.0
grpcio==1.71.0
h11==0.14.0
httpcore==1.0.7
httpx==0.28.1
idna==3.10
imageio==2.37.0
importlib_metadata==8.6.1
ipykernel==6.29.5
ipython==9.0.2
ipython_pygments_lexers==1.1.1
ipywidgets==8.1.5
isoduration==20.11.0
jedi==0.19.2
Jinja2==3.1.6
joblib==1.4.2
json5==0.10.0
jsonpointer==3.0.0
jsonschema==4.23.0
jsonschema-specifications==2024.10.1
jupyter-events==0.12.0
jupyter-lsp==2.2.5
jupyter_client==8.6.3
jupyter_core==5.7.2
jupyter_server==2.15.0
jupyter_server_proxy==4.4.0
jupyter_server_terminals==0.5.3
jupyterlab==4.3.5
jupyterlab_pygments==0.3.0
jupyterlab_server==2.27.3
jupyterlab_widgets==3.0.13
kiwisolver==1.4.8
markdown-it-py==3.0.0
MarkupSafe==3.0.2
matplotlib==3.10.1
matplotlib-inline==0.1.7
mdurl==0.1.2
meshio==5.3.5
mistune==3.1.2
more-itertools==10.6.0
msgpack==1.1.0
multidict==6.1.0
nbclient==0.10.2
nbconvert==7.16.6
nbformat==5.10.4
nest-asyncio==1.6.0
notebook_shim==0.2.4
numpy==2.2.3
overrides==7.7.0
packaging==24.2
pandas==2.2.3
pandocfilters==1.5.1
parso==0.8.4
pillow==11.1.0
platformdirs==4.3.6
pooch==1.8.2
prometheus_client==0.21.1
prompt_toolkit==3.0.50
propcache==0.3.0
protobuf==5.29.3
psutil==7.0.0
pure_eval==0.2.3
pycparser==2.22
Pygments==2.19.1
pyparsing==3.2.1
python-dateutil==2.9.0.post0
python-json-logger==3.3.0
pytz==2025.1
pyvista==0.44.2
pywin32==309
pywinpty==2.0.15
PyYAML==6.0.2
pyzmq==26.2.1
referencing==0.36.2
requests==2.32.3
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
rich==13.9.4
rpds-py==0.23.1
scikit-learn==1.6.1
scipy==1.15.2
scooby==0.10.0
Send2Trash==1.8.3
setuptools==76.0.0
simpervisor==1.0.0
six==1.17.0
sniffio==1.3.1
soupsieve==2.6
stack-data==0.6.3
terminado==0.18.1
threadpoolctl==3.5.0
tinycss2==1.4.0
tornado==6.4.2
tqdm==4.67.1
traitlets==5.14.3
trame==3.8.1
trame-client==3.6.0
trame-server==3.4.0
trame-vtk==2.8.15
trame-vuetify==2.8.1
types-python-dateutil==2.9.0.20241206
typing_extensions==4.12.2
tzdata==2025.1
uri-template==1.3.0
urllib3==2.3.0
vtk==9.3.1
wcwidth==0.2.13
webcolors==24.11.1
webencodings==0.5.1
websocket-client==1.8.0
widgetsnbextension==4.0.13
wslink==2.3.2
yarl==1.18.3
zipp==3.21.0

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions