def shallow2D(use_petsc=False,iplot=0,htmlplot=False,outdir='./_output',solver_type='classic',amr_type=None): #=========================================================================== # Import libraries #=========================================================================== if use_petsc: import clawpack.petclaw as pyclaw else: from clawpack import pyclaw #=========================================================================== # Setup solver and solver parameters #=========================================================================== if solver_type == 'classic': solver = pyclaw.ClawSolver2D() solver.limiters = pyclaw.limiters.tvd.MC solver.dimensional_split=1 elif solver_type == 'sharpclaw': solver = pyclaw.SharpClawSolver2D() from clawpack import riemann solver.rp = riemann.rp2_shallow_roe_with_efix solver.num_waves = 3 solver.bc_lower[0] = pyclaw.BC.wall solver.bc_upper[0] = pyclaw.BC.wall solver.bc_lower[1] = pyclaw.BC.wall solver.bc_upper[1] = pyclaw.BC.wall #=========================================================================== # Initialize domain and state, then initialize the solution associated to the # state and finally initialize aux array #=========================================================================== # resolution of each grid mgrid = 6 # number of initial AMR grids in each dimension msubgrid = 9 if amr_type is not None: m = mgrid else: # number of Domain grid cells expressed as the product of # grid resolution and the number of AMR sub-grids for # easy comparison between the two methods m = mgrid*msubgrid mx = m my = m # Domain: xlower = 0 xupper = 1 ylower = 0 yupper = 1 x = pyclaw.Dimension('x',xlower,xupper,mx) y = pyclaw.Dimension('y',ylower,yupper,my) domain = pyclaw.Domain([x,y]) num_eqn = 3 # Number of equations state = pyclaw.State(domain,num_eqn) grav = 1.0 # Parameter (global auxiliary variable) state.problem_data['grav'] = grav # Initial solution # ================ # Riemann states of the dam break problem damRadius = 0.25 #0.5 hl = 2. ul = 0. vl = 0. hr = 1. ur = 0. vr = 0. qinit(state,hl,ul,vl,hr,ur,vl,damRadius) # This function is defined above # this closure is used by AMR-style codes def qinit_callback(state): qinit(state,hl,ul,vl,hr,ur,vl,damRadius) #=========================================================================== # Set up controller and controller parameters #=========================================================================== claw = pyclaw.Controller() claw.tfinal = 0.1 #0.03 if amr_type is not None: if amr_type == 'peano': import clawpack.peanoclaw as amrclaw claw.solver = amrclaw.Solver(solver ,1/(mgrid*msubgrid) ,qinit_callback ,refinement_criterion=refinement_criterion_time_dependent ) claw.solution = amrclaw.Solution(state, domain) else: raise Exception('unsupported amr_type %s' % amr_type) else: claw.solver = solver claw.solution = pyclaw.Solution(state,domain) #claw.keep_copy = True #claw.outdir = outdir claw.keep_copy = False claw.output_format = None claw.outdir = None claw.num_output_times = 10 #=========================================================================== # Solve the problem #=========================================================================== claw.run_prepare() print 'running on rank: ', claw.solver.peano.rank if claw.solver.peano.rank == 0: status = claw.runMaster() else: status = claw.solver.peano.runWorker() #=========================================================================== # Plot results #=========================================================================== if htmlplot: pyclaw.plot.html_plot(outdir=outdir) if iplot: pyclaw.plot.interactive_plot(outdir=outdir) return claw
def shallow2D(use_petsc=False, outdir='./_output', solver_type='classic', disable_output=False): #=========================================================================== # Import libraries #=========================================================================== import numpy as np import clawpack.peanoclaw as peanoclaw import clawpack.riemann as riemann if use_petsc: import clawpack.petclaw as pyclaw else: import clawpack.pyclaw as pyclaw #=========================================================================== # Setup solver and solver parameters #=========================================================================== subdivisionFactor = 6 if solver_type == 'classic': solver = pyclaw.ClawSolver2D(riemann.shallow_roe_with_efix_2D) solver.limiters = pyclaw.limiters.tvd.MC solver.dimensional_split = 1 elif solver_type == 'sharpclaw': solver = pyclaw.SharpClawSolver2D(riemann.shallow_roe_with_efix_2D) peanoSolver = peanoclaw.Solver(solver, (1. / 3.) / subdivisionFactor, init) solver.dt_initial = 1.0 solver.bc_lower[0] = pyclaw.BC.wall solver.bc_upper[0] = pyclaw.BC.wall solver.bc_lower[1] = pyclaw.BC.wall solver.bc_upper[1] = pyclaw.BC.wall #=========================================================================== # Initialize domain and state, then initialize the solution associated to the # state and finally initialize aux array #=========================================================================== # Domain: from clawpack.pyclaw import geometry print(geometry.__file__) xlower = 0.0 xupper = 1.0 mx = subdivisionFactor ylower = 0.0 yupper = 1.0 my = subdivisionFactor x = pyclaw.Dimension('x', xlower, xupper, mx) y = pyclaw.Dimension('y', ylower, yupper, my) domain = geometry.Domain([x, y]) num_eqn = 3 # Number of equations state = pyclaw.State(domain, num_eqn) grav = 1.0 # Parameter (global auxiliary variable) state.problem_data['grav'] = grav #=========================================================================== # Set up controller and controller parameters #=========================================================================== claw = pyclaw.Controller() claw.tfinal = 0.1 claw.solution = peanoclaw.solution.Solution(state, domain) claw.solver = peanoSolver claw.outdir = outdir if disable_output: claw.output_format = None claw.num_output_times = 5 return claw