예제 #1
0
def test_acoustics_2d_variable():
    """Test variable-coefficient 2D acoustics"""

    import acoustics_2d_interface

    def verify_classic_acoustics(controller):
        import os
        from clawpack.pyclaw.util import check_diff
        import numpy as np
        """ Verifies 2d variable-coefficient acoustics from a previously verified classic run """

        state = controller.frames[controller.num_output_times].state
        dx, dy = controller.solution.domain.grid.delta
        test_q=state.get_q_global()

        if test_q != None:
            thisdir = os.path.dirname(__file__)
            expected_pressure = np.loadtxt(os.path.join(thisdir,'pressure_classic.txt'))
            test_pressure = test_q[0,:,:]
            #test_err = dx*dy*np.linalg.norm(expected_pressure-test_pressure)
            test_err = np.max(np.abs(expected_pressure[:]-test_pressure[:]))
            return check_diff(0, test_err, abstol=1e-1)


    from clawpack.pyclaw.util import gen_variants

    classic_tests = gen_variants(acoustics_2d_interface.setup, verify_classic_acoustics,
                                 solver_type='classic', disable_output=True)

    sharp_tests   = gen_variants(acoustics_2d_interface.setup, verify_classic_acoustics,
                                 solver_type='sharpclaw', disable_output=True)

    from itertools import chain
    for test in chain(classic_tests, sharp_tests):
        yield test
예제 #2
0
def test_2d_acoustics():
    """test_2d_acoustics"""
    def verify_data(data_filename):
        def verify(claw):
            """ verifies 2d homogeneous acoustics from a previously verified run """
            import os
            import numpy as np
            from clawpack.pyclaw.util import check_diff

            #grabs parallel results to process 0, None to other processes
            test_q = claw.solution.state.get_q_global()

            if test_q is not None:
                test_pressure = test_q[0, :, :]
                thisdir = os.path.dirname(__file__)
                expected_pressure = np.loadtxt(
                    os.path.join(thisdir, data_filename))
                return check_diff(expected_pressure,
                                  test_pressure,
                                  reltol=1e-3,
                                  delta=claw.solution.grid.delta)
            else:
                return

        return verify

    from clawpack.pyclaw.util import gen_variants
    import acoustics_2d

    classic_tests = gen_variants(acoustics_2d.setup,
                                 verify_data('verify_classic.txt'),
                                 kernel_languages=('Fortran', ),
                                 solver_type='classic',
                                 disable_output=True)

    ptwise_tests = gen_variants(acoustics_2d.setup,
                                verify_data('verify_classic.txt'),
                                kernel_languages=('Fortran', ),
                                ptwise=True,
                                solver_type='classic',
                                disable_output=True)

    sharp_tests_rk = gen_variants(acoustics_2d.setup,
                                  verify_data('verify_sharpclaw.txt'),
                                  kernel_languages=('Fortran', ),
                                  solver_type='sharpclaw',
                                  time_integrator='SSP104',
                                  disable_output=True)

    sharp_tests_lmm = gen_variants(acoustics_2d.setup,
                                   verify_data('verify_sharpclaw_lmm.txt'),
                                   kernel_languages=('Fortran', ),
                                   solver_type='sharpclaw',
                                   time_integrator='SSPLMMk2',
                                   disable_output=True)

    from itertools import chain
    for test in chain(classic_tests, ptwise_tests, sharp_tests_rk,
                      sharp_tests_lmm):
        yield test
예제 #3
0
def test_3d_acoustics():
    """ Tests for homogeneous and heterogeneous 3D acoustics"""

    def acoustics_verify_homogeneous(claw):
        """ Regression test for 3D homogeneous acoustics equations.
        """

        pinitial = claw.frames[0].state.get_q_global()
        pfinal = claw.frames[claw.num_output_times].state.get_q_global()

        if pinitial is not None:
            pinitial = pinitial[0, :, :, :].reshape(-1)
            pfinal = pfinal[0, :, :, :].reshape(-1)
            grid = claw.solution.state.grid
            final_difference = np.prod(grid.delta)*np.linalg.norm(pfinal-pinitial, ord=1)
            return check_diff(0., final_difference, abstol=1e-1)
        else:
            # In parallel, we check values only for the rank 0 process
            return

    def acoustics_verify_heterogeneous(claw):
        """ Regression test for 3D heterogeneous acoustics equations
        """

        pinitial = claw.frames[0].state.get_q_global()
        pfinal = claw.frames[claw.num_output_times].state.get_q_global()

        if pinitial is not None:
            pfinal = pfinal[0, :, :, :].reshape(-1)
            thisdir = os.path.dirname(__file__)
            verify_pfinal = np.loadtxt(os.path.join(thisdir, 'verify_classic_heterogeneous.txt'))
            norm_err = np.linalg.norm(pfinal-verify_pfinal)
            return check_diff(0, norm_err, abstol=10.)
        else:
            # In parallel, we check values only for the rank 0 process
            return

    classic_homogeneous_tests = gen_variants(acoustics_3d_interface.setup, acoustics_verify_homogeneous,
                                             kernel_languages=('Fortran',),
                                             solver_type='classic', problem='homogeneous',
                                             disable_output=True,mx=128,my=4,mz=4)

    classic_heterogeneous_tests = gen_variants(acoustics_3d_interface.setup, acoustics_verify_heterogeneous,
                                               kernel_languages=('Fortran',),
                                               solver_type='classic', problem='heterogeneous',
                                               disable_output=True,mx=15,my=15,mz=15)

    sharp_homogeneous_tests = gen_variants(acoustics_3d_interface.setup, acoustics_verify_homogeneous,
                                           kernel_languages=('Fortran',),
                                           solver_type='sharpclaw', problem='homogeneous',
                                           disable_output=True,mx=128,my=4,mz=4)

    sharp_heterogeneous_tests = gen_variants(acoustics_3d_interface.setup, acoustics_verify_heterogeneous,
                                             kernel_languages=('Fortran',),
                                             solver_type='sharpclaw', problem='heterogeneous',
                                             disable_output=True,mx=15,my=15,mz=15)

    for test in chain(classic_homogeneous_tests, classic_heterogeneous_tests, sharp_homogeneous_tests,
                      sharp_heterogeneous_tests):
        yield test
예제 #4
0
def test_2d_acoustics():
    """test_2d_acoustics"""

    def verify_data(data_filename):
        def verify(test_state):
            """ verifies 2d homogeneous acoustics from a previously verified run """
            import os
            import numpy as np
            from clawpack.pyclaw.util import check_diff


            #grabs parallel results to process 0, None to other processes
            test_q=test_state.get_q_global()

            if test_q is not None:
                test_pressure = test_q[0,:,:]
                thisdir = os.path.dirname(__file__)
                expected_pressure = np.loadtxt(os.path.join(thisdir,data_filename))
                return check_diff(expected_pressure, test_pressure, reltol=1e-3)
            else:
                return
        return verify

    from clawpack.pyclaw.util import gen_variants
    from acoustics import acoustics2D

    classic_tests = gen_variants(acoustics2D, verify_data('verify_classic.txt'),
                                 kernel_languages=('Fortran',), solver_type='classic', disable_output=True)

    sharp_tests   = gen_variants(acoustics2D, verify_data('verify_sharpclaw.txt'),
                                 kernel_languages=('Fortran',), solver_type='sharpclaw', disable_output=True)

    from itertools import chain
    for test in chain(classic_tests, sharp_tests):
        yield test
