Beispiel #1
0
def test_grid_fine_to_coarse_3d():
    lattice = Lattice(D3Q27, 'cpu', dtype=torch.double)

    flow_f = TaylorGreenVortex3D(40, 1600, 0.15, lattice)
    collision_f = BGKCollision(lattice,
                               tau=flow_f.units.relaxation_parameter_lu)
    sim_f = Simulation(flow_f, lattice, collision_f, streaming=None)

    flow_c = TaylorGreenVortex3D(20, 1600, 0.15, lattice)
    collision_c = BGKCollision(lattice,
                               tau=flow_c.units.relaxation_parameter_lu)
    sim_c = Simulation(flow_c, lattice, collision_c, streaming=None)

    f_c = grid_fine_to_coarse(lattice, sim_f.f,
                              flow_f.units.relaxation_parameter_lu,
                              flow_c.units.relaxation_parameter_lu)

    p_c_init, u_c_init = flow_c.initial_solution(flow_c.grid)
    rho_c_init = flow_c.units.convert_pressure_pu_to_density_lu(p_c_init)
    u_c_init = flow_c.units.convert_velocity_to_lu(u_c_init)
    shear_c_init = lattice.shear_tensor(sim_c.f)
    shear_c = lattice.shear_tensor(f_c)

    assert np.isclose(lattice.u(f_c).cpu().numpy(), u_c_init).all()
    assert np.isclose(lattice.rho(f_c).cpu().numpy(), rho_c_init).all()
    assert torch.isclose(f_c, sim_c.f).all()
    assert torch.isclose(shear_c_init, shear_c).all()
Beispiel #2
0
 def __call__(self, i, t, f):
     if i % self.interval == 0:
         self.fs.append(
             grid_fine_to_coarse(lattice, f.clone(), tau_fine,
                                 tau_coarse).cpu())