"""Union seam bodies and actual support pinning; CPU host-only.""" import unittest import numpy as np from CelerisLab.config import LBMConfig from CelerisLab.lbm.refinement import FixedPatchSet2D,prepare_fine_boundary,_circle_in_coverage from CelerisLab.lbm.synchronized_remap import same_physical_boundary from tests.unit import test_refinement as refinement_tests from tests.unit.test_pinned_body_remap import mesh,body,ready,A from tests.unit.test_synchronized_remap import fields,remap,integrals class UnionBodySupport(unittest.TestCase): def test_seam_circle_matches_single_rectangle(self): cfg=LBMConfig(nx=32,ny=16,viscosity=.1) obj=refinement_tests.PatchSetBoundaryTests.body(16.,8.) def b(rects):return prepare_fine_boundary(cfg,FixedPatchSet2D.from_config(cfg,rects),[obj]) self.assertTrue(same_physical_boundary(b([(4,2,28,14)]),b([(4,2,16,14),(16,2,28,14)]))) with self.assertRaisesRegex(ValueError,'union'): b([(4,2,16,14),(17,2,28,14)]) def test_continuous_disk_not_only_sampled_solids(self): mask=np.ones((8,8),bool);mask[3,3]=False self.assertFalse(_circle_in_coverage(mask,3.99,3.99,.02)) self.assertTrue(_circle_in_coverage(mask,4.1,4.1,.1)) def test_repartition_and_connected_fluid_changes_do_not_pin_rectangles(self): old=mesh(A,(body(),));initial=fields(old) for rects in (((16,16,24,40),(24,16,32,40),A[1]),((12,16,32,40),A[1]),((20,16,36,40),A[1])): new=mesh(rects,(body(),));self.assertTrue(same_physical_boundary(old.boundary,new.boundary)) out=remap(old,new,initial) np.testing.assert_allclose(integrals(old,initial),integrals(new,out.g),rtol=2e-13,atol=2e-12) for a,b,om,nm in zip(initial,out.g,old.leaf_masks,new.leaf_masks): np.testing.assert_array_equal(a[:,om&nm],b[:,om&nm]) def test_runtime_seam_repartition_preserves_boundary_and_live_jets(self): run,module,allocations,storage,objects=ready() try: run.set_jet_amplitude(0,.017,level=2) clone=run.remap_finest(((16,16,24,40),(24,16,32,40),A[1]),objects=objects) try: self.assertEqual(clone._level_boundaries[2].jets[0].amplitude,.017) self.assertTrue(same_physical_boundary(run.boundaries[2],clone.boundaries[2])) for a,b in zip(run.download(),clone.download()):np.testing.assert_array_equal(a,b) finally:clone.close() finally:run.close()