ansys / pymechanical

Pythonic interface to Ansys Mechanical ™
https://mechanical.docs.pyansys.com/
MIT License
38 stars 19 forks source link

Problem in material properties assignment and setting analysis settings such as end time in explicit dynamics simulation #499

Closed Vamsi-IITI closed 12 months ago

Vamsi-IITI commented 12 months ago

🔍 Before submitting the issue

🐞 Description of the bug

I am having trouble with material assignment , and its material model. I want to perform a explicit dynamics simulation using pymechanical. I want to set plate material as aluminium and i want to use material models for plasticity and failure modelling ( Johnson Cook Plasticity and Failure models ) . Please guide me in achieving that. Also the script generated ANsys mechanical is nice but it misses setting analysis settings such as End Time in Explicit dynamics simulation. How to set that ?

Thank you

📝 Steps to reproduce

Jupyter notebook code :-

Fixed constants

structure_length = 0.1 structure_breadth = 0.1 node_length = 0.004

from ansys.mapdl.core import launch_mapdl

start mapdl

mapdl = launch_mapdl() print(mapdl)

enter the preprocessor

mapdl.prep7()

mapdl.units('MKS') # MKS unit system

Create geometry

mapdl.block(0, structure_length, 0, structure_breadth, 0, node_length)

plate = mapdl.cm("PLATE", "VOLU")

mapdl.clocal( 11, 0, structure_length/2, structure_breadth/2, 0) ## Making local coordinate system mapdl.wpcsys('', 11,) ## Shift working plane

initial_distance = node_length + 0.02 ## 20 mm from center of front facesheet of sandwich panel

Bullet

mapdl.cylind(0.005805,0, initial_distance + 0.00825 , initial_distance + 0.04089 ) bullet = mapdl.cm("BULLET","VOLU")

mapdl.csdele(11) ## Delete local coordinate system

Saves the geometry in IGES format

mapdl.cdwrite("ALL",fname="C:/Users/HPRVa/Ballistic_shield_design_optimization/src/ geom",ext='igs')

import json import os import grpc

from ansys.mechanical.core import launch_mechanical

mechanical = launch_mechanical(batch=True, cleanup_on_exit=False) print(mechanical)

output = mechanical.run_python_script( r""" import json

region Context Menu Action

geometry_import_group_11 = Model.GeometryImportGroup geometry_import_13 = geometry_import_group_11.AddGeometryImport()

geometry_import_13_format = Ansys.Mechanical.DataModel.Enums.GeometryImportPreference.\ Format.Automatic geometry_import_13_preferences = Ansys.ACT.Mechanical.Utilities.GeometryImportPreferences() geometry_import_13_preferences.ProcessNamedSelections = True geometry_import_13_preferences.ProcessCoordinateSystems = True

geometry_import_13 = DataModel.GetObjectById(13)

geometry_import_13.Import(r"C:\Users\HPRVa\Ballistic_shield_design_optimization\src\ geom.iges") # Primary Source!

endregion

region Context Menu Action

ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardMKS

endregion

region Details View Action

body_25 = DataModel.GetObjectById(25) body_25.StiffnessBehavior = StiffnessBehavior.Rigid

endregion

region Toolbar Action

model_11 = Model analysis_29 = model_11.AddExplicitDynamicsAnalysis()

endregion

region Context Menu Action

initial_conditions_34 = DataModel.GetObjectById(34) initial_condition_37 = initial_conditions_34.InsertVelocity()

selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) selection.Ids = [55] initial_condition_37.Location = selection

endregion

region Details View Action

initial_condition_37.DefineBy = LoadDefineBy.Components

endregion

region Details View Action

initial_condition_37.ZComponent = Quantity(-400, "m/s")

endregion

solution_30 = analysis_29.Solution

region Context Menu Action

total_deformation_41 = solution_30.AddTotalDeformation()

selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) selection.Ids = [32] total_deformation_41.Location = selection

endregion

region Context Menu Action

velocity_probe_43 = solution_30.AddVelocityProbe()

endregion

region Details View Action

selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) selection.Ids = [55] velocity_probe_43.GeometryLocation = selection

endregion

region Details View Action

velocity_probe_43.ResultSelection = ProbeDisplayFilter.ZAxis

endregion

region Context Menu Action

energy_probe_45 = solution_30.AddEnergyProbe()

endregion

region Details View Action

selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) selection.Ids = [55] energy_probe_45.GeometryLocation = selection

endregion

region Details View Action

mesh_15 = Model.Mesh mesh_15.PhysicsPreference = MeshPhysicsPreferenceType.NonlinearMechanical

endregion

region Details View Action

mesh_15.PhysicsPreference = MeshPhysicsPreferenceType.Explicit

endregion

region Details View Action

mesh_15.ElementSize = Quantity(0.001, "m")

endregion

region Context Menu Action

mesh_15.GenerateMesh()

endregion

Solve and get the results.

Solve Explicit Dynamics Analysis

analysis_29.Solution.Solve(True)

""" )

