Пример #1
0
def save_output(basepath, max_iters):
    merged = merge_subdomains(os.path.join(tmpdir, 'result'),
                              io.filename_iter_digits(max_iters),
                              max_iters,
                              save=False)

    rho = merged['rho']
    lat_nz, lat_ny, lat_nx = rho.shape

    vx = merged['v'][0]
    vy = merged['v'][1]
    vz = merged['v'][2]

    nxh = lat_nx / 2
    nyh = lat_ny / 2
    nzh = lat_nz / 2

    res_vx = (vx[:, nyh, nxh] + vx[:, nyh - 1, nxh - 1]) / 2 / LDCBlock.max_v
    res_vz = (vz[nzh, nyh, :] + vz[nzh - 1, nyh - 1, :]) / 2 / LDCBlock.max_v

    np.savetxt(os.path.join(basepath, 're400_vx.dat'), res_vx)
    np.savetxt(os.path.join(basepath, 're400_vz.dat'), res_vz)

    plt.plot(res_vx, np.linspace(-1.0, 1.0, lat_nz), label='Sailfish')
    plt.plot(np.linspace(-1.0, 1.0, lat_nx), res_vz, label='Sailfish')
Пример #2
0
 def setUpClass(cls):
     global blocks, output
     output = os.path.join(tmpdir, 'ref')
     blocks = 1
     LBSimulationController(SimulationTest, LDCGeometry).run(ignore_cmdline=True)
     cls.digits = io.filename_iter_digits(MAX_ITERS)
     cls.ref = np.load(io.filename(output, cls.digits, 0, MAX_ITERS))
Пример #3
0
 def setUpClass(cls):
     global blocks, output
     output = os.path.join(tmpdir, 'ref')
     blocks = 1
     LBSimulationController(SimulationTest, LDCGeometry).run(ignore_cmdline=True)
     cls.digits = io.filename_iter_digits(MAX_ITERS)
     cls.ref = np.load(io.filename(output, cls.digits, 0, MAX_ITERS))
Пример #4
0
def run_test(name, precision):
    minvec = []
    maxvec = []
    ordvec = []
    basepath = os.path.join('regtest/results', name)

    if not os.path.exists(basepath):
        os.makedirs(basepath)

    xvec = np.linspace(3, 5.5, num=POINTS)
    f = open(os.path.join(basepath, '%s.dat' % precision), 'w')
    output = os.path.join(tmpdir, 'phase_sep')

    max_iters = 50000
    for g in xvec:
        print(' {0}'.format(g), end=' ')
        defaults = {
                'quiet': True,
                'verbose': False,
                'every': 1000,
                'seed': 2348,
                'max_iters': max_iters,
                'output': output,
                'G': -g,
            }

        LBSimulationController(SCSim, LBGeometry2D,
                default_config=defaults).run(ignore_cmdline=True)

        digits = io.filename_iter_digits(max_iters)
        fname = io.filename(output, digits, 0, max_iters)

        data = np.load(fname)
        rho = data['rho']
        avg = np.average(rho)
        order = np.sqrt(np.average(np.square(rho - avg))) / avg

        minvec.append(np.min(rho))
        maxvec.append(np.max(rho))
        ordvec.append(order)
        print(g, minvec[-1], maxvec[-1], ordvec[-1], file=f)

    print()

    f.close()

    plt.clf()
    plt.cla()

    plt.plot(xvec, minvec, 'b.-', label='min rho')
    plt.plot(xvec, maxvec, 'r.-', label='max rho')
    plt.plot(xvec, ordvec, 'k.-', label='order parameter')
    plt.gca().yaxis.grid(True)
    plt.gca().yaxis.grid(True, which='minor')
    plt.gca().xaxis.grid(True)
    plt.gca().xaxis.grid(True, which='minor')
    plt.ylabel('rho / order parameter')
    plt.xlabel('g')
    plt.legend(loc='upper left')
    plt.savefig(os.path.join(basepath, '%s.pdf' % precision), format='pdf')
Пример #5
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)
Пример #6
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)
Пример #7
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'])))
Пример #8
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]
Пример #9
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'])))
Пример #10
0
def save_output(basepath, max_iters):
    merged = merge_subdomains(os.path.join(tmpdir, "result"), io.filename_iter_digits(max_iters), max_iters, save=False)

    rho = merged["rho"]
    lat_ny, lat_nx = rho.shape

    vx = merged["v"][0]
    vy = merged["v"][1]

    nxh = lat_nx / 2
    nyh = lat_ny / 2

    res_vx = (vx[:, nxh] + vx[:, nxh - 1]) / 2 / LDCBlock.max_v
    res_vy = (vy[nyh, :] + vy[nyh - 1, :]) / 2 / LDCBlock.max_v

    plt.plot(res_vx, np.linspace(-1.0, 1.0, lat_ny), label="Sailfish")
    plt.plot(np.linspace(-1.0, 1.0, lat_nx), res_vy, label="Sailfish")

    np.savetxt(os.path.join(basepath, "vx.dat"), res_vx)
    np.savetxt(os.path.join(basepath, "vy.dat"), res_vy)
