def initialize_pressure(self, max_num_steps=100000, tol_pressure=1e-6): """Reinitialize equilibrium distributions with pressure obtained by a Jacobi solver. Note that this method has to be called before initialize_f_neq. """ u = self.lattice.u(self.f) rho = pressure_poisson(self.flow.units, self.lattice.u(self.f), self.lattice.rho(self.f), tol_abs=tol_pressure, max_num_steps=max_num_steps) self.f = self.lattice.equilibrium(rho, u)
def test_pressure_poisson(dtype_device, Stencil): dtype, device = dtype_device lattice = Lattice(Stencil(), device, dtype) flow_class = TaylorGreenVortex2D if Stencil is D2Q9 else TaylorGreenVortex3D flow = flow_class(resolution=32, reynolds_number=100, mach_number=0.05, lattice=lattice) p0, u = flow.initial_solution(flow.grid) u = flow.units.convert_velocity_to_lu(lattice.convert_to_tensor(u)) rho0 = flow.units.convert_pressure_pu_to_density_lu(lattice.convert_to_tensor(p0)) rho = pressure_poisson(flow.units, u, torch.ones_like(rho0)) pfinal = flow.units.convert_density_lu_to_pressure_pu(rho).cpu().numpy() print(p0.max(), p0.min(), p0.mean(), pfinal.max(), pfinal.min(), pfinal.mean()) print((p0 - pfinal).max(), (p0 - pfinal).min()) assert p0 == pytest.approx(pfinal, rel=0.0, abs=0.05)