Exemple #1
0
def interactive_plot(outdir='./_output', file_format='petsc', setplot=None):
    """
    Convenience function for launching an interactive plotting session.
    """
    from clawpack.pyclaw.plot import plot
    plot(setplot,
         outdir=outdir,
         file_format=file_format,
         iplot=True,
         htmlplot=False)
Exemple #2
0
def html_plot(outdir='./_output', file_format='petsc', setplot=None):
    """
    Convenience function for creating html page with plots.
    """
    from clawpack.pyclaw.plot import plot
    plot(setplot,
         outdir=outdir,
         file_format=file_format,
         htmlplot=True,
         iplot=False)
Exemple #3
0
def oscillatory_wind(num_cells, eigen_method, **kargs):
    r"""docstring for oscillatory_wind"""

    # Construct output and plot directory paths
    prefix = 'ml_e%s_n%s' % (eigen_method, num_cells)
    name = 'multilayer/oscillatory_wind'
    outdir, plotdir, log_path = runclaw.create_output_paths(
        name, prefix, **kargs)

    # Redirect loggers
    # This is not working for all cases, see comments in runclaw.py
    for logger_name in [
            'pyclaw.io', 'pyclaw.solution', 'plot', 'pyclaw.solver', 'f2py',
            'data'
    ]:
        runclaw.replace_stream_handlers(logger_name,
                                        log_path,
                                        log_file_append=False)

    # Load in appropriate PyClaw version
    if kargs.get('use_petsc', False):
        import clawpack.petclaw as pyclaw
    else:
        import clawpack.pyclaw as pyclaw

    # =================
    # = Create Solver =
    # =================
    if kargs.get('solver_type', 'classic') == 'classic':
        solver = pyclaw.ClawSolver1D(riemann_solver=layered_shallow_water_1D)
    else:
        raise NotImplementedError(
            'Classic is currently the only supported solver.')

    # Solver method parameters
    solver.cfl_desired = 0.9
    solver.cfl_max = 1.0
    solver.max_steps = 5000
    solver.fwave = True
    solver.kernel_language = 'Fortran'
    solver.limiters = 3
    solver.source_split = 1

    # Boundary conditions
    # Here we implement our own wall boundary conditions for the multi-layer
    # equations
    solver.bc_lower[0] = 0
    solver.bc_upper[0] = 0
    solver.user_bc_lower = ml.bc.wall_qbc_lower
    solver.user_bc_upper = ml.bc.wall_qbc_upper
    solver.aux_bc_lower[0] = 1
    solver.aux_bc_upper[0] = 1

    # Set the before step functioning including the wind forcing
    wind_func = lambda state: ml.aux.set_oscillatory_wind(
        state, A=5.0, N=2.0, omega=2.0, t_length=10.0)
    solver.before_step = lambda solver, solution: ml.step.before_step(
        solver, solution, wind_func=wind_func, raise_on_richardson=True)

    # Use simple friction source term
    solver.step_source = ml.step.friction_source

    # ============================
    # = Create Initial Condition =
    # ============================
    num_layers = 2

    x = pyclaw.Dimension(0.0, 1.0, num_cells)
    domain = pyclaw.Domain([x])
    state = pyclaw.State(domain, 2 * num_layers, 3 + num_layers)
    state.aux[ml.aux.kappa_index, :] = 0.0

    # Set physics data
    state.problem_data['g'] = 9.8
    state.problem_data['manning'] = 0.0
    state.problem_data['rho_air'] = 1.15
    state.problem_data['rho'] = [1025.0, 1045.0]
    state.problem_data['r'] = \
                     state.problem_data['rho'][0] / state.problem_data['rho'][1]
    state.problem_data['one_minus_r'] = 1.0 - state.problem_data['r']
    state.problem_data['num_layers'] = num_layers

    # Set method parameters, this ensures it gets to the Fortran routines
    state.problem_data['eigen_method'] = eigen_method
    state.problem_data['dry_tolerance'] = 1e-3
    state.problem_data['inundation_method'] = 2
    state.problem_data['entropy_fix'] = False

    solution = pyclaw.Solution(state, domain)
    solution.t = 0.0

    # Set aux arrays including bathymetry, wind field and linearized depths
    ml.aux.set_jump_bathymetry(solution.state, 0.5, [-1.0, -1.0])
    wind_func(solution.state)
    ml.aux.set_h_hat(solution.state, 0.5, [0.0, -0.25], [0.0, -0.25])

    # Set sea at rest initial condition
    ml.qinit.set_quiescent_init_condition(solution.state)

    # ================================
    # = Create simulation controller =
    # ================================
    controller = pyclaw.Controller()
    controller.solution = solution
    controller.solver = solver

    # Output parameters
    controller.output_style = 1
    controller.tfinal = 10.0
    controller.num_output_times = 160
    controller.write_aux_init = True
    controller.outdir = outdir
    controller.keep_copy = True
    controller.write_aux_always = True

    # ==================
    # = Run Simulation =
    # ==================
    try:
        state = controller.run()
    except ml.step.RichardsonExceededError as e:
        print e
        # print "Writing out last solution available to frame %s." % str(len(controller.frames))
        # e.solution.write(len(controller.frames),path=controller.outdir,write_aux=True)

    # ============
    # = Plotting =
    # ============
    plot_kargs = {
        'xlower': solution.state.grid.x.lower,
        'xupper': solution.state.grid.x.upper,
        'rho': solution.state.problem_data['rho'],
        'dry_tolerance': solution.state.problem_data['dry_tolerance']
    }
    plot(setplot="./setplot_oscillatory.py",
         outdir=outdir,
         plotdir=plotdir,
         htmlplot=kargs.get('htmlplot', False),
         iplot=kargs.get('iplot', False),
         file_format=controller.output_format,
         **plot_kargs)
