Skip to content

Commit 5219d6f

Browse files
committed
add hdf5 output when plot response is used
1 parent c7da265 commit 5219d6f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pylbm_ui/responses.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#
66
# License: BSD 3 clause
77

8+
import os
89
import numpy as np
910
import sympy as sp
1011
import matplotlib.pyplot as plt
@@ -294,8 +295,14 @@ def __call__(self, sol):
294295
data[solid_cells[tuple(ind)]] = np.nan
295296

296297
fig, ax = plt.subplots()
298+
h5_file, _ = os.path.splitext(self.filename)
299+
h5_dir, h5_file = os.path.split(h5_file)
300+
h5 = pylbm.H5File(sol.domain.mpi_topo, f'{h5_file}_{sol.nt}', h5_dir)
301+
297302
if sol.dim == 1:
298303
x = sol.domain.x
304+
h5.set_grid(x)
305+
299306
ax.plot(x, data,
300307
color='black',
301308
alpha=0.8,
@@ -309,12 +316,17 @@ def __call__(self, sol):
309316
alpha=0.8,
310317
linewidth=1,
311318
)
319+
h5.add_scalar('sol_ref', self.ref_solution)
320+
312321
elif sol.dim == 2:
313322
x, y = sol.domain.x, sol.domain.y
323+
h5.set_grid(x, y)
314324
cmap = copy.copy(matplotlib.cm.get_cmap("RdBu"))
315325
cmap.set_bad('black', 0.8)
316326
extent = [np.amin(x), np.amax(x), np.amin(y), np.amax(y)]
317327
imshow = ax.imshow(data.T, origin='lower', cmap=cmap, extent=extent)
318328
fig.colorbar(imshow, ax=ax)
319329

330+
h5.add_scalar('sol', data)
320331
fig.savefig(self.filename, dpi=300)
332+
h5.save()

0 commit comments

Comments
 (0)