How to get stress tensors on edge of a shell in python results, by defining position and layer

Member Posts: 42
10 Comments First Anniversary 5 Likes Name Dropper
**

Welcome!

It looks like you're new here. Sign in or register to get started.

Best Answer

  • Member, Moderator, Employee Posts: 479
    100 Answers 250 Likes 100 Comments Second Anniversary
    ✭✭✭✭
    edited July 2023 Answer ✓

    Hi @Kev,

    You need use the operatordpf.operators.utility.change_shell_layers() for specifying the layers.
     0:Top, 1: Bottom, 2: BottomTop, 3:Mid, 4:BottomTopMid

    You can read more about it in the DPF operator help. Below is an example code which works well. You can create custom properties (drop-down) to select the Shell-Layer and the Coordinate System.

    1. import mech_dpf
    2. import Ans.DataProcessing as dpf
    3. mech_dpf.setExtAPI(ExtAPI)
    4. dataSource = dpf.DataSources(analysis.ResultFileName)
    5. sx = dpf.operators.result.stress_X()
    6. sx.inputs.data_sources.Connect(dataSource)

    7. ns_op = dpf.operators.scoping.on_named_selection()
    8. ns_op.inputs.data_sources.Connect(dataSource)
    9. ns_op.inputs.requested_location.Connect('Nodal')
    10. ns_op.inputs.named_selection_name.Connect('EDGE')

    11. sx.inputs.mesh_scoping.Connect(ns_op.outputs.mesh_scoping)
    12. sx.inputs.bool_rotate_to_global.Connect(False)

    13. sx_top = dpf.operators.utility.change_shell_layers()
    14. sx_top.inputs.fields_container.Connect(sx)
    15. """
    16. Define Shell layer
    17. """
    18. sx_top.inputs.e_shell_layer.Connect(0)

