Example #1
0
    def test_orientation_channel_pbc(self):
        self.sim.config.periodic_z = True
        self.sim.config.periodic_y = True
        spec = SubdomainSpec3D((0, 0, 0),
                               self.lattice_size,
                               envelope_size=1,
                               id_=0)
        spec.enable_local_periodicity(1)
        spec.enable_local_periodicity(2)
        spec.runner = SubdomainRunner(self.sim,
                                      spec,
                                      output=None,
                                      backend=self.backend,
                                      quit_event=None)
        spec.runner._init_shape()
        sub = self._ChannelSubdomain3D(list(reversed(self.lattice_size)), spec,
                                       D3Q19)
        sub.allocate()
        sub.reset()

        nx, ny, nz = self.lattice_size
        hx, hy, hz = sub._get_mgrid()

        np.testing.assert_equal(sub._orientation[(hx == 0)],
                                D3Q19.vec_to_dir([1, 0, 0]))
        np.testing.assert_equal(sub._orientation[(hx == nx - 1)],
                                D3Q19.vec_to_dir([-1, 0, 0]))
Example #2
0
    def test_orientation_channel_2subdomains(self):
        self.sim.config.periodic_z = True
        self.sim.config.periodic_y = True
        spec0 = SubdomainSpec3D((0, 0, 0),
                                self.lattice_size,
                                envelope_size=1,
                                id_=0)
        spec0.enable_local_periodicity(1)
        spec1 = SubdomainSpec3D((0, 0, self.lattice_size[2]),
                                self.lattice_size,
                                envelope_size=1,
                                id_=1)
        spec1.enable_local_periodicity(1)

        self.assertTrue(spec0.connect(spec1, grid=D3Q19))

        spec0.runner = SubdomainRunner(self.sim,
                                       spec0,
                                       output=None,
                                       backend=self.backend,
                                       quit_event=None)
        spec0.runner._init_shape()
        spec1.runner = SubdomainRunner(self.sim,
                                       spec1,
                                       output=None,
                                       backend=self.backend,
                                       quit_event=None)
        spec1.runner._init_shape()

        sub0 = ChannelSubdomain3D(list(reversed(self.lattice_size)), spec0,
                                  D3Q19)
        sub0.allocate()
        sub0.reset()

        sub1 = ChannelSubdomain3D(list(reversed(self.lattice_size)), spec1,
                                  D3Q19)
        sub1.allocate()
        sub1.reset()

        nx, ny, nz = self.lattice_size
        hx, hy, hz = sub0._get_mgrid()

        np.testing.assert_equal(sub0._orientation[(hx == 0)],
                                D3Q19.vec_to_dir([1, 0, 0]))
        np.testing.assert_equal(sub0._orientation[(hx == nx - 1)],
                                D3Q19.vec_to_dir([-1, 0, 0]))
        np.testing.assert_equal(sub1._orientation[(hx == 0)],
                                D3Q19.vec_to_dir([1, 0, 0]))
        np.testing.assert_equal(sub1._orientation[(hx == nx - 1)],
                                D3Q19.vec_to_dir([-1, 0, 0]))
Example #3
0
    def boundary_conditions(self, hx, hy, hz):
        # Channel walls.
        wall_map = ((hx == 0) | (hx == self.gx - 1))
        self.set_node(wall_map, self.wall_bc)

        h = self.config.H * 2 / 3
        buf_len = CubeChannelGeometry.buf_nz(self.config)

        # For BBL, the number of nodes has to be extended by 1 in every
        # direction other than wall-normal due to the effective wall location,
        # i.e. due to the fact that a sequence of N BBL nodes corresponds to
        # a solid body N-2 across.
        ext = 1 if self.wall_bc.location == -0.5 else 0

        # Cube.
        cube_map = ((hx > 0) & (hx <= h) & (hz >= buf_len + 3 * h - ext) &
                    (hz < buf_len + 4 * h + ext) & (hy >= 2.7 * h - ext) &
                    (hy < 3.7 * h + ext))
        self.set_node(cube_map, self.wall_bc)

        # Outlet.
        outlet_map = (hz == self.gz - 1) & np.logical_not(wall_map)
        self.set_node(
            outlet_map,
            NTEquilibriumDensity(1.0, orientation=D3Q19.vec_to_dir([0, 0,
                                                                    -1])))
