ACP script example - Create 3D LookUpTable

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

I have some element sets defined in ACP:

I would like a Python script that will:

  • loop on all these elements in these specific element sets
  • find the centroid of these elements
  • create a 3D lookup table for the centroids, and define a Fiber Volume Fraction with the value set at as the last part of the name of the element set (The "XX" value in the element set's name will define the fiber volume fraction to be used on that element: "XX" in the name defines a FVF of 0.XX).

Best Answers

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

    ACP has introduced Python scripts:

    The user can select the update mode from this menu:

    Below is an example script that will create a 3D lookup table based on element sets and their names:

    # Script for populating a 3dLookUpTable.
    
    
    # Import necessary modules
    import numpy as np
    
    
    # Get list of element sets which name contains "FiberVolumeFraction"
    model = db.models['ACP Model']
    es_names = [es for es in model.element_sets if 'els_FiberVolumeFraction' in es]
    es_fiberVolumeFraction = []
    for name in es_names:
        es_fiberVolumeFraction.append(model.element_sets[name])
    
    
    # Create numpy arrays to define:
    # - the element coordinates for all elements in the selected element sets
    # - the Fiber Volume Fraction, based on the name of the element set
    fvf_array = np.empty((0,1))
    elem_array = np.empty((0,3))
    for es in es_fiberVolumeFraction:
        # FVF
        fvf_val = float('0.' + es.name.split('_')[-1])
        temp_array = np.full((es.size, 1), fvf_val)
        fvf_array = np.append(fvf_array,temp_array, axis = 0)
        # Element coordinates
        model.select_elements(selection='sel10', op='new', attached_to=es)
        coordinates = model.mesh_query(name = 'coordinates', position = 'centroid', selection = 'sel10')
        elem_array = np.append(elem_array,coordinates, axis = 0)
    
    
    # Delete pre-existing look-up tables if it exists
    lut_names = [lut for lut in model.lookup_tables if 'FVF_LookUptable' in lut]
    for lut in lut_names:
        try:
            del(model.lookup_tables[lut])
        except:
            pass
    
    
    # Create new 3D look-up table
    table = model.create_lookup_table3d(name='FVF_LookUptable')
    table.create_column(name = 'Fiber Volume Fraction', type='scalar', values=None, dimension='dimensionless')
    loc = table.columns['Location']
    fvf = table.columns['Fiber Volume Fraction']
    loc.values = elem_array
    fvf.values = fvf_array
    model.lookup_tables['FVF_LookUptable'].use_default_search_radius = False
    model.lookup_tables['FVF_LookUptable'].search_radius=1.0
    model.field_definitions['FieldDefinition.1'].scalar_field = model.lookup_tables['FVF_LookUptable'].columns['Fiber Volume Fraction']
    
    
    # Update table
    table.update()
    
  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 794
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Answer ✓

    Also see this post for a way to do something similar in Mechanical scripting: https://discuss.ansys.com/discussion/1996/mechanical-python-code-example-write-nodal-information-to-csv-file#latest

Answers