Exemple #4
0
def dry_state(num_cells, eigen_method, entropy_fix, **kargs):
    r"""Run and plot a multi-layer dry state problem"""

    # Construct output and plot directory paths
    name = 'multilayer/dry_state'
    prefix = 'ml_e%s_m%s_fix' % (eigen_method, num_cells)

    if entropy_fix:
        prefix = "".join((prefix, "T"))
    else:
        prefix = "".join((prefix, "F"))
    outdir, plotdir, log_path = runclaw.create_output_paths(
        name, prefix, **kargs)

    # Redirect loggers
    # This is not working for all cases, see comments in runclaw.py
    for logger_name in [
            'pyclaw.io', 'pyclaw.solution', 'plot', 'pyclaw.solver', 'f2py',
            'data'
    ]:
        runclaw.replace_stream_handlers(logger_name,
                                        log_path,
                                        log_file_append=False)

    # Load in appropriate PyClaw version
    if kargs.get('use_petsc', False):
        import clawpack.petclaw as pyclaw
    else:
        import clawpack.pyclaw as pyclaw

    # =================
    # = Create Solver =
    # =================
    if kargs.get('solver_type', 'classic') == 'classic':
        solver = pyclaw.ClawSolver1D(riemann_solver=layered_shallow_water_1D)
    else:
        raise NotImplementedError(
            'Classic is currently the only supported solver.')

    # Solver method parameters
    solver.cfl_desired = 0.9
    solver.cfl_max = 1.0
    solver.max_steps = 5000
    solver.fwave = True
    solver.kernel_language = 'Fortran'
    solver.limiters = 3
    solver.source_split = 1

    # Boundary conditions
    solver.bc_lower[0] = 1
    solver.bc_upper[0] = 1
    solver.aux_bc_lower[0] = 1
    solver.aux_bc_upper[0] = 1

    # Set the before step function
    solver.before_step = lambda solver, solution: ml.step.before_step(
        solver, solution)

    # Use simple friction source term
    solver.step_source = ml.step.friction_source

    # ============================
    # = Create Initial Condition =
    # ============================
    num_layers = 2

    x = pyclaw.Dimension(0.0, 1.0, num_cells)
    domain = pyclaw.Domain([x])
    state = pyclaw.State(domain, 2 * num_layers, 3 + num_layers)
    state.aux[ml.aux.kappa_index, :] = 0.0

    # Set physics data
    state.problem_data['g'] = 9.8
    state.problem_data['manning'] = 0.0
    state.problem_data['rho_air'] = 1.15e-3
    state.problem_data['rho'] = [0.95, 1.0]
    state.problem_data['r'] =   \
                     state.problem_data['rho'][0] / state.problem_data['rho'][1]
    state.problem_data['one_minus_r'] = 1.0 - state.problem_data['r']
    state.problem_data['num_layers'] = num_layers

    # Set method parameters, this ensures it gets to the Fortran routines
    state.problem_data['eigen_method'] = eigen_method
    state.problem_data['dry_tolerance'] = 1e-3
    state.problem_data['inundation_method'] = 2
    state.problem_data['entropy_fix'] = entropy_fix

    solution = pyclaw.Solution(state, domain)
    solution.t = 0.0

    # Set aux arrays including bathymetry, wind field and linearized depths
    ml.aux.set_jump_bathymetry(solution.state, 0.5, [-1.0, -1.0])
    ml.aux.set_no_wind(solution.state)
    ml.aux.set_h_hat(solution.state, 0.5, [0.0, -0.5], [0.0, -1.0])

    # Set sea at rest initial condition
    q_left = [
        0.5 * state.problem_data['rho'][0], 0.0,
        0.5 * state.problem_data['rho'][1], 0.0
    ]
    q_right = [1.0 * state.problem_data['rho'][0], 0.0, 0.0, 0.0]
    ml.qinit.set_riemann_init_condition(solution.state, 0.5, q_left, q_right)

    # ================================
    # = Create simulation controller =
    # ================================
    controller = pyclaw.Controller()
    controller.solution = solution
    controller.solver = solver

    # Output parameters
    controller.output_style = 3
    controller.nstepout = 1
    controller.num_output_times = 100
    controller.write_aux_init = True
    controller.outdir = outdir
    controller.write_aux = True

    # ==================
    # = Run Simulation =
    # ==================
    state = controller.run()

    # ============
    # = Plotting =
    # ============
    plot_kargs = {
        'rho': solution.state.problem_data['rho'],
        'dry_tolerance': solution.state.problem_data['dry_tolerance']
    }
    plot.plot(setplot="./setplot_drystate.py",
              outdir=outdir,
              plotdir=plotdir,
              htmlplot=kargs.get('htmlplot', False),
              iplot=kargs.get('iplot', False),
              file_format=controller.output_format,
              **plot_kargs)
Exemple #5
0
def sloped_shelf(num_cells,eigen_method,**kargs):
    r"""Shelf test"""

    # Construct output and plot directory paths
    prefix = 'ml_e%s_n%s' % (eigen_method,num_cells)
    name = 'multilayer/sloped_shelf'
    outdir,plotdir,log_path = runclaw.create_output_paths(name,prefix,**kargs)
    
    # Redirect loggers
    # This is not working for all cases, see comments in runclaw.py
    for logger_name in ['io','solution','plot','evolve','f2py','data']:
        runclaw.replace_stream_handlers(logger_name,log_path,log_file_append=False)

    # Load in appropriate PyClaw version
    if kargs.get('use_petsc',False):
        import clawpack.petclaw as pyclaw
    else:
        import clawpack.pyclaw as pyclaw
        
    
    # =================
    # = Create Solver =
    # =================
    if kargs.get('solver_type','classic') == 'classic':
        solver = pyclaw.ClawSolver1D()
    else:
        raise NotImplementedError('Classic is currently the only supported solver.')
        
    # Solver method parameters
    solver.cfl_desired = 0.9
    solver.cfl_max = 1.0
    solver.max_steps = 5000
    solver.fwave = True
    solver.kernel_language = 'Fortran'
    solver.num_waves = 4
    solver.limiters = 3
    solver.source_split = 1
        
    # Boundary conditions
    # Use wall boundary condition at beach
    solver.bc_lower[0] = 1
    solver.bc_upper[0] = 0
    solver.user_bc_upper = ml.bc.wall_qbc_upper
    solver.aux_bc_lower[0] = 1
    solver.aux_bc_upper[0] = 1
    
    # Set the Riemann solver
    solver.rp = layered_shallow_water_1D

    # Set the before step function
    solver.before_step = lambda solver,solution:ml.step.before_step(solver,solution)
                                            
    # Use simple friction source term
    solver.step_source = ml.step.friction_source

    
    # ============================
    # = Create Initial Condition =
    # ============================
    num_layers = 2
    
    x = pyclaw.Dimension('x',-400e3,0.0,num_cells)
    domain = pyclaw.Domain([x])
    state = pyclaw.State(domain,2*num_layers,3+num_layers)
    state.aux[ml.aux.kappa_index,:] = 0.0

    # Set physics data
    state.problem_data['g'] = 9.8
    state.problem_data['manning'] = 0.0
    state.problem_data['rho_air'] = 1.15
    state.problem_data['rho'] = [1025.0,1045.0]
    state.problem_data['r'] = state.problem_data['rho'][0] / state.problem_data['rho'][1]
    state.problem_data['one_minus_r'] = 1.0 - state.problem_data['r']
    state.problem_data['num_layers'] = num_layers
    
    # Set method parameters, this ensures it gets to the Fortran routines
    state.problem_data['eigen_method'] = eigen_method
    state.problem_data['dry_tolerance'] = 1e-3
    state.problem_data['inundation_method'] = 2
    state.problem_data['entropy_fix'] = False
    
    solution = pyclaw.Solution(state,domain)
    solution.t = 0.0
    
    # Set aux arrays including bathymetry, wind field and linearized depths
    x0 = -130e3
    x1 = -30e3
    ml.aux.set_sloped_shelf_bathymetry(solution.state,x0,x1,-4000.0,-100.0)
    ml.aux.set_no_wind(solution.state)
    ml.aux.set_h_hat(solution.state,0.5,[0.0,-300.0],[0.0,-300.0])
    
    # Set perturbation to sea at rest
    ml.qinit.set_acta_numerica_init_condition(solution.state,0.4)
    
    
    # ================================
    # = Create simulation controller =
    # ================================
    controller = pyclaw.Controller()
    controller.solution = solution
    controller.solver = solver
    
    # Output parameters
    controller.output_style = 1
    controller.tfinal = 7200.0
    controller.num_output_times = 300

    controller.write_aux_init = True
    controller.outdir = outdir
    controller.write_aux = True
    
    # ==================
    # = Run Simulation =
    # ==================
    state = controller.run()
    
    
    # ============
    # = Plotting =
    # ============
    plot_kargs = {"eta":[0.0,-300.0],
                  "rho":solution.state.problem_data['rho'],
                  "g":solution.state.problem_data['g'],
                  "dry_tolerance":solution.state.problem_data['dry_tolerance'],
                  "bathy_ref_lines":[x0,x1]}
    plot(setplot="./setplot_shelf.py",outdir=outdir,plotdir=plotdir,
         htmlplot=kargs.get('htmlplot',False),iplot=kargs.get('iplot',False),
         file_format=controller.output_format,**plot_kargs)
