Loading dthydro_cfd/rom_cfd/pod_cfd_dash_app.py +55 −30 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ import time from dthydro_cfd.rom_cfd.pod_rom import PODInterpModel # plotly imports import plotly.graph_objects as go import plotly.express as px # dash imports import dash from dash import dcc, html Loading @@ -33,17 +34,18 @@ app.layout = html.Div( dcc.Graph(id='live-update-graph-vane'), dcc.Interval( id='interval-component', interval=2000, # in milliseconds interval=1000, # in milliseconds n_intervals=0 ) ]) ) X_POINTS = f_db["X"][:] Y_POINTS = f_db["Y"][:] Z_POINTS = f_db["Z"][:] X_POINTS = f_db["X"][:].flatten() Y_POINTS = f_db["Y"][:].flatten() Z_POINTS = f_db["Z"][:].flatten() # data thinning PTX = np.random.randint(0, len(X_POINTS), size=6000) P_ = None VA_ = None from collections import deque vane_history = deque(maxlen=50) time_history = deque(maxlen=50) Loading @@ -54,24 +56,35 @@ time_history = deque(maxlen=50) Input('interval-component', 'n_intervals')) def update_graph_live(n): global P_ global VA_ # Read data from database P_ = f_db["P"][:] VA_ = f_db["vane_angle"][:] fig = px.scatter_3d( x=X_POINTS[PTX], y=Y_POINTS[PTX], z=Z_POINTS[PTX], color=P_[PTX], range_color=[0., 400.e3], opacity=0.95, size_max=4, ) fig.update_traces(marker=dict(size=3)) # Draw new figure fig = go.Figure(data=go.Scatter3d( x=X_POINTS.flatten(), y=Y_POINTS.flatten(), z=Z_POINTS.flatten(), mode='markers', marker=dict(size=4, color=P_, opacity=0.9, colorbar=dict(thickness=5)), customdata=P_, hovertemplate=('%{customdata}%'), )) # fig = go.Figure(data=go.Scatter3d( # x=X_POINTS[PTX], # y=Y_POINTS[PTX], # z=Z_POINTS[PTX], # mode='markers', # marker=dict(size=3, color=P_[PTX], opacity=0.95, # colorbar=dict(thickness=5, title="Pressure (Pa)", ), # ), # customdata=P_[PTX], # hovertemplate=('%{customdata}%'), # )) # preserve zoom, pan settings # from: https://stackoverflow.com/questions/68798315/how-to-update-plotly-plot-and-keep-ui-settings fig['layout']['height'] = 600 # px fig['layout']['height'] = 700 # px fig['layout']['uirevision'] = 'const' return fig Loading @@ -81,22 +94,34 @@ def update_graph_live(n): Input('interval-component', 'n_intervals')) def update_graph_live_v(n): # Read data from database pred_vx = f_db["VX"][:] pred_vy = f_db["VY"][:] pred_vz = f_db["VZ"][:] fig_v = go.Figure(data=go.Cone( x=X_POINTS.flatten(), y=Y_POINTS.flatten(), z=Z_POINTS.flatten(), pred_vx = f_db["VX"][:][PTX] pred_vy = f_db["VY"][:][PTX] pred_vz = f_db["VZ"][:][PTX] v_mag = np.sqrt(pred_vx ** 2. + pred_vy ** 2. + pred_vz ** 2.) fig_v = go.Figure(data=[go.Cone( x=X_POINTS[PTX], y=Y_POINTS[PTX], z=Z_POINTS[PTX], u=pred_vx, v=pred_vy, w=pred_vz, sizemode="absolute", sizeref=150, colorbar=dict(thickness=8, title="Velocity (m/s)"), )) fig_v['layout']['height'] = 600 # px # sizemode="absolute", sizeref=3, # colorbar=dict(thickness=8, title="Velocity (m/s)"), ), go.Scatter3d( x=X_POINTS[PTX], y=Y_POINTS[PTX], z=Z_POINTS[PTX], mode='markers', marker=dict(size=2, color=v_mag, opacity=0.65, colorbar=dict(thickness=5, title="Velocity (m/s)", ), ), ) ] ) fig_v['layout']['height'] = 700 # px fig_v['layout']['uirevision'] = 'const' return fig_v Loading dthydro_cfd/rom_cfd/pod_cfd_model.py +21 −6 Original line number Diff line number Diff line Loading @@ -47,7 +47,7 @@ def test_pod_cfd_model(use_plotly=True, snapshot_h5file="cfd_pod_snapshots.h5", n_pod_modes=5): # create the reduced order model(s) pod_model, xyz_points = construct_pod_model(snapshot_h5file, data_name="Pressure (Pa)") pod_model, xyz_points = construct_pod_model(snapshot_h5file, data_name="Pressure (Pa)", n_pod_modes=n_pod_modes) pod_model_vx, _ = construct_pod_model( snapshot_h5file, data_name="Velocity[i] (m/s)") Loading Loading @@ -119,10 +119,10 @@ def test_pod_cfd_model(use_plotly=True, print("Time to make plot: %0.4e (sec)" % (te-ts)) def dynamic_pod_model(snapshot_h5file="cfd_pod_snapshots.h5", n_pod_modes=5): def dynamic_pod_model(snapshot_h5file="cfd_pod_snapshots.h5", n_pod_modes=7): # create the reduced order model(s) pod_model, xyz_points = construct_pod_model(snapshot_h5file, data_name="Pressure (Pa)") pod_model, xyz_points = construct_pod_model(snapshot_h5file, data_name="Pressure (Pa)", n_pod_modes=n_pod_modes) pod_model_vx, _ = construct_pod_model( snapshot_h5file, data_name="Velocity[i] (m/s)") Loading @@ -148,19 +148,34 @@ def dynamic_pod_model(snapshot_h5file="cfd_pod_snapshots.h5", n_pod_modes=5): f_db.create_dataset("Z", data=Z) f_db.flush() current_vane_angle = 8.02 for t in range(100): current_vane_angle = 4.0 min_vane_angle = 4.0 max_vane_angle = 9.0 def get_test_vane_angle(t): """ Returns a vane angle between min and max val as a fn of time Args: t: time """ delta_va = max_vane_angle - min_vane_angle va = (np.sin(t / 8.) * 0.5 + 0.5) * delta_va + min_vane_angle return va for t in range(200): current_vane_angle = get_test_vane_angle(t) time.sleep(1) print("Eval vane angle: %0.2f" % current_vane_angle) ts = time.time() current_vane_angle = 8.02 pred_p = pod_model.predict(current_vane_angle) pred_vx = pod_model_vx.predict(current_vane_angle) pred_vy = pod_model_vy.predict(current_vane_angle) pred_vz = pod_model_vz.predict(current_vane_angle) pred_vmag = np.sqrt(pred_vx**2 + pred_vy**2 + pred_vz**2) te = time.time() print("Max predicted P: %0.4e (Pa)" % max(pred_p)) print("Max predicted V: %0.4e (m/s)" % max(pred_vmag)) print("Time to eval POD ROM: %0.4e (sec)" % (te-ts)) # write ROM eval data to db Loading Loading
dthydro_cfd/rom_cfd/pod_cfd_dash_app.py +55 −30 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ import time from dthydro_cfd.rom_cfd.pod_rom import PODInterpModel # plotly imports import plotly.graph_objects as go import plotly.express as px # dash imports import dash from dash import dcc, html Loading @@ -33,17 +34,18 @@ app.layout = html.Div( dcc.Graph(id='live-update-graph-vane'), dcc.Interval( id='interval-component', interval=2000, # in milliseconds interval=1000, # in milliseconds n_intervals=0 ) ]) ) X_POINTS = f_db["X"][:] Y_POINTS = f_db["Y"][:] Z_POINTS = f_db["Z"][:] X_POINTS = f_db["X"][:].flatten() Y_POINTS = f_db["Y"][:].flatten() Z_POINTS = f_db["Z"][:].flatten() # data thinning PTX = np.random.randint(0, len(X_POINTS), size=6000) P_ = None VA_ = None from collections import deque vane_history = deque(maxlen=50) time_history = deque(maxlen=50) Loading @@ -54,24 +56,35 @@ time_history = deque(maxlen=50) Input('interval-component', 'n_intervals')) def update_graph_live(n): global P_ global VA_ # Read data from database P_ = f_db["P"][:] VA_ = f_db["vane_angle"][:] fig = px.scatter_3d( x=X_POINTS[PTX], y=Y_POINTS[PTX], z=Z_POINTS[PTX], color=P_[PTX], range_color=[0., 400.e3], opacity=0.95, size_max=4, ) fig.update_traces(marker=dict(size=3)) # Draw new figure fig = go.Figure(data=go.Scatter3d( x=X_POINTS.flatten(), y=Y_POINTS.flatten(), z=Z_POINTS.flatten(), mode='markers', marker=dict(size=4, color=P_, opacity=0.9, colorbar=dict(thickness=5)), customdata=P_, hovertemplate=('%{customdata}%'), )) # fig = go.Figure(data=go.Scatter3d( # x=X_POINTS[PTX], # y=Y_POINTS[PTX], # z=Z_POINTS[PTX], # mode='markers', # marker=dict(size=3, color=P_[PTX], opacity=0.95, # colorbar=dict(thickness=5, title="Pressure (Pa)", ), # ), # customdata=P_[PTX], # hovertemplate=('%{customdata}%'), # )) # preserve zoom, pan settings # from: https://stackoverflow.com/questions/68798315/how-to-update-plotly-plot-and-keep-ui-settings fig['layout']['height'] = 600 # px fig['layout']['height'] = 700 # px fig['layout']['uirevision'] = 'const' return fig Loading @@ -81,22 +94,34 @@ def update_graph_live(n): Input('interval-component', 'n_intervals')) def update_graph_live_v(n): # Read data from database pred_vx = f_db["VX"][:] pred_vy = f_db["VY"][:] pred_vz = f_db["VZ"][:] fig_v = go.Figure(data=go.Cone( x=X_POINTS.flatten(), y=Y_POINTS.flatten(), z=Z_POINTS.flatten(), pred_vx = f_db["VX"][:][PTX] pred_vy = f_db["VY"][:][PTX] pred_vz = f_db["VZ"][:][PTX] v_mag = np.sqrt(pred_vx ** 2. + pred_vy ** 2. + pred_vz ** 2.) fig_v = go.Figure(data=[go.Cone( x=X_POINTS[PTX], y=Y_POINTS[PTX], z=Z_POINTS[PTX], u=pred_vx, v=pred_vy, w=pred_vz, sizemode="absolute", sizeref=150, colorbar=dict(thickness=8, title="Velocity (m/s)"), )) fig_v['layout']['height'] = 600 # px # sizemode="absolute", sizeref=3, # colorbar=dict(thickness=8, title="Velocity (m/s)"), ), go.Scatter3d( x=X_POINTS[PTX], y=Y_POINTS[PTX], z=Z_POINTS[PTX], mode='markers', marker=dict(size=2, color=v_mag, opacity=0.65, colorbar=dict(thickness=5, title="Velocity (m/s)", ), ), ) ] ) fig_v['layout']['height'] = 700 # px fig_v['layout']['uirevision'] = 'const' return fig_v Loading
dthydro_cfd/rom_cfd/pod_cfd_model.py +21 −6 Original line number Diff line number Diff line Loading @@ -47,7 +47,7 @@ def test_pod_cfd_model(use_plotly=True, snapshot_h5file="cfd_pod_snapshots.h5", n_pod_modes=5): # create the reduced order model(s) pod_model, xyz_points = construct_pod_model(snapshot_h5file, data_name="Pressure (Pa)") pod_model, xyz_points = construct_pod_model(snapshot_h5file, data_name="Pressure (Pa)", n_pod_modes=n_pod_modes) pod_model_vx, _ = construct_pod_model( snapshot_h5file, data_name="Velocity[i] (m/s)") Loading Loading @@ -119,10 +119,10 @@ def test_pod_cfd_model(use_plotly=True, print("Time to make plot: %0.4e (sec)" % (te-ts)) def dynamic_pod_model(snapshot_h5file="cfd_pod_snapshots.h5", n_pod_modes=5): def dynamic_pod_model(snapshot_h5file="cfd_pod_snapshots.h5", n_pod_modes=7): # create the reduced order model(s) pod_model, xyz_points = construct_pod_model(snapshot_h5file, data_name="Pressure (Pa)") pod_model, xyz_points = construct_pod_model(snapshot_h5file, data_name="Pressure (Pa)", n_pod_modes=n_pod_modes) pod_model_vx, _ = construct_pod_model( snapshot_h5file, data_name="Velocity[i] (m/s)") Loading @@ -148,19 +148,34 @@ def dynamic_pod_model(snapshot_h5file="cfd_pod_snapshots.h5", n_pod_modes=5): f_db.create_dataset("Z", data=Z) f_db.flush() current_vane_angle = 8.02 for t in range(100): current_vane_angle = 4.0 min_vane_angle = 4.0 max_vane_angle = 9.0 def get_test_vane_angle(t): """ Returns a vane angle between min and max val as a fn of time Args: t: time """ delta_va = max_vane_angle - min_vane_angle va = (np.sin(t / 8.) * 0.5 + 0.5) * delta_va + min_vane_angle return va for t in range(200): current_vane_angle = get_test_vane_angle(t) time.sleep(1) print("Eval vane angle: %0.2f" % current_vane_angle) ts = time.time() current_vane_angle = 8.02 pred_p = pod_model.predict(current_vane_angle) pred_vx = pod_model_vx.predict(current_vane_angle) pred_vy = pod_model_vy.predict(current_vane_angle) pred_vz = pod_model_vz.predict(current_vane_angle) pred_vmag = np.sqrt(pred_vx**2 + pred_vy**2 + pred_vz**2) te = time.time() print("Max predicted P: %0.4e (Pa)" % max(pred_p)) print("Max predicted V: %0.4e (m/s)" % max(pred_vmag)) print("Time to eval POD ROM: %0.4e (sec)" % (te-ts)) # write ROM eval data to db Loading