Extract eigen values and eigen vectors from d3eigv files in pydpf

Options
Adya
Adya Member, Employee Posts: 3
First Comment
edited October 2023 in Structures

Extract eigen values and eigen vectors from d3eigv files in pydpf

Tagged:

Comments

  • Adya
    Adya Member, Employee Posts: 3
    First Comment
    edited October 2023
    Options
    from ansys.dpf import core as dpf
    import pandas as pd
    import numpy as np
    import matplotlib.pyplot as plt
    from pxr import Vt
    
    # Load the datasource from a d3eigv file
    # only the first d3eigv file need to be loaded
    ds = dpf.DataSources()
    ds.set_result_file_path(r'\path\to\file\d3eigv', 'd3plot')
    model = dpf.Model(ds)
    print(model)
    
    
    # Extract displacements for all Load steps from d3eigv
    U = model.results.displacement.on_all_time_freqs.eval()
    
    # Get the displacement field for a desired loadstep
    # Here 7 refers  to the 7th loadstep in d3eigv
    print(U)
    u = U.get_field({'time': 6})
    
    """
    # Plot the extracted state
    # Get the camera position once so as to set the view
    cpos = u.plot(deform_by=u,show_edges=False,
           screenshot=r'\path\to\image\state7.png',
           off_screen=False, return_cpos=True)
    print(cpos)
    """
    
    cpos = [(-8739.018807515353, 4113.571013794808, 2869.855509287625),
     (-2424.0205557548243, -648.3712183048058, 229.55202115622455),
     (0.23537139638660276, -0.21357474711933727, 0.9481487927303034)]
    
    cpos = u.plot(deform_by=u,show_edges=False,
           screenshot=r'\path\to\image\state7.png',
           off_screen=True, return_cpos=False,cpos=cpos)
    # Extract the x,y,z displacements from this loadstep
    disp = u.data
    
    # Convert that to a pandas dataframe of numpy ararys
    df = pd.DataFrame({'NodID':np.array(u.scoping.ids),
                       'x-disp':disp[:,0],'y-disp':disp[:,1],
                       'z-disp':disp[:,2]})
    
    print(df.head())
    
    # Convert the displacements to VtArray
    def convert_np_to_vt(my_array: np.ndarray) -> Vt.Vec3fArray:
        return Vt.Vec3fArray.FromNumpy(my_array)
    
    from_numpy: Vt.Vec3fArray = convert_np_to_vt(disp)
    print(from_numpy[:5])