Пример #11
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]
Пример #12
0
def save_output(basepath):
    merged = merge_subdomains(os.path.join(tmpdir, 'result'),
            io.filename_iter_digits(MAX_ITERS), MAX_ITERS, save=False)

    rho = merged['rho']
    lat_ny, lat_nx = rho.shape

    vx = merged['v'][0]
    vy = merged['v'][1]

    nxh = lat_nx / 2
    nyh = lat_ny / 2

    res_vx = (vx[:, nxh] + vx[:, nxh-1]) / 2 / LDCBlock.max_v
    res_vy = (vy[nyh, :] + vy[nyh-1, :]) / 2 / LDCBlock.max_v

    plt.plot(res_vx, np.linspace(-1.0, 1.0, lat_ny), label='Sailfish')
    plt.plot(np.linspace(-1.0, 1.0, lat_nx), res_vy, label='Sailfish')

    np.savetxt(os.path.join(basepath, 'vx.dat'), res_vx)
    np.savetxt(os.path.join(basepath, 'vy.dat'), res_vy)
Пример #13
0
def save_output(basepath):
    merged = merge_subdomains(os.path.join(tmpdir, "result"), io.filename_iter_digits(MAX_ITERS), MAX_ITERS, save=False)

    rho = merged["rho"]
    lat_nz, lat_ny, lat_nx = rho.shape

    vx = merged["v"][0]
    vy = merged["v"][1]
    vz = merged["v"][2]

    nxh = lat_nx / 2
    nyh = lat_ny / 2
    nzh = lat_nz / 2

    res_vx = (vx[:, nyh, nxh] + vx[:, nyh - 1, nxh - 1]) / 2 / LDCBlock.max_v
    res_vz = (vz[nzh, nyh, :] + vz[nzh - 1, nyh - 1, :]) / 2 / LDCBlock.max_v

    np.savetxt(os.path.join(basepath, "re400_vx.dat"), res_vx)
    np.savetxt(os.path.join(basepath, "re400_vz.dat"), res_vz)

    plt.plot(res_vx, np.linspace(-1.0, 1.0, lat_nz), label="Sailfish")
    plt.plot(np.linspace(-1.0, 1.0, lat_nx), res_vz, label="Sailfish")
Пример #14
0
def save_output(basepath, max_iters):
    merged = merge_subdomains(os.path.join(tmpdir, 'result'),
                    io.filename_iter_digits(max_iters), max_iters, save=False)

    rho = merged['rho']
    lat_nz, lat_ny, lat_nx = rho.shape

    vx = merged['v'][0]
    vy = merged['v'][1]
    vz = merged['v'][2]

    nxh = lat_nx / 2
    nyh = lat_ny / 2
    nzh = lat_nz / 2

    res_vx = (vx[:, nyh, nxh] + vx[:, nyh-1, nxh-1]) / 2 / LDCBlock.max_v
    res_vz = (vz[nzh, nyh, :] + vz[nzh-1, nyh-1, :]) / 2 / LDCBlock.max_v

    np.savetxt(os.path.join(basepath, 're400_vx.dat'), res_vx)
    np.savetxt(os.path.join(basepath, 're400_vz.dat'), res_vz)

    plt.plot(res_vx, np.linspace(-1.0, 1.0, lat_nz), label='Sailfish')
    plt.plot(np.linspace(-1.0, 1.0, lat_nx), res_vz, label='Sailfish')
Пример #15
0
def run_test_2d():
    xvec = np.logspace(-3, -1, num=POINTS)
    yvec = np.zeros(POINTS, dtype=np.float64)
    tmpdir = tempfile.mkdtemp()

    summary_path = 'regtest/results/poiseuille/summary.png'
    profile_path = 'regtest/results/poiseuille'

    for i, visc in enumerate(xvec):
        print '%f ' % visc,

        max_iters = int(100 / visc)
        base_path = os.path.join(tmpdir, 'visc{0}'.format(i))

        defaults = {}
        defaults['visc'] = visc
        defaults['max_iters'] = max_iters
        defaults['output'] = base_path

        ctrl = LBSimulationController(TestPoiseuille2D,
                                      default_config=defaults)
        ctrl.run()

        digits = io.filename_iter_digits(max_iters)

        final_iter = 100 * (max_iters / 100)
        fname = io.filename(base_path, digits, 0, final_iter)
        res = np.load(fname)

        vx = res['v'][0]
        nyw = vx.shape[1] / 2
        hy = np.mgrid[0:vx.shape[0]]

        profile_sim = vx[:, nyw]
        profile_th = TestPoiseuille2D.subdomain.velocity_profile(
            ctrl.config, hy)

        yvec[i] = np.nanmax(profile_sim) / np.nanmax(profile_th) - 1.0

        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.plot(
            (profile_th[1:-1] - profile_sim[1:-1]) / np.nanmax(profile_th),
            'b.-')
        plt.gca().set_xbound(0, len(profile_sim) - 2)
        plt.title('(theoretical - simulation) / theo; visc = %f' % visc)
        plt.savefig(os.path.join(profile_path, 'profile{0:02d}.png'.format(i)),
                    format='png')

        plt.clf()
        plt.cla()

    plt.clf()
    plt.cla()

    plt.semilogx(xvec, yvec * 100, 'b.-')
    plt.gca().yaxis.grid(True)
    plt.gca().yaxis.grid(True, which='minor')
    plt.gca().xaxis.grid(True)
    plt.gca().xaxis.grid(True, which='minor')
    plt.ylabel('max velocity / theoretical max velocity - 1 [%]')
    plt.xlabel('viscosity')
    plt.savefig(summary_path, format='png')

    shutil.rmtree(tmpdir)
