Volume and mass of elements above a result threshold

Pernelle Marone-Hitz
Pernelle Marone-Hitz Member, Moderator, Employee Posts: 715
First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
edited June 2023 in Structures

Using ACT scripting, how can I find the elements for which the average stress is above a specific value and sum the volume of these elements, and find the summed mass of these elements ?

Tagged:

Best Answer

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 715
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Answer ✓

    The following code can be adapted. Please note that this simplified example considers that only one material is used in the model.

    # Define threshold
    threshold = Quantity('100 [MPa]')
    
    # init
    summed_volume = 0
    summed_mass = 0
    
    # Insert result
    eqv_stress = ExtAPI.DataModel.Project.Model.Analyses[0].Solution.AddEquivalentStress()
    eqv_stress.DisplayOption = ResultAveragingType.ElementalMean
    eqv_stress.EvaluateAllResults()
    
    # Extract data from plot
    plot_data = eqv_stress.PlotData
    elements = plot_data ['Element']
    result_value = plot_data ['Values']
    
    # Mesh data
    mesh_data = ExtAPI.DataModel.Project.Model.Analyses[0].MeshData
    
    # Handle unit conversion
    import units
    result_unit = result_value.Unit
    mesh_unit = mesh_data.Unit
    scale_factor_stress = units.ConvertUnit(1.,result_unit,threshold.Unit)
    
    
    for index in range(len(elements)):
      if result_value[index]*scale_factor_stress > threshold.Value:
        summed_volume = summed_volume + mesh_data.ElementById(elements[index]).Volume
    
    summed_volume = Quantity(str(summed_volume) + '[' + mesh_unit + '^3]')
    print('Summed volume is: ' + str(summed_volume))
    
    # Get material 
    # WARNING this code demo only grabs the material of the first body in the tree and assumes all elements above use this material
    import materials
    mat = ExtAPI.DataModel.Project.Model.Materials.Children[0]
    # get engineering data material properties for this material
    matED = mat.GetEngineeringDataMaterial()
    density = materials.GetMaterialPropertyByName(matED,"Density")['Density']
    
    # Get mass
    summed_mass = summed_volume.Value*density[1]
    print('Summed mass is: ' +str(summed_mass) + ' [kg]')
    

Answers

  • Lorenz
    Lorenz Member Posts: 6
    Photogenic Name Dropper First Comment

    Hi Pernelle

    You are using *.PlotData in above example to get the stresses. Can we also use dpf?

    Regards

    Lorenz

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 715
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member

    Hi @Lorenz , yes, DPF could also be used for that purpose. I think I had initially written that script before DPF was released.