Volume and mass of elements above a result threshold

Options
Pernelle Marone-Hitz
Pernelle Marone-Hitz Member, Moderator, Employee Posts: 827
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: 827
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Answer ✓
    Options

    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
    Options

    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: 827
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Options

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

  • Jim Kosloski
    Jim Kosloski Member, Employee Posts: 18
    First Anniversary Ansys Employee First Comment
    Options

    I need to do this but more accurately than on an element by element basis. Give the nodal (or integration point stresses) can we determine the volume of that element that is above the threshold value?

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

    @Jim Kosloski This should be doable but only through MAPDL / PyMAPDL I think