How to import Heat Transfer Coefficient from Fluent to LSDYNA?

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

Hi everyone, I would like to Heat Transfer Coefficient from Fluent to LSDYNA.
The HTC file is defined as x,y,z,heat-transfer-coef-wall and will use a different mesh from LSDYNA

Answers

  • DP
    DP Member, Employee Posts: 4
    Name Dropper First Comment
    ✭✭✭
    edited January 24
    import pandas as pd
    from scipy.interpolate import griddata
    import matplotlib.pyplot as plt
    
    # Import the Fluent convection file (csv)
    Fluent_Convection = pd.read_csv('HTC_test')
    length_unit_scale = 1
    
    # Import the nodes coordinates (csv)
    Nodes = pd.read_csv('nodes_lsdyna_20mm.csv')
    
    # Interpolation
    Nodes['heat-transfer-coef'] = griddata(Fluent_Convection[['x-coordinate', 'y-coordinate', 'z-coordinate']].values*length_unit_scale, Fluent_Convection['heat-transfer-coef-wall'].values, Nodes[['x-coordinate', 'y-coordinate', 'z-coordinate']].values, method='nearest',fill_value=0)
    
    # Convert W/m².°C (m.kg.s) to W/m².°C (m.kg.s)
    heat_unit_scale = 1
    Nodes['heat-transfer-coef'] = Nodes['heat-transfer-coef'] * heat_unit_scale
    
    # Import the segment set
    segment_set = pd.read_csv('segment_lsdyna_20mm.csv')
    
    # Create a dictionary to map node id to heat-transfer-coef
    h_dict = Nodes.set_index('nid')['heat-transfer-coef'].to_dict()
    
    # Add new columns mlc1 to mlc4 to segment_set
    segment_set['mlc1'] = segment_set['n1'].map(h_dict)
    segment_set['mlc2'] = segment_set['n2'].map(h_dict)
    segment_set['mlc3'] = segment_set['n3'].map(h_dict)
    segment_set['mlc4'] = segment_set['n4'].map(h_dict)
    segment_set['mlc'] = segment_set[['mlc1', 'mlc2', 'mlc3', 'mlc4']].mean(axis=1)
    
    
    # Define the template
    dyna_temp_original = """*BOUNDARY_CONVECTION_SEGMENT
    $#      n1        n2        n3        n4
    {0},{1},{2},{3}
    $#   hlcid     hmult     tlcid     tmult       loc
    0,{4:.7g},0,0,0,0\n"""
    
    # Open the file for writing
    with open("BOUNDARY_CONVECTION_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['mlc'])
            )
            dyna_fh.write(dyna_temp)
        dyna_fh.write("*END\n")
    
    print("BOUNDARY_CONVECTION_SEGMENT.k file has been created successfully.")
    
    # # Export fringe result for visualize in LSPP
    # 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['mlc'])),float(abs(row['mlc'])),float(abs(row['mlc'])),float(abs(row['mlc']))
            )
            dyna_fh.write(dyna_temp)
        dyna_fh.write("*END\n")
    
    print("ELEMENT_SHELL_THICKNESS.k file has been created successfully.")
    
    # Plotting the data
    def plot_heat_transfer(data, title):
        x = data['x-coordinate']
        y = data['y-coordinate']
        z = data['z-coordinate']
        heat_transfer_coef = data.iloc[:, -1]  # Last column is heat transfer coefficient
    
        fig = plt.figure(figsize=(10, 8))
        ax = fig.add_subplot(111, projection='3d')
    
        sc = ax.scatter(x, y, z, c=heat_transfer_coef, cmap='jet', marker='o')
    
        cbar = plt.colorbar(sc, ax=ax, shrink=0.5, aspect=10)
        cbar.set_label('Heat Transfer Coefficient')
    
        ax.set_xlim(0, 1)
        ax.set_ylim(0, 1)
        ax.set_zlim(0, 1)
    
        ax.set_xlabel('X-Coordinate')
        ax.set_ylabel('Y-Coordinate')
        ax.set_zlabel('Z-Coordinate')
        ax.set_title(f"{title} (Number of nodes: {len(data)})")
    
        ax.set_box_aspect([1, 1, 1])
        ax.view_init(elev=35, azim=45)
    
        plt.show()
    
    plot_heat_transfer(Fluent_Convection, 'Fluent Convection Data')
    plot_heat_transfer(Nodes, 'LSDYNA Nodes Data')