Пример #16
0
def run_test(name, precision):
    minvec = []
    maxvec = []
    ordvec = []
    basepath = os.path.join('regtest/results', name)

    if not os.path.exists(basepath):
        os.makedirs(basepath)

    xvec = np.linspace(3, 5.5, num=POINTS)
    f = open(os.path.join(basepath, '%s.dat' % precision), 'w')
    output = os.path.join(tmpdir, 'phase_sep')

    max_iters = 50000
    for g in xvec:
        print ' {0}'.format(g),
        defaults = {
            'quiet': True,
            'verbose': False,
            'every': 1000,
            'seed': 2348,
            'max_iters': max_iters,
            'output': output,
            'G': -g,
        }

        LBSimulationController(
            SCSim, LBGeometry2D,
            default_config=defaults).run(ignore_cmdline=True)

        digits = io.filename_iter_digits(max_iters)
        fname = io.filename(output, digits, 0, max_iters)

        data = np.load(fname)
        rho = data['rho']
        avg = np.average(rho)
        order = np.sqrt(np.average(np.square(rho - avg))) / avg

        minvec.append(np.min(rho))
        maxvec.append(np.max(rho))
        ordvec.append(order)
        print >> f, g, minvec[-1], maxvec[-1], ordvec[-1]

    print

    f.close()

    plt.clf()
    plt.cla()

    plt.plot(xvec, minvec, 'b.-', label='min rho')
    plt.plot(xvec, maxvec, 'r.-', label='max rho')
    plt.plot(xvec, ordvec, 'k.-', label='order parameter')
    plt.gca().yaxis.grid(True)
    plt.gca().yaxis.grid(True, which='minor')
    plt.gca().xaxis.grid(True)
    plt.gca().xaxis.grid(True, which='minor')
    plt.ylabel('rho / order parameter')
    plt.xlabel('g')
    plt.legend(loc='upper left')
    plt.savefig(os.path.join(basepath, '%s.pdf' % precision), format='pdf')
Пример #17
0
def run_test_2d():
    xvec = np.logspace(-3, -1, num=POINTS)
    yvec = np.zeros(POINTS, dtype=np.float64)
    tmpdir = tempfile.mkdtemp()

    summary_path = 'regtest/results/poiseuille/summary.png'
    profile_path = 'regtest/results/poiseuille'

    for i, visc in enumerate(xvec):
        print '%f ' % visc,

        max_iters = int(100 / visc)
        base_path = os.path.join(tmpdir, 'visc{0}'.format(i))

        defaults = {}
        defaults['visc'] = visc
        defaults['max_iters'] = max_iters
        defaults['output'] = base_path

        ctrl = LBSimulationController(TestPoiseuille2D, default_config=defaults)
        ctrl.run()

        digits = io.filename_iter_digits(max_iters)

        final_iter = 100 * (max_iters / 100)
        fname = io.filename(base_path, digits, 0, final_iter)
        res = np.load(fname)

        vx = res['v'][0]
        nyw = vx.shape[1] / 2
        hy = np.mgrid[0:vx.shape[0]]

        profile_sim = vx[:,nyw]
        profile_th = TestPoiseuille2D.subdomain.velocity_profile(ctrl.config, hy)

        yvec[i] = np.nanmax(profile_sim) / np.nanmax(profile_th) - 1.0

        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.plot((profile_th[1:-1] - profile_sim[1:-1]) / np.nanmax(profile_th), 'b.-')
        plt.gca().set_xbound(0, len(profile_sim)-2)
        plt.title('(theoretical - simulation) / theo; visc = %f' % visc)
        plt.savefig(os.path.join(profile_path, 'profile{0:02d}.png'.format(i)),
                format='png')

        plt.clf()
        plt.cla()

    plt.clf()
    plt.cla()

    plt.semilogx(xvec, yvec * 100, 'b.-')
    plt.gca().yaxis.grid(True)
    plt.gca().yaxis.grid(True, which='minor')
    plt.gca().xaxis.grid(True)
    plt.gca().xaxis.grid(True, which='minor')
    plt.ylabel('max velocity / theoretical max velocity - 1 [%]')
    plt.xlabel('viscosity')
    plt.savefig(summary_path, format='png')

    shutil.rmtree(tmpdir)