Exemple #6
0
def internal_lapping(num_cells, eigen_method, **kargs):
    r"""docstring for oscillatory_wind"""

    # Construct output and plot directory paths
    prefix = 'ml_e%s_n%s' % (eigen_method, num_cells)
    name = 'lapping'
    outdir, plotdir, log_path = runclaw.create_output_paths(
        name, prefix, **kargs)

    # Redirect loggers
    # This is not working for all cases, see comments in runclaw.py
    for logger_name in ['io', 'solution', 'plot', 'evolve', 'f2py', 'data']:
        runclaw.replace_stream_handlers(logger_name,
                                        log_path,
                                        log_file_append=False)

    # Load in appropriate PyClaw version
    if kargs.get('use_petsc', False):
        import clawpack.petclaw as pyclaw
    else:
        import clawpack.pyclaw as pyclaw

    # =================
    # = Create Solver =
    # =================
    if kargs.get('solver_type', 'classic') == 'classic':
        solver = pyclaw.ClawSolver1D()
    else:
        raise NotImplementedError(
            'Classic is currently the only supported solver.')

    # Solver method parameters
    solver.cfl_desired = 0.9
    solver.cfl_max = 1.0
    solver.max_steps = 5000
    solver.fwave = True
    solver.kernel_language = 'Fortran'
    solver.num_waves = 4
    solver.limiters = 3
    solver.source_split = 1

    # Boundary conditions
    solver.bc_lower[0] = 1
    solver.bc_upper[0] = 1
    solver.aux_bc_lower[0] = 1
    solver.aux_bc_upper[0] = 1

    # Set the Riemann solver
    solver.rp = riemann.rp1_layered_shallow_water

    # Set the before step functioning including the wind forcing
    solver.before_step = lambda solver, solution: ml.step.before_step(
        solver, solution)

    # Use simple friction source term
    solver.step_source = ml.step.friction_source

    # ============================
    # = Create Initial Condition =
    # ============================
    num_layers = 2

    x = pyclaw.Dimension('x', 0.0, 1.0, num_cells)
    domain = pyclaw.Domain([x])
    state = pyclaw.State(domain, 2 * num_layers, 3 + num_layers)
    state.aux[ml.aux.kappa_index, :] = 0.0

    # Set physics data
    state.problem_data['g'] = 9.8
    state.problem_data['manning'] = 0.022
    state.problem_data['rho_air'] = 1.15e-3
    state.problem_data['rho'] = [0.95, 1.0]
    state.problem_data[
        'r'] = state.problem_data['rho'][0] / state.problem_data['rho'][1]
    state.problem_data['one_minus_r'] = 1.0 - state.problem_data['r']
    state.problem_data['num_layers'] = num_layers

    # Set method parameters, this ensures it gets to the Fortran routines
    state.problem_data['eigen_method'] = eigen_method
    state.problem_data['dry_tolerance'] = 1e-3
    state.problem_data['inundation_method'] = 2
    state.problem_data['entropy_fix'] = False

    solution = pyclaw.Solution(state, domain)
    solution.t = 0.0

    # Set aux arrays including bathymetry, wind field and linearized depths
    ml.aux.set_sloped_shelf_bathymetry(solution.state, 0.4, 0.6, -1.0, -0.2)
    ml.aux.set_no_wind(solution.state)
    ml.aux.set_h_hat(solution.state, 0.5, [0.0, -0.6], [0.0, -0.6])

    # Set initial condition
    ml.qinit.set_gaussian_init_condition(solution.state,
                                         0.2,
                                         0.2,
                                         0.01,
                                         internal_layer=True)

    # ================================
    # = Create simulation controller =
    # ================================
    controller = pyclaw.Controller()
    controller.solution = solution
    controller.solver = solver

    # Output parameters
    controller.output_style = 1
    controller.tfinal = 2.0
    controller.num_output_times = 50
    controller.write_aux_init = True
    controller.outdir = outdir
    controller.write_aux = True

    # ==================
    # = Run Simulation =
    # ==================
    state = controller.run()

    # ============
    # = Plotting =
    # ============
    plot_kargs = {
        'rho': solution.state.problem_data['rho'],
        'dry_tolerance': solution.state.problem_data['dry_tolerance']
    }
    plot(setplot_path="./setplot_lapping.py",
         outdir=outdir,
         plotdir=plotdir,
         htmlplot=kargs.get('htmlplot', False),
         iplot=kargs.get('iplot', False),
         file_format=controller.output_format,
         **plot_kargs)