예제 #5
0
def test_1d_advection():
    """test_1d_advection

    tests against expected classic, sharpclaw, and high-order weno results """

    import advection_1d

    def verify_expected(expected):
        """ given an expected value, returns a verification function """
        def advection_verify(claw):
            from clawpack.pyclaw.util import check_diff
            import numpy as np

            q0 = claw.frames[0].state.get_q_global()
            qfinal = claw.frames[claw.num_output_times].state.get_q_global()

            if q0 is not None and qfinal is not None:
                dx = claw.solution.domain.grid.delta[0]
                test = dx * np.linalg.norm(qfinal - q0, 1)
                return check_diff(expected, test, reltol=1e-4)
            else:
                return

        return advection_verify

    from clawpack.pyclaw.util import gen_variants

    classic_tests = gen_variants(advection_1d.setup,
                                 verify_expected(3.203924e-04),
                                 kernel_languages=('Python', 'Fortran'),
                                 solver_type='classic',
                                 outdir=None)

    sharp_tests_rk = gen_variants(advection_1d.setup,
                                  verify_expected(1.163605e-05),
                                  kernel_languages=('Python', 'Fortran'),
                                  solver_type='sharpclaw',
                                  time_integrator='SSP104',
                                  outdir=None)

    sharp_tests_lmm = gen_variants(advection_1d.setup,
                                   verify_expected(3.39682948116e-05),
                                   kernel_languages=('Python', 'Fortran'),
                                   solver_type='sharpclaw',
                                   time_integrator='SSPMS32',
                                   outdir=None)

    weno_tests = gen_variants(advection_1d.setup,
                              verify_expected(7.489618e-06),
                              kernel_languages=('Fortran', ),
                              solver_type='sharpclaw',
                              time_integrator='SSP104',
                              weno_order=17,
                              outdir=None)

    from itertools import chain
    for test in chain(classic_tests, sharp_tests_rk, sharp_tests_lmm,
                      weno_tests):
        yield test
def test_acoustics_2d_variable():
    """Test variable-coefficient 2D acoustics"""

    import acoustics_2d_interface

    def verify_acoustics(controller, solver_type='classic'):
        """ Verifies 2d variable-coefficient acoustics from a previously verified classic run """
        import os
        from clawpack.pyclaw.util import check_diff
        import numpy as np

        state = controller.frames[controller.num_output_times].state
        dx, dy = controller.solution.domain.grid.delta
        test_q = state.get_q_global()

        if test_q is not None:
            thisdir = os.path.dirname(__file__)
            expected_pressure = np.loadtxt(
                os.path.join(thisdir, 'pressure_%s.txt' % solver_type))
            test_pressure = test_q[0, :, :]
            #test_err = dx*dy*np.linalg.norm(expected_pressure-test_pressure)
            test_err = np.max(
                np.abs(expected_pressure[:].reshape(-1) -
                       test_pressure[:].reshape(-1)))
            return check_diff(0, test_err, abstol=1e-1)

    from clawpack.pyclaw.util import gen_variants

    verify_func = lambda controller: verify_acoustics(controller,
                                                      solver_type='classic')
    classic_tests = gen_variants(acoustics_2d_interface.setup,
                                 verify_func,
                                 solver_type='classic',
                                 disable_output=True,
                                 num_cells=(50, 50))

    verify_func = lambda controller: verify_acoustics(controller,
                                                      solver_type='sharpclaw')
    sharp_tests_rk = gen_variants(acoustics_2d_interface.setup,
                                  verify_func,
                                  solver_type='sharpclaw',
                                  time_integrator='SSP104',
                                  disable_output=True,
                                  num_cells=(50, 50))

    sharp_tests_lmm = gen_variants(acoustics_2d_interface.setup,
                                   verify_func,
                                   lim_type=1,
                                   solver_type='sharpclaw',
                                   time_integrator='SSPMS32',
                                   disable_output=True,
                                   num_cells=(50, 50))

    from itertools import chain
    for test in chain(classic_tests, sharp_tests_rk, sharp_tests_lmm):
        yield test
예제 #7
0
def test_1d_acoustics():
    """test_1d_acoustics

    tests against known classic, sharpclaw, and high-order weno results """

    from . import acoustics_1d

    def verify_expected(expected):
        """ binds the expected value to the acoustics_verify methods """
        def acoustics_verify(claw):
            from clawpack.pyclaw.util import check_diff
            import numpy as np

            # tests are done across the entire domain of q normally
            q0=claw.frames[0].state.get_q_global()
            qfinal=claw.frames[claw.num_output_times].state.get_q_global()

            # and q_global is only returned on process 0
            if q0 is not None and qfinal is not None:
                q0 = q0.reshape([-1])
                qfinal = qfinal.reshape([-1])
                dx=claw.solution.domain.grid.delta[0]
                test = dx*np.sum(np.abs(qfinal-q0))
                return check_diff(expected, test, abstol=1e-4)
            else:
                return
        return acoustics_verify

    from clawpack.pyclaw.util import gen_variants

    classic_tests = gen_variants(acoustics_1d.setup, verify_expected(0.001049),
                                 kernel_languages=('Python','Fortran'), solver_type='classic', disable_output=True)

    ptwise_tests = gen_variants(acoustics_1d.setup, verify_expected(0.001049),
                                 kernel_languages=('Fortran',), ptwise=True,
                                 solver_type='classic', disable_output=True)


    sharp_tests_rk   = gen_variants(acoustics_1d.setup, verify_expected(0.000299),
                                 kernel_languages=('Python','Fortran'), solver_type='sharpclaw',
                                 time_integrator='SSP104', disable_output=True)

    sharp_tests_lmm   = gen_variants(acoustics_1d.setup, verify_expected(0.000231),
                                 kernel_languages=('Python','Fortran'), solver_type='sharpclaw',
                                 time_integrator='SSPLMMk3', disable_output=True)

    weno_tests    = gen_variants(acoustics_1d.setup, verify_expected(0.000153),
                                 kernel_languages=('Fortran',), solver_type='sharpclaw',
                                 time_integrator='SSP104', weno_order=17, disable_output=True)

    from itertools import chain
    for test in chain(classic_tests, ptwise_tests, sharp_tests_rk, sharp_tests_lmm, weno_tests):
        yield test
예제 #8
0
def test_3d_acoustics():
    """ test_3d_acoustics """

    def acoustics_verify_homogeneous(claw):
        from clawpack.pyclaw.util import check_diff
        import numpy as np

        pinitial = claw.frames[0].state.get_q_global()
        pfinal   = claw.frames[claw.num_output_times].state.get_q_global()

        pinitial = pinitial[0,:,:,:].reshape(-1)
        pfinal   = pfinal[0,:,:,:].reshape(-1)
        grid = claw.solution.state.grid
        final_difference =np.prod(grid.delta)*np.linalg.norm(pfinal-pinitial,ord=1)

        return check_diff(0.00286, final_difference, abstol=1e-4)

    def acoustics_verify_heterogeneous(claw):
        import os
        import numpy as np
        from clawpack.pyclaw.util import check_diff

        pinitial = claw.frames[0].state.get_q_global()
        pfinal   = claw.frames[claw.num_output_times].state.get_q_global()

        pinitial = pinitial[0,:,:,:].reshape(-1)
        pfinal   = pfinal[0,:,:,:].reshape(-1)
        grid = claw.solution.state.grid
        final_difference =np.prod(grid.delta)*np.linalg.norm(pfinal-pinitial,ord=1)

        thisdir = os.path.dirname(__file__)
        verify_pfinal = np.loadtxt(os.path.join(thisdir,'verify_classic_heterogeneous.txt'))
        norm_err = np.linalg.norm(pfinal-verify_pfinal)
        return check_diff(0, norm_err, abstol=2e-1)



    from clawpack.pyclaw.util import gen_variants
    import acoustics_3d_interface

    homogeneous_tests   = gen_variants(acoustics_3d_interface.setup, acoustics_verify_homogeneous,
                                       kernel_languages=('Fortran',), 
                                       solver_type='classic', test='homogeneous',
                                       disable_output=True)

    heterogeneous_tests = gen_variants(acoustics_3d_interface.setup, acoustics_verify_heterogeneous,
                                       kernel_languages=('Fortran',), 
                                       solver_type='classic', test='heterogeneous',
                                       disable_output=True)
    
    from itertools import chain
    for test in chain(homogeneous_tests, heterogeneous_tests):
        yield test
