Datasets:
added dataloader
Browse files- README.md +52 -1
- data_vis.ipynb +0 -0
- fsi_animation.gif → fsi_animation_dx.gif +2 -2
- fsi_animation_pressue.gif +3 -0
- fsi_reader.py +30 -5
- plotting.py +174 -0
README.md
CHANGED
|
@@ -6,4 +6,55 @@ tags:
|
|
| 6 |
- physics
|
| 7 |
- Fluid-Solid-Interaction
|
| 8 |
- Fluid-Dynamics
|
| 9 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
- physics
|
| 7 |
- Fluid-Solid-Interaction
|
| 8 |
- Fluid-Dynamics
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
## Dataset Description: Fluid-Solid Interaction Simulations
|
| 12 |
+
|
| 13 |
+
For each time step \( t \), the simulation records the following variables:
|
| 14 |
+
|
| 15 |
+
### **Velocity**
|
| 16 |
+
\[
|
| 17 |
+
\mathbf{v}_t = \begin{bmatrix} v_{x,t} \\ v_{y,t} \end{bmatrix}
|
| 18 |
+
\]
|
| 19 |
+
where \( v_{x,t} \) and \( v_{y,t} \) are the velocity components in the \( x \) and \( y \) directions, respectively.
|
| 20 |
+
|
| 21 |
+
### **Pressure**
|
| 22 |
+
\[
|
| 23 |
+
P_t
|
| 24 |
+
\]
|
| 25 |
+
which represents the pressure field at time \( t \).
|
| 26 |
+
|
| 27 |
+
### **Displacement**
|
| 28 |
+
\[
|
| 29 |
+
\mathbf{d}_t = \begin{bmatrix} d_{x,t} \\ d_{y,t} \end{bmatrix}
|
| 30 |
+
\]
|
| 31 |
+
where \( d_{x,t} \) and \( d_{y,t} \) denote the displacement in the \( x \) and \( y \) directions, respectively.
|
| 32 |
+
|
| 33 |
+
---
|
| 34 |
+
|
| 35 |
+
## **Mesh Representation**
|
| 36 |
+
The initial mesh is given by:
|
| 37 |
+
\[
|
| 38 |
+
\mathbf{M}_0 = \begin{bmatrix} x_1 & y_1 \\ x_2 & y_2 \\ \vdots & \vdots \\ x_N & y_N \end{bmatrix} \in \mathbb{R}^{N \times 2}
|
| 39 |
+
\]
|
| 40 |
+
where each row \( (x_i, y_i) \) represents a mesh point in 2D space.
|
| 41 |
+
|
| 42 |
+
Since the mesh is time-dependent, the mesh at time \( t \) is updated based on displacement:
|
| 43 |
+
|
| 44 |
+
\[
|
| 45 |
+
\mathbf{M}_t = \mathbf{M}_0 + \mathbf{d}_t
|
| 46 |
+
\]
|
| 47 |
+
|
| 48 |
+
where
|
| 49 |
+
\[
|
| 50 |
+
\mathbf{d}_t = \begin{bmatrix} d_{x,t,1} & d_{y,t,1} \\ d_{x,t,2} & d_{y,t,2} \\ \vdots & \vdots \\ d_{x,t,N} & d_{y,t,N} \end{bmatrix} \in \mathbb{R}^{N \times 2}
|
| 51 |
+
\]
|
| 52 |
+
is the displacement field at time \( t \).
|
| 53 |
+
|
| 54 |
+
Thus, the updated coordinates of the mesh points at time \( t \) are:
|
| 55 |
+
|
| 56 |
+
\[
|
| 57 |
+
(x_i^t, y_i^t) = (x_i^0 + d_{x,t,i}, y_i^0 + d_{y,t,i}) \quad \forall i = 1, \dots, N
|
| 58 |
+
\]
|
| 59 |
+
|
| 60 |
+
This formulation describes how the mesh deforms over time due to displacement.
|
data_vis.ipynb
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
fsi_animation.gif → fsi_animation_dx.gif
RENAMED
|
File without changes
|
fsi_animation_pressue.gif
ADDED
|
Git LFS Details
|
fsi_reader.py
CHANGED
|
@@ -8,14 +8,38 @@ import h5py
|
|
| 8 |
class FsiDataReader():
|
| 9 |
def __init__(self,
|
| 10 |
location,
|
| 11 |
-
mu
|
| 12 |
in_lets_x1=None,
|
| 13 |
in_lets_x2=None,):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
self.location = location
|
| 15 |
self._x1 = ['-4.0', '-2.0', '0.0', '2.0', '4.0', '6.0']
|
| 16 |
self._x2 = ['-4.0', '-2.0', '0', '2.0', '4.0', '6.0']
|
| 17 |
self._mu = ['0.1', '0.01', '0.5', '5', '1.0', '10.0']
|
| 18 |
-
# keeping vx,xy, P, dx,dy
|
| 19 |
self.varable_idices = [0, 1, 3, 4, 5]
|
| 20 |
|
| 21 |
if mu is not None:
|
|
@@ -33,6 +57,7 @@ class FsiDataReader():
|
|
| 33 |
|
| 34 |
# assert _mu = 0.5 should not be mixed with other mu values
|
| 35 |
assert not('0.5' in self._mu and len(self._mu) > 1), "mu=0.5 should not be mixed with other mu values"
|
|
|
|
| 36 |
|
| 37 |
|
| 38 |
def load_mesh(self, location):
|
|
@@ -138,10 +163,10 @@ class FsiDataReader():
|
|
| 138 |
for x2 in self._x2:
|
| 139 |
try:
|
| 140 |
if mu == 0.5:
|
| 141 |
-
mu_data = self.get_data_txt(mu, x1, x2)
|
| 142 |
else:
|
| 143 |
-
mu_data =
|
| 144 |
-
mu_data_t0 = mu_data[:1,:,:]
|
| 145 |
mu_data_t1 = mu_data[1:,:,:]
|
| 146 |
data_t0.append(mu_data_t0)
|
| 147 |
data_t1.append(mu_data_t1)
|
|
|
|
| 8 |
class FsiDataReader():
|
| 9 |
def __init__(self,
|
| 10 |
location,
|
| 11 |
+
mu,
|
| 12 |
in_lets_x1=None,
|
| 13 |
in_lets_x2=None,):
|
| 14 |
+
'''
|
| 15 |
+
Data set of fluid solid interaction simulations.
|
| 16 |
+
At each time step t, the simulataion records 5 variables:
|
| 17 |
+
velocity_t = [vx_t, vy_t]: velocity in x and y direction,
|
| 18 |
+
P_t: pressure,
|
| 19 |
+
displacment_t = [dx_t, dy_t]: displacement in x and y direction.
|
| 20 |
+
|
| 21 |
+
The inital mesh is loaded as self.input_mesh. The mesh is a 2D mesh with 2 columns. The first column is the x coordinate and the second column is the y coordinate.
|
| 22 |
+
|
| 23 |
+
The mesh is time dependent i.e., the mesh changes with time.
|
| 24 |
+
The mesh at time t is given by mesh_t = self.input_mesh + displacement_t.
|
| 25 |
+
|
| 26 |
+
Parameters
|
| 27 |
+
----------
|
| 28 |
+
location : str
|
| 29 |
+
path to the directory containing the data
|
| 30 |
+
mu : list, optional
|
| 31 |
+
list mu vlues. The siumulations corresponding to the mu values will be loaded. The values should be one of ['0.1', '0.01', '0.5', '5', '1.0', '10.0'] and slould exactly match the string values given here. The mu='0.5' should not be loaded separately.
|
| 32 |
+
in_lets_x1, : list, optional
|
| 33 |
+
list of x1 parameter controlling the inlet boundary condition of the simulation. The values should be one of ['-4.0', '-2.0', '0.0', '2.0', '4.0', '6.0'] and slould exactly match the string values given here. default is None, which loads all the values.
|
| 34 |
+
in_lets_x2 : list, optional
|
| 35 |
+
list of x2 parameter controlling the inlet boundary condition of the simulation. The values should be one of ['-4.0', '-2.0', '0.0', '2.0', '4.0', '6.0'] and slould exactly match the string values given here. default is None, which loads all the values.
|
| 36 |
+
|
| 37 |
+
'''
|
| 38 |
self.location = location
|
| 39 |
self._x1 = ['-4.0', '-2.0', '0.0', '2.0', '4.0', '6.0']
|
| 40 |
self._x2 = ['-4.0', '-2.0', '0', '2.0', '4.0', '6.0']
|
| 41 |
self._mu = ['0.1', '0.01', '0.5', '5', '1.0', '10.0']
|
| 42 |
+
# keeping vx, xy, P, dx,dy
|
| 43 |
self.varable_idices = [0, 1, 3, 4, 5]
|
| 44 |
|
| 45 |
if mu is not None:
|
|
|
|
| 57 |
|
| 58 |
# assert _mu = 0.5 should not be mixed with other mu values
|
| 59 |
assert not('0.5' in self._mu and len(self._mu) > 1), "mu=0.5 should not be mixed with other mu values"
|
| 60 |
+
self.load_mesh(location)
|
| 61 |
|
| 62 |
|
| 63 |
def load_mesh(self, location):
|
|
|
|
| 163 |
for x2 in self._x2:
|
| 164 |
try:
|
| 165 |
if mu == 0.5:
|
| 166 |
+
mu_data = self.get_data_txt(mu, x1, x2)
|
| 167 |
else:
|
| 168 |
+
mu_data = self.get_data(mu, x1, x2)
|
| 169 |
+
mu_data_t0 = mu_data[:-1,:,:]
|
| 170 |
mu_data_t1 = mu_data[1:,:,:]
|
| 171 |
data_t0.append(mu_data_t0)
|
| 172 |
data_t1.append(mu_data_t1)
|
plotting.py
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fsi_reader import FsiDataReader
|
| 2 |
+
import matplotlib.pyplot as plt
|
| 3 |
+
import numpy as np
|
| 4 |
+
from matplotlib.tri import Triangulation
|
| 5 |
+
from matplotlib.animation import FuncAnimation
|
| 6 |
+
from scipy.interpolate import griddata
|
| 7 |
+
|
| 8 |
+
def single_plot(data, mesh_points):
|
| 9 |
+
data = np.squeeze(data) # Shape becomes (1317,)
|
| 10 |
+
print(data.shape)
|
| 11 |
+
print(mesh_points.shape)
|
| 12 |
+
x, y = mesh_points[:, 0], mesh_points[:, 1]
|
| 13 |
+
|
| 14 |
+
# Create figure with subplots
|
| 15 |
+
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(16, 6),
|
| 16 |
+
gridspec_kw={'width_ratios': [1, 1.2]})
|
| 17 |
+
|
| 18 |
+
# Approach 1: Triangulation-based contour plot
|
| 19 |
+
tri = Triangulation(x, y)
|
| 20 |
+
contour = ax1.tricontourf(tri, data, levels=40, cmap='viridis')
|
| 21 |
+
fig.colorbar(contour, ax=ax1, label='Value', shrink=0.3)
|
| 22 |
+
ax1.set_title('Contour Plot of Field Data')
|
| 23 |
+
ax1.set_aspect('equal')
|
| 24 |
+
|
| 25 |
+
# Approach 2: Scatter plot with interpolated background
|
| 26 |
+
grid_x, grid_y = np.mgrid[x.min():x.max():100j, y.min():y.max():100j]
|
| 27 |
+
grid_z = griddata((x, y), data, (grid_x, grid_y), method='cubic')
|
| 28 |
+
|
| 29 |
+
im = ax2.imshow(grid_z.T, origin='lower', extent=[x.min(), x.max(),
|
| 30 |
+
y.min(), y.max()], cmap='plasma')
|
| 31 |
+
ax2.scatter(x, y, c=data, edgecolor='k', lw=0.3, cmap='plasma', s=15)
|
| 32 |
+
fig.colorbar(im, ax=ax2, label='Interpolated Value', shrink=0.3)
|
| 33 |
+
ax2.set_title('Interpolated Surface with Sample Points')
|
| 34 |
+
|
| 35 |
+
# Common formatting
|
| 36 |
+
for ax in (ax1, ax2):
|
| 37 |
+
ax.set_xlabel('X Coordinate')
|
| 38 |
+
ax.set_ylabel('Y Coordinate')
|
| 39 |
+
ax.grid(True, alpha=0.3)
|
| 40 |
+
|
| 41 |
+
plt.tight_layout()
|
| 42 |
+
plt.show()
|
| 43 |
+
|
| 44 |
+
def create_field_animation(data_frames, mesh_frames, interval=100, save_path=None):
|
| 45 |
+
"""
|
| 46 |
+
Create an animation of time-varying 2D field data on a mesh.
|
| 47 |
+
|
| 48 |
+
Parameters:
|
| 49 |
+
-----------
|
| 50 |
+
data_frames : list of arrays
|
| 51 |
+
List of data arrays for each time frame (each with shape [1, 1317, 1] or similar)
|
| 52 |
+
mesh_frames : list of arrays or single array
|
| 53 |
+
Either a list of mesh coordinates for each frame or a single fixed mesh
|
| 54 |
+
interval : int
|
| 55 |
+
Delay between animation frames in milliseconds
|
| 56 |
+
save_path : str, optional
|
| 57 |
+
Path to save the GIF animation
|
| 58 |
+
"""
|
| 59 |
+
|
| 60 |
+
plt.rcParams.update({
|
| 61 |
+
'font.size': 20, # Base font size
|
| 62 |
+
'axes.titlesize': 20, # Title font size
|
| 63 |
+
'axes.labelsize': 20, # Axis label size
|
| 64 |
+
'xtick.labelsize': 20, # X-tick label size
|
| 65 |
+
'ytick.labelsize': 18, # Y-tick label size
|
| 66 |
+
'figure.titlesize': 22 # Super title size (if used)
|
| 67 |
+
})
|
| 68 |
+
|
| 69 |
+
# Determine if mesh is fixed or time-varying
|
| 70 |
+
mesh_varying = isinstance(mesh_frames, list)
|
| 71 |
+
|
| 72 |
+
# Get initial mesh and data
|
| 73 |
+
mesh_initial = mesh_frames[0] if mesh_varying else mesh_frames
|
| 74 |
+
data_initial = np.squeeze(data_frames[0])
|
| 75 |
+
|
| 76 |
+
# Extract coordinates
|
| 77 |
+
x, y = mesh_initial[:, 0], mesh_initial[:, 1]
|
| 78 |
+
|
| 79 |
+
# Create figure
|
| 80 |
+
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(50, 10),
|
| 81 |
+
gridspec_kw={'width_ratios': [1.5, 1.5]})
|
| 82 |
+
|
| 83 |
+
# Calculate global min/max for consistent colorbars
|
| 84 |
+
all_data = np.concatenate([np.squeeze(frame) for frame in data_frames])
|
| 85 |
+
vmin, vmax = all_data.min(), all_data.max()
|
| 86 |
+
|
| 87 |
+
# Create initial triangulation
|
| 88 |
+
tri_initial = Triangulation(x, y)
|
| 89 |
+
|
| 90 |
+
# Set up first subplot - contour
|
| 91 |
+
contour = ax1.tricontourf(tri_initial, data_initial, levels=40, cmap='viridis',
|
| 92 |
+
vmin=vmin, vmax=vmax)
|
| 93 |
+
# Add contour lines for better visibility
|
| 94 |
+
contour_lines = ax1.tricontour(tri_initial, data_initial, levels=15,
|
| 95 |
+
colors='black', linewidths=0.5, alpha=0.7)
|
| 96 |
+
|
| 97 |
+
fig.colorbar(contour, ax=ax1, label='Value', shrink=0.3)
|
| 98 |
+
ax1.set_title('Contour Plot of Field Data')
|
| 99 |
+
ax1.set_aspect('equal')
|
| 100 |
+
|
| 101 |
+
# Set up second subplot - interpolated surface with scatter points
|
| 102 |
+
grid_x, grid_y = np.mgrid[x.min():x.max():100j, y.min():y.max():100j]
|
| 103 |
+
grid_z = griddata((x, y), data_initial, (grid_x, grid_y), method='cubic')
|
| 104 |
+
|
| 105 |
+
im = ax2.imshow(grid_z.T, origin='lower', extent=[x.min(), x.max(),
|
| 106 |
+
y.min(), y.max()],
|
| 107 |
+
cmap='plasma', vmin=vmin, vmax=vmax)
|
| 108 |
+
scat = ax2.scatter(x, y, c=data_initial, edgecolor='k', lw=0.3,
|
| 109 |
+
cmap='plasma', s=15, vmin=vmin, vmax=vmax)
|
| 110 |
+
|
| 111 |
+
fig.colorbar(im, ax=ax2, label='Interpolated Value', shrink=0.3)
|
| 112 |
+
ax2.set_title('Interpolated Surface with Sample Points')
|
| 113 |
+
|
| 114 |
+
# Common formatting
|
| 115 |
+
for ax in (ax1, ax2):
|
| 116 |
+
ax.set_xlabel('X Coordinate')
|
| 117 |
+
ax.set_ylabel('Y Coordinate')
|
| 118 |
+
ax.grid(True, alpha=0.3)
|
| 119 |
+
|
| 120 |
+
# Add frame counter
|
| 121 |
+
time_text = ax1.text(0.02, 0.98, '', transform=ax1.transAxes,
|
| 122 |
+
fontsize=10, va='top', ha='left')
|
| 123 |
+
|
| 124 |
+
plt.tight_layout()
|
| 125 |
+
|
| 126 |
+
# Update function for animation
|
| 127 |
+
def update(frame):
|
| 128 |
+
# Get current data
|
| 129 |
+
data = np.squeeze(data_frames[frame])
|
| 130 |
+
|
| 131 |
+
# Get current mesh if varying
|
| 132 |
+
if mesh_varying:
|
| 133 |
+
mesh = mesh_frames[frame]
|
| 134 |
+
x, y = mesh[:, 0], mesh[:, 1]
|
| 135 |
+
tri = Triangulation(x, y)
|
| 136 |
+
else:
|
| 137 |
+
mesh = mesh_frames
|
| 138 |
+
x, y = mesh[:, 0], mesh[:, 1]
|
| 139 |
+
tri = tri_initial
|
| 140 |
+
|
| 141 |
+
# Update contour plot
|
| 142 |
+
for c in ax1.collections:
|
| 143 |
+
c.remove()
|
| 144 |
+
new_contour = ax1.tricontourf(tri, data, levels=40, cmap='viridis',
|
| 145 |
+
vmin=vmin, vmax=vmax)
|
| 146 |
+
new_lines = ax1.tricontour(tri, data, levels=15, colors='black',
|
| 147 |
+
linewidths=0.5, alpha=0.7)
|
| 148 |
+
|
| 149 |
+
# Update interpolated surface
|
| 150 |
+
grid_z = griddata((x, y), data, (grid_x, grid_y), method='cubic')
|
| 151 |
+
im.set_array(grid_z.T)
|
| 152 |
+
|
| 153 |
+
# Update scatter points
|
| 154 |
+
scat.set_offsets(mesh)
|
| 155 |
+
scat.set_array(data)
|
| 156 |
+
|
| 157 |
+
# Update frame counter
|
| 158 |
+
time_text.set_text(f'Frame: {frame+1}/{len(data_frames)}')
|
| 159 |
+
|
| 160 |
+
return [new_contour, new_lines, im, scat, time_text]
|
| 161 |
+
|
| 162 |
+
# Create animation
|
| 163 |
+
anim = FuncAnimation(fig, update, frames=len(data_frames),
|
| 164 |
+
interval=interval, blit=False)
|
| 165 |
+
|
| 166 |
+
# Save if path provided
|
| 167 |
+
if save_path:
|
| 168 |
+
print(f"Saving animation to {save_path}...")
|
| 169 |
+
if save_path.endswith('.gif'):
|
| 170 |
+
anim.save(save_path, writer='pillow', dpi=150)
|
| 171 |
+
else:
|
| 172 |
+
anim.save(save_path, writer='ffmpeg', dpi=150)
|
| 173 |
+
|
| 174 |
+
return anim
|