Answers

  • Member Posts: 42
    10 Comments First Anniversary 5 Likes Name Dropper
    **

    I would like to create a python result file that mimics a user plot With the populated fields as shown in the figure below:

    So far this is as far as I have gone with the code below (Showing just a section of the code):

    dataSource = dpf.DataSources(analysis.ResultFileName)
    DisplayDict = {}
    DisplayDict[0] = dpf.locations.nodal
    DisplayDict[1] = dpf.locations.elemental
    DisplayDict[2] = dpf.locations.elemental_nodal

    GrphicsTypeDict = {}
    GrphicsTypeDict[1] = dpf.enums.GFXContourType.GeomFaceScoping
    #endregion

    MeshScoping=MeshScopingFromNS(NS)
    global TimeFreqSupport
    TimeFreqSupport=GetResultsTimeData()

    WriteMessage("Setup results operator")
    ResultOp = dpf.operators.result.stress_X () #dpf.operators.result.stress_von_mises()
    ResultOp.inputs.bool_rotate_to_global.Connect(False)
    ResultOp.inputs.mesh_scoping.Connect(MeshScoping)
    TimeScoping=GetTimeScoping(TimeSelectionType, Step, CalcTimeHistory)
    ResultOp.inputs.time_scoping.Connect(TimeScoping)
    ResultOp.inputs.data_sources.Connect(dataSource)
    if Display==0 or Display==1:
    ResultOp.inputs.requested_location.Connect(DisplayDict[Display])

    When I evaluate this pyresult, I get a different stress distribution which tells me some of the properties are not set correctly.

    Would appreciate the help with this greatly :)
    Cheers

  • Member Posts: 42
    10 Comments First Anniversary 5 Likes Name Dropper
    **

    Hi Ayush thanks for the help.
    I did make adjustments to the code as per your instructions however I am still struggling to replicate the results of the user plot.
    I have attached an archived file with my python result file and the user plot file in there. would greatly appreciate it if someone could have a look and tell me what an I missing.

    Here's the result of the user plot:

    And here is what my Python result is producing:

    Here is the updated code just in case. Will appreciate the help :

    def define_dpf_workflow(analysis):

    1. #region Get the user property values
    2. GroupName="Options"
    3. CS = PropValue(GroupName+"/"+"Coordinate System")
    4. Position = int(PropValue(GroupName+"/"+"Position"))
    5. Display = int(PropValue(GroupName+"/"+"Display Option"))
    6. global DebugMode
    7. DebugMode = bool(int(PropValue(GroupName+"/"+"Debug Mode")))

    8. GroupName="Time Points"
    9. TimeSelectionType = int(PropValue(GroupName+"/"+"Time Selection Type"))
    10. Step = int(PropValue(GroupName+"/"+"Step"))
    11. CalcTimeHistory = bool(int(PropValue(GroupName+"/"+"Calculate Time History")))

    12. NS = PropValue("Scoping/Scoping/Named Selection")

    13. #endregion
    14. #region import standard modules
    15. global dataSource
    16. dataSource = dpf.DataSources(analysis.ResultFileName)
    17. DisplayDict = {}
    18. DisplayDict[0] = dpf.locations.nodal
    19. DisplayDict[1] = dpf.locations.elemental
    20. DisplayDict[2] = dpf.locations.elemental_nodal

    21. GrphicsTypeDict = {}
    22. GrphicsTypeDict[1] = dpf.enums.GFXContourType.GeomFaceScoping
    23. #endregion

    24. MeshScoping=MeshScopingFromNS(NS)
    25. global TimeFreqSupport
    26. TimeFreqSupport=GetResultsTimeData()

    27. WriteMessage("Setup results operator")
    28. ResultOp = dpf.operators.result.stress_X () #dpf.operators.result.stress_von_mises()
    29. ResultOp.inputs.bool_rotate_to_global.Connect(False) #setting to solution coordiante system
    30. ResultOp.inputs.mesh_scoping.Connect(MeshScoping)
    31. TimeScoping=GetTimeScoping(TimeSelectionType, Step, CalcTimeHistory)
    32. ResultOp.inputs.time_scoping.Connect(TimeScoping)
    33. ResultOp.inputs.data_sources.Connect(dataSource)
    34. if Display==0 or Display==1:
    35. ResultOp.inputs.requested_location.Connect(DisplayDict[Display])
    36. sx_top = dpf.operators.utility.change_shell_layers()
    37. sx_top.inputs.fields_container.Connect(ResultOp)
    38. sx_top.inputs.e_shell_layer.Connect(0)#0:Top, 1: Bottom, 2: BottomTop, 3:Mid, 4:BottomTopMid

    39. WriteMessage("Get displacement operator for showing warped model")
    40. u = dpf.operators.result.displacement()
    41. uMeshScoping=MeshScopingFromNS(NS, requested_location=dpf.locations.nodal)
    42. u.inputs.mesh_scoping.Connect(uMeshScoping)
    43. u.inputs.time_scoping.Connect(dpf.TimeFreqScopingFactory.ScopingByLoadSteps([Step]))
    44. u.inputs.data_sources.Connect(dataSource)

    45. WriteMessage("region Setup the final workflow")
    46. dpf_workflow = dpf.Workflow()

    47. GraphicsType = GetGraphicsType(NS)
    48. OutputContourObj = sx_top
    49. if GraphicsType!=None:
    50. dpf_workflow.SetOutputContour(sx_top, GraphicsType)
    51. else:
    52. dpf_workflow.SetOutputContour(sx_top)
    53. dpf_workflow.SetOutputWarpField(u)

    54. dpf_workflow.Record('wf_id', False)
    55. this.WorkflowId = dpf_workflow.GetRecordedId()
    56. return
  • Member, Moderator, Employee Posts: 479
    100 Answers 250 Likes 100 Comments Second Anniversary
    ✭✭✭✭
    edited July 2023

    @Kev , Looking at line 12 of your code above, I am not sure of the way you are scoping the nodes. I suggest select the edges, create a named selection, convert that into nodes and then use the nodal named selection in the scoping of the DPF code. That should give you the same results.

  • Member, Moderator, Employee Posts: 479
    100 Answers 250 Likes 100 Comments Second Anniversary
    ✭✭✭✭

    @Kev, I would recommend you to reach out via the standard Ansys Technical support, as this might involve model debugging and hence not a post for Ansys Developer Forum but a question for standard Ansys Technical Support. There you can even share your model and one of the Ansys Tech Support Engineers will help you debug the issue.

This discussion has been closed.