def save(mpi_topo, x, y, m, num): h5 = pylbm.H5File(mpi_topo, filename, path, num) h5.set_grid(x, y) h5.add_vector('velocity', [sol.m[qx], sol.m[qy]]) h5.add_scalar('Vx', sol.m[qx]) h5.add_scalar('T', sol.m[T]) h5.save()
def save(mpi_topo, x, y, m, num): h5 = pylbm.H5File(mpi_topo, filename, path, num) h5.set_grid(x, y) h5.add_scalar('rho', m[rho]) h5.add_scalar('E', m[E]) h5.add_vector('velocity', [m[qx], m[qy]]) h5.add_vector('B', [m[Bx], m[By]]) h5.save()
def save(sol, im): x, y, z = sol.domain.x, sol.domain.y, sol.domain.z h5 = pylbm.H5File(sol.mpi_topo, 'karman', './karman', im) h5.set_grid(x, y, z) h5.add_scalar('rho', sol.m[rho]) qx_n, qy_n, qz_n = sol.m[qx], sol.m[qy], sol.m[qz] h5.add_vector('velocity', [qx_n, qy_n, qz_n]) h5.save()
def save(sol, num): x, y, z = sol.domain.x, sol.domain.y, sol.domain.z h5 = pylbm.H5File(sol.domain.mpi_topo, 'poiseuille', './poiseuille', num) h5.set_grid(x, y, z) h5.add_scalar('pressure', sol.m[p]) qx_n, qy_n, qz_n = sol.m[ux], sol.m[uy], sol.m[uz] h5.add_vector('velocity', [qx_n, qy_n, qz_n]) h5.save()
def save(sol, im): x, y, z = sol.domain.x, sol.domain.y, sol.domain.z h5 = pylbm.H5File(sol.mpi_topo, 'lid_cavity', './lid_cavity', im) h5.set_grid(x, y, z) h5.add_scalar('mass', sol.m[mass]) qx_n, qy_n, qz_n = sol.m[qx], sol.m[qy], sol.m[qz] h5.add_vector('velocity', [qx_n, qy_n, qz_n]) h5.save()
def write(filename, data): grid = [data.domain.x] if data.dim > 1: grid.append(data.domain.y) if data.dim == 3: grid.append(data.domain.z) h5 = pylbm.H5File(data.domain.mpi_topo, os.path.basename(filename), os.path.dirname(filename)) h5.set_grid(*grid) slices = [] for i in data.domain.in_or_out.shape: slices.append(slice(1, i - 1)) slices = tuple(slices) for consm in data.scheme.consm.keys(): clean_data = data.m[consm].copy() clean_data[data.domain.in_or_out[slices] != data.domain.valin] = 0 h5.add_scalar(consm.name, clean_data) h5.save()
def save_data(self, field): has_ref = hasattr(self.test_case, 'ref_solution') if isinstance(field, set): filename = 'solution' else: filename = f'{field}' h5 = pylbm.H5File(self.sol.domain.mpi_topo, filename, self.path, self.sol.nt) if self.sol.dim == 1: h5.set_grid(self.sol.domain.x) elif self.sol.dim == 2: h5.set_grid(self.sol.domain.x, self.sol.domain.y) def save_one_field(f): data = self.get_data(f) h5.add_scalar(f, data) if has_ref: if self.sol.dim == 1: data_ref = self.test_case.ref_solution( self.sol.t, self.sol.domain.x, f) elif self.sol.dim == 2: data_ref = self.test_case.ref_solution( self.sol.t, self.sol.domain.x, self.sol.domain.y, f) else: data_ref = self.test_case.ref_solution( self.sol.t, self.sol.domain.x, self.sol.domain.y, self.sol.domain.z, f) h5.add_scalar(f'{f}_ref', data_ref) if isinstance(field, set): for f in field: save_one_field(f) else: save_one_field(field) h5.save()
def save_data(self, field): if isinstance(field, set): filename = 'solution' else: filename = f'{field}' h5 = pylbm.H5File(self.sol.domain.mpi_topo, filename, self.path, self.sol.nt) if self.sol.dim == 1: h5.set_grid(self.sol.domain.x) elif self.sol.dim == 2: h5.set_grid(self.sol.domain.x, self.sol.domain.y) if isinstance(field, set): for f in field: data = self.get_data(f) h5.add_scalar(f, data) else: data = self.get_data(field) h5.add_scalar(field, data) h5.save()
def save(sol, im): x, y, z = sol.domain.x, sol.domain.y, sol.domain.z h5 = pylbm.H5File(sol.mpi_topo, 'rayleigh-benard', './rayleigh-benard', im) h5.set_grid(x, y, z) h5.add_scalar('T', sol.m[T]) h5.save()
def save(sol, im): x, y, z = sol.domain.x, sol.domain.y, sol.domain.z h5 = pylbm.H5File(sol.domain.mpi_topo, 'advection', './advection', im) h5.set_grid(x, y, z) h5.add_scalar('u', sol.m[u]) h5.save()
def save(sol, filename, path, num): h5 = pylbm.H5File(sol.domain.mpi_topo, filename, path, num) h5.set_grid(sol.domain.x, sol.domain.y) h5.add_scalar('rho', sol.m[rho]) h5.save()
def __call__(self, sol): func = sp.lambdify(list(self.expr.atoms(sp.Symbol)), self.expr, "numpy", dummify=False) to_subs = {str(k): sol.m[k] for k in sol.scheme.consm.keys()} to_subs.update({str(k): v for k, v in sol.scheme.param.items()}) args = {str(s): to_subs[str(s)] for s in self.expr.atoms(sp.Symbol)} data = func(**args) solid_cells = sol.domain.in_or_out != sol.domain.valin vmax = sol.domain.stencil.vmax ind = [] for vm in vmax: ind.append(slice(vm, -vm)) ind = np.asarray(ind) data[solid_cells[tuple(ind)]] = np.nan fig, ax = plt.subplots() h5_file, _ = os.path.splitext(self.filename) h5_dir, h5_file = os.path.split(h5_file) h5 = pylbm.H5File(sol.domain.mpi_topo, f'{h5_file}_{sol.nt}', h5_dir) if sol.dim == 1: x = sol.domain.x h5.set_grid(x) ax.plot( x, data, color='black', alpha=0.8, linewidth=2, marker='.', markersize=10, ) if self.ref_solution is not None: ax.plot( x, self.ref_solution, color='black', alpha=0.8, linewidth=1, ) h5.add_scalar('sol_ref', self.ref_solution) elif sol.dim == 2: x, y = sol.domain.x, sol.domain.y h5.set_grid(x, y) cmap = copy.copy(matplotlib.cm.get_cmap("RdBu")) cmap.set_bad('black', 0.8) extent = [np.amin(x), np.amax(x), np.amin(y), np.amax(y)] imshow = ax.imshow(data.T, origin='lower', cmap=cmap, extent=extent) fig.colorbar(imshow, ax=ax) h5.add_scalar('sol', data) fig.savefig(self.filename, dpi=300) h5.save()