Also you can run pymechanical script portion in ansys mechanical GUI, once geom.iges is generated e1.zip

💻 Which operating system are you using?

Windows

📀 Which ANSYS version are you using?

Ansys 2023 R1

🐍 Which Python version are you using?

3.11

📦 Installed packages

aiofiles==22.1.0
aiohttp==3.8.4
aiosignal==1.3.1
aiosqlite==0.19.0
ansys-api-dyna==0.3.2
ansys-api-fluent==0.3.12
ansys-api-mapdl==0.5.1
ansys-api-mechanical==0.1.0
ansys-api-meshing-prime==0.1.1
ansys-api-platform-instancemanagement==1.0.0b3
ansys-api-pyensight==0.3.0
ansys-api-sherlock==0.1.14
ansys-api-systemcoupling==0.1.0
ansys-dpf-composites==0.2.0
ansys-dpf-core==0.8.1
ansys-dpf-gate==0.3.1
ansys-dpf-gatebin==0.4.1
ansys-dpf-post==0.4.0
ansys-dyna-core==0.4.2
ansys-dynamicreporting-core==0.4.0
ansys-fluent-core==0.14.0
ansys-grantami-bomanalytics==1.1.3
ansys-grantami-bomanalytics-openapi==1.0.0
ansys-grantami-recordlists==1.0.0
ansys-grantami-serverapi-openapi==1.0.0
ansys-grpc-dpf==0.8.1
ansys-mapdl-core==0.64.0
ansys-mapdl-reader==0.52.13
ansys-math-core==0.1.1
ansys-mechanical-core==0.8.0
ansys-meshing-prime==0.4.0
ansys-motorcad-core==0.1.3
ansys-openapi-common==1.2.1
ansys-optislang-core==0.2.1
ansys-platform-instancemanagement==1.1.1
ansys-pyensight-core==0.5.3
ansys-pythonnet==3.1.0rc1
ansys-seascape==0.2.0
ansys-sherlock-core==0.2.0
ansys-systemcoupling-core==0.1.3
anyio==3.6.2
appdirs==1.4.4
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
arrow==1.2.3
asgiref==3.7.2
asttokens==2.2.1
async-timeout==4.0.2
attrs==23.1.0
Babel==2.12.1
backcall==0.2.0
beautifulsoup4==4.12.2
bleach==6.0.0
build==1.0.3
cachetools==5.3.1
certifi==2023.5.7
cffi==1.15.1
charset-normalizer==3.1.0
click==8.1.3
clr-loader==0.2.6
colorama==0.4.6
comm==0.1.3
contourpy==1.0.7
cryptography==41.0.3
cycler==0.11.0
debugpy==1.6.7
decorator==5.1.1
defusedxml==0.7.1
Django==4.2.5
docutils==0.20.1
executing==1.2.0
fastjsonschema==2.16.3
filelock==3.12.3
fonttools==4.39.4
fqdn==1.5.1
frozenlist==1.3.3
geomdl==5.3.1
google-api-core==2.11.1
google-api-python-client==2.98.0
google-auth==2.22.0
google-auth-httplib2==0.1.0
googleapis-common-protos==1.59.0
grpcio==1.54.0
grpcio-status==1.48.2
h5py==3.9.0
httplib2==0.22.0
idna==3.4
imageio==2.28.1
importlib-metadata==6.6.0
importlib-resources==5.12.0
ipycanvas==0.13.1
ipyevents==2.0.1
ipykernel==6.23.0
ipython==8.13.2
ipython-genutils==0.2.0
ipyvtklink==0.2.3
ipywidgets==7.7.5
isoduration==20.11.0
jaraco.classes==3.3.0
jedi==0.18.2
Jinja2==3.1.2
json5==0.9.11
jsonpointer==2.3
jsonschema==4.17.3
jupyter-events==0.6.3
jupyter-ydoc==0.2.4
jupyter_client==8.2.0
jupyter_core==5.3.0
jupyter_server==2.5.0
jupyter_server_fileid==0.9.0
jupyter_server_terminals==0.4.4
jupyter_server_ydoc==0.8.0
jupyterlab==3.6.3
jupyterlab-pygments==0.2.2
jupyterlab-widgets==1.1.4
jupyterlab_server==2.22.1
keyring==24.2.0
kiwisolver==1.4.4
lxml==4.9.3
markdown-it-py==3.0.0
MarkupSafe==2.1.2
matplotlib==3.6.2
matplotlib-inline==0.1.6
mdurl==0.1.2
mistune==2.0.5
more-itertools==10.1.0
multidict==6.0.4
nbclassic==1.0.0
nbclient==0.7.4
nbconvert==7.4.0
nbformat==5.8.0
nest-asyncio==1.5.6
notebook==6.5.4
notebook_shim==0.2.3
numpy==1.24.3
packaging==23.1
pandas==2.1.0
pandocfilters==1.5.0
parso==0.8.3
pickleshare==0.7.5
Pillow==9.5.0
pkginfo==1.9.6
platformdirs==3.5.0
plumbum==1.8.2
pooch==1.7.0
prometheus-client==0.16.0
prompt-toolkit==3.0.38
protobuf==3.20.3
protoc-gen-swagger==0.1.0
psutil==5.9.5
pure-eval==0.2.2
pyaedt==0.6.76
pyansys==2023.2.9
pyansys-docker==5.0.4
pyansys-tools-versioning==0.3.3
pyasn1==0.5.0
pyasn1-modules==0.3.0
pycparser==2.21
Pygments==2.15.1
pyiges==0.2.1
pyparsing==3.0.9
pypiwin32==223
pypng==0.20220715.0
pyproject_hooks==1.0.0
pyrsistent==0.19.3
pyspnego==0.9.2
python-dateutil==2.8.2
python-json-logger==2.0.7
pythonnet==3.0.1
pytwin==0.3.0
pytz==2023.3.post1
pyvista==0.37.0
pywin32==306
pywin32-ctypes==0.2.2
pywinpty==2.0.10
PyYAML==6.0
pyzmq==25.0.2
readme-renderer==41.0
requests==2.30.0
requests-negotiate-sspi==0.5.2
requests-ntlm==1.2.0
requests-toolbelt==1.0.0
rfc3339-validator==0.1.4
rfc3986==2.0.0
rfc3986-validator==0.1.1
rich==13.5.2
rpyc==5.3.1
rsa==4.9
scipy==1.10.1
scooby==0.7.2
Send2Trash==1.8.2
six==1.16.0
sniffio==1.3.0
soupsieve==2.4.1
sqlparse==0.4.4
stack-data==0.6.2
terminado==0.17.1
tinycss2==1.2.1
tomli==2.0.1
tornado==6.3.1
tqdm==4.65.0
traitlets==5.9.0
trame==2.4.0
trame-client==2.7.5
trame-components==2.1.0
trame-deckgl==2.0.1
trame-markdown==2.0.2
trame-matplotlib==2.0.1
trame-plotly==2.1.0
trame-rca==0.3.1
trame-router==2.0.1
trame-server==2.11.0
trame-simput==2.3.1
trame-vega==2.0.2
trame-vtk==2.4.4
trame-vuetify==2.2.4
twine==4.0.2
typing==3.7.4.3
typing_extensions==4.5.0
tzdata==2023.3
uri-template==1.2.0
uritemplate==4.1.1
urllib3==1.26.18
vtk==9.2.6
wcwidth==0.2.6
webcolors==1.13
webencodings==0.5.1
websocket-client==1.5.1
widgetsnbextension==3.6.4
wslink==1.10.1
y-py==0.5.9
yarl==1.9.2
ypy-websocket==0.8.2
zipp==3.15.0
Vamsi-IITI commented 12 months ago