Exemple #7
0
def oscillatory_wind(num_cells,eigen_method,**kargs):
    r"""docstring for oscillatory_wind"""

    # Construct output and plot directory paths
    prefix = 'ml_e%s_n%s' % (eigen_method,num_cells)
    name = 'multilayer/oscillatory_wind'
    outdir,plotdir,log_path = runclaw.create_output_paths(name,prefix,**kargs)
    
    # Redirect loggers
    # This is not working for all cases, see comments in runclaw.py
    for logger_name in ['io','solution','plot','evolve','f2py','data']:
        runclaw.replace_stream_handlers(logger_name,log_path,log_file_append=False)

    # Load in appropriate PyClaw version
    if kargs.get('use_petsc',False):
        import clawpack.petclaw as pyclaw
    else:
        import clawpack.pyclaw as pyclaw

    # =================
    # = Create Solver =
    # =================
    if kargs.get('solver_type','classic') == 'classic':
        solver = pyclaw.ClawSolver1D()
    else:
        raise NotImplementedError('Classic is currently the only supported solver.')
        
    # Solver method parameters
    solver.cfl_desired = 0.9
    solver.cfl_max = 1.0
    solver.max_steps = 5000
    solver.fwave = True
    solver.kernel_language = 'Fortran'
    solver.num_waves = 4
    solver.limiters = 3
    solver.source_split = 1
        
    # Boundary conditions
    # Here we implement our own wall boundary conditions for the multi-layer 
    # equations
    solver.bc_lower[0] = 0 
    solver.bc_upper[0] = 0
    solver.user_bc_lower = ml.bc.wall_qbc_lower
    solver.user_bc_upper = ml.bc.wall_qbc_upper
    solver.aux_bc_lower[0] = 1
    solver.aux_bc_upper[0] = 1
    
    # Set the Riemann solver
    solver.rp = layered_shallow_water_1D

    # Set the before step functioning including the wind forcing
    wind_func = lambda state:ml.aux.set_oscillatory_wind(state,
                                        A=5.0,N=2.0,omega=2.0,t_length=10.0)
    solver.before_step = lambda solver,solution:ml.step.before_step(solver,solution,
                                            wind_func=wind_func,raise_on_richardson=True)
                                            
    # Use simple friction source term
    solver.step_source = ml.step.friction_source
    
    # ============================
    # = Create Initial Condition =
    # ============================
    num_layers = 2
    
    x = pyclaw.Dimension('x',0.0,1.0,num_cells)
    domain = pyclaw.Domain([x])
    state = pyclaw.State(domain,2*num_layers,3+num_layers)
    state.aux[ml.aux.kappa_index,:] = 0.0

    # Set physics data
    state.problem_data['g'] = 9.8
    state.problem_data['manning'] = 0.0
    state.problem_data['rho_air'] = 1.15
    state.problem_data['rho'] = [1025.0,1045.0]
    state.problem_data['r'] = state.problem_data['rho'][0] / state.problem_data['rho'][1]
    state.problem_data['one_minus_r'] = 1.0 - state.problem_data['r']
    state.problem_data['num_layers'] = num_layers
    
    # Set method parameters, this ensures it gets to the Fortran routines
    state.problem_data['eigen_method'] = eigen_method
    state.problem_data['dry_tolerance'] = 1e-3
    state.problem_data['inundation_method'] = 2
    state.problem_data['entropy_fix'] = False
    
    solution = pyclaw.Solution(state,domain)
    solution.t = 0.0
    
    # Set aux arrays including bathymetry, wind field and linearized depths
    ml.aux.set_jump_bathymetry(solution.state,0.5,[-1.0,-1.0])
    wind_func(solution.state)
    ml.aux.set_h_hat(solution.state,0.5,[0.0,-0.25],[0.0,-0.25])
    
    # Set sea at rest initial condition
    ml.qinit.set_quiescent_init_condition(solution.state)
    
    # ================================
    # = Create simulation controller =
    # ================================
    controller = pyclaw.Controller()
    controller.solution = solution
    controller.solver = solver
    
    # Output parameters
    controller.output_style = 1
    controller.tfinal = 10.0
    controller.num_output_times = 160
    controller.write_aux_init = True
    controller.outdir = outdir
    controller.keep_copy = True
    controller.write_aux_always = True
    
    # ==================
    # = Run Simulation =
    # ==================
    try:
        state = controller.run()
    except ml.step.RichardsonExceededError as e:
        print e
        # print "Writing out last solution available to frame %s." % str(len(controller.frames))
        # e.solution.write(len(controller.frames),path=controller.outdir,write_aux=True)
    
    # ============
    # = Plotting =
    # ============
    plot_kargs = {'xlower':solution.state.grid.x.lower,
                  'xupper':solution.state.grid.x.upper,
                  'rho':solution.state.problem_data['rho'],
                  'dry_tolerance':solution.state.problem_data['dry_tolerance']}
    plot(setplot="./setplot_oscillatory.py",outdir=outdir,
         plotdir=plotdir,htmlplot=kargs.get('htmlplot',False),
         iplot=kargs.get('iplot',False),file_format=controller.output_format,
         **plot_kargs)
def smooth_test(eigen_method, dry=False, **kargs):
    r"""Smooth well-balanced test"""

    # Construct output and plot directory paths
    prefix = 'ml_e%s_d%s' % (eigen_method,dry)
    name = 'multilayer/well_balancing_smooth'
    outdir,plotdir,log_path = runclaw.create_output_paths(name,prefix,**kargs)
    
    # Redirect loggers
    # This is not working for all cases, see comments in runclaw.py
    for logger_name in ['pyclaw.io', 'pyclaw.solution', 'plot', 'pyclaw.solver',
                        'f2py','data']:
        runclaw.replace_stream_handlers(logger_name, log_path, log_file_append=False)

    # Load in appropriate PyClaw version
    if kargs.get('use_petsc',False):
        import clawpack.petclaw as pyclaw
    else:
        import clawpack.pyclaw as pyclaw

    # =================
    # = Create Solver =
    # =================
    if kargs.get('solver_type','classic') == 'classic':
        solver = pyclaw.ClawSolver1D(riemann_solver=layered_shallow_water_1D)
    else:
        raise NotImplementedError('Classic is currently the only supported solver.')
        
    # Solver method parameters
    solver.cfl_desired = 0.9
    solver.cfl_max = 1.0
    solver.max_steps = 5000
    solver.fwave = True
    solver.kernel_language = 'Fortran'
    solver.limiters = 3
    solver.source_split = 1
        
    # Boundary conditions
    # Use wall boundary condition at beach
    solver.bc_lower[0] = 1
    solver.bc_upper[0] = 1
    solver.aux_bc_lower[0] = 1
    solver.aux_bc_upper[0] = 1

    # Set the before step function
    solver.before_step = lambda solver,solution:ml.step.before_step(solver,
                                                                    solution)
                                            
    # Use simple friction source term
    solver.step_source = ml.step.friction_source

    
    # ============================
    # = Create Initial Condition =
    # ============================
    num_layers = 2
    
    x = pyclaw.Dimension(0.0, 10.0, 200)
    domain = pyclaw.Domain([x])
    state = pyclaw.State(domain, 2 * num_layers, 3 + num_layers)
    state.aux[ml.aux.kappa_index,:] = 0.0

    # Set physics data
    state.problem_data['g'] = 9.8
    state.problem_data['manning'] = 0.0
    state.problem_data['rho_air'] = 1.15
    state.problem_data['rho'] = [0.98,1.0]
    state.problem_data['r'] = state.problem_data['rho'][0] / state.problem_data['rho'][1]
    state.problem_data['one_minus_r'] = 1.0 - state.problem_data['r']
    state.problem_data['num_layers'] = num_layers
    
    # Set method parameters, this ensures it gets to the Fortran routines
    state.problem_data['eigen_method'] = eigen_method
    state.problem_data['dry_tolerance'] = 1e-3
    state.problem_data['inundation_method'] = 2
    state.problem_data['entropy_fix'] = False
    
    solution = pyclaw.Solution(state,domain)
    solution.t = 0.0
    
    # Set aux arrays including bathymetry, wind field and linearized depths
    ml.aux.set_gaussian_bathymetry(solution.state, 10.0, 5, numpy.sqrt(5 / 2), 
                                                   5.0)
    ml.aux.set_no_wind(solution.state)
    if dry:
        ml.aux.set_h_hat(solution.state, 0.5, [0.0, -6.0], [0.0, -6.0])
    else:
        ml.aux.set_h_hat(solution.state, 0.5, [0.0, -4.0], [0.0, -4.0])

    # Set perturbation to sea at rest
    ml.qinit.set_quiescent_init_condition(solution.state)
    
    
    # ================================
    # = Create simulation controller =
    # ================================
    controller = pyclaw.Controller()
    controller.solution = solution
    controller.solver = solver
    
    # Output parameters
    controller.output_style = 1
    controller.tfinal = 10.0
    controller.num_output_times = 1
    controller.write_aux_init = True
    controller.outdir = outdir
    controller.write_aux = True
    
    # ==================
    # = Run Simulation =
    # ==================
    state = controller.run()
    
    # ============
    # = Plotting =
    # ============
    plot_kargs = {"rho":solution.state.problem_data['rho'],
                  "dry_tolerance":solution.state.problem_data['dry_tolerance']}
    plot(setplot="./setplot_well_balanced.py",outdir=outdir,
         plotdir=plotdir, htmlplot=kargs.get('htmlplot',False),
         iplot=kargs.get('iplot',False),
         file_format=controller.output_format,**plot_kargs)
