-
-
November 21, 2024 at 8:13 amtigers1227Subscriber
Despite identical geometry, material, contact, analysis settings, and boundary conditions, the deformation, stress, and strain results differ between the static structural modeling created through ANSYS Workbench and that created using Python code. Upon further inspection, there are discrepancies in certain settings, as shown in the attached images. I would like to understand the reasons for these differences and potential solutions. Additionally, in the modal analysis, the rubber material exhibits abnormal behavior, passing through the outer structure and expanding unusually. Thank you for your assistance.
#--- PyMechanical 라이브러리 가져오기 및 Mechanical 실행 (Batch Mode) --#from ansys.mechanical.core import launch_mechanicalmechanical = launch_mechanical(batch=False, cleanup_on_exit=False)#-------------------------------------------------------------------------##--- 형상 파일이 위치한 경로 정의 -------------------------------------------#geom = "C:/Users/hyu3/Desktop/SDD_macro/lower_arm_stp_files/final_assemble_lower_Arm_and_bush3.stp" # 사용 환경에 맞게 수정하기 !mechanical.run_python_script(f"geom_path='{geom}'")#-------------------------------------------------------------------------##--- Mechanical에 형상 가져오기 -------------------------------------------#mechanical.run_python_script('''geom_import_gr = Model.GeometryImportGroupgeom_import = geom_import_gr.AddGeometryImport()geom_import_fm = Ansys.Mechanical.DataModel.Enums.GeometryImportPreference.Format.Automaticgeom_import_pr = Ansys.ACT.Mechanical.Utilities.GeometryImportPreferences()geom_import_pr.ProcessNamedSelections = Truegeom_import_pr.ProcessCoordinateSystems = Truegeom_import.Import(geom_path, geom_import_fm, geom_import_pr)''')#-------------------------------------------------------------------------##--- 재료 파일이 위치한 경로 정의 -------------------------------------------#material_path1 = "C:/Users/hyu3/Desktop/SDD_macro/ansys_macro_code/material_files/stainless_material.xml" # 사용 환경에 맞게 수정하기mechanical.run_python_script(f"material_path1='{material_path1}'")material_path2 = "C:/Users/hyu3/Desktop/modal_test/calculated_ogden_prony_density_ansys.xml" # 사용 환경에 맞게 수정하기 #calculated_ogden_prony_ansys는 ogden 3parameter 와 prony 사용한거임.mechanical.run_python_script(f"material_path2='{material_path2}'")#-------------------------------------------------------------------------##--- 저장된 재료 불러오기 ----여기서 material1 은 stainless, material2는 hyper elastic 재료----------------------------------------#mechanical.run_python_script('''materials = Model.Materialsimported_materials1 = materials.Import(material_path1)''')mechanical.run_python_script('''materials = Model.Materialsimported_materials2 = materials.Import(material_path2)''')#-------------------------------------------------------------------------##--- 재료 차례로 lowerarm, inner, rubber, outer 적용-------------------------------------------------#mechanical.run_python_script('''# lowerarm Body ID: 21with Transaction():body = DataModel.GetObjectById(21)body.Material = imported_materials1[0].Name# inner1 Body ID: 25with Transaction():body = DataModel.GetObjectById(25)body.Material = imported_materials1[0].Name# rubber1 Body ID: 28with Transaction():body = DataModel.GetObjectById(28)body.Material = imported_materials2[0].Name# outer1 Body ID: 31with Transaction():body = DataModel.GetObjectById(31)body.Material = imported_materials1[0].Name# inner2 Body ID: 34with Transaction():body = DataModel.GetObjectById(34)body.Material = imported_materials1[0].Name# rubber2 Body ID: 37with Transaction():body = DataModel.GetObjectById(37)body.Material = imported_materials2[0].Name# outer2 Body ID: 40with Transaction():body = DataModel.GetObjectById(40)body.Material = imported_materials1[0].Name# inner3 Body ID: 43with Transaction():body = DataModel.GetObjectById(43)body.Material = imported_materials1[0].Name# rubber3 Body ID: 46with Transaction():body = DataModel.GetObjectById(46)body.Material = imported_materials2[0].Name# outer3 Body ID: 49with Transaction():body = DataModel.GetObjectById(49)body.Material = imported_materials1[0].Name''')#-----------------------------------------------------------------------------------##--- nonlinear, thermal 효과 적용 ---------------------#mechanical.run_python_script('''with Transaction():body_21 = DataModel.GetObjectById(21)body_21.NonlinearEffects = Falsebody_21.ThermalStrainEffects = Falsewith Transaction():body_25 = DataModel.GetObjectById(25)body_25.NonlinearEffects = Falsebody_25.ThermalStrainEffects = False# rubber1 Body ID: 28with Transaction():body_28 = DataModel.GetObjectById(28)body_28.NonlinearEffects = Truebody_28.ThermalStrainEffects = False# outer1 Body ID: 31with Transaction():body_31 = DataModel.GetObjectById(31)body_31.NonlinearEffects = Falsebody_31.ThermalStrainEffects = False# inner2 Body ID: 34with Transaction():body_34 = DataModel.GetObjectById(34)body_34.NonlinearEffects = Falsebody_34.ThermalStrainEffects = False# rubber2 Body ID: 37with Transaction():body_37 = DataModel.GetObjectById(37)body_37.NonlinearEffects = Truebody_37.ThermalStrainEffects = False# outer2 Body ID: 40with Transaction():body_40 = DataModel.GetObjectById(40)body_40.NonlinearEffects = Falsebody_40.ThermalStrainEffects = False# inner3 Body ID: 43with Transaction():body_43 = DataModel.GetObjectById(43)body_43.NonlinearEffects = Falsebody_43.ThermalStrainEffects = False# rubber3 Body ID: 46with Transaction():body_46 = DataModel.GetObjectById(46)body_46.NonlinearEffects = Truebody_46.ThermalStrainEffects = False# outer3 Body ID: 49with Transaction():body_49 = DataModel.GetObjectById(49)body_49.NonlinearEffects = Falsebody_49.ThermalStrainEffects = False''')#------------------------------------------##--- Contact 정의 ----------------------------------------------------------------------------#mechanical.run_python_script('''#region Contact Region 53contact_region_53 = DataModel.GetObjectById(53)selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [239, 240]contact_region_53.SourceLocation = selectionselection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [156, 155]contact_region_53.TargetLocation = selectioncontact_region_53.ContactType = ContactType.Bonded#endregion#region Contact Region 56contact_region_56 = DataModel.GetObjectById(56)selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [320, 321]contact_region_56.SourceLocation = selectionselection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [154, 153]contact_region_56.TargetLocation = selectioncontact_region_56.ContactType = ContactType.Bonded#endregion#region Contact Region 59contact_region_59 = DataModel.GetObjectById(59)selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [401, 402]contact_region_59.SourceLocation = selectionselection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [131, 132]contact_region_59.TargetLocation = selectioncontact_region_59.ContactType = ContactType.Bondedcontact_region_59.PinballRegion = ContactPinballType.Radiuscontact_region_59.PinballRadius = Quantity(0.5, "mm")#endregion#region Contact Region 62contact_region_62 = DataModel.GetObjectById(62)selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [214, 215]contact_region_62.SourceLocation = selectionselection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [185, 186]contact_region_62.TargetLocation = selectioncontact_region_62.ContactType = ContactType.Bonded#endregion#region Contact Region 65contact_region_65 = DataModel.GetObjectById(65)selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [212, 213]contact_region_65.SourceLocation = selectionselection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [241, 242]contact_region_65.TargetLocation = selectioncontact_region_65.ContactType = ContactType.Bonded#endregion#region Contact Region 68contact_region_68 = DataModel.GetObjectById(68)selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [295, 296]contact_region_68.SourceLocation = selectionselection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [266, 267]contact_region_68.TargetLocation = selectioncontact_region_68.ContactType = ContactType.Bonded#endregion#region Contact Region 71contact_region_71 = DataModel.GetObjectById(71)selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [293, 294]contact_region_71.SourceLocation = selectionselection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [154, 153]contact_region_71.TargetLocation = selectioncontact_region_71.ContactType = ContactType.Bondedcontact_region_71.PinballRegion = ContactPinballType.Radiuscontact_region_71.PinballRadius = Quantity(0.5, "mm")#endregion#region Contact Region 74contact_region_74 = DataModel.GetObjectById(74)selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [376, 377]contact_region_74.SourceLocation = selectionselection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [347, 348]contact_region_74.TargetLocation = selectioncontact_region_74.ContactType = ContactType.Bondedcontact_region_74.PinballRegion = ContactPinballType.Radiuscontact_region_74.PinballRadius = Quantity(0.5, "mm")#endregion#region Contact Region 77contact_region_77 = DataModel.GetObjectById(77)selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [374, 375]contact_region_77.SourceLocation = selectionselection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [403, 404]contact_region_77.TargetLocation = selectioncontact_region_77.ContactType = ContactType.Bondedcontact_region_77.PinballRegion = ContactPinballType.Radiuscontact_region_77.PinballRadius = Quantity(0.5, "mm")#endregion''')#---------------------------------------------------------------## ---mesh 설정 ----------------------- #mechanical.run_python_script('''mesh_13 = Model.Meshcontact_sizing_84 = mesh_13.AddContactSizing()contact_sizing_84.ContactRegion = contact_region_53#region Context Menu Actioncontact_sizing_85 = mesh_13.AddContactSizing()contact_sizing_85.ContactRegion = contact_region_56#region Context Menu Actioncontact_sizing_86 = mesh_13.AddContactSizing()contact_sizing_86.ContactRegion = contact_region_59contact_sizing_86.ElementSize = Quantity(2.0, "mm")#region Context Menu Actioncontact_sizing_87 = mesh_13.AddContactSizing()contact_sizing_87.ContactRegion = contact_region_62#region Context Menu Actioncontact_sizing_88 = mesh_13.AddContactSizing()contact_sizing_88.ContactRegion = contact_region_65#region Context Menu Actioncontact_sizing_89 = mesh_13.AddContactSizing()contact_sizing_89.ContactRegion = contact_region_68#region Context Menu Actioncontact_sizing_90 = mesh_13.AddContactSizing()contact_sizing_90.ContactRegion = contact_region_71#region Context Menu Actioncontact_sizing_91 = mesh_13.AddContactSizing()contact_sizing_91.ContactRegion = contact_region_74#region Context Menu Actioncontact_sizing_92 = mesh_13.AddContactSizing()contact_sizing_92.ContactRegion = contact_region_77contact_sizing_92.ElementSize = Quantity(1.5, "mm")#endregion#region Context Menu Actionsizing_99 = mesh_13.AddSizing()selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [359, 369, 366, 362]sizing_99.Location = selectionsizing_99.Type = SizingType.NumberOfDivisionssizing_99.NumberOfDivisions = 10#endregion#region Context Menu Actionface_meshing_101 = mesh_13.AddFaceMeshing()selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [378]face_meshing_101.Location = selectionface_meshing_101.InternalNumberOfDivisions = 3#endregion#region Context Menu Actionsizing_103 = mesh_13.AddSizing()selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [280, 287, 283, 282]sizing_103.Location = selectionsizing_103.Type = SizingType.NumberOfDivisionssizing_103.NumberOfDivisions = 10#endregion#region Context Menu Actionface_meshing_105 = mesh_13.AddFaceMeshing()selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [298]face_meshing_105.Location = selectionface_meshing_105.InternalNumberOfDivisions = 3#endregion#region Context Menu Actionsizing_107 = mesh_13.AddSizing()selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [199, 206, 202, 201]sizing_107.Location = selectionsizing_107.Type = SizingType.NumberOfDivisionssizing_107.NumberOfDivisions = 10#endregion#region Context Menu Actionface_meshing_109 = mesh_13.AddFaceMeshing()selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [217]face_meshing_109.Location = selectionface_meshing_109.InternalNumberOfDivisions = 3#endregion#region Context Menu Actionsizing_115 = mesh_13.AddSizing()selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [334, 341, 337, 336]sizing_115.Location = selectionsizing_115.Type = SizingType.NumberOfDivisionssizing_115.NumberOfDivisions = 10#endregion#region Context Menu Actionface_meshing_117 = mesh_13.AddFaceMeshing()selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [352]face_meshing_117.Location = selectionface_meshing_117.InternalNumberOfDivisions = 1#endregion#region Context Menu Actionsizing_119 = mesh_13.AddSizing()selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [255, 256, 260, 253]sizing_119.Location = selectionsizing_119.Type = SizingType.NumberOfDivisionssizing_119.NumberOfDivisions = 10#endregion#region Context Menu Actionface_meshing_121 = mesh_13.AddFaceMeshing()selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [271]face_meshing_121.Location = selectionface_meshing_121.InternalNumberOfDivisions = 1#endregion#region Context Menu Actionsizing_123 = mesh_13.AddSizing()selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [172, 179, 175, 174]sizing_123.Location = selectionsizing_123.Type = SizingType.NumberOfDivisionssizing_123.NumberOfDivisions = 10#endregion#region Context Menu Actionface_meshing_125 = mesh_13.AddFaceMeshing()selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [190]face_meshing_125.Location = selectionface_meshing_125.InternalNumberOfDivisions = 1#endregion#region Context Menu Actionmesh_13.GenerateMesh()#endregion''')#---------------------------------------##--- Static Structural 시스템 생성 ----------------------------------------#mechanical.run_python_script('Model.AddStaticStructuralAnalysis()')#-------------------------------------------------------------------------##--- Analysis Setting에서 Large Deflecion on 명령 ----------------------------------------#mechanical.run_python_script('''analysis = Model.Analyses[0] # 첫 번째 생성된 해석을 참조analysis_settings = analysis.AnalysisSettingsanalysis_settings.LargeDeflection = True''')#-------------------------------------------------------------------------##--- Analysis Setting에서 Auto time Stepping 명령 ----------------------------------------#mechanical.run_python_script('''analysis = Model.Analyses[0] # 첫 번째 생성된 해석을 참조analysis_settings = analysis.AnalysisSettingswith Transaction():analysis_settings.AutomaticTimeStepping = AutomaticTimeStepping.Onanalysis_settings.InitialSubsteps = 10analysis_settings.MinimumSubsteps = 10analysis_settings.MaximumSubsteps = 1000''')#-------------------------------------------------------------------------## --- boundary condition 설정 -------------------------------------------------------------------------#mechanical.run_python_script('''#region Context Menu Actiondisplacement = analysis.AddDisplacement()selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [190, 189]displacement.Location = selectiondisplacement.DefineBy = LoadDefineBy.Components#--- Transaction()을 이용해서 칸에 있는 값을 설정해줄 수 있음. -------------------------------#with Transaction():displacement.ZComponent.Output.DiscreteValues = [Quantity(0, "mm")] # Z Component 값을 0 mm로 설정#endregion#region Context Menu Actiondisplacement = analysis.AddDisplacement()selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [271, 269, 268, 270]displacement.Location = selectiondisplacement.DefineBy = LoadDefineBy.Componentswith Transaction():displacement.ZComponent.Output.DiscreteValues = [Quantity(0, "mm")] # Z Component 값을 0 mm로 설정#endregion#region Context Menu Actiondisplacement = analysis.AddDisplacement()selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [351, 352]displacement.Location = selectiondisplacement.DefineBy = LoadDefineBy.Componentswith Transaction():displacement.XComponent.Output.DiscreteValues = [Quantity(0, "mm")] # X Component 값을 0 mm로 설정#endregion#region Context Menu Actioncompression_only_support = analysis.AddCompressionOnlySupport()selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [188, 187]compression_only_support.Location = selection#endregion#region Context Menu Actioncompression_only_support = analysis.AddCompressionOnlySupport()selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [269, 268]compression_only_support.Location = selection#endregion#region Context Menu Actiondisplacement = analysis.AddDisplacement()selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)selection.Ids = [347, 348]displacement.Location = selectionwith Transaction():displacement.XComponent.Output.DiscreteValues = [Quantity(1, "mm")] # X Component 값을 1 mm로 설정displacement.YComponent.Output.DiscreteValues = [Quantity(2, "mm")] # Y Component 값을 1 mm로 설정displacement.ZComponent.Output.DiscreteValues = [Quantity(0, "mm")] # Z Component 값을 0 mm로 설정#endregion''')#--------------------------------------------------------------------##---해석결과에 Total Deformation, Equivalent Stress, Equivalent Elastic Strain 추가 ---------------------------------------#mechanical.run_python_script('''Model.Analyses[0].Solution.AddTotalDeformation()Model.Analyses[0].Solution.AddEquivalentStress()Model.Analyses[0].Solution.AddEquivalentElasticStrain()''')#-------------------------------------------------------------------------##--- Solve ! Static_structure 해석 실행-----------------------------------------------------------#mechanical.run_python_script('Model.Solve()')#------------------------------------------------------------------------------------------------##--- Modal 시스템 생성 ----------------------------------------#mechanical.run_python_script('Model.AddModalAnalysis()')#-------------------------------------------------------------------------##--- Modal 시스템의 Pre-Stress 을 Static Structure 로 설정----------------------------------------## PyMechanical을 통한 Pre-Stress 설정 변경mechanical.run_python_script('''model = ExtAPI.DataModel.Project.Modelst=model.Analyses[0]mo=model.Analyses[1]prst=mo.InitialConditions[0]prst.PreStressICEnvironment=st # Set st to None if no prestress is needed''')#-------------------------------------------------------------------------##--- Modal 시스템의 Analysis Setting 설정 최대 찾는 mode 5개----------------------------------------#mechanical.run_python_script('''# Analysis Settings 객체에 접근 (정확한 ID 확인 필요)modal_analysis = Model.Analyses[1] # 두 번째 해석 시스템이 Modal 해석인 경우analysis_settings = modal_analysis.AnalysisSettings# Maximum Modes to Find 값을 5으로 설정with Transaction():analysis_settings.MaximumModesToFind = 5''')#-------------------------------------------------------------------------##--- Modal 시스템의 해석 결과 추가----------------------------------------#mechanical.run_python_script('''# Modal 해석 시스템에 접근 (두 번째 해석 시스템이 Modal 해석인 경우)modal_analysis = Model.Analyses[1]solution = modal_analysis.Solution# 해석 결과 추가with Transaction():solution.AddTotalDeformation()''')#-------------------------------------------------------------------------##--- Modal 해석 실행 -------------------------------------------------------------#mechanical.run_python_script('Model.Analyses[1].Solution.Solve()')#-------------------------------------------------------------------------## --- modal 결과전체 plot ------------------------------------------------------#mechanical.run_python_script('''#region Context Menu Action# 해석 객체에서 Solution 찾기analysis = ExtAPI.DataModel.Project.Model.Analyses[1] # 첫 번째 해석 참조solution = next(child for child in analysis.Children if child.Name == "Solution") # 이름으로 Solution 찾기# 결과를 모든 세트에서 생성solution.CreateResultsAtAllSets(140) # 필요한 경우 140을 변경#endregion#region Miscellaneous commands# 모든 결과를 평가solution.EvaluateAllResults()#endregion''') -
November 21, 2024 at 8:16 am
-
Viewing 1 reply thread
- You must be logged in to reply to this topic.
Ansys Innovation Space
Trending discussions
- Problem with access to session files
- Ayuda con Error: “Unable to access the source: EngineeringData”
- At least one body has been found to have only 1 element in at least 2 directions
- Error when opening saved Workbench project
- Geometric stiffness matrix for solid elements
- How to apply Compression-only Support?
- How to select the interface delamination surface of a laminate?
- Timestep range set for animation export
- Image to file in Mechanical is bugged and does not show text
- SMART crack under fatigue conditions, different crack sizes can’t growth
Top Contributors
-
1236
-
543
-
523
-
225
-
209
Top Rated Tags
© 2024 Copyright ANSYS, Inc. All rights reserved.
Ansys does not support the usage of unauthorized Ansys software. Please visit www.ansys.com to obtain an official distribution.