Example #4
0
    def test_orientation_channel_pbc(self):
        self.sim.config.periodic_z = True
        self.sim.config.periodic_y = True
        spec = SubdomainSpec3D((0, 0, 0), self.lattice_size, envelope_size=1, id_=0)
        spec.enable_local_periodicity(1)
        spec.enable_local_periodicity(2)
        spec.runner = SubdomainRunner(self.sim, spec, output=None,
                                      backend=self.backend, quit_event=None)
        spec.runner._init_shape()
        sub = ChannelSubdomain3D(list(reversed(self.lattice_size)), spec, D3Q19)
        sub.allocate()
        sub.reset()

        nx, ny, nz = self.lattice_size
        hx, hy, hz = sub._get_mgrid()

        np.testing.assert_equal(sub._orientation[(hx == 0)],
                                D3Q19.vec_to_dir([1, 0, 0]))
        np.testing.assert_equal(sub._orientation[(hx == nx - 1)],
                                D3Q19.vec_to_dir([-1, 0, 0]))
Example #5
0
    def test_orientation_channel_2subdomains(self):
        self.sim.config.periodic_z = True
        self.sim.config.periodic_y = True
        spec0 = SubdomainSpec3D((0, 0, 0), self.lattice_size, envelope_size=1, id_=0)
        spec0.enable_local_periodicity(1)
        spec1 = SubdomainSpec3D((0, 0, self.lattice_size[2]),
                                 self.lattice_size, envelope_size=1, id_=1)
        spec1.enable_local_periodicity(1)

        self.assertTrue(spec0.connect(spec1, grid=D3Q19))

        spec0.runner = SubdomainRunner(self.sim, spec0, output=None,
                                       backend=self.backend, quit_event=None)
        spec0.runner._init_shape()
        spec1.runner = SubdomainRunner(self.sim, spec1, output=None,
                                       backend=self.backend, quit_event=None)
        spec1.runner._init_shape()

        sub0 = self._ChannelSubdomain3D(list(reversed(self.lattice_size)), spec0, D3Q19)
        sub0.allocate()
        sub0.reset()

        sub1 = self._ChannelSubdomain3D(list(reversed(self.lattice_size)), spec1, D3Q19)
        sub1.allocate()
        sub1.reset()

        nx, ny, nz = self.lattice_size
        hx, hy, hz = sub0._get_mgrid()

        np.testing.assert_equal(sub0._orientation[(hx == 0)],
                                D3Q19.vec_to_dir([1, 0, 0]))
        np.testing.assert_equal(sub0._orientation[(hx == nx - 1)],
                                D3Q19.vec_to_dir([-1, 0, 0]))
        np.testing.assert_equal(sub1._orientation[(hx == 0)],
                                D3Q19.vec_to_dir([1, 0, 0]))
        np.testing.assert_equal(sub1._orientation[(hx == nx - 1)],
                                D3Q19.vec_to_dir([-1, 0, 0]))
