def test_conversion_reversible(lattice): units = UnitConversion(lattice, reynolds_number=1000, mach_number=0.05, characteristic_length_lu=100, characteristic_length_pu=2*np.pi, characteristic_velocity_pu=2, characteristic_density_pu=0.7) assert units.convert_velocity_to_lu(units.convert_velocity_to_pu(2.0)) == pytest.approx(2.0) assert units.convert_time_to_lu(units.convert_time_to_pu(2.0)) == pytest.approx(2.0) assert units.convert_length_to_lu(units.convert_length_to_pu(2.0)) == pytest.approx(2.0) assert units.convert_density_to_lu(units.convert_density_to_pu(2.0)) == pytest.approx(2.0) assert units.convert_pressure_to_lu(units.convert_pressure_to_pu(2.0)) == pytest.approx(2.0) assert units.convert_density_lu_to_pressure_pu(units.convert_pressure_pu_to_density_lu(2.0)) == pytest.approx(2.0) assert units.convert_energy_to_lu(units.convert_energy_to_pu(2.0)) == pytest.approx(2.0) assert units.convert_incompressible_energy_to_lu(units.convert_incompressible_energy_to_pu(2.0)) == pytest.approx(2.0)
def test_equilibrium_boundary_pu(f_lattice): f, lattice = f_lattice mask = (f[0] > 0).cpu().numpy() # will contain all points units = UnitConversion(lattice, reynolds_number=1) pressure = 0 velocity = 0.1 * np.ones(lattice.D) feq = lattice.equilibrium( lattice.convert_to_tensor( units.convert_pressure_pu_to_density_lu(pressure)), lattice.convert_to_tensor(units.convert_velocity_to_lu(velocity))) feq_field = torch.einsum("q,q...->q...", feq, torch.ones_like(f)) eq_boundary = EquilibriumBoundaryPU(mask, lattice, units, velocity=velocity, pressure=pressure) f = eq_boundary(f) assert f.cpu().numpy() == pytest.approx(feq_field.cpu().numpy())