Also please guide me how to on erosion controls on material failure using Pymechanical. Since analysis settings aren't being recorded by Ansys Mechanical

koubaa commented 12 months ago

@Vamsi-IITI

Try this:

analysis_29.ErosionOnMaterialFailureType=True
analysis_29.SetStepEndTime(1,Quantity(1, "s"))

There are some parts of the mechanical UI for which recording does not yet work. I think you ran into one of them!

Material modeling is missing from pymechanical at the moment. A workaround right now is you can define the material model in the Ansys Workbench UI and export the material library as a file, and then import that file into pymechanical.

Vamsi-IITI commented 12 months ago

Hi @koubaa , The above code didn't work. Screenshot 2023-11-21 084623

pmaroneh commented 12 months ago

Hi @Vamsi-IITI , these settings are available at the Analysis Settings level, and not at the analysis level. Try this:

analysis = ExtAPI.DataModel.Project.Model.Analyses[0] # adapt this to reference your analysis
settings = analysis.AnalysisSettings
settings.ErosionOnMaterialFailureType = True
settings.SetStepEndTime(1,Quantity(1,"s"))
Vamsi-IITI commented 12 months ago

Hi @pmaroneh, Thank you very much. This worked very well.

Vamsi-IITI commented 12 months ago

I just have one issue now. That's with specifying material and material model. Recording gives code like this `with Transaction(True): body_25 = DataModel.GetObjectById(25) body_25.Material = "ce7f3c8f-cb53-4f3e-9517-ac8ade5cd762"

endregion`

But that doesn't work

pmaroneh commented 12 months ago

@Vamsi-IITI , from the body level, you should be able to use the material's name directly: body.Material = 'Structural Steel' These questions would better belong in the Ansys Developer Forum. There are many posts there that would help you. If you are new to scripting in Mechanical, and if you have access to the Ansys Learning Hub, I would recommend you to follow the Mechanical Scripting course.

Vamsi-IITI commented 12 months ago

I face error like this : image

Even from GUI , I didn't understand how to export material model ( like Johnson Cook plasticity and failure models ) . Please guide me how to achieve this .

dipinknair commented 12 months ago

@Vamsi-IITI, as @pmaroneh mentioned these questions would better belong in the Ansys Developer Forum. If you are still facing any issues related to pymechanical specifically, please add comments or else we can close this issue.