def test_acoustics_2d_variable():
    """Test variable-coefficient 2D acoustics"""

    import acoustics_2d_interface

    def verify_acoustics(controller, solver_type='classic'):
        """ Verifies 2d variable-coefficient acoustics from a previously verified classic run """
        import os
        from clawpack.pyclaw.util import check_diff
        import numpy as np

        state = controller.frames[controller.num_output_times].state
        dx, dy = controller.solution.domain.grid.delta
        test_q = state.get_q_global()

        if test_q is not None:
            thisdir = os.path.dirname(__file__)
            expected_pressure = np.loadtxt(os.path.join(thisdir,
                                               'pressure_%s.txt' % solver_type))
            test_pressure = test_q[0,:,:]
            #test_err = dx*dy*np.linalg.norm(expected_pressure-test_pressure)
            test_err = np.max(np.abs(expected_pressure[:].reshape(-1) - 
                                     test_pressure[:].reshape(-1)))
            return check_diff(0, test_err, abstol=1e-1)


    from clawpack.pyclaw.util import gen_variants

    verify_func = lambda controller: verify_acoustics(controller, solver_type='classic')
    classic_tests = gen_variants(acoustics_2d_interface.setup, verify_func,
                                 solver_type='classic', disable_output=True, 
                                 num_cells=(50, 50))

    verify_func = lambda controller: verify_acoustics(controller, solver_type='sharpclaw')
    sharp_tests_rk   = gen_variants(acoustics_2d_interface.setup, 
                                    verify_func,
                                    solver_type='sharpclaw', 
                                    time_integrator='SSP104', 
                                    disable_output=True, num_cells=(50, 50))

    sharp_tests_lmm   = gen_variants(acoustics_2d_interface.setup, 
                                     verify_func, lim_type=1,
                                     solver_type='sharpclaw', 
                                     time_integrator='SSPLMMk2', 
                                     disable_output=True,
                                     num_cells=(50, 50))

    from itertools import chain
    for test in chain(classic_tests, sharp_tests_rk, sharp_tests_lmm):
        yield test
예제 #10
0
def test_1d_stego():
    """test_stego

    Tests against expected solution for stegoton problem."""

    from . import stegoton

    def verify_expected(expected):
        """ given an expected value, returns a verification function """
        def stego_verify(claw):
            from clawpack.pyclaw.util import check_diff
            import numpy as np

            q0 = claw.frames[0].state.get_q_global()
            qfinal = claw.frames[claw.num_output_times].state.get_q_global()

            if q0 is not None and qfinal is not None:
                dx = claw.solution.domain.grid.delta[0]
                test = dx * np.linalg.norm(qfinal - q0, 1)
                return check_diff(expected, test, reltol=1e-3)
            else:
                return

        return stego_verify

    from clawpack.pyclaw.util import gen_variants
    classic_tests = gen_variants(stegoton.setup,
                                 verify_expected(0.104401108929),
                                 kernel_languages=["Fortran", "Python"],
                                 solver_type='classic',
                                 outdir=None)

    from itertools import chain
    for test in chain(classic_tests):
        yield test
예제 #11
0
def test_euler_3d_rising_hot_sphere():
    """test_euler_3d_rising_hot_sphere"""
    def verify_classic_rising_hot_sphere(controller):
        """ verifies 3d euler rising hot sphere from a previously verified classic run """

        import os
        from clawpack.pyclaw.util import check_diff
        import numpy as np

        test_q=controller.solution.state.get_q_global()

        if test_q != None:
            thisdir = os.path.dirname(__file__)
            expected_density = np.loadtxt(os.path.join(thisdir,'verify_rising_hot_sphere_classic_1.txt'))
            nx = np.size(test_q,1)
            test_density = np.reshape(test_q[0,nx/2,:,:],np.size(test_q[0,nx/2,:,:]),order='F')
            test_err = np.linalg.norm(expected_density-test_density)
            expected_err = 0
            return check_diff(expected_err, test_err, abstol=1e-12)

    #main code
    try:
        import scipy
    except ImportError:
        from nose import SkipTest
        raise SkipTest("Unable to import scipy, is it installed?")

    import rising_hot_sphere
    
    from clawpack.pyclaw.util import gen_variants
    for test in gen_variants(rising_hot_sphere.euler3d, verify_classic_rising_hot_sphere,kernel_languages=('Fortran',),solver_type='classic', disable_output=True,mx=80, my=80, mz=80, tfinal=1.0, num_output_times=1):
        yield test
예제 #12
0
def test_1d_stego():
    """test_stego

    Tests against expected solution for stegoton problem."""

    from . import stegoton

    def verify_expected(expected):
        """ given an expected value, returns a verification function """
        def stego_verify(claw):
            from clawpack.pyclaw.util import check_diff
            import numpy as np

            q0 = claw.frames[0].state.get_q_global()
            qfinal = claw.frames[claw.num_output_times].state.get_q_global()

            if q0 is not None and qfinal is not None:
                dx = claw.solution.domain.grid.delta[0]
                test = dx * np.linalg.norm(qfinal - q0, 1)
                return check_diff(expected, test, reltol=1e-3)
            else:
                return
        return stego_verify

    from clawpack.pyclaw.util import gen_variants
    classic_tests = gen_variants(stegoton.setup, verify_expected(0.104401108929),
                                             kernel_languages=["Fortran", "Python"],
                                             solver_type='classic',
                                             outdir=None)

    from itertools import chain
    for test in chain(classic_tests):
        yield test
예제 #13
0
def test_2d_sill():
    """test_2d_sill

    Tests against expected classic solution of shallow water equations over
    a sill."""

    from . import sill

    def verify_expected(expected):
        def sill_verify(claw):
            from clawpack.pyclaw.util import check_diff
            import numpy as np

            q0 = claw.frames[0].state.get_q_global()
            qfinal = claw.frames[claw.num_output_times].state.get_q_global()

            if q0 is not None and qfinal is not None:
                dx, dy = claw.solution.domain.grid.delta
                total_mass = dx * dy * np.linalg.norm(qfinal[0,:,:].reshape(-1), 1)
                return check_diff(expected, total_mass, reltol=1e-3)
            else:
                return
        return sill_verify

    from clawpack.pyclaw.util import gen_variants
    classic_tests = gen_variants(sill.setup, verify_expected(3.7439),
                                 kernel_languages=["Fortran"],
                                 solver_type='classic', outdir=None)

    from itertools import chain
    for test in chain(classic_tests):
        yield test
예제 #14
0
def test_2d_euler_shockbubble():
    """test_2d_euler_shockbubble"""
    def verify_classic_shockbubble(test_state):
        import os
        from clawpack.pyclaw.util import check_diff
        import numpy as np
        """ verifies 2d euler shockbubble from a previously verified classic run """

        test_q=test_state.get_q_global()


        if test_q != None:
            thisdir = os.path.dirname(__file__)
            expected_density = np.loadtxt(os.path.join(thisdir,'verify_shockbubble_classic.txt'))
            test_density = test_q[0,:,:]
            test_err = np.linalg.norm(expected_density-test_density)
            expected_err = 0
            return check_diff(expected_err, test_err, abstol=1e-12)

    from shockbubble import shockbubble
    
    from clawpack.pyclaw.util import gen_variants
    for test in gen_variants(shockbubble, verify_classic_shockbubble, 
                             kernel_languages=('Fortran',), solver_type='classic'):
        yield test
def test_2d_euler_shockbubble():
    """test_2d_euler_shockbubble"""
    def verify_classic_shockbubble(controller):
        """ verifies 2d euler shockbubble from a previously verified classic run """

        import os
        from clawpack.pyclaw.util import check_diff
        import numpy as np

        test_q=controller.solution.state.get_q_global()


        if test_q != None:
            thisdir = os.path.dirname(__file__)
            expected_density = np.loadtxt(os.path.join(thisdir,'verify_shockbubble_classic.txt'))
            test_density = test_q[0,:,:]
            test_err = np.linalg.norm(expected_density-test_density)
            expected_err = 0
            return check_diff(expected_err, test_err, abstol=1e-12)

    try:
        import scipy
    except ImportError:
        from nose import SkipTest
        raise SkipTest("Unable to import scipy, is it installed?")

    import shock_bubble_interaction
    
    from clawpack.pyclaw.util import gen_variants
    for test in gen_variants(shock_bubble_interaction.setup, verify_classic_shockbubble, 
                             kernel_languages=('Fortran',),
                             solver_type='classic', disable_output=True,
                             mx=160, my=40, tfinal=0.2, num_output_times=1):
        yield test
