ACP script example - Create 3D LookUpTable

Member, Moderator, Employee Posts: 888
100 Answers 500 Comments 250 Likes Second Anniversary
✭✭✭✭
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).

Welcome!

It looks like you're new here. Sign in or register to get started.

Best Answers

  • Member, Moderator, Employee Posts: 888
    100 Answers 500 Comments 250 Likes Second Anniversary
    ✭✭✭✭
    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:

    1. # Script for populating a 3dLookUpTable.
    2.  
    3.  
    4. # Import necessary modules
    5. import numpy as np
    6.  
    7.  
    8. # Get list of element sets which name contains "FiberVolumeFraction"
    9. model = db.models['ACP Model']
    10. es_names = [es for es in model.element_sets if 'els_FiberVolumeFraction' in es]
    11. es_fiberVolumeFraction = []
    12. for name in es_names:
    13.     es_fiberVolumeFraction.append(model.element_sets[name])
    14.  
    15.  
    16. # Create numpy arrays to define:
    17. # - the element coordinates for all elements in the selected element sets
    18. # - the Fiber Volume Fraction, based on the name of the element set
    19. fvf_array = np.empty((0,1))
    20. elem_array = np.empty((0,3))
    21. for es in es_fiberVolumeFraction:
    22.     # FVF
    23.     fvf_val = float('0.' + es.name.split('_')[-1])
    24.     temp_array = np.full((es.size, 1), fvf_val)
    25.     fvf_array = np.append(fvf_array,temp_array, axis = 0)
    26.     # Element coordinates
    27.     model.select_elements(selection='sel10', op='new', attached_to=es)
    28.     coordinates = model.mesh_query(name = 'coordinates', position = 'centroid', selection = 'sel10')
    29.     elem_array = np.append(elem_array,coordinates, axis = 0)
    30.  
    31.  
    32. # Delete pre-existing look-up tables if it exists
    33. lut_names = [lut for lut in model.lookup_tables if 'FVF_LookUptable' in lut]
    34. for lut in lut_names:
    35.     try:
    36.         del(model.lookup_tables[lut])
    37.     except:
    38.         pass
    39.  
    40.  
    41. # Create new 3D look-up table
    42. table = model.create_lookup_table3d(name='FVF_LookUptable')
    43. table.create_column(name = 'Fiber Volume Fraction', type='scalar', values=None, dimension='dimensionless')
    44. loc = table.columns['Location']
    45. fvf = table.columns['Fiber Volume Fraction']
    46. loc.values = elem_array
    47. fvf.values = fvf_array
    48. model.lookup_tables['FVF_LookUptable'].use_default_search_radius = False
    49. model.lookup_tables['FVF_LookUptable'].search_radius=1.0
    50. model.field_definitions['FieldDefinition.1'].scalar_field = model.lookup_tables['FVF_LookUptable'].columns['Fiber Volume Fraction']
    51.  
    52.  
    53. # Update table
    54. table.update()
  • Member, Moderator, Employee Posts: 888
    100 Answers 500 Comments 250 Likes Second Anniversary
    ✭✭✭✭
    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

Welcome!

It looks like you're new here. Sign in or register to get started.