How to retrieve "floating point ops" from solve.out file in Mechanical ?

Bruno Gaudin
Bruno Gaudin Member, Employee Posts: 6
First Anniversary Ansys Employee Solution Developer Community of Practice Member 5 Likes
✭✭✭
edited June 2023 in Structures

I need to create a parameter studies with 'floating point ops' as outputs parameters :


Tagged:

Answers

  • Bruno Gaudin
    Bruno Gaudin Member, Employee Posts: 6
    First Anniversary Ansys Employee Solution Developer Community of Practice Member 5 Likes
    ✭✭✭

    I have created a python code script which parse the solve.out file :

    (should be inserted underneath solution as a After Solve Target callback)


    Here the code used for the Script part :

    def after_solve(this, analysis):# Do not edit this line
        """
        Called after solving the parent analysis.
        Keyword Arguments : 
            this -- the datamodel object instance of the python code object you are currently editing in the tree
            analysis -- Static Structural
        """
     
        # To access properties created using the Property Provider, please use the following command.
        # this.GetCustomPropertyByPath("your_property_group_name/your_property_name")
     
     
        # To access scoping properties use the following to access geometry scoping and named selection respectively:
        # this.GetCustomPropertyByPath("your_property_group_name/your_property_name/Geometry Selection")
        # this.GetCustomPropertyByPath("your_property_group_name/your_property_name/Named Selection")
     
     
        solution=ExtAPI.DataModel.Project.Model.Analyses[0].Solution
        
        
        import os
        FileDir=ExtAPI.DataModel.AnalysisList[0].WorkingDir
        TextFile='solve.out'
        SolveOutLines = [] #Declare an empty list named "lines"
        with open(os.path.join(FileDir, TextFile), "r") as in_file:  
            for line in in_file: #For each line of text store in a string variable named "SolveOutLines", and
                SolveOutLines.append(line)
        search = "no. of floating point ops for factor"
        search2= "no. of floating point ops for solve"
        
        for line in range(len(SolveOutLines)):
            if search in SolveOutLines[line]:
                split=SolveOutLines[line].split()
    
    
                split2=split[8].split('D+')
    
    
                value=float(split2[0])
                expo=float(split2[1])
                answer=value*10**expo
            if search2 in SolveOutLines[line]:
                split=SolveOutLines[line].split()
    
    
                split2=split[8].split('D+')
    
    
                value=float(split2[0])
                expo=float(split2[1])
                answer2=value*10**expo
    
    
        this.GetCustomPropertyByPath("Outputs/no. of floating point ops for factor").Value = answer
        this.GetCustomPropertyByPath("Outputs/no. of floating point ops for solve").Value = answer2
    

    And here the code used for Property Provider part :

    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("Outputs")
        
        # Create a property with control type Expression and a property with control type Double, and add it to the Group 1
        double_prop = group.AddProperty("no. of floating point ops for factor", Control.Double)
        double_prop.CanParameterize = True
        double_prop.ParameterType = ParameterType.Output
        
        double_prop = group.AddProperty("no. of floating point ops for solve", Control.Double)
        double_prop.CanParameterize = True
        double_prop.ParameterType = ParameterType.Output
        
        # The valid range set here is used by the IsValid handler in the Provider class, please look at the class definition above.
        # If interested in the implementation, please look at the class definition below
        this.PropertyProvider = provider