How do I perform Load Case combination of principal stresses using DPF (Python Result) in Mechanical

Ayush Kumar
Ayush Kumar Member, Moderator, Employee Posts: 389
First Anniversary Ansys Employee Solution Developer Community of Practice Member First Answer
edited June 2023 in Structures

How do I perform Load Case combination of principal stresses using DPF (Python Result) in Mechanical?

Example: LC1- LC2

User defined results Solution Combination in Mechanical does a combination on the calculated results eg. Principal or SEQV, which is not the right way. The combination should be done on the stress tensor level and then Principal or SEQV should be calculated based on the new stress tensor. How do I do this using DPF and plot the results as contour on the body in Mechanical?

enter image description here

Tagged:

Answers

  • Ayush Kumar
    Ayush Kumar Member, Moderator, Employee Posts: 389
    First Anniversary Ansys Employee Solution Developer Community of Practice Member First Answer
    Answer ✓

    You can use the following code to plot load case combination on S1 (Maximum Principal Stress), the time scoping needs to be adjusted as per your analysis.

    For S2 and S3 use p_inv.outputs.field_eig_2 and p_inv.outputs.field_eig_3 respectively.

    def post_started_301(sender, analysis):# Do not edit this line
        define_dpf_workflow(analysis)
    
    def define_dpf_workflow(analysis):
        import mech_dpf
        import Ans.DataProcessing as dpf
        dataSource = dpf.DataSources(analysis.ResultFileName)
        
        # Instantiate Stress Tensor
        stress_tensor = dpf.operators.result.stress()
        # For LC1
        timeScop = dpf.Scoping()
        timeScop.Ids = [1, 2]
        stress_tensor.inputs.time_scoping.Connect(timeScop)
        stress_tensor.inputs.data_sources.Connect(dataSource)
        
        # Scale LC2 to -1
        stress_tensor_lc2_sc = dpf.operators.math.scale(field=stress_tensor.outputs.fields_container.GetData()[1], ponderation=-1.0)
        # Add load cases
        stress_tensor_combi = dpf.operators.math.add(fieldA=stress_tensor.outputs.fields_container.GetData()[0], fieldB=stress_tensor_lc2_sc)
        
        # Principal Invariants - Principal Stresses
        p_inv = dpf.operators.invariant.principal_invariants()
        p_inv.inputs.field.Connect(stress_tensor_combi)
    
        # Plot Combined S1 or Maximum Principal Stress
        dpf_workflow = dpf.Workflow()
        dpf_workflow.Add(p_inv)
    
        # Plot contour
        dpf_workflow.SetOutputContour(p_inv.outputs.field_eig_1)
        wf_id = dpf_workflow.Record('wf_id', True)
        this.WorkflowId = dpf_workflow.GetRecordedId()