def periodic_bathy(num_periods, **kargs):

    outdir = "./_output"
    plotdir = "./_plots"

    # Construct output and plot directory paths
    # outdir,plotdir,log_path = runclaw.create_output_paths(name,prefix,**kargs)
    
    # Redirect loggers
    # This is not working for all cases, see comments in runclaw.py
    # for logger_name in ['io','solution','plot','evolve','f2py','data']:
    #     runclaw.replace_stream_handlers(logger_name,log_path,log_file_append=False)

    # Load in appropriate PyClaw version
    if kargs.get('use_petsc',False):
        import clawpack.petclaw as pyclaw
    else:
        import clawpack.pyclaw as pyclaw

    # =================
    # = Create Solver =
    # =================
    if kargs.get('solver_type','classic') == 'classic':
        solver = pyclaw.ClawSolver1D()
    else:
        raise NotImplementedError('Classic is currently the only supported solver.')
        
    # Solver method parameters
    solver.cfl_desired = 0.9
    solver.cfl_max = 1.0
    solver.max_steps = 5000
    solver.fwave = True
    solver.kernel_language = 'Fortran'
    solver.num_waves = 4
    solver.limiters = 3
    solver.source_split = 1
        
    # Boundary conditions
    solver.bc_lower[0] = 1
    solver.bc_upper[0] = 1
    solver.aux_bc_lower[0] = 1
    solver.aux_bc_upper[0] = 1

    # Set the Riemann solver
    solver.rp = riemann.layered_shallow_water_1D

    # Set the before step functioning including the wind forcing
    # solver.before_step = lambda solver,solution:ml.step.before_step(solver,solution)
                                            
    # Use simple friction source term
    # solver.step_source = ml.step.friction_source
    
    
    # ============================
    # = Create Initial Condition =
    # ============================
    num_layers = 2
    grid_cells_per_period = 40
    
    x = pyclaw.Dimension('x', 0.0, float(num_periods), 
                                            num_periods * grid_cells_per_period)
    domain = pyclaw.Domain([x])
    state = pyclaw.State(domain, 2 * num_layers, 3 + num_layers)
    state.aux[kappa_index,:] = 0.0

    # Set physics data
    state.problem_data['g'] = 9.8
    state.problem_data['manning'] = 0.0
    state.problem_data['rho_air'] = 1.15e-3
    state.problem_data['rho'] = [0.95,1.0]
    state.problem_data['r'] = state.problem_data['rho'][0] / state.problem_data['rho'][1]
    state.problem_data['one_minus_r'] = 1.0 - state.problem_data['r']
    state.problem_data['num_layers'] = num_layers
    
    # Set method parameters, this ensures it gets to the Fortran routines
    state.problem_data['eigen_method'] = 2
    state.problem_data['dry_tolerance'] = 1e-3
    state.problem_data['inundation_method'] = 2
    state.problem_data['entropy_fix'] = False
    
    solution = pyclaw.Solution(state,domain)
    solution.t = 0.0
    
    # Set aux arrays including bathymetry, wind field and linearized depths
    # solution.state.aux[0,:] = -0.5 + 0.3 * np.sin(2.0 * np.pi * x.centers)
    solution.state.aux[0,:] = -np.ones(x.centers.shape)  \
                              + (np.mod(np.floor(x.centers),2) == 1) * 0.5

    # Wind
    solution.state.aux[1,:] = np.zeros(x.centers.shape)

    # Set initial condition and h_hat
    lower_layer_eta = -0.4
    solution.state.q[1,:] = 0.0
    solution.state.q[2,:] = 0.0
    solution.state.q[3,:] = 0.0
    for i in xrange(x.centers.shape[0]):
        if solution.state.aux[0,i] < lower_layer_eta:
            solution.state.aux[2,i] = 0.0 - lower_layer_eta
            solution.state.aux[3,i] = lower_layer_eta

            solution.state.q[0,i] = 0.0 - lower_layer_eta
            solution.state.q[2,i] = lower_layer_eta - solution.state.aux[0,i]
        else:
            solution.state.aux[2,i] = 0.0 - solution.state.aux[0,i]
            solution.state.aux[3,i] = solution.state.aux[0,i]

            solution.state.q[0,i] = 0.0 - solution.state.aux[0,i]

    # Add plane wave
    solution.state.q[0,:] += 0.1 * np.exp(-(x.centers - 5.0)**2 / 1.0**2)

    # Add densities
    solution.state.q[0:2,:] *= state.problem_data['rho'][0]
    solution.state.q[2:,:]  *= state.problem_data['rho'][1]
    
    # ================================
    # = Create simulation controller =
    # ================================
    controller = pyclaw.Controller()
    controller.solution = solution
    controller.solver = solver
    
    # Output parameters
    controller.output_style = 1
    controller.tfinal = 50.0
    controller.num_output_times = 50
    controller.write_aux_init = True
    controller.outdir = outdir
    controller.write_aux = True
    
    # ==================
    # = Run Simulation =
    # ==================
    state = controller.run()
    
    # ============
    # = Plotting =
    # ============
    plot_kargs = {'rho':solution.state.problem_data['rho'],
                  'dry_tolerance':solution.state.problem_data['dry_tolerance']}
    
    make_plots.plot(setplot=setplot, outdir=outdir, plotdir=plotdir,
         htmlplot=kargs.get('htmlplot',False), iplot=kargs.get('iplot',False),
         file_format=controller.output_format, **plot_kargs)
Exemple #10
0
def rarefaction(num_cells,eigen_method,entropy_fix,**kargs):
    r"""docstring for oscillatory_wind"""

    # Construct output and plot directory paths
    prefix = 'ml_e%s_m%s_fix' % (eigen_method,num_cells)
    if entropy_fix:
        prefix = "".join((prefix,"T"))
    else:
        prefix = "".join((prefix,"F"))
    name = 'all_rare'
    outdir,plotdir,log_path = runclaw.create_output_paths(name,prefix,**kargs)
    
    # Redirect loggers
    # This is not working for all cases, see comments in runclaw.py
    for logger_name in ['io','solution','plot','evolve','f2py','data']:
        runclaw.replace_stream_handlers(logger_name,log_path,log_file_append=False)

    # Load in appropriate PyClaw version
    if kargs.get('use_petsc',False):
        import clawpack.petclaw as pyclaw
    else:
        import clawpack.pyclaw as pyclaw


    # =================
    # = Create Solver =
    # =================
    if kargs.get('solver_type','classic') == 'classic':
        solver = pyclaw.ClawSolver1D()
    else:
        raise NotImplementedError('Classic is currently the only supported solver.')
        
    # Solver method parameters
    solver.cfl_desired = 0.9
    solver.cfl_max = 1.0
    solver.max_steps = 5000
    solver.fwave = True
    solver.kernel_language = 'Fortran'
    solver.num_waves = 4
    solver.limiters = 3
    solver.source_split = 1
        
    # Boundary conditions
    solver.bc_lower[0] = 1
    solver.bc_upper[0] = 1
    solver.aux_bc_lower[0] = 1
    solver.aux_bc_upper[0] = 1
    
    # Set the Riemann solver
    solver.rp = riemann.rp1_layered_shallow_water

    # Set the before step function
    solver.before_step = lambda solver,solution:ml.step.before_step(solver,solution)
                                            
    # Use simple friction source term
    solver.step_source = ml.step.friction_source
    
    
    # ============================
    # = Create Initial Condition =
    # ============================
    num_layers = 2
    
    x = pyclaw.Dimension('x',0.0,1.0,num_cells)
    domain = pyclaw.Domain([x])
    state = pyclaw.State(domain,2*num_layers,3+num_layers)
    state.aux[ml.aux.kappa_index,:] = 0.0

    # Set physics data
    state.problem_data['g'] = 9.8
    state.problem_data['manning'] = 0.0
    state.problem_data['rho_air'] = 1.15e-3
    state.problem_data['rho'] = [0.95,1.0]
    state.problem_data['r'] = state.problem_data['rho'][0] / state.problem_data['rho'][1]
    state.problem_data['one_minus_r'] = 1.0 - state.problem_data['r']
    state.problem_data['num_layers'] = num_layers
    
    # Set method parameters, this ensures it gets to the Fortran routines
    state.problem_data['eigen_method'] = eigen_method
    state.problem_data['dry_tolerance'] = 1e-3
    state.problem_data['inundation_method'] = 2
    state.problem_data['entropy_fix'] = entropy_fix
    
    solution = pyclaw.Solution(state,domain)
    solution.t = 0.0
    
    # Set aux arrays including bathymetry, wind field and linearized depths
    eta = [0.0,-0.5]
    ml.aux.set_jump_bathymetry(solution.state,0.5,[-1.0,-1.0])
    ml.aux.set_no_wind(solution.state)
    ml.aux.set_h_hat(solution.state,0.5,eta,eta)
    
    # Set sea at rest initial condition with diverging velocities
    u_left = [0.0,-0.5]
    u_right = [0.0,0.5]
    h_hat = [eta[0] - eta[1],eta[1] + 1.0]
    q_left = [h_hat[0] * state.problem_data['rho'][0],
              u_left[0] * h_hat[0] * state.problem_data['rho'][0],
              h_hat[1] * state.problem_data['rho'][1],
              u_left[1] * h_hat[1] * state.problem_data['rho'][1]]

    q_right = [h_hat[0] * state.problem_data['rho'][0],
               u_right[0] * h_hat[0] * state.problem_data['rho'][0],
               h_hat[1] * state.problem_data['rho'][1],
               u_right[1] * h_hat[1] * state.problem_data['rho'][1]]
    ml.qinit.set_riemann_init_condition(state,0.5,q_left,q_right)
    
    
    # ================================
    # = Create simulation controller =
    # ================================
    controller = pyclaw.Controller()
    controller.solution = solution
    controller.solver = solver
    
    # Output parameters
    controller.output_style = 3
    controller.nstepout = 1
    controller.num_output_times = 100
    controller.write_aux_init = True
    controller.outdir = outdir
    controller.write_aux = True
    
    
    # ==================
    # = Run Simulation =
    # ==================
    state = controller.run()
    
    
    # ============
    # = Plotting =
    # ============
    plot_kargs = {'rho':solution.state.problem_data['rho'],
                  'dry_tolerance':solution.state.problem_data['dry_tolerance']}
    plot(setplot_path="./setplot_drystate.py",outdir=outdir,plotdir=plotdir,
         htmlplot=kargs.get('htmlplot',False),iplot=kargs.get('iplot',False),
         file_format=controller.output_format,**plot_kargs)