예제 #16
0
def test_1d_dambreak():
    """
    Tests solution against reference solution for shallow water dam break.
    """

    from . import dam_break
    import os
    

    def verify_expected():
        """ given an expected value, returns a verification function """
        def dambreak_verify(claw):
            from clawpack.pyclaw.util import check_diff
            import numpy as np

            thisdir = os.path.dirname(__file__)
            expected_depth = np.loadtxt(os.path.join(thisdir,'./dam_break_ref.txt'))

            test_solution = claw.frames[claw.num_output_times].state.get_q_global()

            if test_solution is not None:
                return check_diff(expected_depth, test_solution[0,:], reltol=1e-3)
            else:
                return
        return dambreak_verify

    from clawpack.pyclaw.util import gen_variants
    classic_tests = gen_variants(dam_break.setup, verify_expected(),
                                             riemann_solver="hlle",
                                             solver_type='classic',
                                             disable_output=True)

    from itertools import chain
    for test in chain(classic_tests):
        yield test
예제 #17
0
파일: test_sill.py 프로젝트: feipaat/pyclaw
def test_1d_sill():
    """test_1d_sill

    tests against expected classic solution of shallow water equations over
    a sill."""

    import sill

    def verify_expected(expected):
        """ given an expected value, returns a verification function """
        def sill_verify(claw):
            from clawpack.pyclaw.util import check_diff
            import numpy as np

            q0 = claw.frames[0].state.get_q_global()
            qfinal = claw.frames[claw.num_output_times].state.get_q_global()

            if q0 != None and qfinal != None:
                dx = claw.solution.domain.grid.delta[0]
                test = dx * np.linalg.norm(qfinal - q0, 1)
                return check_diff(expected, test, reltol=1e-4)
            else:
                return
        return sill_verify

    from clawpack.pyclaw.util import gen_variants
    classic_tests = gen_variants(sill.setup, verify_expected(4.04169269142e-4), 
                                             kernel_languages=["Python"],
                                             solver_type='classic',
                                             outdir=None)

    from itertools import chain
    for test in chain(classic_tests):
        yield test
예제 #18
0
def test_2d_euler_shockbubble():
    """test_2d_euler_shockbubble"""
    def verify_classic_shockbubble(controller):
        """ verifies 2d euler shockbubble from a previously verified classic run """

        import os
        from clawpack.pyclaw.util import check_diff
        import numpy as np

        test_q = controller.solution.state.get_q_global()

        if test_q != None:
            thisdir = os.path.dirname(__file__)
            expected_density = np.loadtxt(
                os.path.join(thisdir, 'verify_shockbubble_classic.txt'))
            test_density = test_q[0, :, :]
            test_err = np.linalg.norm(expected_density - test_density)
            expected_err = 0
            return check_diff(expected_err, test_err, abstol=1e-12)

    try:
        import scipy
    except ImportError:
        from nose import SkipTest
        raise SkipTest("Unable to import scipy, is it installed?")

    import shock_bubble_interaction

    from clawpack.pyclaw.util import gen_variants
    for test in gen_variants(shock_bubble_interaction.setup,
                             verify_classic_shockbubble,
                             kernel_languages=('Fortran', ),
                             solver_type='classic',
                             disable_output=True):
        yield test
예제 #19
0
def test_1d_dambreak():
    """
    Tests solution against reference solution for shallow water dam break.
    """

    from . import radial_dam_break
    import os
    

    def verify_expected():
        """ given an expected value, returns a verification function """
        def dambreak_verify(claw):
            from clawpack.pyclaw.util import check_diff
            import numpy as np

            thisdir = os.path.dirname(__file__)
            expected_depth = np.loadtxt(os.path.join(thisdir,'./dam_break_ref.txt'))

            test_solution = claw.frames[claw.num_output_times].state.get_q_global()

            if test_solution is not None:
                return check_diff(expected_depth, test_solution[0,:], reltol=1e-3)
            else:
                return
        return dambreak_verify

    from clawpack.pyclaw.util import gen_variants
    classic_tests = gen_variants(radial_dam_break.setup, verify_expected(),
                                             riemann_solver="hlle",
                                             solver_type='classic',
                                             disable_output=True)

    from itertools import chain
    for test in chain(classic_tests):
        yield test
예제 #20
0
def test_acoustics_2d_variable():
    """Test variable-coefficient 2D acoustics on mapped grids"""

    import acoustics_2d_inclusions

    def verify_acoustics_inclusions(controller, solver_type='classic'):
        """ Regression test against data from a previous run."""
        import os
        from clawpack.pyclaw.util import check_diff
        import numpy as np

        state = controller.frames[controller.num_output_times].state
        dx, dy = controller.solution.domain.grid.delta
        test_q = state.get_q_global()

        if test_q is not None:
            thisdir = os.path.dirname(__file__)
            expected_pressure = np.load(os.path.join(thisdir,
                                        'pressure.npz'))['arr_0']
            test_pressure = test_q[0,:,:]
            test_err = np.max(np.abs(expected_pressure[:].reshape(-1) - 
                                     test_pressure[:].reshape(-1)))
            return check_diff(0, test_err, abstol=1e-7)


    from clawpack.pyclaw.util import gen_variants

    verify_func = lambda controller: verify_acoustics_inclusions(controller, solver_type='classic')
    classic_tests = gen_variants(acoustics_2d_inclusions.setup, verify_func,
                                 solver_type='classic', disable_output=True, 
                                 num_cells=100,num_output_times=1)

    from itertools import chain
    for test in chain(classic_tests):
        yield test
예제 #21
0
def test_sedov_and_hdf():
    """Test HDF I/O on Sedov 3D Euler application"""

    try:
        import h5py
        import scipy
    except ImportError:
        import nose
        raise nose.SkipTest

    import Sedov

    def verify_sedov(controller):
        import os
        from clawpack.pyclaw.util import check_diff
        from clawpack.pyclaw import Solution
        
        thisdir = os.path.dirname(__file__)
        verify_dir = os.path.join(thisdir,'./Sedov_regression')
        
        # Expected solution
        sol_expected = Solution()
        sol_expected.read(1,path=verify_dir,file_format='hdf',read_aux=False)
        expected_q = sol_expected.state.q

        # Test solution
        sol_test = Solution()
        sol_test.read(1,path=controller.outdir,
                        file_format=controller.output_format,
                        read_aux=False,
                        options=controller.output_options)
        test_q = sol_test.state.get_q_global()


        if test_q is not None:
            q_err = check_diff(expected_q, test_q, reltol=1e-6)
            if q_err is not None:
                return q_err
        else:
            return

    from clawpack.pyclaw.util import gen_variants
    tempdir = './_sedov_test_results'
    classic_tests = gen_variants(Sedov.setup, 
                                 verify_sedov, solver_type='classic', 
                                 outdir=tempdir, num_cells=(16, 16, 16),
                                 num_output_times=1)

    import shutil
    from itertools import chain
    try:
        for test in chain(classic_tests):
            yield test
    finally:
        ERROR_STR= """Error removing %(path)s, %(error)s """
        try:
            shutil.rmtree(tempdir )
        except OSError as (errno, strerror):
            print ERROR_STR % {'path' : tempdir, 'error': strerror }
