Example #1
0
def run_regression_tests(regression_dir="_regression_tests", \
            regression_output_files="all", \
            regression_plot_files="all", \
            make_new=True, run_tests=True, compare_results=True, \
            relocatable=False):

    if make_new:
        # Compile code from scratch to make sure up to date:
        os.system('make new')

    if run_tests:

        if os.path.exists(regression_dir):
            ans = raw_input("Directory %s exists, ok to overwrite? " %
                            regression_dir)
            if ans == 'y':
                os.system('rm -rf %s' % regression_dir)
            else:
                print "*** Aborting regression tests"
                sys.exit()

        os.system('mkdir %s' % regression_dir)

        # -----------------------------------------------------------
        # Define the regression test runs:
        # -----------------------------------------------------------

        # initialize rundata using setrun but then change some things for each run:
        rundata = setrun()
        clawdata = rundata.clawdata
        amrdata = rundata.amrdata

        #--------------
        # Test 1:
        #--------------

        suffix = "_test1"
        outdir = regression_dir + "/_output" + suffix
        plotdir = regression_dir + "/_plots" + suffix

        amrdata.amr_levels_max = 1
        rundata.write()

        runclaw(xclawcmd="xamr", outdir=outdir, print_git_status=True)
        plotclaw(outdir=outdir, plotdir=plotdir)

        #--------------
        # Test 2:
        #--------------
        amrdata.amr_levels_max = 2
        rundata.write()

        suffix = "_test2"
        outdir = regression_dir + "/_output" + suffix
        plotdir = regression_dir + "/_plots" + suffix

        runclaw(xclawcmd="xamr", outdir=outdir, print_git_status=True)
        plotclaw(outdir=outdir, plotdir=plotdir)

        #--------------
        # Test 3:
        #--------------

        amrdata.amr_levels_max = 3
        rundata.write()

        suffix = "_test3"
        outdir = regression_dir + "/_output" + suffix
        plotdir = regression_dir + "/_plots" + suffix

        runclaw(xclawcmd="xamr", outdir=outdir, print_git_status=True)
        plotclaw(outdir=outdir, plotdir=plotdir)

        # ----------------------------------------------------
        # End of test case definitions
        # ----------------------------------------------------

        print "Output and plots are in ", regression_dir

    regression_ok = None

    if compare_results:
        regression_ok = compare_regression_tests(regression_dir,\
                        regression_output_files, regression_plot_files, \
                        relocatable=relocatable)
        if regression_ok:
            print "The specified regression files are identical in all"
            print "    directories checked"
        else:
            print "*** Some regression tests did not pass"

    return regression_ok
if __name__ == "__main__":

    # help message
    if sys.argv[1] == "--help" or sys.argv[1] == "-h":
        print("Usage:")
        print("\tpython run.py case_folder_name")
        sys.exit(0)

    # paths
    repo_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    claw_dir = os.path.join(repo_dir, "solver", "clawpack")
    case_dir = os.path.abspath(sys.argv[1])
    solver = os.path.join(repo_dir, "solver", "bin", "xgeoclaw")

    # set CLAW environment variable to satisfy some Clawpack functions' need
    os.environ["CLAW"] = claw_dir

    # make clawpack searchable
    sys.path.insert(0, claw_dir)
    from clawpack.clawutil import runclaw

    # create *.data files
    create_data(case_dir)

    # run simulation
    runclaw.runclaw(
        xclawcmd=solver, outdir=os.path.join(case_dir, "_output"),
        overwrite=False, restart=None, rundir=case_dir, print_git_status=True,
        nohup=False, nice=None)
