How to plot an External DesignLife Result file in Top & Bottom for shell elements?

Javier Vique
Javier Vique Member, Employee Posts: 84
Second Anniversary 5 Answers 25 Likes 10 Comments
✭✭✭✭

Embedded DesignLife has the option to plot the results coming from a *.csv file from DesignLife with the tool "External DesignLife Result". However, it does it for the Top or Bottom layer, not both at the same time.

Answers

  • Javier Vique
    Javier Vique Member, Employee Posts: 84
    Second Anniversary 5 Answers 25 Likes 10 Comments
    ✭✭✭✭

    Python Result object allows you to plot Top & Bottom results. Below a script can be found that makes that plot, with 2 assumptions:
    1. The file to be read from DesignLife has its standard name dl_results.csv
    2. Headers in this file are the common ones, meaning that the first line with data is the 12th one.
    Inputs to be given by the customer are just the paths of the top and bottom DL folders. They are included as properties in the Python Result object.
    User can activate Reverse Rainbow and Logarithmic scale for the legend if desired.

    def post_started(sender, analysis):# Do not edit this line
        define_dpf_workflow(analysis)
    
    # Uncomment this function to enable retrieving results from the table/chart
    # def table_retrieve_result(value):# Do not edit this line
        # import mech_dpf
        # import Ans.DataProcessing as dpf
        # wf = dpf.Workflow(this.WorkflowId)
        # wf.Connect('contour_selector', value)
        # this.Evaluate()
    
    def ImportCsv(FilePath):
        import csv
        data_dict = {}
        with open(FilePath) as CsvFile:
            CsvReader = csv.reader(CsvFile, delimiter=',')
            Rows = list(CsvReader)
            for row in Rows[11:]:
                key = float(row[0])
                value = float(row[2])
                data_dict[key] = value
        return data_dict
    
    
    def define_dpf_workflow(analysis):
        # Read results from DL
        import os
        path_top = this.GetCustomPropertyByPath("DL results paths/Path Top").Value
        file_top = os.path.join(path_top,'dl_results.csv')
        dict_top = ImportCsv(file_top)
        path_bot = this.GetCustomPropertyByPath("DL results paths/Path Bottom").Value
        file_bot = os.path.join(path_bot,'dl_results.csv')
        dict_bot = ImportCsv(file_bot)
    
        import mech_dpf
        import Ans.DataProcessing as dpf
    
        mech_dpf.setExtAPI(ExtAPI)
        dataSource = dpf.DataSources(analysis.ResultFileName)
    
        ResultOp = dpf.operators.result.stress_X()
        ResultOp.inputs.data_sources.Connect(dataSource)
        ResultOp_TopBot = dpf.operators.utility.change_shell_layers()
        ResultOp_TopBot.inputs.fields_container.Connect(ResultOp)
        ResultOp_TopBot.inputs.e_shell_layer.Connect(2)
        FatigueResults = ResultOp_TopBot.outputs.fields_container.GetDataT1()[0]
    
        for Id in FatigueResults.ScopingIds:
            Index = FatigueResults.Scoping.IndexById(Id)
            ResultTop = dict_top[Id]
            ResultBot = dict_bot[Id]
            FatigueResults.UpdateEntityDataByEntityIndex(Index,[ResultBot,ResultTop])
    
        output = dpf.operators.utility.forward()
        output.inputs.any.Connect(FatigueResults)
        dpf_workflow = dpf.Workflow()
        dpf_workflow.Add(output)
        dpf_workflow.SetOutputContour(output)
        dpf_workflow.Record('wf_id', False)
        this.WorkflowId = dpf_workflow.GetRecordedId()
    

    Properties definition:

    def reload_props():
        this.PropertyProvider = None
    
        # comment the following return to allow the rest of the function definition to be executed and add properties
        #return
    
        """
        Some sample code is provided below that shows how to:
            1. Create an instance of the Provider. The Provider class is used to add custom properties to the details.
            2. Use the Provider instance to add custom properties.
            3. Configure those custom properties.
        """
    
        # Create the property instance
        provider = Provider()
    
        # Create a group named Group 1.
        group = provider.AddGroup("DL results paths")
    
        # Create a property with control type Expression and a property with control type Double, and add it to the Group 1
        expression_prop1 = group.AddProperty("Path Top", Control.Expression)
        expression_prop2 = group.AddProperty("Path Bottom", Control.Expression)
    
        this.PropertyProvider = provider