예제 #22
0
def test_1d_advection():
    """test_1d_advection

    tests against expected classic, sharpclaw, and high-order weno results """

    import advection_1d

    def verify_expected(expected):
        """ given an expected value, returns a verification function """
        def advection_verify(claw):
            from clawpack.pyclaw.util import check_diff
            import numpy as np

            q0=claw.frames[0].state.get_q_global()
            qfinal=claw.frames[claw.num_output_times].state.get_q_global()

            if q0 != None and qfinal != None:
                dx=claw.solution.domain.grid.delta[0]
                test = dx*np.linalg.norm(qfinal-q0,1)
                return check_diff(expected, test, reltol=1e-4)
            else:
                return
        return advection_verify

    from clawpack.pyclaw.util import gen_variants

    classic_tests = gen_variants(advection_1d.setup, verify_expected(3.203924e-04),
                                 kernel_languages=('Python','Fortran'),
                                 solver_type='classic', outdir=None)

    sharp_tests_rk  = gen_variants(advection_1d.setup, verify_expected(1.163605e-05),
                                 kernel_languages=('Python','Fortran'),
                                 solver_type='sharpclaw',time_integrator='SSP104', outdir=None)

    sharp_tests_lmm = gen_variants(advection_1d.setup, verify_expected(3.39682948116e-05),
                                 kernel_languages=('Python','Fortran'),
                                 solver_type='sharpclaw',time_integrator='SSPMS32', outdir=None)

    weno_tests = gen_variants(advection_1d.setup, verify_expected(7.489618e-06),
                                 kernel_languages=('Fortran',), solver_type='sharpclaw', 
                                 time_integrator='SSP104', weno_order=17,
                                 outdir=None)

    from itertools import chain
    for test in chain(classic_tests, sharp_tests_rk, sharp_tests_lmm, weno_tests):
        yield test
예제 #23
0
def test_2d_acoustics():
    """test_2d_acoustics"""

    def verify_data(data_filename):
        def verify(claw):
            """ verifies 2d homogeneous acoustics from a previously verified run """
            import os
            import numpy as np
            from clawpack.pyclaw.util import check_diff


            #grabs parallel results to process 0, None to other processes
            test_q=claw.solution.state.get_q_global()

            if test_q is not None:
                test_pressure = test_q[0,:,:]
                thisdir = os.path.dirname(__file__)
                expected_pressure = np.loadtxt(os.path.join(thisdir,data_filename))
                return check_diff(expected_pressure, test_pressure, reltol=1e-3,
                                    delta=claw.solution.grid.delta)
            else:
                return
        return verify

    from clawpack.pyclaw.util import gen_variants
    from . import acoustics_2d

    classic_tests = gen_variants(acoustics_2d.setup, verify_data('verify_classic.txt'),
                                 kernel_languages=('Fortran',), solver_type='classic', disable_output=True)

    ptwise_tests = gen_variants(acoustics_2d.setup, verify_data('verify_classic.txt'),
                                 kernel_languages=('Fortran',), ptwise=True, solver_type='classic', disable_output=True)

    sharp_tests_rk   = gen_variants(acoustics_2d.setup, verify_data('verify_sharpclaw.txt'),
                                 kernel_languages=('Fortran',), solver_type='sharpclaw', 
                                 time_integrator='SSP104', disable_output=True)

    sharp_tests_lmm   = gen_variants(acoustics_2d.setup, verify_data('verify_sharpclaw_lmm.txt'),
                                 kernel_languages=('Fortran',), solver_type='sharpclaw', 
                                 time_integrator='SSPLMMk2', disable_output=True)

    from itertools import chain
    for test in chain(classic_tests, ptwise_tests, sharp_tests_rk, sharp_tests_lmm):
        yield test
예제 #24
0
def test_3d_acoustics():
    """ test_3d_acoustics """
    def acoustics_verify_homogeneous(return_tuple):
        from clawpack.pyclaw.util import check_diff

        if return_tuple != None:
            test_final_difference = return_tuple[1]
            return check_diff(0.00286, test_final_difference, abstol=1e-4)
        return

    def acoustics_verify_heterogeneous(return_tuple):
        import os
        import numpy as np
        from clawpack.pyclaw.util import check_diff

        if return_tuple != None:
            test_pfinal = return_tuple[0]
            thisdir = os.path.dirname(__file__)
            verify_pfinal = np.loadtxt(
                os.path.join(thisdir, 'verify_classic_heterogeneous.txt'))
            norm_err = np.linalg.norm(test_pfinal - verify_pfinal)
            return check_diff(0, norm_err, abstol=2e-1)
        return

    from clawpack.pyclaw.util import gen_variants
    from acoustics import acoustics3D

    homogeneous_tests = gen_variants(acoustics3D,
                                     acoustics_verify_homogeneous,
                                     kernel_languages=('Fortran', ),
                                     solver_type='classic',
                                     test='homogeneous',
                                     disable_output=True)

    heterogeneous_tests = gen_variants(acoustics3D,
                                       acoustics_verify_heterogeneous,
                                       kernel_languages=('Fortran', ),
                                       solver_type='classic',
                                       test='heterogeneous',
                                       disable_output=True)

    from itertools import chain
    for test in chain(homogeneous_tests, heterogeneous_tests):
        yield test
예제 #25
0
def test_1d_acoustics():
    """test_1d_acoustics

    tests against known classic, sharpclaw, and high-order weno results """

    from acoustics import acoustics

    def verify_expected(expected):
        """ binds the expected value to the acoustics_verify methods """
        def acoustics_verify(claw):
            from clawpack.pyclaw.util import check_diff
            import numpy as np

            # tests are done across the entire domain of q normally
            q0=claw.frames[0].state.get_q_global()
            qfinal=claw.frames[claw.num_output_times].state.get_q_global()

            # and q_global is only returned on process 0
            if q0 != None and qfinal != None:
                q0 = q0.reshape([-1])
                qfinal = qfinal.reshape([-1])
                dx=claw.solution.domain.grid.delta[0]
                test = dx*np.sum(np.abs(qfinal-q0))
                return check_diff(expected, test, abstol=1e-4)
            else:
                return
        return acoustics_verify

    from clawpack.pyclaw.util import gen_variants

    classic_tests = gen_variants(acoustics, verify_expected(0.00104856594174),
                                 kernel_languages=('Python','Fortran'), solver_type='classic')

    sharp_tests   = gen_variants(acoustics, verify_expected(0.000298879563857),
                                 kernel_languages=('Python','Fortran'), solver_type='sharpclaw')

    weno_tests    = gen_variants(acoustics, verify_expected(0.000153070447918),
                                 kernel_languages=('Fortran',), solver_type='sharpclaw',
                                 weno_order=17)

    from itertools import chain
    for test in chain(classic_tests, sharp_tests, weno_tests):
        yield test
예제 #26
0
def test_2d_acoustics():
    """test_2d_acoustics"""
    def verify_data(data_filename):
        def verify(test_state):
            """ verifies 2d homogeneous acoustics from a previously verified run """
            import os
            import numpy as np
            from clawpack.pyclaw.util import check_diff

            #grabs parallel results to process 0, None to other processes
            test_q = test_state.get_q_global()

            if test_q is not None:
                test_pressure = test_q[0, :, :]
                thisdir = os.path.dirname(__file__)
                expected_pressure = np.loadtxt(
                    os.path.join(thisdir, data_filename))
                return check_diff(expected_pressure,
                                  test_pressure,
                                  reltol=1e-3)
            else:
                return

        return verify

    from clawpack.pyclaw.util import gen_variants
    from acoustics import acoustics2D

    classic_tests = gen_variants(acoustics2D,
                                 verify_data('verify_classic.txt'),
                                 kernel_languages=('Fortran', ),
                                 solver_type='classic',
                                 disable_output=True)

    sharp_tests = gen_variants(acoustics2D,
                               verify_data('verify_sharpclaw.txt'),
                               kernel_languages=('Fortran', ),
                               solver_type='sharpclaw',
                               disable_output=True)

    from itertools import chain
    for test in chain(classic_tests, sharp_tests):
        yield test
예제 #27
0
def test_3d_acoustics():
    """ test_3d_acoustics """

    def acoustics_verify_homogeneous(return_tuple):
        from clawpack.pyclaw.util import check_diff

        if return_tuple != None:
            test_final_difference = return_tuple[1]
            return check_diff(0.00286, test_final_difference, abstol=1e-4)
        return

    def acoustics_verify_heterogeneous(return_tuple):
        import os
        import numpy as np
        from clawpack.pyclaw.util import check_diff

        if return_tuple != None:
            test_pfinal = return_tuple[0]
            thisdir = os.path.dirname(__file__)
            verify_pfinal = np.loadtxt(os.path.join(thisdir,'verify_classic_heterogeneous.txt'))
            norm_err = np.linalg.norm(test_pfinal-verify_pfinal)
            return check_diff(0, norm_err, abstol=2e-1)
        return

    from clawpack.pyclaw.util import gen_variants
    from acoustics import acoustics3D

    homogeneous_tests   = gen_variants(acoustics3D, acoustics_verify_homogeneous,
                                       kernel_languages=('Fortran',), 
                                       solver_type='classic', test='homogeneous',
                                       disable_output=True)

    heterogeneous_tests = gen_variants(acoustics3D, acoustics_verify_heterogeneous,
                                       kernel_languages=('Fortran',), 
                                       solver_type='classic', test='heterogeneous',
                                       disable_output=True)
    
    from itertools import chain
    for test in chain(homogeneous_tests, heterogeneous_tests):
        yield test
예제 #28
0
def test_acoustics_2d_variable():
    """Test variable-coefficient 2D acoustics"""

    import acoustics_2d_interface

    def verify_classic_acoustics(controller):
        import os
        from clawpack.pyclaw.util import check_diff
        import numpy as np
        """ Verifies 2d variable-coefficient acoustics from a previously verified classic run """

        state = controller.frames[controller.num_output_times].state
        dx, dy = controller.solution.domain.grid.delta
        test_q = state.get_q_global()

        if test_q != None:
            thisdir = os.path.dirname(__file__)
            expected_pressure = np.loadtxt(
                os.path.join(thisdir, 'pressure_classic.txt'))
            test_pressure = test_q[0, :, :]
            #test_err = dx*dy*np.linalg.norm(expected_pressure-test_pressure)
            test_err = np.max(np.abs(expected_pressure[:] - test_pressure[:]))
            return check_diff(0, test_err, abstol=1e-1)

    from clawpack.pyclaw.util import gen_variants

    classic_tests = gen_variants(acoustics_2d_interface.setup,
                                 verify_classic_acoustics,
                                 solver_type='classic',
                                 disable_output=True)

    sharp_tests = gen_variants(acoustics_2d_interface.setup,
                               verify_classic_acoustics,
                               solver_type='sharpclaw',
                               disable_output=True)

    from itertools import chain
    for test in chain(classic_tests, sharp_tests):
        yield test
예제 #29
0
파일: test_sill.py 프로젝트: yoon-gu/pyclaw
def test_1d_sill():
    """test_1d_sill

    tests against expected classic solution of shallow water equations over
    a sill."""

    import sill

    def verify_expected(expected):
        """ given an expected value, returns a verification function """
        def sill_verify(claw):
            from clawpack.pyclaw.util import check_diff
            import numpy as np

            q0 = claw.frames[0].state.get_q_global()
            qfinal = claw.frames[claw.num_output_times].state.get_q_global()

            if q0 is not None and qfinal is not None:
                dx = claw.solution.domain.grid.delta[0]
                test = dx * np.linalg.norm(qfinal - q0, 1)
                return check_diff(expected, test, reltol=1e-4)
            else:
                return

        return sill_verify

    from clawpack.pyclaw.util import gen_variants
    classic_tests = gen_variants(sill.setup,
                                 verify_expected(4.04169269142e-4),
                                 kernel_languages=["Python"],
                                 solver_type='classic',
                                 outdir=None)

    from itertools import chain
    for test in chain(classic_tests):
        yield test
예제 #30
0
def test_3d_acoustics():
    """ Tests for homogeneous and heterogeneous 3D acoustics"""
    def acoustics_verify_homogeneous(claw):
        """ Regression test for 3D homogeneous acoustics equations.
        """

        pinitial = claw.frames[0].state.get_q_global()
        pfinal = claw.frames[claw.num_output_times].state.get_q_global()

        if pinitial is not None:
            pinitial = pinitial[0, :, :, :].reshape(-1)
            pfinal = pfinal[0, :, :, :].reshape(-1)
            grid = claw.solution.state.grid
            final_difference = np.prod(grid.delta) * np.linalg.norm(
                pfinal - pinitial, ord=1)
            return check_diff(0., final_difference, abstol=1e-1)
        else:
            # In parallel, we check values only for the rank 0 process
            return

    def acoustics_verify_heterogeneous(claw):
        """ Regression test for 3D heterogeneous acoustics equations
        """

        pinitial = claw.frames[0].state.get_q_global()
        pfinal = claw.frames[claw.num_output_times].state.get_q_global()

        if pinitial is not None:
            pfinal = pfinal[0, :, :, :].reshape(-1)
            thisdir = os.path.dirname(__file__)
            verify_pfinal = np.loadtxt(
                os.path.join(thisdir, 'verify_classic_heterogeneous.txt'))
            norm_err = np.linalg.norm(pfinal - verify_pfinal)
            return check_diff(0, norm_err, abstol=10.)
        else:
            # In parallel, we check values only for the rank 0 process
            return

    classic_homogeneous_tests = gen_variants(acoustics_3d_interface.setup,
                                             acoustics_verify_homogeneous,
                                             kernel_languages=('Fortran', ),
                                             solver_type='classic',
                                             problem='homogeneous',
                                             disable_output=True,
                                             mx=128,
                                             my=4,
                                             mz=4)

    classic_heterogeneous_tests = gen_variants(acoustics_3d_interface.setup,
                                               acoustics_verify_heterogeneous,
                                               kernel_languages=('Fortran', ),
                                               solver_type='classic',
                                               problem='heterogeneous',
                                               disable_output=True,
                                               mx=15,
                                               my=15,
                                               mz=15)

    sharp_homogeneous_tests = gen_variants(acoustics_3d_interface.setup,
                                           acoustics_verify_homogeneous,
                                           kernel_languages=('Fortran', ),
                                           solver_type='sharpclaw',
                                           problem='homogeneous',
                                           disable_output=True,
                                           mx=128,
                                           my=4,
                                           mz=4)

    sharp_heterogeneous_tests = gen_variants(acoustics_3d_interface.setup,
                                             acoustics_verify_heterogeneous,
                                             kernel_languages=('Fortran', ),
                                             solver_type='sharpclaw',
                                             problem='heterogeneous',
                                             disable_output=True,
                                             mx=15,
                                             my=15,
                                             mz=15)

    for test in chain(classic_homogeneous_tests, classic_heterogeneous_tests,
                      sharp_homogeneous_tests, sharp_heterogeneous_tests):
        yield test
예제 #31
0
def test_2d_psystem():
    """test_2d_psystem"""

    def verify_data():
        def verify(controller):
            """ verifies gauge values generated by 2d psystem application 
            from a previously verified run """
            
            import os
            import numpy as np
            from clawpack.pyclaw.util import check_diff

            test_state = controller.solution.state

            gauge_files = test_state.grid.gauge_files
            test_gauge_data_mem = test_state.gauge_data
            expected_gauges=[]
            thisdir = os.path.dirname(__file__)
            
            expected_list=[]
            error_list=[]
            test_passed = True
            if test_gauge_data_mem is not None:
                for i, gauge in enumerate(gauge_files):
                    test_gauge_data_io = np.loadtxt(gauge.name)
                    verify_file = os.path.join(thisdir,'verify_' +
                                            gauge.name.split('/')[-1])
                    expected_gauges.append(np.loadtxt(verify_file))
                    return_value_mem = check_diff(expected_gauges[i], 
                    test_gauge_data_mem[i], reltol=1e-4)
                    return_value_io = check_diff(expected_gauges[i], 
                    test_gauge_data_io, reltol=1e-4)
                    
                    if (return_value_mem is not None or
                        return_value_io is not None):
                        expected_list.append(return_value_mem[0])
                        error_list.append([return_value_mem[1],return_value_io[1]])
                        test_passed = False


                if test_passed:
                    return None
                else:
                    return(expected_list, error_list,return_value_io[2] ,'')
            else:
                return
                
        return verify

    from clawpack.pyclaw.util import gen_variants
    import psystem_2d
    import shutil
    tempdir = './_for_temp_pyclaw_test'
    classic_tests = gen_variants(psystem_2d.setup, verify_data(),
                                 kernel_languages=('Fortran',), 
                                 solver_type='classic', 
                                 disable_output=True,
                                 outdir=tempdir, cells_per_layer=10,
                                 tfinal=40)
    from itertools import chain

    try:
        for test in chain(classic_tests):
            yield test

    finally:
        
        try:
            from petsc4py import PETSc
            PETSc.COMM_WORLD.Barrier()
        except ImportError:
            print """Unable to import petsc4py.
                   This should not be a problem unless you
                   are trying to run in parallel."""
        
        
        ERROR_STR= """Error removing %(path)s, %(error)s """
        try:         
            shutil.rmtree(tempdir )
        except OSError as (errno, strerror):
            print ERROR_STR % {'path' : tempdir, 'error': strerror }
