Overview of postprocessing capabilities in Ansys

Javier Vique
Javier Vique Member, Employee Posts: 76
First Answer First Anniversary Name Dropper 5 Likes

In civil engineering, APDL has been traditionally used for both building up the models and postprocessing. Nowadays, many engineers are building their models in Mechanical, but they still use APDL snippet commands for getting some output data into txt files that are used afterwards in in-house tools. Which are the alternatives to this workflow?


Best Answer

  • Javier Vique
    Javier Vique Member, Employee Posts: 76
    First Answer First Anniversary Name Dropper 5 Likes
    Answer ✓

    The model of a 3D frame modeled by beam elements shown below is used as demo for giving an overview of the different options for postprocessing with Ansys. The final target of the user would be making an output of SMISC1 (axial force on i node) and SMISC2 (y bending on i node) on specific named selections (NS1 & NS2) for the last substep of the only available step. This output will be used in an in-house tool made in Excel.

    APDL snippet commands:
    *VWRITE commands are used for getting the output. Here the script:

    *get,elem_min,elem,,num,mind           !Min element in model
    *get,elem_max,elem,,num,maxd           !Max element in model
    *GET,ELEMCOUNT,ELEM,0,COUNT            !Elements in named selection
    *DIM,EARRAY,ARRA,ELEMCOUNT,1           !Elements array
    *VGET,EARRAY(1,1),ELEM,,ELIST          !Elements list
    *dim,emask,array,elem_max              !Mask to select elements in named selection

    Mechanical scripting:
    Two user-defined results (UDR) are created and they are evaluated for both named selections, making use of ExportToTextFile method. Here the script:

    import os
    folderpath = r'here_my_path'
    Solution = ExtAPI.DataModel.Project.Model.Analyses[0].Solution
    NamedSelections = ExtAPI.DataModel.GetObjectsByType(DataModelObjectCategory.NamedSelection)
    AxialSol = Solution.AddUserDefinedResult()
    AxialSol.Expression = 'SMISC1'
    BendingYSol = Solution.AddUserDefinedResult()
    BendingYSol.Expression = 'SMISC2'
    for NS in NamedSelections:
        axial_name = NS.Name + '_axial.txt'
        bendy_name = NS.Name + '_bendingY.txt'
        filename1 = os.path.join(folderpath,axial_name)
        filename2 = os.path.join(folderpath,bendy_name)
        AxialSol.Location = NS
        BendingYSol.Location = NS

    An alternative, which would be more efficient, is using Result Reader and BEAM_AXIAL_F & BEAM_BENDING_M. Additionally, this would allow to make the export directly to Excel, but please be aware that the output is slightly different, since this output gives 2 values per element (node i and node j), so it is giving SMISC1-14 and SMISC2-15, not just SMISC1 & SMISC2. For details about result reader, please have a look at our user manual:
    https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/corp/v232/en/act_cust_mech/Postprocess_externalResultRetrieval.html?q=result reader

    Data Postprocessing Framework:
    DPF allows us to make this export, bringing the data into Excel. Here the script:

    ## Here an Excel is open following solution available in Dev Forum:
    # https://discuss.ansys.com/discussion/308/write-information-to-excel-example-on-mesh-quality
    import clr
    from Microsoft.Office.Interop import Excel
    excel = Excel.ApplicationClass()
    excel.Visible = True # makes the Excel application visible to the user
    excel.ScreenUpdating = True     # Enables screen refreshing
    # opening a workbook
    filename = r"here_your_path\Book1.xlsx" #Specify existing Excel document
    workbook = excel.Workbooks.Open(filename)
    # adding a worksheet
    ws = workbook.Worksheets.Add() # Add a new worksheet and change its name
    ws.Name = "MyNewSheet"
    ws.Cells(1,1).Value = "Named Selection"
    ws.Cells(1,2).Value = "Element"
    ws.Cells(1,3).Value = "Axial"
    ws.Cells(1,4).Value = "BendingY"
    i = 2
    ## Here mech-dpf is used to get SMISC1 & SMISC2
    import os
    import mech_dpf
    import Ans.DataProcessing as dpf
    folderpath = r'D:\01.Support\Salesforce\00033923\DPF_results'
    dataSource = dpf.DataSources(analysis.ResultFileName)
    named_selections = ['NS_1','NS_2']
    op_smisc = dpf.operators.result.mapdl.smisc()
    smisc1 = op_smisc.outputs.fields_container.GetData()
    smisc2 = op_smisc.outputs.fields_container.GetData()
    for j in named_selections:
        ns = model.GetNamedSelection(j)
        for elemid in ns.Ids:
            ws.Cells(i,1).Value = j
            ws.Cells(i,2).Value = elemid
            ws.Cells(i,3).Value = smisc1[0].GetEntityDataById(elemid)[0]
            ws.Cells(i,4).Value = smisc2[0].GetEntityDataById(elemid)[0]
            i = i + 1
    print('Script has finished, review your Excel file')

    For big models, there might be some alternatives to GetEntityDataById(elemid) to get results faster.

    Below the verification for element 100: