Example #1
0
def run_test(name):
    basepath = os.path.join('results', name)
    if not os.path.exists(basepath):
        os.makedirs(basepath)

    ctrl = LBSimulationController(TestLDCSim)
    ctrl.run(ignore_cmdline=True)
    horiz = np.loadtxt('ldc_golden/re400_horiz', skiprows=1)
    vert = np.loadtxt('ldc_golden/re400_vert', skiprows=1)

    plt.plot(2 * (horiz[:, 0] - 0.5),
             -2 * (horiz[:, 1] - 0.5),
             '.',
             label='Sheu, Tsai paper')
    plt.plot(2 * (vert[:, 0] - 0.5),
             -2 * (vert[:, 1] - 0.5),
             '.',
             label='Sheu, Tsai paper')
    save_output(basepath, MAX_ITERS)
    plt.legend(loc='lower right')
    plt.gca().yaxis.grid(True)
    plt.gca().xaxis.grid(True)
    plt.gca().xaxis.grid(True, which='minor')
    plt.gca().yaxis.grid(True, which='minor')

    plt.title('Lid Driven Cavity, Re = 400')
    print os.path.join(basepath, 're400.pdf')
    plt.savefig(os.path.join(basepath, 're400.pdf'), format='pdf')

    plt.clf()
    plt.cla()
    plt.show()
    shutil.rmtree(tmpdir)
Example #2
0
 def test_horiz_2blocks(self):
     global blocks, output
     output = os.path.join(tmpdir, 'horiz_2block')
     blocks = 2
     ctrl = LBSimulationController(SimulationTest, SphereGeometry)
     ctrl.run(ignore_cmdline=True)
     util.verify_fields(self.ref, output, self.digits, MAX_ITERS)
Example #3
0
    def test_timeseries(self):
        settings = {
            'debug_single_process': True,
            'quiet': True,
            'lat_nx': 64,
            'lat_ny': 32,
            'max_iters': 1,
            'check_invalid_results_host': False,
            'check_invalid_results_gpu': False,
            'every': 1,
        }

        x1 = np.arange(0, 20 * 8, 8)
        x2 = np.arange(0, 60 * 1.61, 1.61)
        x3 = np.arange(0, 20 * 4, 4)

        # This one test time-wrapping and a non-integer step size.
        cc = np.hstack([cos_timeseries, cos_timeseries, cos_timeseries])

        f1 = interp1d(x1, sin_timeseries, kind='linear')
        f2 = interp1d(x2, cc, kind='linear')
        f3 = interp1d(x3, 2.0 * sin_timeseries, kind='linear')

        ctrl = LBSimulationController(TestSim, default_config=settings)
        ctrl.run(ignore_cmdline=True)
        runner = ctrl.master.runner
        sim = ctrl.master.sim

        while sim.iteration < 60:
            runner.step(True)
            runner._fields_to_host(True)
            self.assertAlmostEqual(sim.rho[0,5], f1(sim.iteration - 1), places=6)
            self.assertAlmostEqual(sim.rho[0,6], f2(sim.iteration - 1), places=6)
            self.assertAlmostEqual(sim.rho[0,7], f3(sim.iteration - 1), places=6)
Example #4
0
def run_test(name):
    basepath = os.path.join("results", name)
    if not os.path.exists(basepath):
        os.makedirs(basepath)

    ctrl = LBSimulationController(TestLDCSim, TestLDCGeometry)
    ctrl.run()
    horiz = np.loadtxt("ldc_golden/re400_horiz", skiprows=1)
    vert = np.loadtxt("ldc_golden/re400_vert", skiprows=1)

    plt.plot(2 * (horiz[:, 0] - 0.5), -2 * (horiz[:, 1] - 0.5), label="Sheu, Tsai paper")
    plt.plot(2 * (vert[:, 0] - 0.5), -2 * (vert[:, 1] - 0.5), label="Sheu, Tsai paper")
    save_output(basepath)
    plt.legend(loc="lower right")
    plt.gca().yaxis.grid(True)
    plt.gca().xaxis.grid(True)
    plt.gca().xaxis.grid(True, which="minor")
    plt.gca().yaxis.grid(True, which="minor")

    plt.title("Lid Driven Cavity, Re = 400")
    print os.path.join(basepath, "re400.pdf")
    plt.savefig(os.path.join(basepath, "re400.pdf"), format="pdf")

    plt.clf()
    plt.cla()
    plt.show()
    shutil.rmtree(tmpdir)
Example #5
0
def run_test(name, re, max_iters, i):
    print 'Testing Re = %s' % re

    basepath = os.path.join('results', name, 're%s' % re)
    if not os.path.exists(basepath):
        os.makedirs(basepath)

    ctrl = LBSimulationController(TestLDCSim,
                                  default_config={'re': re, 'max_iters': max_iters})
    ctrl.run(ignore_cmdline=True)
    horiz = np.loadtxt('ldc_golden/vx2d', skiprows=4)
    vert = np.loadtxt('ldc_golden/vy2d', skiprows=4)

    plt.plot(horiz[:, 0] * 2 - 1, horiz[:, i], '.', label='Paper')
    plt.plot(vert[:, i], 2 * (vert[:, 0] - 0.5), '.', label='Paper')
    save_output(basepath, max_iters)
    plt.legend(loc='lower right')
    plt.gca().yaxis.grid(True)
    plt.gca().xaxis.grid(True)
    plt.gca().xaxis.grid(True, which='minor')
    plt.gca().yaxis.grid(True, which='minor')

    plt.title('2D Lid Driven Cavity, Re = %s' % re)
    print os.path.join(basepath, 'results.pdf')
    plt.savefig(os.path.join(basepath, 'results.pdf'), format='pdf')

    plt.clf()
    plt.cla()
    plt.show()
Example #6
0
    def test_x_face_propagation(self):
        global tmpdir
        ctrl = LBSimulationController(SingleBlockPeriodicSimulationTest,
                                      SingleBlockGeoTest)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, 'per_single_out')
        b0 = np.load(io.dists_filename(output, 1, 0, 1))['arr_0']
        ae = np.testing.assert_equal

        ae(b0[vi(-1, 0, 0), 32, 32, 64], np.float32(0.11))
        ae(b0[vi(-1, 1, 0), 32, 33, 64], np.float32(0.12))
        ae(b0[vi(-1, -1, 0), 32, 31, 64], np.float32(0.13))
        ae(b0[vi(-1, 0, 1), 33, 32, 64], np.float32(0.14))
        ae(b0[vi(-1, 0, -1), 31, 32, 64], np.float32(0.15))

        ae(b0[vi(0, 1, 0), 33, 1, 31], np.float32(0.41))
        ae(b0[vi(0, 0, 1), 1, 35, 31], np.float32(0.42))

        ae(b0[vi(-1, 0, 0), 1, 1, 64], np.float32(0.21))
        ae(b0[vi(0, -1, 0), 1, 62, 1], np.float32(0.22))
        ae(b0[vi(0, 0, -1), 66, 1, 1], np.float32(0.23))

        ae(b0[vi(-1, -1, 0), 1, 62, 64], np.float32(0.24))
        ae(b0[vi(0, -1, -1), 66, 62, 1], np.float32(0.25))
        ae(b0[vi(-1, 0, -1), 66, 1, 64], np.float32(0.26))

        ae(b0[vi(-1, 0, 0), 32, 1, 64], np.float32(0.31))
        ae(b0[vi(-1, -1, 0), 32, 1, 64], np.float32(0.32))
Example #7
0
    def test_vert_spread(self):
        def ic(self, runner):
            dbuf = runner._debug_get_dist()
            dbuf[:] = 0.0

            if runner._spec.id == 0:
                dbuf[vi(-1, 1), 128, 64] = 0.11
                dbuf[vi(0, 1), 128, 64] = 0.12
                dbuf[vi(1, 1), 128, 64] = 0.13

            runner._debug_set_dist(dbuf)

        VertTest = type("VertTest", (AASimulationTest,), {"initial_conditions": ic})
        ctrl = LBSimulationController(VertTest, Vertical2BlockGeo)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, "test_out")
        b0 = np.load(io.dists_filename(output, 1, 0, 1))["arr_0"]
        b1 = np.load(io.dists_filename(output, 1, 1, 1))["arr_0"]
        ae = np.testing.assert_equal

        # No propagation in the first step, but the distributions are stored
        # in opposite slots.
        ae(b1[vi(1, -1), 0, 64], np.float32(0.11))
        ae(b1[vi(0, -1), 0, 64], np.float32(0.12))
        ae(b1[vi(-1, -1), 0, 64], np.float32(0.13))
Example #8
0
    def test_3d(self):
        s = settings
        s.update({
            'lat_nx': NX,
            'lat_ny': NY,
            'lat_nz': NZ})

        TestSim.subdomain = TestSubdomain3D
        TestSim.subdomain_runner = TestSubdomainRunner3D

        ctrl = LBSimulationController(TestSim, default_config=s)
        ctrl.run(ignore_cmdline=True)

        sim = ctrl.master.sim
        # reduction over Z, Y
        np.testing.assert_array_almost_equal(
            ctrl.master.runner.ret_x,
            np.sum(np.sum(sim.data, axis=0), axis=0))

        # reduction over Z, X
        np.testing.assert_array_almost_equal(
            ctrl.master.runner.ret_y,
            np.sum(np.sum(sim.data, axis=0), axis=1))

        # reduction over Y, X
        np.testing.assert_array_almost_equal(
            ctrl.master.runner.ret_z,
            np.sum(np.sum(sim.data, axis=1), axis=1))
Example #9
0
def run_test(name, i):
    global RE
    RE = reynolds[i]
    global MAX_ITERS
    MAX_ITERS = max_iters[i]
    basepath = os.path.join('results', name, 're%s' % RE)
    if not os.path.exists(basepath):
        os.makedirs(basepath)

    ctrl = LBSimulationController(TestLDCSim, TestLDCGeometry)
    ctrl.run()
    horiz = np.loadtxt('ldc_golden/vx2d', skiprows=4)
    vert = np.loadtxt('ldc_golden/vy2d', skiprows=4)

    plt.plot(horiz[:, 0] * 2 - 1, horiz[:, i+1], label='Paper')
    plt.plot(vert[:, i+1], 2 * (vert[:, 0] - 0.5), label='Paper')
    save_output(basepath)
    plt.legend(loc='lower right')
    plt.gca().yaxis.grid(True)
    plt.gca().xaxis.grid(True)
    plt.gca().xaxis.grid(True, which='minor')
    plt.gca().yaxis.grid(True, which='minor')

    plt.title('Lid Driven Cavity, Re = %s' % RE)
    print os.path.join(basepath, 'results.pdf')
    plt.savefig(os.path.join(basepath, 'results.pdf'), format='pdf')

    plt.clf()
    plt.cla()
    plt.show()
Example #10
0
    def test_corner_global_periodic(self):
        global tmpdir, periodic_y
        periodic_y = True

        def ic(self, runner):
            dbuf = runner._debug_get_dist()
            dbuf[:] = 0.0
            dbuf[vi(1, 1), 256, 256] = 0.11
            dbuf[vi(-1, -1), 1, 1] = 0.12
            dbuf[vi(1, -1), 1, 256] = 0.13
            dbuf[vi(-1, 1), 256, 1] = 0.14
            runner._debug_set_dist(dbuf)
            runner._debug_set_dist(dbuf, False)

        CornerTest = type('CornerTest', (SimulationTest, ),
                          {'initial_conditions': ic})
        ctrl = LBSimulationController(CornerTest)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, 'test_out')
        b0 = np.load(io.dists_filename(output, 1, 0, 1))['arr_0']
        ae = np.testing.assert_equal

        ae(b0[vi(1, 1), 1, 1], np.float32(0.11))
        ae(b0[vi(-1, -1), 256, 256], np.float32(0.12))
        ae(b0[vi(1, -1), 256, 1], np.float32(0.13))
        ae(b0[vi(-1, 1), 1, 256], np.float32(0.14))
Example #11
0
    def test_vert_spread(self):
        def ic(self, runner):
            dbuf = runner._debug_get_dist()
            dbuf[:] = 0.0

            if runner._spec.id == 0:
                dbuf[vi(-1, 1), 128, 64] = 0.11
                dbuf[vi(0, 1), 128, 64] = 0.12
                dbuf[vi(1, 1), 128, 64] = 0.13

            runner._debug_set_dist(dbuf)

        VertTest = type('VertTest', (AASimulationTest, ),
                        {'initial_conditions': ic})
        ctrl = LBSimulationController(VertTest, Vertical2BlockGeo)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, 'test_out')
        b0 = np.load(io.dists_filename(output, 1, 0, 1))['arr_0']
        b1 = np.load(io.dists_filename(output, 1, 1, 1))['arr_0']
        ae = np.testing.assert_equal

        # No propagation in the first step, but the distributions are stored
        # in opposite slots.
        ae(b1[vi(1, -1), 0, 64], np.float32(0.11))
        ae(b1[vi(0, -1), 0, 64], np.float32(0.12))
        ae(b1[vi(-1, -1), 0, 64], np.float32(0.13))
Example #12
0
    def test_horiz_spread(self):
        def ic(self, runner):
            dbuf = runner._debug_get_dist()
            dbuf[:] = 0.0

            if runner._spec.id == 0:
                dbuf[vi(1, 0), 64, 128] = 0.11
                dbuf[vi(1, 1), 64, 128] = 0.12
                dbuf[vi(1, -1), 64, 128] = 0.13

            runner._debug_set_dist(dbuf)

        HorizTest = type('HorizTest', (AASimulationTest,),
                {'initial_conditions': ic})
        ctrl = LBSimulationController(HorizTest, DoubleBlockGeometryTest)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, 'test_out')
        b0 = np.load(io.dists_filename(output, 1, 0, 1))['arr_0']
        b1 = np.load(io.dists_filename(output, 1, 1, 1))['arr_0']
        ae = np.testing.assert_equal

        # No propagation in the first step, but the distributions are stored
        # in opposite slots.
        ae(b1[vi(-1, 0), 64, 0], np.float32(0.11))
        ae(b1[vi(-1, -1), 64, 0], np.float32(0.12))
        ae(b1[vi(-1, 1), 64, 0], np.float32(0.13))
Example #13
0
    def test_3d(self):
        s = settings
        s.update({
            'lat_nx': NX,
            'lat_ny': NY,
            'lat_nz': NZ})

        TestSim.subdomain = TestSubdomain3D
        TestSim.subdomain_runner = TestSubdomainRunner3D

        ctrl = LBSimulationController(TestSim, default_config=s)
        ctrl.run(ignore_cmdline=True)

        sim = ctrl.master.sim
        # reduction over Z, Y
        np.testing.assert_array_almost_equal(
            ctrl.master.runner.ret_x,
            np.sum(np.sum(sim.data, axis=0), axis=0))

        # reduction over Z, X
        np.testing.assert_array_almost_equal(
            ctrl.master.runner.ret_y,
            np.sum(np.sum(sim.data, axis=0), axis=1))

        # reduction over Y, X
        np.testing.assert_array_almost_equal(
            ctrl.master.runner.ret_z,
            np.sum(np.sum(sim.data, axis=1), axis=1))
Example #14
0
    def test_corner_global_periodic(self):
        global tmpdir, periodic_y
        periodic_y = True

        def ic(self, runner):
            dbuf = runner._debug_get_dist()
            dbuf[:] = 0.0
            dbuf[vi(1, 1), 256, 256] = 0.11
            dbuf[vi(-1, -1), 1, 1] = 0.12
            dbuf[vi(1, -1), 1, 256] = 0.13
            dbuf[vi(-1, 1), 256, 1] = 0.14
            runner._debug_set_dist(dbuf)
            runner._debug_set_dist(dbuf, False)

        CornerTest = type("CornerTest", (SimulationTest,), {"initial_conditions": ic})
        ctrl = LBSimulationController(CornerTest)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, "test_out")
        b0 = np.load(io.dists_filename(output, 1, 0, 1))["arr_0"]
        ae = np.testing.assert_equal

        ae(b0[vi(1, 1), 1, 1], np.float32(0.11))
        ae(b0[vi(-1, -1), 256, 256], np.float32(0.12))
        ae(b0[vi(1, -1), 256, 1], np.float32(0.13))
        ae(b0[vi(-1, 1), 1, 256], np.float32(0.14))
Example #15
0
def run_test(name, re, max_iters, i):
    print("Testing Re = %s" % re)

    basepath = os.path.join("results", name, "re%s" % re)
    if not os.path.exists(basepath):
        os.makedirs(basepath)

    ctrl = LBSimulationController(TestLDCSim, default_config={"re": re, "max_iters": max_iters})
    ctrl.run(ignore_cmdline=True)
    horiz = np.loadtxt("ldc_golden/vx2d", skiprows=4)
    vert = np.loadtxt("ldc_golden/vy2d", skiprows=4)

    plt.plot(horiz[:, 0] * 2 - 1, horiz[:, i], ".", label="Paper")
    plt.plot(vert[:, i], 2 * (vert[:, 0] - 0.5), ".", label="Paper")
    save_output(basepath, max_iters)
    plt.legend(loc="lower right")
    plt.gca().yaxis.grid(True)
    plt.gca().xaxis.grid(True)
    plt.gca().xaxis.grid(True, which="minor")
    plt.gca().yaxis.grid(True, which="minor")

    plt.title("2D Lid Driven Cavity, Re = %s" % re)
    print(os.path.join(basepath, "results.pdf"))
    plt.savefig(os.path.join(basepath, "results.pdf"), format="pdf")

    plt.clf()
    plt.cla()
    plt.show()
Example #16
0
    def test_x_face_propagation(self):
        global tmpdir
        ctrl = LBSimulationController(SingleBlockPeriodicSimulationTest,
                SingleBlockGeoTest)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, 'per_single_out')
        b0 = np.load(io.dists_filename(output, 1, 0, 1))
        ae = np.testing.assert_equal

        ae(b0[vi(-1, 0, 0), 32, 32, 64], np.float32(0.11))
        ae(b0[vi(-1, 1, 0), 32, 33, 64], np.float32(0.12))
        ae(b0[vi(-1, -1, 0), 32, 31, 64], np.float32(0.13))
        ae(b0[vi(-1, 0, 1), 33, 32, 64], np.float32(0.14))
        ae(b0[vi(-1, 0, -1), 31, 32, 64], np.float32(0.15))

        ae(b0[vi(0, 1, 0), 33, 1, 31], np.float32(0.41))
        ae(b0[vi(0, 0, 1), 1, 35, 31], np.float32(0.42))

        ae(b0[vi(-1, 0, 0), 1, 1, 64], np.float32(0.21))
        ae(b0[vi(0, -1, 0), 1, 62, 1], np.float32(0.22))
        ae(b0[vi(0, 0, -1), 66, 1, 1], np.float32(0.23))

        ae(b0[vi(-1, -1, 0), 1, 62, 64], np.float32(0.24))
        ae(b0[vi(0, -1, -1), 66, 62, 1], np.float32(0.25))
        ae(b0[vi(-1, 0, -1), 66, 1, 64], np.float32(0.26))

        ae(b0[vi(-1, 0, 0), 32, 1, 64], np.float32(0.31))
        ae(b0[vi(-1, -1, 0), 32, 1, 64], np.float32(0.32))
    def test_3d(self):
        settings = {
            'debug_single_process': True,
            'quiet': True,
            'check_invalid_results_gpu': False,
            'check_invalid_results_host': False,
            'max_iters': 1,
            'lat_nx': NX,
            'lat_ny': NY,
            'lat_nz': NZ
        }

        ctrl = LBSimulationController(TestSim, default_config=settings)
        ctrl.run(ignore_cmdline=True)
        sim = ctrl.master.sim

        vort = util.vorticity(sim.v)
        vort_sq = vort[0]**2 + vort[1]**2 + vort[2]**2

        # Convert the velocity field to double precision.
        dbl_v = [x.astype(np.float64) for x in sim.v]

        self.assertAlmostEqual(util.kinetic_energy(dbl_v), sim.kinetic_energy)
        self.assertAlmostEqual(util.enstrophy(dbl_v, dx=1.0), sim.enstrophy)

        np.testing.assert_array_almost_equal(sim.v_sq,
                                             sim.vx**2 + sim.vy**2 + sim.vz**2)
        np.testing.assert_array_almost_equal(sim.vort_sq, vort_sq)
Example #18
0
def run_test(name):
    basepath = os.path.join('results', name)
    if not os.path.exists(basepath):
        os.makedirs(basepath)

    ctrl = LBSimulationController(TestLDCSim)
    ctrl.run(ignore_cmdline=True)
    horiz = np.loadtxt('ldc_golden/re400_horiz', skiprows=1)
    vert = np.loadtxt('ldc_golden/re400_vert', skiprows=1)

    plt.plot(2 * (horiz[:,0] - 0.5), -2 * (horiz[:,1] - 0.5), '.', label='Sheu, Tsai paper')
    plt.plot(2 * (vert[:,0] - 0.5), -2 * (vert[:,1] - 0.5), '.', label='Sheu, Tsai paper')
    save_output(basepath, MAX_ITERS)
    plt.legend(loc='lower right')
    plt.gca().yaxis.grid(True)
    plt.gca().xaxis.grid(True)
    plt.gca().xaxis.grid(True, which='minor')
    plt.gca().yaxis.grid(True, which='minor')

    plt.title('Lid Driven Cavity, Re = 400')
    print os.path.join(basepath, 're400.pdf' )
    plt.savefig(os.path.join(basepath, 're400.pdf' ), format='pdf')

    plt.clf()
    plt.cla()
    plt.show()
    shutil.rmtree(tmpdir)
    def test_3d(self):
        settings = {
            'debug_single_process': True,
            'quiet': True,
            'check_invalid_results_gpu': False,
            'check_invalid_results_host': False,
            'max_iters': 1,
            'lat_nx': NX,
            'lat_ny': NY,
            'lat_nz': NZ}

        ctrl = LBSimulationController(TestSim, default_config=settings)
        ctrl.run(ignore_cmdline=True)
        sim = ctrl.master.sim

        vort = util.vorticity(sim.v)
        vort_sq = vort[0]**2 + vort[1]**2 + vort[2]**2

        # Convert the velocity field to double precision.
        dbl_v = [x.astype(np.float64) for x in sim.v]

        self.assertAlmostEqual(util.kinetic_energy(dbl_v), sim.kinetic_energy)
        self.assertAlmostEqual(util.enstrophy(dbl_v, dx=1.0), sim.enstrophy)

        np.testing.assert_array_almost_equal(sim.v_sq, sim.vx**2 + sim.vy**2 + sim.vz**2)
        np.testing.assert_array_almost_equal(sim.vort_sq, vort_sq)
Example #20
0
 def test_8blocks(self):
     global blocks, output
     output = os.path.join(tmpdir, 'horiz_8block')
     blocks = 8
     ctrl = LBSimulationController(SimulationTest, LDCGeometry)
     ctrl.run(ignore_cmdline=True)
     util.verify_fields(self.ref, output, self.digits, MAX_ITERS)
Example #21
0
    def test_horiz_spread(self):
        ctrl = LBSimulationController(PeriodicSimulationTest,
                                      TwoBlocksXConnGeoTest)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, 'per_horiz_out')
        b0 = np.load(io.dists_filename(output, 1, 0, 1))['arr_0']
        b1 = np.load(io.dists_filename(output, 1, 1, 1))['arr_0']

        ae = np.testing.assert_equal

        ae(b1[vi(-1, 0, 0), 32, 32, 64], np.float32(0.11))
        ae(b1[vi(-1, 1, 0), 32, 33, 64], np.float32(0.12))
        ae(b1[vi(-1, -1, 0), 32, 31, 64], np.float32(0.13))
        ae(b1[vi(-1, 0, 1), 33, 32, 64], np.float32(0.14))
        ae(b1[vi(-1, 0, -1), 31, 32, 64], np.float32(0.15))

        ae(b0[vi(1, 0, 0), 1, 1, 1], np.float32(0.21))
        ae(b0[vi(1, 1, 0), 1, 2, 1], np.float32(0.22))
        ae(b0[vi(1, 0, 1), 2, 1, 1], np.float32(0.23))

        ae(b0[vi(1, 0, 0), 1, 32, 1], np.float32(0.33))
        ae(b0[vi(1, 1, 0), 1, 33, 1], np.float32(0.34))
        ae(b0[vi(1, -1, 0), 1, 31, 1], np.float32(0.35))
        ae(b0[vi(1, 0, 1), 2, 32, 1], np.float32(0.36))
Example #22
0
def run_benchmark(lattice_size: tuple,
                  block_size: int = 128,
                  timesteps: int = 1000,
                  boundary_split: bool = False,
                  periodic: tuple = (False, False, True)):
    settings = {
        'verbose': True,
        'mode': 'benchmark',
        'access_pattern': 'AB',
        'model': 'bgk',
        'grid': 'D3Q19',
        'init_iters': 10,
        'max_iters': timesteps,
        'block_size': block_size,
        'lat_nx': lattice_size[0],
        'lat_ny': lattice_size[1],
        'lat_nz': lattice_size[2],
        'periodic_x': periodic[0],
        'periodic_y': periodic[1],
        'periodic_z': periodic[2],
        'use_intrinsics': True,
        'precision': 'double',
        'node_addressing': 'direct',
        'incompressible': True,
        'every': 500,
    }

    ctrl = LBSimulationController(LDCSim, LBGeometry3D, settings)
    timing_infos, min_timings, max_timings, subdomains = ctrl.run()

    mlups_comp = float(0)
    mlups_total = float(0)
    for ti in timing_infos:
        block = subdomains[ti.subdomain_id]
        mlups_comp += (block.num_nodes / ti.comp) * 1e-6
        mlups_total += (block.num_nodes / ti.total) * 1e-6

    data = {
        "cubicBlockSize": lattice_size[0],
        "timesteps": timesteps,
        "cudaBlockSize": block_size,
        "fullyPeriodic": all(periodic) is True,
        "mlupsPerProcess": mlups_comp,
        "boundarySplit": boundary_split,
    }

    csv_exists = False
    if os.path.isfile("singleNode.csv") is True:
        csv_exists = True

    with open("singleNode.csv", "a") as csvfile:
        writer = csv.writer(csvfile)
        if csv_exists is False:
            # Write header
            writer.writerow(list(sorted(data.keys())))

        writer.writerow([data[key] for key in sorted(data.keys())])

    print(f"MLUPS (compute): {mlups_comp}")
Example #23
0
    def test_horiz_spread(self):

        def ic(self, runner):
            dbuf = runner._debug_get_dist()
            dbuf[:] = 0.0

            if runner._spec.id == 1:
                dbuf[vi(1, 0), 128, 128] = 0.11
                dbuf[vi(1, 1), 128, 128] = 0.12
                dbuf[vi(1, -1), 128, 128] = 0.13

                # At the top
                dbuf[vi(1, 0), 256, 128] = 0.31
                dbuf[vi(1, 1), 256, 128] = 0.32
                dbuf[vi(1, -1), 256, 128] = 0.33

                dbuf[vi(-1, -1), 256, 128] = 0.66   # should not be overwritten
            elif runner._spec.id == 0:
                dbuf[vi(-1, 0), 128, 1] = 0.21
                dbuf[vi(-1, 1), 128, 1] = 0.22
                dbuf[vi(-1, -1), 128, 1] = 0.23

                # At the bottom
                dbuf[vi(-1, 0), 1, 1] = 0.41
                dbuf[vi(-1, 1), 1, 1] = 0.42
                dbuf[vi(-1, -1), 1, 1] = 0.43

                dbuf[vi(1, 1), 1, 1] = 0.77     # should not be overwritten

            runner._debug_set_dist(dbuf)
            runner._debug_set_dist(dbuf, False)

        HorizTest = type('HorizTest', (SimulationTest,),
                {'initial_conditions': ic})
        ctrl = LBSimulationController(HorizTest, DoubleBlockGeometryTest)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, 'test_out')
        b0 = np.load(io.dists_filename(output, 1, 0, 1))['arr_0']
        b1 = np.load(io.dists_filename(output, 1, 1, 1))['arr_0']

        ae = np.testing.assert_equal

        ae(b0[vi(1, 0), 128, 1], np.float32(0.11))
        ae(b0[vi(1, 1), 129, 1], np.float32(0.12))
        ae(b0[vi(1, -1), 127, 1], np.float32(0.13))

        ae(b0[vi(1, 0), 256, 1], np.float32(0.31))
        ae(b0[vi(1, -1), 255, 1], np.float32(0.33))

        ae(b1[vi(-1, 0), 128, 128], np.float32(0.21))
        ae(b1[vi(-1, 1), 129, 128], np.float32(0.22))
        ae(b1[vi(-1, -1), 127, 128], np.float32(0.23))

        ae(b1[vi(-1, 0), 1, 128], np.float32(0.41))
        ae(b1[vi(-1, 1), 2, 128], np.float32(0.42))

        ae(b1[vi(-1, -1), 256, 128], np.float32(0.66))
        ae(b0[vi(1, 1), 1, 1], np.float32(0.77))
Example #24
0
 def test_sizes(sizes):
     for w, h in sizes:
         print "Testing {0} x {1}...".format(w, h)
         settings.update({"lat_nx": int(w), "lat_ny": int(h)})
         ctrl = LBSimulationController(LDCSim, LBGeometry2D, settings)
         timing_infos, blocks = ctrl.run()
         summary.append(util.summarize(timing_infos, blocks))
         timings.append(timing_infos)
Example #25
0
 def test_sizes(sizes, geo_cls):
     for w, h, d in sizes:
         print 'Testing {0} x {1} x {2}...'.format(w, h, d)
         settings.update({'lat_nx': int(w), 'lat_ny': int(h), 'lat_nz': int(d)})
         ctrl = LBSimulationController(LDCSim, geo_cls, settings)
         timing_infos, blocks = ctrl.run()
         summary.append(util.summarize(timing_infos, blocks))
         timings.append(timing_infos)
Example #26
0
 def test_sizes(sizes, geo_cls):
     for w, h in sizes:
         print 'Testing {0} x {1}...'.format(w, h)
         settings.update({'lat_nx': int(w), 'lat_ny': int(h)})
         ctrl = LBSimulationController(LDCSim, geo_cls, settings)
         timing_infos, blocks = ctrl.run()
         summary.append(util.summarize(timing_infos, blocks))
         timings.append(timing_infos)
Example #27
0
 def setUpClass(cls):
     global blocks, output
     output = os.path.join(tmpdir, 'href')
     blocks = 1
     ctrl = LBSimulationController(SimulationTest, SphereGeometry)
     ctrl.run(ignore_cmdline=True)
     cls.digits = io.filename_iter_digits(MAX_ITERS)
     cls.ref = np.load(io.filename(output, cls.digits, 0, MAX_ITERS))
Example #28
0
 def setUpClass(cls):
     global blocks, output
     output = os.path.join(tmpdir, 'href')
     blocks = 1
     ctrl = LBSimulationController(SimulationTest, SphereGeometry)
     ctrl.run(ignore_cmdline=True)
     cls.digits = io.filename_iter_digits(MAX_ITERS)
     cls.ref = np.load(io.filename(output, cls.digits, 0, MAX_ITERS))
Example #29
0
    def test_horiz_spread(self):
        def ic(self, runner):
            dbuf = runner._debug_get_dist()
            dbuf[:] = 0.0

            if runner._spec.id == 1:
                dbuf[vi(1, 0), 128, 128] = 0.11
                dbuf[vi(1, 1), 128, 128] = 0.12
                dbuf[vi(1, -1), 128, 128] = 0.13

                # At the top
                dbuf[vi(1, 0), 256, 128] = 0.31
                dbuf[vi(1, 1), 256, 128] = 0.32
                dbuf[vi(1, -1), 256, 128] = 0.33

                dbuf[vi(-1, -1), 256, 128] = 0.66  # should not be overwritten
            elif runner._spec.id == 0:
                dbuf[vi(-1, 0), 128, 1] = 0.21
                dbuf[vi(-1, 1), 128, 1] = 0.22
                dbuf[vi(-1, -1), 128, 1] = 0.23

                # At the bottom
                dbuf[vi(-1, 0), 1, 1] = 0.41
                dbuf[vi(-1, 1), 1, 1] = 0.42
                dbuf[vi(-1, -1), 1, 1] = 0.43

                dbuf[vi(1, 1), 1, 1] = 0.77  # should not be overwritten

            runner._debug_set_dist(dbuf)
            runner._debug_set_dist(dbuf, False)

        HorizTest = type('HorizTest', (SimulationTest, ),
                         {'initial_conditions': ic})
        ctrl = LBSimulationController(HorizTest, DoubleBlockGeometryTest)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, 'test_out')
        b0 = np.load(io.dists_filename(output, 1, 0, 1))['arr_0']
        b1 = np.load(io.dists_filename(output, 1, 1, 1))['arr_0']

        ae = np.testing.assert_equal

        ae(b0[vi(1, 0), 128, 1], np.float32(0.11))
        ae(b0[vi(1, 1), 129, 1], np.float32(0.12))
        ae(b0[vi(1, -1), 127, 1], np.float32(0.13))

        ae(b0[vi(1, 0), 256, 1], np.float32(0.31))
        ae(b0[vi(1, -1), 255, 1], np.float32(0.33))

        ae(b1[vi(-1, 0), 128, 128], np.float32(0.21))
        ae(b1[vi(-1, 1), 129, 128], np.float32(0.22))
        ae(b1[vi(-1, -1), 127, 128], np.float32(0.23))

        ae(b1[vi(-1, 0), 1, 128], np.float32(0.41))
        ae(b1[vi(-1, 1), 2, 128], np.float32(0.42))

        ae(b1[vi(-1, -1), 256, 128], np.float32(0.66))
        ae(b0[vi(1, 1), 1, 1], np.float32(0.77))
Example #30
0
    def test_b0_spread(self):
        global tmpdir

        def ic(self, runner):
            dbuf = runner._debug_get_dist()
            dbuf[:] = 0.0

            if runner._spec.id == 0:
                # Top right corner
                dbuf[vi(1, 1), 128, 128] = 0.11
                dbuf[vi(0, 1), 128, 128] = 0.01
                dbuf[vi(1, 0), 128, 128] = 0.10
                dbuf[vi(0, -1), 128, 128] = 0.02
                dbuf[vi(-1, 0), 128, 128] = 0.20
                dbuf[vi(1, -1), 128, 128] = 0.30
                dbuf[vi(-1, 1), 128, 128] = 0.40

                # Bottom right corner
                dbuf[vi(1, 1), 1, 128] = 0.50
                dbuf[vi(1, -1), 1, 128] = 0.51
                dbuf[vi(1, 0), 1, 128] = 0.52
            elif runner._spec.id == 1:
                dbuf[vi(1, 0), 127, 128] = 0.60
                dbuf[vi(1, 1), 127, 128] = 0.61
                dbuf[vi(1, -1), 127, 128] = 0.62
                dbuf[vi(1, 0), 128, 128] = 0.70
                dbuf[vi(1, -1), 128, 128] = 0.71

            runner._debug_set_dist(dbuf)
            runner._debug_set_dist(dbuf, False)

        RightSide = type('RightSide', (SimulationTest, ),
                         {'initial_conditions': ic})
        ctrl = LBSimulationController(RightSide, GeometryTest)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, 'test_out')
        b0 = np.load(io.dists_filename(output, 1, 0, 1))['arr_0']
        b1 = np.load(io.dists_filename(output, 1, 1, 1))['arr_0']
        b2 = np.load(io.dists_filename(output, 1, 2, 1))['arr_0']
        b3 = np.load(io.dists_filename(output, 1, 3, 1))['arr_0']
        ae = np.testing.assert_equal

        ae(b3[vi(1, 1), 1, 1], np.float32(0.11))
        ae(b0[vi(-1, 0), 128, 127], np.float32(0.20))
        ae(b0[vi(0, -1), 127, 128], np.float32(0.02))
        ae(b2[vi(1, 0), 128, 1], np.float32(0.10))
        ae(b1[vi(0, 1), 1, 128], np.float32(0.01))
        ae(b2[vi(1, -1), 127, 1], np.float32(0.30))
        ae(b1[vi(-1, 1), 1, 127], np.float32(0.40))
        ae(b2[vi(1, 1), 2, 1], np.float32(0.50))
        ae(b2[vi(1, 0), 1, 1], np.float32(0.52))

        ae(b3[vi(1, 0), 127, 1], np.float32(0.60))
        ae(b3[vi(1, 0), 128, 1], np.float32(0.70))
        ae(b3[vi(1, 1), 128, 1], np.float32(0.61))
        ae(b3[vi(1, -1), 127, 1], np.float32(0.71))
        ae(b3[vi(1, -1), 126, 1], np.float32(0.62))
Example #31
0
    def test_b0_spread(self):
        global tmpdir

        def ic(self, runner):
            dbuf = runner._debug_get_dist()
            dbuf[:] = 0.0

            if runner._spec.id == 0:
                # Top right corner
                dbuf[vi(1, 1), 128, 128] = 0.11
                dbuf[vi(0, 1), 128, 128] = 0.01
                dbuf[vi(1, 0), 128, 128] = 0.10
                dbuf[vi(0, -1), 128, 128] = 0.02
                dbuf[vi(-1, 0), 128, 128] = 0.20
                dbuf[vi(1, -1), 128, 128] = 0.30
                dbuf[vi(-1, 1), 128, 128] = 0.40

                # Bottom right corner
                dbuf[vi(1, 1), 1, 128] = 0.50
                dbuf[vi(1, -1), 1, 128] = 0.51
                dbuf[vi(1, 0), 1, 128] = 0.52
            elif runner._spec.id == 1:
                dbuf[vi(1, 0), 127, 128] = 0.60
                dbuf[vi(1, 1), 127, 128] = 0.61
                dbuf[vi(1, -1), 127, 128] = 0.62
                dbuf[vi(1, 0), 128, 128] = 0.70
                dbuf[vi(1, -1), 128, 128] = 0.71

            runner._debug_set_dist(dbuf)
            runner._debug_set_dist(dbuf, False)

        RightSide = type("RightSide", (SimulationTest,), {"initial_conditions": ic})
        ctrl = LBSimulationController(RightSide, GeometryTest)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, "test_out")
        b0 = np.load(io.dists_filename(output, 1, 0, 1))["arr_0"]
        b1 = np.load(io.dists_filename(output, 1, 1, 1))["arr_0"]
        b2 = np.load(io.dists_filename(output, 1, 2, 1))["arr_0"]
        b3 = np.load(io.dists_filename(output, 1, 3, 1))["arr_0"]
        ae = np.testing.assert_equal

        ae(b3[vi(1, 1), 1, 1], np.float32(0.11))
        ae(b0[vi(-1, 0), 128, 127], np.float32(0.20))
        ae(b0[vi(0, -1), 127, 128], np.float32(0.02))
        ae(b2[vi(1, 0), 128, 1], np.float32(0.10))
        ae(b1[vi(0, 1), 1, 128], np.float32(0.01))
        ae(b2[vi(1, -1), 127, 1], np.float32(0.30))
        ae(b1[vi(-1, 1), 1, 127], np.float32(0.40))
        ae(b2[vi(1, 1), 2, 1], np.float32(0.50))
        ae(b2[vi(1, 0), 1, 1], np.float32(0.52))

        ae(b3[vi(1, 0), 127, 1], np.float32(0.60))
        ae(b3[vi(1, 0), 128, 1], np.float32(0.70))
        ae(b3[vi(1, 1), 128, 1], np.float32(0.61))
        ae(b3[vi(1, -1), 127, 1], np.float32(0.71))
        ae(b3[vi(1, -1), 126, 1], np.float32(0.62))
Example #32
0
    def test_depth_spread(self):
        global tmpdir
        DepthTest = type('DepthTest', (SimulationTest,), {'axis': 2})
        ctrl = LBSimulationController(DepthTest, TwoBlocksZConnGeoTest)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, 'test_out')
        b0 = np.load(io.dists_filename(output, 1, 0, 1))
        b1 = np.load(io.dists_filename(output, 1, 1, 1))
        self._verify(b0, b1, DepthTest)
Example #33
0
    def test_vert_spread(self):
        global tmpdir
        VertTest = type('VertTest', (SimulationTest,), {'axis': 1})
        ctrl = LBSimulationController(VertTest, TwoBlocksYConnGeoTest)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, 'test_out')
        b0 = np.load(io.dists_filename(output, 1, 0, 1))['arr_0']
        b1 = np.load(io.dists_filename(output, 1, 1, 1))['arr_0']
        self._verify(b0, b1, VertTest)
Example #34
0
    def test_depth_spread(self):
        global tmpdir
        DepthTest = type('DepthTest', (SimulationTest, ), {'axis': 2})
        ctrl = LBSimulationController(DepthTest, TwoBlocksZConnGeoTest)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, 'test_out')
        b0 = np.load(io.dists_filename(output, 1, 0, 1))['arr_0']
        b1 = np.load(io.dists_filename(output, 1, 1, 1))['arr_0']
        self._verify(b0, b1, DepthTest)
Example #35
0
    def test_2subdomains(self):
        ctrl = LBSimulationController(AASimulationTest2,
                                      EqualSubdomainsGeometry3D)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, 'test_out')
        b0 = np.load(io.dists_filename(output, 1, 0, 2))['arr_0']
        b1 = np.load(io.dists_filename(output, 1, 1, 2))['arr_0']
        ae = np.testing.assert_equal

        ae(b0[vi(0, 1, -1), 40, 39, 10], np.float32(0.11))
Example #36
0
    def test_2subdomains(self):
        ctrl = LBSimulationController(AASimulationTest2,
                                      EqualSubdomainsGeometry3D)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, 'test_out')
        b0 = np.load(io.dists_filename(output, 1, 0, 2))['arr_0']
        b1 = np.load(io.dists_filename(output, 1, 1, 2))['arr_0']
        ae = np.testing.assert_equal

        ae(b0[vi(0, 1, -1), 40, 39, 10], np.float32(0.11))
Example #37
0
    def test_horiz_global_periodic(self):
        global tmpdir

        def ic(self, runner):
            dbuf = runner._debug_get_dist()
            dbuf[:] = 0.0

            dbuf[vi(1, 0), 128, 256] = 0.11
            dbuf[vi(1, 1), 128, 256] = 0.12
            dbuf[vi(1, -1), 128, 256] = 0.13

            # At the top
            dbuf[vi(1, 0), 256, 256] = 0.31
            dbuf[vi(1, 1), 256, 256] = 0.32
            dbuf[vi(1, -1), 256, 256] = 0.33

            dbuf[vi(-1, -1), 256, 256] = 0.66  # should not be overwritten
            dbuf[vi(-1, 0), 128, 1] = 0.21
            dbuf[vi(-1, 1), 128, 1] = 0.22
            dbuf[vi(-1, -1), 128, 1] = 0.23

            # At the bottom
            dbuf[vi(-1, 0), 1, 1] = 0.41
            dbuf[vi(-1, 1), 1, 1] = 0.42
            dbuf[vi(-1, -1), 1, 1] = 0.43

            dbuf[vi(1, 1), 1, 1] = 0.77  # should not be overwritten

            runner._debug_set_dist(dbuf)
            runner._debug_set_dist(dbuf, False)

        HorizTest = type("HorizTest", (SimulationTest,), {"initial_conditions": ic})
        ctrl = LBSimulationController(HorizTest)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, "test_out")
        b0 = np.load(io.dists_filename(output, 1, 0, 1))["arr_0"]
        ae = np.testing.assert_equal

        ae(b0[vi(1, 0), 128, 1], np.float32(0.11))
        ae(b0[vi(1, 1), 129, 1], np.float32(0.12))
        ae(b0[vi(1, -1), 127, 1], np.float32(0.13))
        ae(b0[vi(1, 0), 256, 1], np.float32(0.31))
        ae(b0[vi(1, -1), 255, 1], np.float32(0.33))

        ae(b0[vi(-1, 0), 128, 256], np.float32(0.21))
        ae(b0[vi(-1, 1), 129, 256], np.float32(0.22))
        ae(b0[vi(-1, -1), 127, 256], np.float32(0.23))
        ae(b0[vi(-1, 0), 1, 256], np.float32(0.41))
        ae(b0[vi(-1, 1), 2, 256], np.float32(0.42))

        ae(b0[vi(1, 1), 1, 1], np.float32(0.77))
        ae(b0[vi(-1, -1), 256, 256], np.float32(0.66))
Example #38
0
    def test_spread(self):
        def ic(self, runner):
            dbuf = runner._debug_get_dist()
            dbuf[:] = 0.0

            if runner._spec.id == 1:
                dbuf[vi(1, 0), 1, 128] = 0.11
                dbuf[vi(1, 1), 1, 128] = 0.12
                dbuf[vi(1, -1), 1, 128] = 0.13

                # At the top
                dbuf[vi(1, 0), 256, 128] = 0.31
                dbuf[vi(1, 1), 256, 128] = 0.32
                dbuf[vi(1, -1), 256, 128] = 0.33

            elif runner._spec.id == 0:
                dbuf[vi(-1, 0), 256, 1] = 0.21
                dbuf[vi(-1, 1), 256, 1] = 0.22
                dbuf[vi(-1, -1), 256, 1] = 0.23

                # At the bottom
                dbuf[vi(-1, 0), 1, 1] = 0.41
                dbuf[vi(-1, 1), 1, 1] = 0.42
                dbuf[vi(-1, -1), 1, 1] = 0.43

            runner._debug_set_dist(dbuf)
            runner._debug_set_dist(dbuf, False)

        HorizTest = type("HorizTest", (SimulationTest,), {"initial_conditions": ic})
        ctrl = LBSimulationController(HorizTest, DoubleBlockGeometryTest)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, "test_out")
        b0 = np.load(io.dists_filename(output, 1, 0, 1))["arr_0"]
        b1 = np.load(io.dists_filename(output, 1, 1, 1))["arr_0"]
        ae = np.testing.assert_equal

        ae(b0[vi(1, 0), 1, 1], np.float32(0.11))
        ae(b0[vi(1, 1), 2, 1], np.float32(0.12))
        ae(b0[vi(1, -1), 256, 1], np.float32(0.13))

        ae(b0[vi(1, 0), 256, 1], np.float32(0.31))
        ae(b0[vi(1, 1), 1, 1], np.float32(0.32))
        ae(b0[vi(1, -1), 255, 1], np.float32(0.33))

        ae(b1[vi(-1, 0), 256, 128], np.float32(0.21))
        ae(b1[vi(-1, 1), 1, 128], np.float32(0.22))
        ae(b1[vi(-1, -1), 255, 128], np.float32(0.23))

        ae(b1[vi(-1, 0), 1, 128], np.float32(0.41))
        ae(b1[vi(-1, 1), 2, 128], np.float32(0.42))
        ae(b1[vi(-1, -1), 256, 128], np.float32(0.43))
Example #39
0
    def test_shift_3d(self):
        global output
        output = os.path.join(tmpdir, 'baseline')
        LBSimulationController(SCTestSim3D,
                               LBGeometry3D).run(ignore_cmdline=True)
        digits = io.filename_iter_digits(MAX_ITERS_3D)
        ref = np.load(io.filename(output, digits, 0, MAX_ITERS_3D))

        output = os.path.join(tmpdir, 'shifted')
        SCTestDomain3D.shift = True
        LBSimulationController(SCTestSim3D,
                               LBGeometry3D).run(ignore_cmdline=True)
        shifted = np.load(io.filename(output, digits, 0, MAX_ITERS_3D))
        self._verify(ref, shifted)
Example #40
0
    def test_4subdomains(self):
        ctrl = LBSimulationController(AASimulationTest, FourSubdomainsTest)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, 'test_out')
        b0 = np.load(io.dists_filename(output, 1, 0, 1))['arr_0']
        b1 = np.load(io.dists_filename(output, 1, 1, 1))['arr_0']
        b2 = np.load(io.dists_filename(output, 1, 2, 1))['arr_0']
        b3 = np.load(io.dists_filename(output, 1, 3, 1))['arr_0']
        ae = np.testing.assert_equal

        # No propagation in the first step, but the distributions are stored
        # in opposite slots.
        ae(b3[vi(0, -1, -1), 0, 0, 10], np.float32(0.11))
Example #41
0
    def test_4subdomains(self):
        ctrl = LBSimulationController(AASimulationTest, FourSubdomainsTest)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, 'test_out')
        b0 = np.load(io.dists_filename(output, 1, 0, 1))
        b1 = np.load(io.dists_filename(output, 1, 1, 1))
        b2 = np.load(io.dists_filename(output, 1, 2, 1))
        b3 = np.load(io.dists_filename(output, 1, 3, 1))
        ae = np.testing.assert_equal

        # No propagation in the first step, but the distributions are stored
        # in opposite slots.
        ae(b3[vi(0, -1, -1), 0, 0, 10], np.float32(0.11))
Example #42
0
    def test_4corners(self):
        global tmpdir
        ctrl = LBSimulationController(SimulationTest, GeometryTest)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, "test_out")
        b0 = np.load(io.dists_filename(output, 1, 0, 1))["arr_0"]
        b1 = np.load(io.dists_filename(output, 1, 1, 1))["arr_0"]
        b2 = np.load(io.dists_filename(output, 1, 2, 1))["arr_0"]
        b3 = np.load(io.dists_filename(output, 1, 3, 1))["arr_0"]

        np.testing.assert_equal(b0[vi(-1, -1), 128, 128], np.float32(0.44))
        np.testing.assert_equal(b1[vi(-1, 1), 1, 128], np.float32(0.33))
        np.testing.assert_equal(b2[vi(1, -1), 128, 1], np.float32(0.22))
        np.testing.assert_equal(b3[vi(1, 1), 1, 1], np.float32(0.11))
Example #43
0
    def test_4corners(self):
        global tmpdir
        ctrl = LBSimulationController(SimulationTest, GeometryTest)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, 'test_out')
        b0 = np.load(io.dists_filename(output, 1, 0, 1))['arr_0']
        b1 = np.load(io.dists_filename(output, 1, 1, 1))['arr_0']
        b2 = np.load(io.dists_filename(output, 1, 2, 1))['arr_0']
        b3 = np.load(io.dists_filename(output, 1, 3, 1))['arr_0']

        np.testing.assert_equal(b0[vi(-1, -1), 128, 128], np.float32(0.44))
        np.testing.assert_equal(b1[vi(-1, 1), 1, 128], np.float32(0.33))
        np.testing.assert_equal(b2[vi(1, -1), 128, 1], np.float32(0.22))
        np.testing.assert_equal(b3[vi(1, 1), 1, 1], np.float32(0.11))
Example #44
0
    def test_3blocks(self):
        def ic(self, runner):
            dbuf = runner._debug_get_dist()
            dbuf[:] = 0.0

            if runner._spec.id == 0:
                dbuf[vi(1, 1), 128, 128] = 0.11
                dbuf[vi(0, 1), 128, 128] = 0.12
                dbuf[vi(1, 0), 128, 128] = 0.13
                dbuf[vi(1, -1), 128, 128] = 0.14
                dbuf[vi(-1, 1), 128, 128] = 0.15
            elif runner._spec.id == 1:
                dbuf[vi(-1, -1), 1, 128] = 0.16
                dbuf[vi(0, -1), 1, 128] = 0.17
            elif runner._spec.id == 2:
                dbuf[vi(-1, -1), 129, 1] = 0.18
                dbuf[vi(-1, -1), 128, 1] = 0.19
                dbuf[vi(-1, 0), 128, 1] = 0.20

            runner._debug_set_dist(dbuf)

        SimTest = type('SimTest', (AASimulationTest, ),
                       {'initial_conditions': ic})
        ctrl = LBSimulationController(SimTest, ThreeBlocksGeometryTest)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, 'test_out')
        b0 = np.load(io.dists_filename(output, 1, 0, 1))['arr_0']
        b1 = np.load(io.dists_filename(output, 1, 1, 1))['arr_0']
        b2 = np.load(io.dists_filename(output, 1, 2, 1))['arr_0']
        ae = np.testing.assert_equal

        # No propagation in the first step, but the distributions are stored
        # in opposite slots.
        ae(b2[vi(-1, -1), 128, 0], np.float32(0.11))
        ae(b2[vi(-1, 0), 128, 0], np.float32(0.13))
        ae(b2[vi(-1, 1), 128, 0], np.float32(0.14))
        ae(b1[vi(1, -1), 0, 128], np.float32(0.15))
        ae(b1[vi(0, -1), 0, 128], np.float32(0.12))

        # From b1
        ae(b0[vi(1, 1), 129, 128], np.float32(0.16))
        ae(b0[vi(0, 1), 129, 128], np.float32(0.17))

        # From b2
        ae(b0[vi(1, 1), 128, 129], np.float32(0.19))
        ae(b0[vi(1, 1), 129, 129], np.float32(0.18))
        ae(b0[vi(1, 0), 128, 129], np.float32(0.20))
Example #45
0
    def test_3blocks(self):
        def ic(self, runner):
            dbuf = runner._debug_get_dist()
            dbuf[:] = 0.0

            if runner._spec.id == 0:
                dbuf[vi(1, 1), 128, 128] = 0.11
                dbuf[vi(0, 1), 128, 128] = 0.12
                dbuf[vi(1, 0), 128, 128] = 0.13
                dbuf[vi(1, -1), 128, 128] = 0.14
                dbuf[vi(-1, 1), 128, 128] = 0.15
            elif runner._spec.id == 1:
                dbuf[vi(-1, -1), 1, 128] = 0.16
                dbuf[vi(0, -1), 1, 128] = 0.17
            elif runner._spec.id == 2:
                dbuf[vi(-1, -1), 129, 1] = 0.18
                dbuf[vi(-1, -1), 128, 1] = 0.19
                dbuf[vi(-1, 0), 128, 1] = 0.20

            runner._debug_set_dist(dbuf)

        SimTest = type('SimTest', (AASimulationTest,),
                {'initial_conditions': ic})
        ctrl = LBSimulationController(SimTest, ThreeBlocksGeometryTest)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, 'test_out')
        b0 = np.load(io.dists_filename(output, 1, 0, 1))['arr_0']
        b1 = np.load(io.dists_filename(output, 1, 1, 1))['arr_0']
        b2 = np.load(io.dists_filename(output, 1, 2, 1))['arr_0']
        ae = np.testing.assert_equal

        # No propagation in the first step, but the distributions are stored
        # in opposite slots.
        ae(b2[vi(-1, -1), 128, 0], np.float32(0.11))
        ae(b2[vi(-1, 0), 128, 0], np.float32(0.13))
        ae(b2[vi(-1, 1), 128, 0], np.float32(0.14))
        ae(b1[vi(1, -1), 0, 128], np.float32(0.15))
        ae(b1[vi(0, -1), 0, 128], np.float32(0.12))

        # From b1
        ae(b0[vi(1, 1), 129, 128], np.float32(0.16))
        ae(b0[vi(0, 1), 129, 128], np.float32(0.17))

        # From b2
        ae(b0[vi(1, 1), 128, 129], np.float32(0.19))
        ae(b0[vi(1, 1), 129, 129], np.float32(0.18))
        ae(b0[vi(1, 0), 128, 129], np.float32(0.20))
Example #46
0
 def setUpClass(cls):
     global output
     output = os.path.join(tmpdir, 'ref')
     LBSimulationController(FESimulationTest,
                            LBGeometry2D).run(ignore_cmdline=True)
     cls.digits = io.filename_iter_digits(MAX_ITERS)
     cls.ref = np.load(io.filename(output, cls.digits, 0, MAX_ITERS))
Example #47
0
    def test_scratch_space(self):
        ctrl = LBSimulationController(TestSim, default_config={
            'debug_single_process': True,
            'quiet': True,
            'lat_nx': self.nx,
            'lat_ny': self.ny,
            'max_iters': 1})
        ctrl.run(ignore_cmdline=True)
        sim = ctrl.master.sim

        hy, hx = np.mgrid[0:self.ny,0:self.nx]

        np.testing.assert_allclose(sim.output_x[hx == 0], (hx[hx == 0] + 1) / 10.0)
        np.testing.assert_allclose(sim.output_y[hx == 0], (hy[hx == 0] + 1) / 10.0)
        np.testing.assert_allclose(sim.output_xy[hx == 0],
                ((hx[hx == 0] + 1) * (hy[hx == 0] + 1) / 10.0))
Example #48
0
    def test_2d(self):
        s = settings
        s.update({"lat_nx": NX, "lat_ny": NY})

        TestSim.subdomain = TestSubdomain2D
        TestSim.subdomain_runner = TestSubdomainRunner2D

        ctrl = LBSimulationController(TestSim, default_config=s)
        ctrl.run(ignore_cmdline=True)

        sim = ctrl.master.sim
        # reduction over Y
        np.testing.assert_array_almost_equal(ctrl.master.runner.ret_x, np.sum(sim.data, axis=0))
        # reduction over X
        np.testing.assert_array_almost_equal(ctrl.master.runner.ret_y, np.sum(sim.data, axis=1))
        # reduction over X with a finalization step
        np.testing.assert_array_almost_equal(ctrl.master.runner.ret_y2, np.sum(sim.data, axis=1))
Example #49
0
def run_benchmark(num_blocks):
    # Lattice size is optimized for Tesla C2050.
    settings = {
        'max_iters': 1000,
        'every': 500,
        'quiet': True,
        'block_size': 128,
        'subdomains': num_blocks,
        'conn_axis': 'y',
        'lat_nx': 5118,
        'lat_ny': 5800 * num_blocks,
    }

    ctrl = LBSimulationController(LDCSim, EqualSubdomainsGeometry2D, settings)
    timing_infos, min_timings, max_timings, subdomains = ctrl.run()
    util.save_result('weak_2d_single', num_blocks, timing_infos, min_timings,
                     max_timings, subdomains)
Example #50
0
def run_benchmark(num_blocks):
    # Lattice size is optimized for Tesla C2050.
    settings = {
        'max_iters': 1000,
        'every': 500,
        'quiet': True,
        'block_size': 128,
        'subdomains': num_blocks,
        'conn_axis': 'y',
        'lat_nx': 5118,
        'lat_ny': 5800 * num_blocks,
        }

    ctrl = LBSimulationController(LDCSim, EqualSubdomainsGeometry2D, settings)
    timing_infos, min_timings, max_timings, subdomains = ctrl.run()
    util.save_result('weak_2d_single', num_blocks, timing_infos, min_timings,
            max_timings, subdomains)
Example #51
0
    def test_shift_3d(self):
        global output
        output = os.path.join(tmpdir, 'baseline')
        LBSimulationController(FETestSim3D,
                               LBGeometry3D).run(ignore_cmdline=True)
        digits = io.filename_iter_digits(MAX_ITERS_3D)
        ref = np.load(io.filename(output, digits, 0, MAX_ITERS_3D))

        output = os.path.join(tmpdir, 'shifted')
        FETestDomain3D.shift = True
        LBSimulationController(FETestSim3D,
                               LBGeometry3D).run(ignore_cmdline=True)
        shifted = np.load(io.filename(output, digits, 0, MAX_ITERS_3D))
        match_fields(ref['rho'], shifted['rho'])
        match_fields(ref['phi'], shifted['phi'])
        self.assertFalse(np.any(np.isnan(ref['rho'])))
        self.assertFalse(np.any(np.isnan(ref['phi'])))
        self.assertFalse(np.any(np.isnan(shifted['rho'])))
        self.assertFalse(np.any(np.isnan(shifted['phi'])))
Example #52
0
    def test_propagation(self):
        global tmpdir
        ctrl = LBSimulationController(ThreeBlocksSimulationTest, ThreeBlocksGeometryTest)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, "test_out")
        b0 = np.load(io.dists_filename(output, 1, 0, 1))["arr_0"]
        b1 = np.load(io.dists_filename(output, 1, 1, 1))["arr_0"]
        b2 = np.load(io.dists_filename(output, 1, 2, 1))["arr_0"]

        ae = np.testing.assert_equal

        ae(b0[vi(0, -1), 128, 64], np.float32(0.21))
        ae(b1[vi(0, 1), 1, 64], np.float32(0.13))
        ae(b2[vi(1, 0), 64, 1], np.float32(0.12))
        ae(b2[vi(1, 0), 64 + 128, 1], np.float32(0.23))
        ae(b0[vi(-1, 0), 64, 128], np.float32(0.31))
        ae(b2[vi(1, 1), 129, 1], np.float32(0.11))
        ae(b2[vi(1, -1), 128, 1], np.float32(0.22))
