Commit 37efeda2 authored by William Gurecky's avatar William Gurecky
Browse files

adds pod model for cfd pressure data

parent f3e860d9
Loading
Loading
Loading
Loading
+56 −0
Original line number Diff line number Diff line
"""
Proper Orthogonal Decomposition method with interpolation
for turbine chamber 3D model.

Author: William Gurecky.  wll@ornl.gov.  June 2023
"""
import numpy as np
from scipy.stats import norm
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d, RBFInterpolator
import h5py
from dthydro_cfd.rom_cfd.pod_rom import PODInterpModel


def construct_pod_model(snapshot_h5file):
    # read the snapshot data from the hdf5 file
    h5f = h5py.File(snapshot_h5file, mode='r')
    xyz_points = h5f["/points"][:]

    # read the pressure field snapshotsa
    snapshot_matrix = []
    snapshot_params = []
    snapshot_names = h5f["/snapshots"].keys()
    for snap_name in snapshot_names:
        case_data = h5f["/snapshots/" + snap_name + "/Pressure (Pa)"][:]
        case_params = h5f["/snapshots/" + snap_name + "/params"][:]
        snapshot_matrix.append(case_data)
        snapshot_params.append(case_params)
    snapshot_matrix = np.asarray(snapshot_matrix, dtype=np.float32)
    snapshot_params = np.asarray(snapshot_params, dtype=np.float32)

    # clean up
    h5f.close()

    # create POD model
    n_pod_modes = 5
    pod_model = PODInterpModel(max_modes=n_pod_modes, pod_method="svd")
    pod_model.fit(snapshot_matrix, snapshot_params)

    # evaluate the pod model at an vane angle not in training set
    pred_vane_angle = 8.02
    pred_p = pod_model.predict(pred_vane_angle)

    # create 3d plot figure of predicted pressure distribution
    fig = plt.figure()
    ax = fig.add_subplot(projection='3d')
    ax.scatter(xyz_points[:, 0], xyz_points[:, 1], xyz_points[:, 2], c=pred_p)
    # ax.add_colorbar()
    plt.show()
    pass



if __name__ == "__main__":
    construct_pod_model("cfd_pod_snapshots.h5")
+1 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ class PODInterpModel(object):
        interp_method: Method used to interpolate weights between known
            snapshot locations. Either "linear" or "spline" or "nn"
    """
    def __init__(self, interp_method='linear', max_modes=10, pod_method="eig"):
    def __init__(self, interp_method='linear', max_modes=10, pod_method="svd"):
        self.interp_method = interp_method
        self.max_modes = max_modes
        self.n_t_dim = 0