How do I extract Max. and Min over Time for different Cases in Mechanical LSDyna using DPF?

Options
Ayush Kumar
Ayush Kumar Member, Moderator, Employee Posts: 411
First Anniversary Ansys Employee Solution Developer Community of Practice Member First Answer
edited February 12 in Structures

How do I extract Max. and Min over Time for different Cases in Mechanical LSDyna using DPF?

Comments

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

    This is a Python Result Solution in 2024R1:

    Python Code

    def post_started(sender, analysis):# Do not edit this line
        define_dpf_workflow(analysis)
    
    
    def define_dpf_workflow(analysis):
        import os
        import mech_dpf
        import Ans.DataProcessing as dpf
        mech_dpf.setExtAPI(ExtAPI)
    
        analysis = Model.Analyses[0]
        case_nr = this.GetCustomPropertyByPath("Cases/Case Number").ValueString
    
        ds = dpf.DataSources()
        d3plot_path = os.path.join(analysis.WorkingDir, "case%s.d3plot" % case_nr)
        act_units_file = os.path.join(analysis.WorkingDir, "file.actunits")
        ds.SetResultFilePath(d3plot_path, 'd3plot')
        ds.AddFilePath(act_units_file, "actunits")
    
        streams = dpf.operators.metadata.streams_provider(data_sources=ds)
        stream = streams.outputs.getstreams_container()
    
        time_freq_support = dpf.operators.metadata.time_freq_provider()
        time_freq_support.inputs.streams_container.Connect(stream)
        n_sets = time_freq_support.outputs.time_freq_support.GetData().NumberSets
    
        time_steps = range(1, n_sets + 1)
        timeScop = dpf.Scoping()
        timeScop.Ids = time_steps
    
        seqv = dpf.operators.result.stress_von_mises()
        seqv.inputs.requested_location.Connect(dpf.locations.nodal)
        seqv.inputs.time_scoping.Connect(timeScop)
        seqv.inputs.streams_container.Connect(stream)
        seqv_fc = seqv.outputs.fields_container.GetData()
    
        seqv_min_max = dpf.operators.min_max.min_max_over_time_by_entity(fields_container=seqv_fc)
        seqv_max_time = seqv_min_max.outputs.getmax()[0]
        seqv_min_time = seqv_min_max.outputs.getmin()[0]
    
        if this.GetCustomPropertyByPath("Min Max over Time/Type").ValueString == "Maximum over Time":
            out_f = seqv_max_time
        elif this.GetCustomPropertyByPath("Min Max over Time/Type").ValueString == "Minimum over Time":
            out_f = seqv_min_time
    
        out_op = dpf.operators.utility.forward_field()
        out_op.inputs.field.Connect(out_f)
    
        stream.ReleaseHandles()
        dpf_workflow = dpf.Workflow()
        dpf_workflow.Add(out_op)
        dpf_workflow.SetOutputContour(out_op)
        dpf_workflow.Record('wf_id', False)
        this.WorkflowId = dpf_workflow.GetRecordedId()
    

    Property Provider

    def reload_props():
        this.PropertyProvider = None
    
        # Create the property instance
        provider = Provider()
    
        # Create a new group named Cases
        group = provider.AddGroup("Cases")
    
        # Add an options property to the group
        options_prop = group.AddProperty("Case Number", Control.Options)
        solver = Model.Analyses[0].Solver
        n_cases = solver.Properties['Step Controls/NCases'].Value
        n_cases_opt = {}
        for case in range(1, int(n_cases) + 1):
            n_cases_opt.update({case: "%s" % case})
    
        # Add a couple options to the options property.
        options_prop.Options = n_cases_opt
        options_prop.Value = 1
    
        group = provider.AddGroup("Min Max over Time")
    
        # Add an options property to the second group
        options_prop = group.AddProperty("Type", Control.Options)
    
        # Add a couple options to the options property.
        options_prop.Options = {1 : "Maximum over Time", 2 : "Minimum over Time"}
        options_prop.Value = "Maximum over Time"
    
        this.PropertyProvider = provider