Exemple #11
0
def wave_family(num_cells,eigen_method,wave_family,dry_state=True,**kargs):
    r"""docstring for oscillatory_wind"""

    # Construct output and plot directory paths
    prefix = 'ml_e%s_n%s' % (eigen_method,num_cells)
    if dry_state:
        name = 'multilayer/dry_wave_%s' % wave_family
    else:
        name = 'multilayer/wet_wave_%s' % wave_family
    outdir,plotdir,log_path = runclaw.create_output_paths(name,prefix,**kargs)
    
    # Redirect loggers
    # This is not working for all cases, see comments in runclaw.py
    for logger_name in ['pyclaw.io','pyclaw.solution','plot','pyclaw.solver','f2py','data']:
        runclaw.replace_stream_handlers(logger_name,log_path,log_file_append=False)

    # Load in appropriate PyClaw version
    if kargs.get('use_petsc',False):
        import clawpack.petclaw as pyclaw
    else:
        import clawpack.pyclaw as pyclaw

    # =================
    # = Create Solver =
    # =================
    if kargs.get('solver_type','classic') == 'classic':
        solver = pyclaw.ClawSolver1D()
    else:
        raise NotImplementedError('Classic is currently the only supported solver.')
        
    # Solver method parameters
    solver.cfl_desired = 0.9
    solver.cfl_max = 1.0
    solver.max_steps = 5000
    solver.fwave = True
    solver.kernel_language = 'Fortran'
    solver.num_waves = 4
    solver.limiters = 3
    solver.source_split = 1
        
    # Boundary conditions
    solver.bc_lower[0] = 1
    solver.bc_upper[0] = 1
    solver.aux_bc_lower[0] = 1
    solver.aux_bc_upper[0] = 1

    # Set the Riemann solver
    solver.rp = layered_shallow_water_1D

    # Set the before step functioning including the wind forcing
    solver.before_step = lambda solver,solution:ml.step.before_step(solver,solution)
                                            
    # Use simple friction source term
    solver.step_source = ml.step.friction_source
    
    
    # ============================
    # = Create Initial Condition =
    # ============================
    num_layers = 2
    
    x = pyclaw.Dimension('x',0.0,1.0,num_cells)
    domain = pyclaw.Domain([x])
    state = pyclaw.State(domain,2*num_layers,3+num_layers)
    state.aux[ml.aux.kappa_index,:] = 0.0

    # Set physics data
    state.problem_data['g'] = 9.8
    state.problem_data['manning'] = 0.0
    state.problem_data['rho_air'] = 1.15e-3
    state.problem_data['rho'] = [0.95,1.0]
    state.problem_data['r'] = state.problem_data['rho'][0] / state.problem_data['rho'][1]
    state.problem_data['one_minus_r'] = 1.0 - state.problem_data['r']
    state.problem_data['num_layers'] = num_layers
    
    # Set method parameters, this ensures it gets to the Fortran routines
    state.problem_data['eigen_method'] = eigen_method
    state.problem_data['dry_tolerance'] = 1e-3
    state.problem_data['inundation_method'] = 2
    state.problem_data['entropy_fix'] = False
    
    solution = pyclaw.Solution(state,domain)
    solution.t = 0.0
    
    # Set aux arrays including bathymetry, wind field and linearized depths
    if dry_state:
        ml.aux.set_jump_bathymetry(solution.state,0.5,[-1.0,-0.2])
    else:
        ml.aux.set_jump_bathymetry(solution.state,0.5,[-1.0,-1.0])
    ml.aux.set_no_wind(solution.state)
    ml.aux.set_h_hat(solution.state,0.5,[0.0,-0.6],[0.0,-0.6])
    
    # Set initial condition
    if wave_family == 3:
        ml.qinit.set_wave_family_init_condition(solution.state,wave_family,0.45,0.1)
    elif wave_family == 4:
        # The perturbation must be less in this case otherwise the internal
        # wave will crest the bathymetry jump
        ml.qinit.set_wave_family_init_condition(solution.state,wave_family,0.45,0.04)

    
    # ================================
    # = Create simulation controller =
    # ================================
    controller = pyclaw.Controller()
    controller.solution = solution
    controller.solver = solver
    
    # Output parameters
    controller.output_style = 1
    controller.tfinal = 0.5
    controller.num_output_times = 50
    controller.write_aux_init = True
    controller.outdir = outdir
    controller.write_aux = True
    
    # ==================
    # = Run Simulation =
    # ==================
    state = controller.run()
    
    # ============
    # = Plotting =
    # ============
    plot_kargs = {'wave_family':wave_family,
                  'rho':solution.state.problem_data['rho'],
                  'dry_tolerance':solution.state.problem_data['dry_tolerance']}
    plot(setplot="./setplot_wave_family.py",outdir=outdir,plotdir=plotdir,
         htmlplot=kargs.get('htmlplot',False),iplot=kargs.get('iplot',False),
         file_format=controller.output_format,**plot_kargs)
Exemple #12
0
def setup(kernel_language='Python',
          use_petsc=False,
          outdir='./_output',
          solver_type='classic'):

    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

    params = load_parameters('parameters_h_box_wave.txt')
    xlower = float(params['xlower'])
    xupper = float(params['xupper'])
    cells_number = int(params['cells_number'])
    nw = int(
        params['wall_position'])  # index of the edge used to present the wall
    alpha = float(params['fraction'])
    wall_height = float(params['wall_height'])

    x = pyclaw.Dimension(xlower, xupper, cells_number, name='x')
    domain = pyclaw.Domain(x)
    state = pyclaw.State(domain, 2, 2)
    xc = state.grid.x.centers

    # Gravitational constant
    state.problem_data['grav'] = 9.8
    state.problem_data['sea_level'] = 0.0

    # Wall position
    state.problem_data['wall_position'] = nw
    state.problem_data['wall_height'] = wall_height
    state.problem_data['fraction'] = alpha
    state.problem_data['dry_tolerance'] = 0.001
    state.problem_data['max_iteration'] = 1
    state.problem_data['method'] = 'h_box_wave'
    state.problem_data['zero_width'] = True
    state.problem_data['arrival_state'] = False

    solver = pyclaw.ClawSolver1D(
        shallow_1D_redistribute_wave.shallow_fwave_hbox_dry_1d)

    solver.limiters = pyclaw.limiters.tvd.vanleer
    solver.order = 1
    solver.cfl_max = 0.8
    solver.cfl_desired = 0.7
    solver.kernel_language = "Python"
    solver.fwave = True
    solver.num_waves = 2
    solver.num_eqn = 2
    solver.before_step = before_step
    solver.bc_lower[0] = pyclaw.BC.wall
    solver.bc_upper[0] = pyclaw.BC.wall
    solver.aux_bc_lower[0] = pyclaw.BC.wall
    solver.aux_bc_upper[0] = pyclaw.BC.wall

    # Initial Conditions
    state.index_capa = 1
    xpxc = cells_number * 1.0 / (cells_number - 1)
    state.problem_data['xpxc'] = xpxc
    state.aux[0, :] = -0.8 * numpy.ones(xc.shape)

    ## slope bathymetry
    # bathymetry = numpy.linspace(-0.8, -0.4, xc.shape[0] - 1, endpoint=True)
    # state.aux[0,:nw-1] = bathymetry[:nw-1]
    # state.aux[0,nw-1] = bathymetry[nw-1]
    # state.aux[0,nw:] = bathymetry[nw-1:]
    # state.aux[0,:] = numpy.linspace(-0.8, -0.4, xc.shape[0], endpoint=True)

    state.aux[1, :] = xpxc
    state.aux[1, nw - 1] = alpha * xpxc
    state.aux[1, nw] = (1 - alpha) * xpxc
    state.q[0, :] = 0.0 - state.aux[0, :]
    state.q[0, :nw - 5] += 0.4
    state.q[0, nw:] = 0.0  #dry state in the right of wall
    state.q[0, :] = state.q[0, :].clip(min=0)
    state.q[1, :] = 0.0

    claw = pyclaw.Controller()
    claw.keep_copy = True
    claw.tfinal = 10.0
    claw.solution = pyclaw.Solution(state, domain)
    claw.solver = solver
    # claw.setplot = setplot
    claw.write_aux_init = True

    claw.output_style = 1
    claw.num_output_times = 20
    claw.nstepout = 1

    # if outdir is not None:
    #     claw.outdir = outdir
    # else:
    #     claw.output_format = None

    claw.outdir = outdir
    if outdir is None:
        claw.output_format = None

    claw.run()

    plot_kargs = {'problem_data': state.problem_data}
    plot(setplot="./setplot_h_box_wave.py",
         iplot=False,
         htmlplot=True,
         **plot_kargs)
