How to import heating flux obtain from Speos to LSDYNA

DP
DP Member, Employee Posts: 2
Name Dropper First Comment
✭✭✭

Hi everyone, I would like to map heating flux from Speos to LSDYNA.
The Speos Absorption file is defined as x,y,z,absorption and will use a different mesh from LSDYNA

Best Answer

  • DP
    DP Member, Employee Posts: 2
    Name Dropper First Comment
    ✭✭✭
    edited November 2024 Answer ✓
    import pandas as pd
    from scipy.interpolate import griddata
    
    # Import the Speos absorption file (csv)(x,y,z,Absorption)
    Speos_Absorption = pd.read_csv('Speos_Absorption.csv')
    
    # Import the lsdyna nodes coordinates (csv)(x,y,z)
    Nodes = pd.read_csv('lsdyna_nodes.csv')
    
    # Interpolation
    # 0 is used by to fill in for requested points outside of the convex hull of the input points
    Nodes['Absorption'] = griddata(Speos_Absorption[['x', 'y', 'z']].values, Speos_Absorption['Absorption'].values, Nodes[['x', 'y', 'z']].values, method='linear', fill_value=0)
    
    # Convert W/m² (m.kg.s) to mW/mm² (mm.t.s)
    unit_scale = 1E-3
    # Negative flux direction (into the volume)
    flux_direction = -1
    Nodes['Absorption'] = Nodes['Absorption'] * unit_scale * flux_direction
    
    # Import the segment set (n1,n2,n3,n4) that correspond to the face to map
    segment_set = pd.read_csv('set_segment_face.csv')
    
    # Create a dictionary to map node id to mlc
    mlc_dict = Nodes.set_index('nid')['Absorption'].to_dict()
    
    # Add new columns mlc1 to mlc4 to segment_set
    segment_set['mlc1'] = segment_set['n1'].map(mlc_dict)
    segment_set['mlc2'] = segment_set['n2'].map(mlc_dict)
    segment_set['mlc3'] = segment_set['n3'].map(mlc_dict)
    segment_set['mlc4'] = segment_set['n4'].map(mlc_dict)
    
    # Define the template
    dyna_temp_original = """*BOUNDARY_FLUX_SEGMENT
    $#      n1        n2        n3        n4
    {0},{1},{2},{3}
    $#    lcid      mlc1      mlc2      mlc3      mlc4       loc     nhisv    unused
    0,{4:.7g},{5:.7g},{6:.7g},{7:.7g},0,0\n"""
    
    # Open the file for writing
    with open("Boundary_Flux_Segment.k", "w") as dyna_fh:
        dyna_fh.write("*KEYWORD\n")
    
        # Iterate over each row in segment_set
        for index, row in segment_set.iterrows():
            dyna_temp = dyna_temp_original.format(
                int(row['n1']), int(row['n2']), int(row['n3']), int(row['n4']),
                float(row['mlc1']), float(row['mlc2']), float(row['mlc3']), float(row['mlc4'])
            )
            dyna_fh.write(dyna_temp)
        dyna_fh.write("*END\n")
    
    print("Boundary_Flux_Segment.k file has been created successfully.")
    
    # Define the template
    dyna_temp_original = """*ELEMENT_SHELL_THICKNESS
    $#   eid     pid      n1      n2      n3      n4      n5      n6      n7      n8
    {0},1,{1},{2},{3},{4}
    $#         thic1           thic2           thic3           thic4            beta
    {5:.7g},{6:.7g},{7:.7g},{8:.7g},0.0\n"""
    
    # Open the file for writing
    with open("ELEMENT_SHELL_THICKNESS.k", "w") as dyna_fh:
        dyna_fh.write("*KEYWORD\n")
    
        # Iterate over each row in segment_set
        for index, row in segment_set.iterrows():
            dyna_temp = dyna_temp_original.format(
                index+1, int(row['n1']), int(row['n2']), int(row['n3']), int(row['n4']),
                float(abs(row['mlc1'])),float(abs(row['mlc2'])),float(abs(row['mlc3'])),float(abs(row['mlc4']))
            )
            dyna_fh.write(dyna_temp)
        dyna_fh.write("*END\n")
    
    print("ELEMENT_SHELL_THICKNESS.k file has been created successfully.")
    # Once generated, please open the file in LS-Prepost and save it to the version you are using.