Example #6
0
    def test_orientation_box(self):
        spec = SubdomainSpec3D((0, 0, 0), self.lattice_size, envelope_size=1, id_=0)
        spec.runner = SubdomainRunner(self.sim, spec, output=None,
                                      backend=self.backend, quit_event=None)
        spec.runner._init_shape()
        sub = OrientationSubdomain3D(list(reversed(self.lattice_size)), spec, D3Q19)
        sub.allocate()
        sub.reset()

        nx, ny, nz = self.lattice_size
        hx, hy, hz = sub._get_mgrid()

        xx = np.logical_not((hx == 0) | (hx == nx - 1))
        yy = np.logical_not((hy == 0) | (hy == ny - 1))
        zz = np.logical_not((hz == 0) | (hz == nz - 1))

        np.testing.assert_equal(sub._orientation[(hx == 0) & yy & zz],
                                D3Q19.vec_to_dir([1, 0, 0]))
        np.testing.assert_equal(sub._orientation[(hy == 0) & xx & zz],
                                D3Q19.vec_to_dir([0, 1, 0]))
        np.testing.assert_equal(sub._orientation[(hz == 0) & yy & xx],
                                D3Q19.vec_to_dir([0, 0, 1]))
        np.testing.assert_equal(sub._orientation[(hx == nx - 1) & yy & zz],
                                D3Q19.vec_to_dir([-1, 0, 0]))
        np.testing.assert_equal(sub._orientation[(hy == ny - 1) & xx & zz],
                                D3Q19.vec_to_dir([0, -1, 0]))
        np.testing.assert_equal(sub._orientation[(hz == nz - 1) & yy & xx],
                                D3Q19.vec_to_dir([0, 0, -1]))

        # No orientation vector for edge nodes.
        np.testing.assert_equal(sub._orientation[(hx == 0) & (hy == 0)], 0)
        np.testing.assert_equal(sub._orientation[(hx == 0) & (hz == 0)], 0)
        np.testing.assert_equal(sub._orientation[(hz == 0) & (hy == 0)], 0)

        np.testing.assert_equal(sub._orientation[(hx == 0) & (hy == ny - 1)], 0)
        np.testing.assert_equal(sub._orientation[(hx == 0) & (hz == nz - 1)], 0)
        np.testing.assert_equal(sub._orientation[(hz == 0) & (hy == ny - 1)], 0)

        np.testing.assert_equal(sub._orientation[(hx == nx - 1) & (hy == 0)], 0)
        np.testing.assert_equal(sub._orientation[(hx == nx - 1) & (hz == 0)], 0)
        np.testing.assert_equal(sub._orientation[(hz == nz - 1) & (hy == 0)], 0)

        np.testing.assert_equal(sub._orientation[(hx == nx - 1) & (hy == ny - 1)], 0)
        np.testing.assert_equal(sub._orientation[(hx == nx - 1) & (hz == nz - 1)], 0)
        np.testing.assert_equal(sub._orientation[(hz == nz - 1) & (hy == ny - 1)], 0)

        # No orientation vector for corner nodes.
        np.testing.assert_equal(sub._orientation[0, 0, 0], 0)
        np.testing.assert_equal(sub._orientation[0, 0, nx - 1], 0)
        np.testing.assert_equal(sub._orientation[0, ny - 1, 0], 0)
        np.testing.assert_equal(sub._orientation[0, ny - 1, nx - 1], 0)
        np.testing.assert_equal(sub._orientation[nz - 1, 0, 0], 0)
        np.testing.assert_equal(sub._orientation[nz - 1, 0, nx - 1], 0)
        np.testing.assert_equal(sub._orientation[nz - 1, ny - 1, 0], 0)
        np.testing.assert_equal(sub._orientation[nz - 1, ny - 1, nx - 1], 0)
Example #7
0
    def boundary_conditions(self, hx, hy, hz):
        # Channel walls.
        wall_map = ((hx == 0) | (hx == self.gx - 1))
        self.set_node(wall_map, self.wall_bc)

        h = self.config.H * 2 / 3
        buf_len = CubeChannelGeometry.buf_nz(self.config)

        # For BBL, the number of nodes has to be extended by 1 in every
        # direction other than wall-normal due to the effective wall location,
        # i.e. due to the fact that a sequence of N BBL nodes corresponds to
        # a solid body N-2 across.
        ext = 1 if self.wall_bc.location == -0.5 else 0

        # Cube.
        cube_map = ((hx > 0) & (hx <= h) &
                    (hz >= buf_len + 3 * h - ext) & (hz < buf_len + 4 * h + ext) &
                    (hy >= 2.7 * h - ext) & (hy < 3.7 * h + ext))
        self.set_node(cube_map, self.wall_bc)

        # Outlet.
        outlet_map = (hz == self.gz - 1) & np.logical_not(wall_map)
        self.set_node(outlet_map, NTEquilibriumDensity(1.0,
                                                      orientation=D3Q19.vec_to_dir([0,0,-1])))