Example #53
0
    def test_2d(self):
        s = settings
        s.update({'lat_nx': NX, 'lat_ny': NY})

        TestSim.subdomain = TestSubdomain2D
        TestSim.subdomain_runner = TestSubdomainRunner2D

        ctrl = LBSimulationController(TestSim, default_config=s)
        ctrl.run(ignore_cmdline=True)

        sim = ctrl.master.sim
        # reduction over Y
        np.testing.assert_array_almost_equal(ctrl.master.runner.ret_x,
                                             np.sum(sim.data, axis=0))
        # reduction over X
        np.testing.assert_array_almost_equal(ctrl.master.runner.ret_y,
                                             np.sum(sim.data, axis=1))
        # reduction over X with a finalization step
        np.testing.assert_array_almost_equal(ctrl.master.runner.ret_y2,
                                             np.sum(sim.data, axis=1))
Example #54
0
    def setUpClass(cls):
        global blocks, vertical, output
        output = os.path.join(tmpdir, 'href')
        blocks = 1
        LBSimulationController(
            SimulationTest, EqualSubdomainsGeometry2D).run(ignore_cmdline=True)
        cls.digits = io.filename_iter_digits(MAX_ITERS)
        cls.href = np.load(io.filename(output, cls.digits, 0, MAX_ITERS))
        cls.hrho = cls.href['rho']
        cls.hvx = cls.href['v'][0]
        cls.hvy = cls.href['v'][1]

        output = os.path.join(tmpdir, 'vref')
        vertical = True
        LBSimulationController(
            SimulationTest, EqualSubdomainsGeometry2D).run(ignore_cmdline=True)
        cls.vref = np.load(io.filename(output, cls.digits, 0, MAX_ITERS))
        cls.vrho = cls.vref['rho']
        cls.vvx = cls.vref['v'][0]
        cls.vvy = cls.vref['v'][1]
Example #55
0
    def test_propagation(self):
        global tmpdir
        ctrl = LBSimulationController(ThreeBlocksSimulationTest,
                                      ThreeBlocksGeometryTest)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, 'test_out')
        b0 = np.load(io.dists_filename(output, 1, 0, 1))['arr_0']
        b1 = np.load(io.dists_filename(output, 1, 1, 1))['arr_0']
        b2 = np.load(io.dists_filename(output, 1, 2, 1))['arr_0']

        ae = np.testing.assert_equal

        ae(b0[vi(0, -1), 128, 64], np.float32(0.21))
        ae(b1[vi(0, 1), 1, 64], np.float32(0.13))
        ae(b2[vi(1, 0), 64, 1], np.float32(0.12))
        ae(b2[vi(1, 0), 64 + 128, 1], np.float32(0.23))
        ae(b0[vi(-1, 0), 64, 128], np.float32(0.31))
        ae(b2[vi(1, 1), 129, 1], np.float32(0.11))
        ae(b2[vi(1, -1), 128, 1], np.float32(0.22))
Example #56
0
    def test_scratch_space(self):
        ctrl = LBSimulationController(TestSim,
                                      default_config={
                                          'debug_single_process': True,
                                          'quiet': True,
                                          'lat_nx': self.nx,
                                          'lat_ny': self.ny,
                                          'max_iters': 1
                                      })
        ctrl.run(ignore_cmdline=True)
        sim = ctrl.master.sim

        hy, hx = np.mgrid[0:self.ny, 0:self.nx]

        np.testing.assert_allclose(sim.output_x[hx == 0],
                                   (hx[hx == 0] + 1) / 10.0)
        np.testing.assert_allclose(sim.output_y[hx == 0],
                                   (hy[hx == 0] + 1) / 10.0)
        np.testing.assert_allclose(sim.output_xy[hx == 0],
                                   ((hx[hx == 0] + 1) *
                                    (hy[hx == 0] + 1) / 10.0))
Example #57
0
    def test_horiz_spread(self):
        ctrl = LBSimulationController(MisalignedHorizTest,
                                      TwoBlocksShiftedXConnGeoTest)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, 'test_out')
        b0 = np.load(io.dists_filename(output, 1, 0, 1))['arr_0']
        b1 = np.load(io.dists_filename(output, 1, 1, 1))['arr_0']

        ae = np.testing.assert_equal
        ae(b1[vi(1, 0, 0), 8, 5, 1], np.float32(0.11))
        ae(b1[vi(1, 1, 0), 8, 6, 1], np.float32(0.12))
        ae(b1[vi(1, -1, 0), 8, 4, 1], np.float32(0.13))
        ae(b1[vi(1, 0, 1), 9, 5, 1], np.float32(0.14))
        ae(b1[vi(1, 0, -1), 7, 5, 1], np.float32(0.15))

        ae(b0[vi(-1, 0, 0), 17, 9, 20], np.float32(0.21))
        ae(b0[vi(-1, 1, 0), 17, 10, 20], np.float32(0.22))
        ae(b0[vi(-1, -1, 0), 17, 8, 20], np.float32(0.23))
        ae(b0[vi(-1, 0, 1), 18, 9, 20], np.float32(0.24))
        ae(b0[vi(-1, 0, -1), 16, 9, 20], np.float32(0.25))
Example #58
0
    def test_vert_spread(self):
        ctrl = LBSimulationController(MisalignedVertTest,
                                      TwoBlocksShiftedYConnGeoTest)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, 'test_out')
        b0 = np.load(io.dists_filename(output, 1, 0, 1))['arr_0']
        b1 = np.load(io.dists_filename(output, 1, 1, 1))['arr_0']

        ae = np.testing.assert_equal
        ae(b1[vi(0, 1, 0), 5, 1, 20], np.float32(0.11))
        ae(b1[vi(1, 1, 0), 5, 1, 21], np.float32(0.12))
        ae(b1[vi(-1, 1, 0), 5, 1, 19], np.float32(0.13))
        ae(b1[vi(0, 1, 1), 6, 1, 20], np.float32(0.14))
        ae(b1[vi(0, 1, -1), 4, 1, 20], np.float32(0.15))

        ae(b0[vi(0, -1, 0), 5, 30, 30], np.float32(0.21))
        ae(b0[vi(1, -1, 0), 5, 30, 31], np.float32(0.22))
        ae(b0[vi(-1, -1, 0), 5, 30, 29], np.float32(0.23))
        ae(b0[vi(0, -1, 1), 6, 30, 30], np.float32(0.24))
        ae(b0[vi(0, -1, -1), 4, 30, 30], np.float32(0.25))
Example #59
0
    def test_horiz_spread(self):
        """Two blocks connected along the X axis, with Y PBC enabled.

        This test verifies distribution streaming from the corner nodes
        on the surface connecting the two blocks."""
        def ic(self, runner):
            dbuf = runner._debug_get_dist()
            dbuf[:] = 0.0

            if runner._spec.id == 1:
                # At the top
                dbuf[vi(-1, 0), 256, 1] = 0.31
                dbuf[vi(-1, 1), 256, 1] = 0.32
                dbuf[vi(-1, -1), 256, 1] = 0.33
            elif runner._spec.id == 0:
                # At the bottom
                dbuf[vi(1, 0), 1, 128] = 0.41
                dbuf[vi(1, 1), 1, 128] = 0.42
                dbuf[vi(1, -1), 1, 128] = 0.43

            runner._debug_set_dist(dbuf)
            runner._debug_set_dist(dbuf, False)

        HorizTest = type('HorizTest', (SimulationTest, ),
                         {'initial_conditions': ic})
        ctrl = LBSimulationController(HorizTest, DoubleBlockGeometryTest)
        ctrl.run(ignore_cmdline=True)

        output = os.path.join(tmpdir, 'test_out')
        b0 = np.load(io.dists_filename(output, 1, 0, 1))['arr_0']
        b1 = np.load(io.dists_filename(output, 1, 1, 1))['arr_0']
        ae = np.testing.assert_equal

        ae(b0[vi(-1, 0), 256, 128], np.float32(0.31))
        ae(b0[vi(-1, -1), 255, 128], np.float32(0.33))
        ae(b0[vi(-1, 1), 1, 128], np.float32(0.32))

        ae(b1[vi(1, 0), 1, 1], np.float32(0.41))
        ae(b1[vi(1, 1), 2, 1], np.float32(0.42))
        ae(b1[vi(1, -1), 256, 1], np.float32(0.43))