Example #3
0
def run_regression_tests(regression_dir="_regression_tests", \
            regression_output_files="all", \
            regression_plot_files="all", \
            make_new=True, run_tests=True, compare_results=True):

    if make_new:
        # Compile code from scratch to make sure up to date:
        os.system('make new')

    if run_tests:

        if os.path.exists(regression_dir):
            ans = raw_input("Directory %s exists, ok to overwrite? " % regression_dir)
            if ans=='y':
                os.system('rm -rf %s' % regression_dir)
            else:
                print "*** Aborting regression tests"
                sys.exit()

        os.system('mkdir %s' % regression_dir)

        # -----------------------------------------------------------
        # Define the regression test runs:
        # -----------------------------------------------------------

        # initialize rundata using setrun but then change some things for each run:
        rundata = setrun()
        clawdata = rundata.clawdata
        amrdata = rundata.amrdata


        #--------------
        # Test 1:
        #--------------

        suffix = "_test1"
        outdir = regression_dir + "/_output" + suffix
        plotdir = regression_dir + "/_plots" + suffix

        amrdata.amr_levels_max = 1
        rundata.write()

        runclaw(xclawcmd = "xamr", outdir=outdir, print_git_status=True)
        plotclaw(outdir=outdir, plotdir=plotdir)

        #--------------
        # Test 2:
        #--------------
        amrdata.amr_levels_max = 2
        rundata.write()

        suffix = "_test2"
        outdir = regression_dir + "/_output" + suffix
        plotdir = regression_dir + "/_plots" + suffix

        runclaw(xclawcmd = "xamr", outdir=outdir, print_git_status=True)
        plotclaw(outdir=outdir, plotdir=plotdir)

        #--------------
        # Test 3:
        #--------------

        amrdata.amr_levels_max = 3
        rundata.write()

        suffix = "_test3"
        outdir = regression_dir + "/_output" + suffix
        plotdir = regression_dir + "/_plots" + suffix

        runclaw(xclawcmd = "xamr", outdir=outdir, print_git_status=True)
        plotclaw(outdir=outdir, plotdir=plotdir)

        # ----------------------------------------------------
        # End of test case definitions
        # ----------------------------------------------------

        print "Output and plots are in ", regression_dir


    if compare_results:
        regression_ok = compare_regression_tests(regression_dir,\
                        regression_output_files, regression_plot_files)
        if regression_ok:
            print "The specified regression files are identical in all"
            print "    directories checked"
        else:
            print "*** Some regression tests did not pass"

    return regression_ok
Example #4
0
    dx = (xupper - xlower)/mx


    #Set setrun clawdata (some maybe unnecessary, will see)
    rundata=setrun.setrun('classic')

    rundata.clawdata.num_cells[0] = mx
    rundata.clawdata.num_output_times = mframe	# output_times=1 won't work for high grid resolution
    rundata.clawdata.tfinal = 0.100000e+00
    rundata.clawdata.lower[0] = xlower
    rundata.clawdata.upper[0] = xupper 
    rundata.clawdata.order = 1
    rundata.clawdata.bc_lower[0] = 'periodic'#'user'   # at xlower
    rundata.clawdata.bc_upper[0] = 'periodic'#'extrap'   # at xupper
    rundata.write()
    runclaw(xclawcmd='xclaw',outdir=outdir)	# xclaw.exe file produced after make .exe 

    #Get the material parameters
    aux = np.loadtxt(outdir+'/fort.a0000',skiprows=5)	# don't delate skiprows or set it equal 6 

    plotdata = ClawPlotData()
    plotdata.outdir=outdir

    #Read in the solution
    dat = plotdata.getframe(mframe)
    u = dat.q[0,:]

#    print u

    stress = np.exp(u*aux) - 1	# not sure why here don't need aux[0,:]
    stress = u
Example #5
0
print('outdir_bouss = ', outdir_bouss)

outdir_swe = '_output_swe'
print('outdir_swe = ', outdir_swe)

run_code = False  # set to False if output already exists

if run_code:
    # create executable and .data files:
    os.system('make .exe')
    rundata = setrun.setrun()

    # Boussinesq:
    rundata.bouss_data.bouss = True
    rundata.write()
    runclaw(xclawcmd='xgeo', outdir=outdir_bouss)  # run clawpack code

    # Shallow water equations:
    rundata.bouss_data.bouss = False
    rundata.write()
    runclaw(xclawcmd='xgeo', outdir=outdir_swe)  # run clawpack code

savefig_ext = '.png'
figdir = './figures'
os.system('mkdir -p %s' % figdir)


def save_figure(fname):
    """Save figure to figdir with desired extension"""
    full_fname = os.path.join(figdir, fname) + savefig_ext
    savefig(full_fname, bbox_inches='tight')
os.system('mkdir -p %s' % figdir)


def save_figure(fname):
    """Save figure to figdir with desired extension"""
    full_fname = os.path.join(figdir, fname) + savefig_ext
    savefig(full_fname, bbox_inches='tight')
    print('Created %s' % full_fname)


xs = 10.e3
xlimits = [-150e3, 50e3]
outdir = '_output_xw10'

if run_code:
    runclaw(xclawcmd='xgeo', outdir=outdir)  # run clawpack code

griddata = loadtxt(outdir + '/celledges.data', skiprows=1)
xgrid = griddata[:, 0]
zgrid = griddata[:, 1]
xcell = 0.5 * (xgrid[:-1] + xgrid[1:])

figure(11, figsize=(7, 3))
clf()
#plot(xgrid,zgrid,'k')
if 1:
    fill_between(xgrid, zgrid, 0, color=[0.7, 0.7, 1])
    plot(xgrid, zgrid, 'k')
    plot(xgrid, 0 * zgrid, 'b')
    ylim(-3500, 300)
#title('Bathymetry')
import os

from clawpack.clawutil.runclaw import runclaw

runclaw('xamr',outdir='_output',nohup=True, nice=10)

import os

from clawpack.clawutil.runclaw import runclaw

runclaw('xamr', outdir='_output', nohup=True, nice=10)