def test_acoustics_2d_variable_io():
    """Test I/O on variable-coefficient 2D acoustics application"""

    from acoustics import acoustics2D

    def verify_acoustics_io(controller):
        """ Verifies I/O on 2d variable-coefficient acoustics application"""
        import os
        from clawpack.pyclaw.util import check_diff
        import numpy as np
        from pyclaw import Solution

        thisdir = os.path.dirname(__file__)
        verify_dir = os.path.join(thisdir, "./io_test_verification")

        # Expected solution
        sol_0_expected = Solution()
        sol_0_expected.read(0, path=verify_dir, file_format="ascii", file_prefix=None, read_aux=True)
        expected_aux = sol_0_expected.state.aux

        sol_20_expected = Solution()
        sol_20_expected.read(20, path=verify_dir, file_format="ascii", file_prefix=None, read_aux=False)
        expected_q = sol_20_expected.state.q

        # Test solution
        sol_0_test = Solution()
        sol_0_test.read(
            0, path=controller.outdir, file_format=controller.output_format, file_prefix=None, read_aux=True
        )
        test_aux = sol_0_test.state.get_aux_global()

        sol_20_test = Solution()
        sol_20_test.read(
            20, path=controller.outdir, file_format=controller.output_format, file_prefix=None, read_aux=False
        )
        test_q = sol_20_test.state.get_q_global()

        test_passed = True
        if test_q is not None:
            q_err = check_diff(expected_q, test_q, reltol=1e-4)
            if q_err is not None:
                test_passed = False
        else:
            return

        if test_aux is not None:
            aux_err = check_diff(expected_aux, test_aux, reltol=1e-4)
            if aux_err is not None:
                test_passed = False
        else:
            return

        if test_passed:
            return None
        else:
            return ([q_err[0], aux_err[0]], [q_err[1], aux_err[1]], q_err[2])

    from clawpack.pyclaw.util import gen_variants

    tempdir = "./_io_test_results"
    classic_tests = gen_variants(acoustics2D, verify_acoustics_io, solver_type="classic", outdir=tempdir)

    import shutil
    from itertools import chain

    try:
        for test in chain(classic_tests):
            yield test
    finally:
        ERROR_STR = """Error removing %(path)s, %(error)s """
        try:
            shutil.rmtree(tempdir)
        except OSError as (errno, strerror):
            print ERROR_STR % {"path": tempdir, "error": strerror}
예제 #33
0
def test_2d_psystem():
    """test_2d_psystem"""

    def verify_data():
        def verify(test_state):
            """ verifies gauge values generated by 2d psystem application 
            from a previously verified run """
            
            import os
            import numpy as np
            from clawpack.pyclaw.util import check_diff

            gauge_files = test_state.grid.gauge_files
            test_gauge_data_mem = test_state.gauge_data
            expected_gauges=[]
            thisdir = os.path.dirname(__file__)
            
            expected_list=[]
            error_list=[]
            test_passed = True
            if test_gauge_data_mem is not None:
                for i, gauge in enumerate(gauge_files):
                    test_gauge_data_io = np.loadtxt(gauge.name)
                    verify_file = os.path.join(thisdir,'verify_' +
                                            gauge.name.split('/')[-1])
                    expected_gauges.append(np.loadtxt(verify_file))
                    return_value_mem = check_diff(expected_gauges[i], 
                    test_gauge_data_mem[i], reltol=1e-2)
                    return_value_io = check_diff(expected_gauges[i], 
                    test_gauge_data_io, reltol=1e-2)
                    
                    if (return_value_mem is not None or
                        return_value_io is not None):
                        expected_list.append(return_value_mem[0])
                        error_list.append([return_value_mem[1],return_value_io[1]])
                        test_passed = False


                if test_passed:
                    return None
                else:
                    return(expected_list, error_list,return_value_io[2] )
            else:
                return
                
        return verify

    from clawpack.pyclaw.util import gen_variants
    from psystem import psystem2D
    import shutil
    tempdir = './_for_temp_pyclaw_test'
    classic_tests = gen_variants(psystem2D, verify_data(),
                                 kernel_languages=('Fortran',), 
                                 solver_type='classic', 
                                 disable_output=True,
                                 outdir=tempdir)
    from itertools import chain
    try:
        for test in chain(classic_tests):
            yield test

    finally:
        ERROR_STR= """Error removing %(path)s, %(error)s """
        try:
            shutil.rmtree(tempdir )
        except OSError as (errno, strerror):
            print ERROR_STR % {'path' : tempdir, 'error': strerror }
예제 #34
0
def test_2d_psystem():
    """test_2d_psystem"""

    def verify_data():
        def verify(controller):
            """ verifies gauge values generated by 2d psystem application 
            from a previously verified run """
            
            import os
            import numpy as np
            from clawpack.pyclaw.util import check_diff

            test_state = controller.solution.state

            gauge_files = test_state.grid.gauge_files
            test_gauge_data_mem = test_state.gauge_data
            expected_gauges=[]
            thisdir = os.path.dirname(__file__)
            
            expected_list=[]
            error_list=[]
            test_passed = True
            if test_gauge_data_mem is not None:
                for i, gauge in enumerate(gauge_files):
                    test_gauge_data_io = np.loadtxt(gauge.name)
                    verify_file = os.path.join(thisdir,'verify_' +
                                            gauge.name.split('/')[-1])
                    expected_gauges.append(np.loadtxt(verify_file))
                    return_value_mem = check_diff(expected_gauges[i], 
                    test_gauge_data_mem[i], reltol=1e-4)
                    return_value_io = check_diff(expected_gauges[i], 
                    test_gauge_data_io, reltol=1e-4)
                    
                    if (return_value_mem is not None or
                        return_value_io is not None):
                        expected_list.append(return_value_mem[0])
                        error_list.append([return_value_mem[1],return_value_io[1]])
                        test_passed = False


                if test_passed:
                    return None
                else:
                    return(expected_list, error_list,return_value_io[2] ,'')
            else:
                return
                
        return verify

    from clawpack.pyclaw.util import gen_variants
    import psystem_2d
    import shutil
    tempdir = './_for_temp_pyclaw_test'
    classic_tests = gen_variants(psystem_2d.setup, verify_data(),
                                 kernel_languages=('Fortran',), 
                                 solver_type='classic', 
                                 outdir=tempdir, cells_per_layer=6,
                                 tfinal=1.)
    from itertools import chain

    try:
        for test in chain(classic_tests):
            yield test

    finally:
        
        try:
            from petsc4py import PETSc
            PETSc.COMM_WORLD.Barrier()
        except ImportError:
            print """Unable to import petsc4py.
                   This should not be a problem unless you
                   are trying to run in parallel."""
        
        
        ERROR_STR= """Error removing %(path)s, %(error)s """
        try:         
            shutil.rmtree(tempdir )
        except OSError as (errno, strerror):
            print ERROR_STR % {'path' : tempdir, 'error': strerror }