Example #8
0
    def test_orientation_box(self):
        spec = SubdomainSpec3D((0, 0, 0), self.lattice_size, envelope_size=1, id_=0)
        spec.runner = SubdomainRunner(self.sim, spec, output=None,
                                      backend=self.backend, quit_event=None)
        spec.runner._init_shape()

        class _OrientationSubdomain3D(Subdomain3D):
            def boundary_conditions(self, hx, hy, hz):
                self.set_node((hx == 0) | (hy == 0) | (hz == 0) | (hz == self.gz - 1) |
                              (hx == self.gx - 1) | (hy == self.gy - 1),
                              NTEquilibriumDensity(1.0))

        sub = _OrientationSubdomain3D(list(reversed(self.lattice_size)), spec, D3Q19)
        sub.allocate()
        sub.reset()

        nx, ny, nz = self.lattice_size
        hx, hy, hz = sub._get_mgrid()

        xx = np.logical_not((hx == 0) | (hx == nx - 1))
        yy = np.logical_not((hy == 0) | (hy == ny - 1))
        zz = np.logical_not((hz == 0) | (hz == nz - 1))

        np.testing.assert_equal(sub._orientation[(hx == 0) & yy & zz],
                                D3Q19.vec_to_dir([1, 0, 0]))
        np.testing.assert_equal(sub._orientation[(hy == 0) & xx & zz],
                                D3Q19.vec_to_dir([0, 1, 0]))
        np.testing.assert_equal(sub._orientation[(hz == 0) & yy & xx],
                                D3Q19.vec_to_dir([0, 0, 1]))
        np.testing.assert_equal(sub._orientation[(hx == nx - 1) & yy & zz],
                                D3Q19.vec_to_dir([-1, 0, 0]))
        np.testing.assert_equal(sub._orientation[(hy == ny - 1) & xx & zz],
                                D3Q19.vec_to_dir([0, -1, 0]))
        np.testing.assert_equal(sub._orientation[(hz == nz - 1) & yy & xx],
                                D3Q19.vec_to_dir([0, 0, -1]))

        # No orientation vector for edge nodes.
        np.testing.assert_equal(sub._orientation[(hx == 0) & (hy == 0)], 0)
        np.testing.assert_equal(sub._orientation[(hx == 0) & (hz == 0)], 0)
        np.testing.assert_equal(sub._orientation[(hz == 0) & (hy == 0)], 0)

        np.testing.assert_equal(sub._orientation[(hx == 0) & (hy == ny - 1)], 0)
        np.testing.assert_equal(sub._orientation[(hx == 0) & (hz == nz - 1)], 0)
        np.testing.assert_equal(sub._orientation[(hz == 0) & (hy == ny - 1)], 0)

        np.testing.assert_equal(sub._orientation[(hx == nx - 1) & (hy == 0)], 0)
        np.testing.assert_equal(sub._orientation[(hx == nx - 1) & (hz == 0)], 0)
        np.testing.assert_equal(sub._orientation[(hz == nz - 1) & (hy == 0)], 0)

        np.testing.assert_equal(sub._orientation[(hx == nx - 1) & (hy == ny - 1)], 0)
        np.testing.assert_equal(sub._orientation[(hx == nx - 1) & (hz == nz - 1)], 0)
        np.testing.assert_equal(sub._orientation[(hz == nz - 1) & (hy == ny - 1)], 0)

        # No orientation vector for corner nodes.
        np.testing.assert_equal(sub._orientation[0, 0, 0], 0)
        np.testing.assert_equal(sub._orientation[0, 0, nx - 1], 0)
        np.testing.assert_equal(sub._orientation[0, ny - 1, 0], 0)
        np.testing.assert_equal(sub._orientation[0, ny - 1, nx - 1], 0)
        np.testing.assert_equal(sub._orientation[nz - 1, 0, 0], 0)
        np.testing.assert_equal(sub._orientation[nz - 1, 0, nx - 1], 0)
        np.testing.assert_equal(sub._orientation[nz - 1, ny - 1, 0], 0)
        np.testing.assert_equal(sub._orientation[nz - 1, ny - 1, nx - 1], 0)
