Remove MRT from the FixedPatch2D rejection matrix (TRT and other rejections retained); convert host MRT tests to stdlib unittest; add GPU gates for unshifted dense-vs-blocked MRT two-level roots (exact bits) and a shifted all-blocked three-level MRT smoke checking per-level omega. No numerical source change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
45 lines
2.2 KiB
Python
45 lines
2.2 KiB
Python
"""Host guards and source contract for MRT reuse in refined/blocked stepping (no CUDA)."""
|
|
from pathlib import Path
|
|
import unittest
|
|
|
|
from CelerisLab.config import LBMConfig
|
|
from CelerisLab.lbm.refinement import FixedPatch2D
|
|
|
|
KERNELS = Path(__file__).resolve().parents[2] / "src/CelerisLab/lbm/kernels"
|
|
BOUNDS = (8, 6, 16, 14)
|
|
|
|
|
|
class RefinementMRTHost(unittest.TestCase):
|
|
def test_patch_accepts_implemented_models(self):
|
|
for collision in ("SRT", "MRT"):
|
|
with self.subTest(collision=collision):
|
|
FixedPatch2D.from_config(LBMConfig(nx=24, ny=20, viscosity=.1, collision=collision), BOUNDS)
|
|
|
|
def test_patch_rejects_unimplemented(self):
|
|
for options in (dict(collision="TRT"), dict(collision="MRT", les_enabled=True)):
|
|
with self.subTest(options=options), self.assertRaises(ValueError):
|
|
FixedPatch2D.from_config(LBMConfig(nx=24, ny=20, viscosity=.1, **options), BOUNDS)
|
|
|
|
def test_srt_statements_and_guards_preserved(self):
|
|
"""MRT is an additive compile-time branch; SRT statements and other guards remain."""
|
|
blocks = (KERNELS / "blocks.cu").read_text()
|
|
channel = (KERNELS / "step/block_channel.cu").read_text()
|
|
refinement = (KERNELS / "refinement.cu").read_text()
|
|
for text in ("compute_feq_from_momentum(drho, jx, jy, ux, uy, feq);",
|
|
"compute_feq(rho, ux, uy, feq);",
|
|
"collide_srt_no_force(f, feq, d_params.omega);"):
|
|
self.assertIn(text, blocks)
|
|
self.assertIn("collide_srt(f, feq, forcing, omega);", channel)
|
|
self.assertIn("collide_srt_no_force(f, feq, d_params.omega);", refinement)
|
|
for source in (blocks, refinement):
|
|
self.assertIn("(COLLISION_MODEL != 0 && COLLISION_MODEL != 2)", source)
|
|
self.assertIn("USE_LES", source)
|
|
self.assertIn("STORE_PRECISION != 0", source)
|
|
self.assertIn('#if COLLISION_MODEL == 2\n#include "operators/collision_mrt.cuh"\n#endif', source)
|
|
self.assertIn("USE_DDF_SHIFTING ||", refinement) # dense/mixed shifted stays rejected
|
|
for source in (blocks, channel, refinement):
|
|
self.assertEqual(source.count("collide_mrt_no_force("), 1)
|
|
|
|
|
|
if __name__ == "__main__": unittest.main()
|