def test_acoustics_2d_variable_io():
    """Test I/O on variable-coefficient 2D acoustics application"""

    import acoustics_2d_interface

    def verify_acoustics_io(controller):
        """ Verifies I/O on 2d variable-coefficient acoustics application"""
        import os
        from clawpack.pyclaw.util import check_diff
        from clawpack.pyclaw import Solution

        thisdir = os.path.dirname(__file__)
        verify_dir = os.path.join(thisdir, './io_test_verification')

        # Expected solution
        sol_0_expected = Solution()
        sol_0_expected.read(0,
                            path=verify_dir,
                            file_format='ascii',
                            file_prefix=None,
                            read_aux=True)
        expected_aux = sol_0_expected.state.aux

        sol_20_expected = Solution()
        sol_20_expected.read(20,
                             path=verify_dir,
                             file_format='ascii',
                             file_prefix=None,
                             read_aux=False)
        expected_q = sol_20_expected.state.q

        # Test solution
        sol_0_test = Solution()
        sol_0_test.read(0,
                        path=controller.outdir,
                        file_format=controller.output_format,
                        file_prefix=None,
                        read_aux=True,
                        options=controller.output_options)
        test_aux = sol_0_test.state.get_aux_global()

        sol_20_test = Solution()
        sol_20_test.read(20,
                         path=controller.outdir,
                         file_format=controller.output_format,
                         file_prefix=None,
                         read_aux=False,
                         options=controller.output_options)
        test_q = sol_20_test.state.get_q_global()

        if test_q is not None:
            q_err = check_diff(expected_q, test_q, reltol=1e-6)
            if q_err is not None:
                return q_err
        else:
            return

        if test_aux is not None:
            aux_err = check_diff(expected_aux, test_aux, reltol=1e-6)
            if aux_err is not None:
                return aux_err
        else:
            return

    from clawpack.pyclaw.util import gen_variants
    tempdir = './_io_test_results'
    classic_tests = gen_variants(acoustics_2d_interface.setup,
                                 verify_acoustics_io,
                                 solver_type='classic',
                                 outdir=tempdir,
                                 num_cells=(50, 50))

    import shutil
    from itertools import chain
    try:
        for test in chain(classic_tests):
            yield test
    finally:
        ERROR_STR = """Error removing %(path)s, %(error)s """
        try:
            shutil.rmtree(tempdir)
        except OSError as (errno, strerror):
            print ERROR_STR % {'path': tempdir, 'error': strerror}
예제 #36
0
def test_sedov_and_hdf():
    """Test HDF I/O on Sedov 3D Euler application"""

    try:
        import h5py
        import scipy
    except ImportError:
        import nose
        raise nose.SkipTest

    from . import Sedov

    def verify_sedov(controller):
        import os
        from clawpack.pyclaw.util import check_diff
        from clawpack.pyclaw import Solution
        
        thisdir = os.path.dirname(__file__)
        verify_dir = os.path.join(thisdir,'./Sedov_regression')

        # Expected solution
        sol_expected = Solution()
        sol_expected.read(1,path=verify_dir,file_format='hdf',read_aux=False)
        assert sol_expected.t == 0.1
        expected_q = sol_expected.state.q

        # Test solution
        sol_test = Solution()
        sol_test.read(1,path=controller.outdir,
                        file_format=controller.output_format,
                        read_aux=False,
                        options=controller.output_options)
        test_q = sol_test.state.get_q_global()


        if test_q is not None:
            q_err = check_diff(expected_q, test_q, reltol=1e-6)
            if q_err is not None:
                return q_err
        else:
            return

    from clawpack.pyclaw.util import gen_variants
    tempdir = './_sedov_test_results'
    classic_tests = gen_variants(Sedov.setup, 
                                 verify_sedov, solver_type='classic',
                                 disable_petsc=True,
                                 outdir=tempdir, num_cells=(16, 16, 16),
                                 num_output_times=1)

    import shutil
    from itertools import chain
    try:
        for test in chain(classic_tests):
            yield test
    finally:
        ERROR_STR= """Error removing %(path)s, %(error)s """
        try:
            shutil.rmtree(tempdir )
        except OSError as xxx_todo_changeme:
            (errno, strerror) = xxx_todo_changeme.args
            print(ERROR_STR % {'path' : tempdir, 'error': strerror })
def test_acoustics_2d_variable_io():
    """Test I/O on variable-coefficient 2D acoustics application"""

    import acoustics_2d_interface

    def verify_acoustics_io(controller):
        """ Verifies I/O on 2d variable-coefficient acoustics application"""
        import os
        from clawpack.pyclaw.util import check_diff
        from clawpack.pyclaw import Solution
        
        thisdir = os.path.dirname(__file__)
        verify_dir = os.path.join(thisdir,'./io_test_verification')
        
        # Expected solution
        sol_0_expected = Solution()
        sol_0_expected.read(0,path=verify_dir,file_format='ascii',
                               file_prefix=None,read_aux=True)
        expected_aux = sol_0_expected.state.aux

        sol_20_expected = Solution()
        sol_20_expected.read(20,path=verify_dir,file_format='ascii',
                               file_prefix=None,read_aux=False)
        expected_q = sol_20_expected.state.q

        # Test solution
        sol_0_test = Solution()
        sol_0_test.read(0,path=controller.outdir,
                        file_format=controller.output_format,
                        file_prefix=None,read_aux=True,
                        options=controller.output_options)
        test_aux = sol_0_test.state.get_aux_global()

        sol_20_test = Solution()
        sol_20_test.read(20,path=controller.outdir,
                        file_format=controller.output_format,
                        file_prefix=None,read_aux=False,
                        options=controller.output_options)
        test_q = sol_20_test.state.get_q_global()


        if test_q is not None:
            q_err = check_diff(expected_q, test_q, reltol=1e-6)
            if q_err is not None:
                return q_err
        else:
            return

        if test_aux is not None:
            aux_err = check_diff(expected_aux, test_aux, reltol=1e-6)
            if aux_err is not None:
                return aux_err
        else:
            return


    from clawpack.pyclaw.util import gen_variants
    tempdir = './_io_test_results'
    classic_tests = gen_variants(acoustics_2d_interface.setup, 
                                 verify_acoustics_io, solver_type='classic', 
                                 outdir=tempdir, num_cells=(50, 50), disable_petsc=True)

    import shutil
    from itertools import chain
    try:
        for test in chain(classic_tests):
            yield test
    finally:
        ERROR_STR= """Error removing %(path)s, %(error)s """
        try:
            shutil.rmtree(tempdir )
        except OSError as (errno, strerror):
            print ERROR_STR % {'path' : tempdir, 'error': strerror }
예제 #38
0
def test_1d_advection():
    """test_1d_advection

    tests against expected classic results """

    from . import advection_1d_nonunif

    def verify_expected(expected):
        """ given an expected value, returns a verification function """
        def advection_verify(claw):
            from clawpack.pyclaw.util import check_diff
            import numpy as np

            q0 = claw.frames[0].state.get_q_global()
            qfinal = claw.frames[claw.num_output_times].state.get_q_global()

            if q0 is not None and qfinal is not None:
                dx = claw.solution.domain.grid.delta[0]
                test = dx * np.linalg.norm(qfinal - q0, 1)
                return check_diff(expected, test, reltol=1e-4)
            else:
                return

        return advection_verify

    def verify_expected_nonunif(expected):
        """ given an expected value, returns a verification function for the nonuniform advection ex"""
        from clawpack.pyclaw.util import check_diff
        import numpy as np

        def mapc2p_nonunif(xc):
            neg = -1 * (xc < 0) + (xc > 0)
            xp = xc**2
            xp = neg * xp
            return xp

        def advection_nu_verify(claw):
            q0 = claw.frames[0].state.get_q_global()
            qfinal = claw.frames[claw.num_output_times].state.get_q_global()
            if q0 is not None and qfinal is not None:
                dx = claw.solution.domain.grid.delta[0]
                grid1d = claw.frames[0].state.grid
                grid1d.mapc2p = mapc2p_nonunif
                nx = 100
                aux = np.zeros((1, nx))
                aux[0, :] = np.diff(grid1d.p_nodes) / np.diff(grid1d.x.nodes)
                test = abs(np.sum(dx * aux[0, :] * (qfinal - q0)))
                return check_diff(expected, test, reltol=1e-4)
            else:
                return

        return advection_nu_verify

    from clawpack.pyclaw.util import gen_variants

    classic_tests = gen_variants(
        advection_1d_nonunif.setup,
        verify_expected_nonunif(7.817097663620487e-17),
        kernel_languages=('Python', 'Fortran'),
        solver_type='classic',
        outdir=None)

    from itertools import chain
    for test in chain(classic_tests):
        yield test