Example #9
0
    def test_orientation(self):
        spec = SubdomainSpec3D((0, 0, 0),
                               self.lattice_size,
                               envelope_size=1,
                               id_=0)
        spec.runner = SubdomainRunner(self.sim,
                                      spec,
                                      output=None,
                                      backend=self.backend,
                                      quit_event=None)
        spec.runner._init_shape()
        sub = TestSubdomain3D(list(reversed(self.lattice_size)), spec, D3Q19)
        sub.reset()
        sub._encoder.detect_orientation(sub._orientation_base)

        nx, ny, nz = self.lattice_size
        hx, hy, hz = sub._get_mgrid()

        xx = np.logical_not((hx == 0) | (hx == nx - 1))
        yy = np.logical_not((hy == 0) | (hy == ny - 1))
        zz = np.logical_not((hz == 0) | (hz == nz - 1))

        np.testing.assert_equal(sub._orientation[(hx == 0) & yy & zz],
                                D3Q19.vec_to_dir([1, 0, 0]))
        np.testing.assert_equal(sub._orientation[(hy == 0) & xx & zz],
                                D3Q19.vec_to_dir([0, 1, 0]))
        np.testing.assert_equal(sub._orientation[(hz == 0) & yy & xx],
                                D3Q19.vec_to_dir([0, 0, 1]))
        np.testing.assert_equal(sub._orientation[(hx == nx - 1) & yy & zz],
                                D3Q19.vec_to_dir([-1, 0, 0]))
        np.testing.assert_equal(sub._orientation[(hy == ny - 1) & xx & zz],
                                D3Q19.vec_to_dir([0, -1, 0]))
        np.testing.assert_equal(sub._orientation[(hz == nz - 1) & yy & xx],
                                D3Q19.vec_to_dir([0, 0, -1]))

        # No orientation vector for edge nodes.
        np.testing.assert_equal(sub._orientation[(hx == 0) & (hy == 0)], 0)
        np.testing.assert_equal(sub._orientation[(hx == 0) & (hz == 0)], 0)
        np.testing.assert_equal(sub._orientation[(hz == 0) & (hy == 0)], 0)

        np.testing.assert_equal(sub._orientation[(hx == 0) & (hy == ny - 1)],
                                0)
        np.testing.assert_equal(sub._orientation[(hx == 0) & (hz == nz - 1)],
                                0)
        np.testing.assert_equal(sub._orientation[(hz == 0) & (hy == ny - 1)],
                                0)

        np.testing.assert_equal(sub._orientation[(hx == nx - 1) & (hy == 0)],
                                0)
        np.testing.assert_equal(sub._orientation[(hx == nx - 1) & (hz == 0)],
                                0)
        np.testing.assert_equal(sub._orientation[(hz == nz - 1) & (hy == 0)],
                                0)

        np.testing.assert_equal(
            sub._orientation[(hx == nx - 1) & (hy == ny - 1)], 0)
        np.testing.assert_equal(
            sub._orientation[(hx == nx - 1) & (hz == nz - 1)], 0)
        np.testing.assert_equal(
            sub._orientation[(hz == nz - 1) & (hy == ny - 1)], 0)

        # No orientation vector for corner nodes.
        np.testing.assert_equal(sub._orientation[0, 0, 0], 0)
        np.testing.assert_equal(sub._orientation[0, 0, nx - 1], 0)
        np.testing.assert_equal(sub._orientation[0, ny - 1, 0], 0)
        np.testing.assert_equal(sub._orientation[0, ny - 1, nx - 1], 0)
        np.testing.assert_equal(sub._orientation[nz - 1, 0, 0], 0)
        np.testing.assert_equal(sub._orientation[nz - 1, 0, nx - 1], 0)
        np.testing.assert_equal(sub._orientation[nz - 1, ny - 1, 0], 0)
        np.testing.assert_equal(sub._orientation[nz - 1, ny - 1, nx - 1], 0)
Example #10
0
import numpy as np
import unittest
from sailfish.config import LBConfig
from sailfish.controller import LBGeometryProcessor
from sailfish.geo import LBGeometry2D
from sailfish.subdomain import Subdomain2D, SubdomainSpec2D, SubdomainSpec3D
from sailfish.sym import D2Q9, D3Q15, D3Q19

vi = lambda x, y: D2Q9.vec_idx([x, y])
vi3 = lambda x, y, z: D3Q19.vec_idx([x, y, z])
vi15 = lambda x, y, z: D3Q15.vec_idx([x, y, z])


def _verify_partial_map(self, conn, expected_map):
    self.assertEqual(set(conn.dst_partial_map.keys()),
                     set(expected_map.keys()))
    for key, val in expected_map.iteritems():
        self.assertEqual(set([tuple(x) for x in val]),
                         set([tuple(x) for x in conn.dst_partial_map[key]]))


class TestBlock3D(unittest.TestCase):
    def test_subdomain_connection_y(self):
        base = SubdomainSpec3D((10, 10, 10), (10, 10, 12),
                               envelope_size=1,
                               id_=0)
        face_hi = SubdomainSpec3D.Y_HIGH

        # exact match
        b1 = SubdomainSpec3D((10, 20, 10), (10, 5, 12), envelope_size=1, id_=1)
        self.assertTrue(base.connect(b1, grid=D3Q19))
Example #11
0
        return blocks


class TwoBlocksZConnGeoTest(LBGeometry3D):
    def subdomains(self, n=None):
        blocks = []
        blocks.append(SubdomainSpec3D((0, 0, 0), (64, 66, 64)))
        blocks.append(SubdomainSpec3D((0, 0, 64), (64, 66, 64)))
        return blocks


mem_align = 32
block_size = 64
tmpdir = None
periodic_x = False
vi = lambda x, y, z: D3Q19.vec_idx([x, y, z])
vi2 = lambda x, y, z: D3Q15.vec_idx([x, y, z])


class SimulationTest(LBFluidSim):
    subdomain = BlockTest
    axis = 0

    @classmethod
    def modify_config(cls, config):
        config.relaxation_enabled = False

    @classmethod
    def update_defaults(cls, defaults):
        if cls.axis == 0:
            lat_nx = 128