Exemple #13
0
def jump_shelf(wave_height, **kargs):
    r"""Shelf test"""

    # Single layer test
    single_layer = kargs.get("single_layer", False)

    # Construct output and plot directory paths
    if single_layer:
        prefix = 'sl_h%s' % (int(wave_height))
    elif kargs.get("internal_only", False):
        prefix = 'il_h%s' % (int(wave_height))
    else:
        prefix = 'ml_h%s' % (int(wave_height))
    name = 'multilayer/tsunami/jump'
    outdir,plotdir,log_path = runclaw.create_output_paths(name,prefix,**kargs)
    
    # Redirect loggers
    # This is not working for all cases, see comments in runclaw.py
    for logger_name in ['pyclaw.io','pyclaw.solution','plot','pyclaw.solver','f2py','data']:
        runclaw.replace_stream_handlers(logger_name,log_path,log_file_append=False)

    # Load in appropriate PyClaw version
    if kargs.get('use_petsc',False):
        import clawpack.petclaw as pyclaw
    else:
        import clawpack.pyclaw as pyclaw

    # =================
    # = Create Solver =
    # =================
    if kargs.get('solver_type','classic') == 'classic':
        solver = pyclaw.ClawSolver1D()
    else:
        raise NotImplementedError('Classic is currently the only supported solver.')
        
    # Solver method parameters
    solver.cfl_desired = 0.9
    solver.cfl_max = 1.0
    solver.max_steps = 5000
    solver.fwave = True
    solver.kernel_language = 'Fortran'
    solver.num_waves = 4
    solver.limiters = 3
    solver.source_split = 1
    solver.num_eqn = 4
        
    # Boundary conditions
    # Use wall boundary condition at beach
    solver.bc_lower[0] = 1
    solver.bc_upper[0] = 0
    solver.user_bc_upper = ml.bc.wall_qbc_upper
    solver.aux_bc_lower[0] = 1
    solver.aux_bc_upper[0] = 1
    
    # Set the Riemann solver
    solver.rp = layered_shallow_water_1D

    # Set the before step function
    solver.before_step = lambda solver,solution:ml.step.before_step(solver,
                                                                    solution)
                                            
    # Use simple friction source term
    solver.step_source = ml.step.friction_source

    
    # ============================
    # = Create Initial Condition =
    # ============================
    num_layers = 2
    
    x = pyclaw.Dimension(-400e3, 0.0, 2000)
    domain = pyclaw.Domain([x])
    state = pyclaw.State(domain,2*num_layers,3+num_layers)
    state.aux[ml.aux.kappa_index,:] = 0.0

    # Set physics data
    state.problem_data['g'] = 9.8
    state.problem_data['manning'] = 0.0
    state.problem_data['rho_air'] = 1.15
    state.problem_data['rho'] = [1025.0, 1045.0]
    state.problem_data['r'] = state.problem_data['rho'][0] / state.problem_data['rho'][1]
    state.problem_data['one_minus_r'] = 1.0 - state.problem_data['r']
    state.problem_data['num_layers'] = num_layers
    
    # Set method parameters, this ensures it gets to the Fortran routines
    state.problem_data['eigen_method'] = 2
    state.problem_data['dry_tolerance'] = 1e-3
    state.problem_data['inundation_method'] = 2
    state.problem_data['entropy_fix'] = False
    
    solution = pyclaw.Solution(state,domain)
    solution.t = 0.0
    
    # Set aux arrays including bathymetry, wind field and linearized depths
    ml.aux.set_jump_bathymetry(solution.state,-30e3,[-4000.0,-100.0])
    ml.aux.set_no_wind(solution.state)
    if single_layer:
        ml.aux.set_h_hat(solution.state, 0.5, [0.0, -1e10], [0.0, -1e10])
    else:
        ml.aux.set_h_hat(solution.state, 0.5, [0.0, -300.0], [0.0, -300.0])
    
    # Ocean at rest
    ml.qinit.set_quiescent_init_condition(state, single_layer=single_layer)
    # Set surface perturbations
    # set_tsunami_init_condition(solution.state, wave_height, single_layer=single_layer,
                                                    # bounds=[-50e3, -30e3])
    set_acta_numerica_init_condition(state, wave_height, single_layer=single_layer, internal_only=kargs.get('internal_only', False))
    # Set momentum from horizontal movement
    # set_momentum_impulse(solution.state, energy_impulse, single_layer=single_layer,
                                                # bounds=[-50e3, -30e3])
    
    # ================================
    # = Create simulation controller =
    # ================================
    controller = pyclaw.Controller()
    controller.solution = solution
    controller.solver = solver
    
    # Output parameters
    controller.output_style = 1
    controller.tfinal = 7200.0 * 2
    controller.num_output_times = 300 * 2
    # controller.output_style = 2
    # controller.out_times = [0.0,720.0,2400.0,4800.0,7200.0]
    controller.write_aux_init = True
    controller.outdir = outdir
    controller.write_aux = True
    
    # ==================
    # = Run Simulation =
    # ==================
    state = controller.run()
    
    # ============
    # = Plotting =
    # ============
    plot_kargs = {"eta":[0.0,-300.0],
                  "rho":solution.state.problem_data['rho'],
                  "g":solution.state.problem_data['g'],
                  "dry_tolerance":solution.state.problem_data['dry_tolerance'],
                  "bathy_ref_lines":[-30e3]}
    plot(setplot="./setplot_shelf.py",outdir=outdir,plotdir=plotdir,
         htmlplot=kargs.get('htmlplot',False),iplot=kargs.get('iplot',False),
         file_format=controller.output_format,**plot_kargs)
Exemple #14
0
def html_plot(outdir='./_output',file_format='petsc'):
    """
    Convenience function for creating html page with plots.
    """
    from clawpack.pyclaw.plot import plot
    plot(outdir=outdir,file_format=file_format,iplot=False,htmlplot=True)
Exemple #15
0
def interactive_plot(outdir='./_output',file_format='petsc'):
    """
    Convenience function for launching an interactive plotting session.
    """
    from clawpack.pyclaw.plot import plot
    plot(outdir=outdir,file_format=file_format,iplot=True,htmlplot=False)