Closed Vamsi-IITI closed 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
@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.
Hi @koubaa , The above code didn't work.
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"))
Hi @pmaroneh, Thank you very much. This worked very well.
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"
But that doesn't work
@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.
I face error like this :
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 .
@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.
🔍 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