ACP script example - Create 3D LookUpTable

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

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

    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

  • Josef Behal
    Josef Behal Member Posts: 22
    First Comment Name Dropper
    Options

    Hi I would like to read excel file in ACP, but I'm not able to import for example openpyxl module. I need to use excel because of some further calculations in it.

    Is there any way how to install this package?

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

    Hi @Josef Behal , please create a new post for this question. Thank you.

  • Ramkumar1213456
    Ramkumar1213456 Member Posts: 1
    First Comment
    Options

    How you created look up table in ACP pre, could you please tell me in detail?

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

    @Ramkumar1213456 I'm afraid I don't understand your question. The table is created by the script I provided. If you want to create a look-up manually I would suggest having a look at the ACP documentation, contacting your local support provider or creating a post in the community forum of the Ansys Innovation Space.