test: add opt-in shifted FP32 Jet CV control

This commit is contained in:
2026-10-18 02:34:54 -07:00
parent 80546a0d95
commit 17f3f11007
3 changed files with 73 additions and 4 deletions
+35
View File
@@ -28,6 +28,41 @@ def eq(rho, u, v):
class Host(unittest.TestCase):
def test_shifted_storage_receipt_preserves_physical_case(self):
for scale in (1, 2):
base = case(scale)
shifted = case(scale, ddf_shifting=True)
self.assertFalse(base.pop("ddf_shifting"))
self.assertTrue(shifted.pop("ddf_shifting"))
self.assertEqual(base.pop("storage_variant")["name"], "unshifted_fp32")
self.assertEqual(shifted.pop("storage_variant")["name"], "shifted_fp32")
self.assertEqual(base, shifted)
def test_shifted_physical_download_roundtrip(self):
from CelerisLab.lbm.population_storage import _encode_physical, _decode_stored
from run_jet_circle_cv import moments
from jet_cv_measurements import primitives
for speed in (0.03, 0.015):
seed = state((9, 48, 64), speed)
self.assertEqual(seed.dtype, np.float32)
plain = _decode_stored(_encode_physical(seed, False), False)
decoded = _decode_stored(_encode_physical(seed, True), True)
self.assertEqual(decoded.dtype, np.float64)
np.testing.assert_array_equal(plain, seed)
# Same FP32 physical seed; only encoding quantization may differ.
np.testing.assert_allclose(decoded, seed, rtol=0, atol=3e-10)
rho, momentum, velocity = moments(decoded)
rho2, velocity2 = primitives(decoded, CX, CY)
np.testing.assert_array_equal(rho, rho2)
np.testing.assert_array_equal(velocity, velocity2)
np.testing.assert_allclose(momentum, rho * velocity, atol=1e-17)
fluid = np.ones(seed.shape[1:], bool)
inv, flux = cv(decoded, fluid, (0, 0), (5, 4, 25, 20), 0.0072)
expected, _ = cv(seed, fluid, (0, 0), (5, 4, 25, 20), 0.0072)
np.testing.assert_allclose(inv, expected, rtol=0, atol=1e-6)
np.testing.assert_allclose(flux, 0, atol=1e-14)
def test_descriptor_and_uniform_closed_flux(self):
from CelerisLab.lbm.descriptors import D2Q9_EX, D2Q9_EY