diff --git a/fvmbook/chap21/radialdam/1drad/Makefile b/fvmbook/chap21/radialdam/1drad/Makefile new file mode 100644 index 00000000..bc72da36 --- /dev/null +++ b/fvmbook/chap21/radialdam/1drad/Makefile @@ -0,0 +1,56 @@ + +# Makefile for Clawpack code in this directory. +# This version only sets the local files and frequently changed +# options, and then includes the standard makefile pointed to by CLAWMAKE. +CLAWMAKE = $(CLAW)/clawutil/src/Makefile.common + +# See the above file for details and a list of make options, or type +# make .help +# at the unix prompt. + + +# Adjust these variables if desired: +# ---------------------------------- + +CLAW_PKG = classic # Clawpack package to use +EXE = xclaw # Executable to create +SETRUN_FILE = setrun.py # File containing function to make data +OUTDIR = _output # Directory for output +SETPLOT_FILE = setplot.py # File containing function to set plots +PLOTDIR = _plots # Directory for plots + +OVERWRITE ?= True # False ==> make a copy of OUTDIR first +RESTART ?= False # Should = clawdata.restart in setrun + +# Environment variable FC should be set to fortran compiler, e.g. gfortran + +# Compiler flags can be specified here or set as an environment variable +FFLAGS ?= + +# --------------------------------- +# List of sources for this program: +# --------------------------------- + +MODULES = \ + +SOURCES = \ + qinit.f \ + src1.f \ + setprob.f \ + $(CLAW)/riemann/src/rp1_shallow_roe_with_efix.f90 \ + $(CLAW)/classic/src/1d/setaux.f90 \ + $(CLAW)/classic/src/1d/bc1.f \ + $(CLAW)/classic/src/1d/b4step1.f90 \ + $(CLAW)/classic/src/1d/driver.f90 \ + $(CLAW)/classic/src/1d/claw1ez.f \ + $(CLAW)/classic/src/1d/claw1.f \ + $(CLAW)/classic/src/1d/copyq1.f \ + $(CLAW)/classic/src/1d/inlinelimiter.f90 \ + $(CLAW)/classic/src/1d/opendatafile.f \ + $(CLAW)/classic/src/1d/out1.f \ + $(CLAW)/classic/src/1d/step1.f90 + +#------------------------------------------------------------------- +# Include Makefile containing standard definitions and make options: +include $(CLAWMAKE) + diff --git a/fvmbook/chap21/radialdam/1drad/README.rst b/fvmbook/chap21/radialdam/1drad/README.rst new file mode 100644 index 00000000..194fa593 --- /dev/null +++ b/fvmbook/chap21/radialdam/1drad/README.rst @@ -0,0 +1,16 @@ + +.. _fvmbook_chap21/radialdam/1drad: + +Radial dam-break problem for 2D shallow water equations +-------------------------------------------------------- + +Example [book/chap21/radialdam/1drad] to accompany the book +`Finite Volume Methods for Hyperbolic Problems +`_ +by R. J. LeVeque. + +Converted to Clawpack 5.0 form in 2016. + +The code in this directory solves the 1d shallow water equations with a +geometric source term for the radial symmetry. It is used to create a +reference solution for comparison to the 2d solution. diff --git a/fvmbook/chap21/radialdam/1drad/U.m b/fvmbook/chap21/radialdam/1drad/U.m new file mode 100644 index 00000000..170299ef --- /dev/null +++ b/fvmbook/chap21/radialdam/1drad/U.m @@ -0,0 +1,3 @@ +function U = U(data); +% compute the velocity from the momentum and depth: +U = data(:,2)/data(:,1); diff --git a/fvmbook/chap21/radialdam/1drad/afterframe.m b/fvmbook/chap21/radialdam/1drad/afterframe.m new file mode 100644 index 00000000..8170617f --- /dev/null +++ b/fvmbook/chap21/radialdam/1drad/afterframe.m @@ -0,0 +1,17 @@ + +if (mq==(1:2)) + subplot(2,1,1) + axis([0 2.5 0 2.1]) + + subplot(2,1,2) + axis([0 2.5 -.3 .7]) + end + +if (mq==1) + axis([0 2.5 0 2.1]) + end + +if (mq==2) + axis([0 2.5 -.3 .7]) + end + diff --git a/fvmbook/chap21/radialdam/1drad/makefig.m b/fvmbook/chap21/radialdam/1drad/makefig.m new file mode 100644 index 00000000..c7e530e3 --- /dev/null +++ b/fvmbook/chap21/radialdam/1drad/makefig.m @@ -0,0 +1,16 @@ + +% first run with 12 output times up to t=1.5 + + +for Frame=0:2:12 + for mq=1:2 + clf + Haxes = axes('position',[.1 .1 .8 .3]); + set(Haxes,'fontsize',15) + plotframe1 + %axis([-1 1 -1 1]) + eval(['print raddam' num2str(Frame) 'q' num2str(mq) ' -deps']) + query + end + end + diff --git a/fvmbook/chap21/radialdam/1drad/qinit.f b/fvmbook/chap21/radialdam/1drad/qinit.f new file mode 100644 index 00000000..d97e5f28 --- /dev/null +++ b/fvmbook/chap21/radialdam/1drad/qinit.f @@ -0,0 +1,32 @@ +c +c +c ========================================================= + subroutine qinit(meqn,mbc,mx,xlower,dx,q,maux,aux) +c ========================================================= +c +c # Set initial conditions for q. +c +c + implicit double precision (a-h,o-z) + dimension q(meqn,1-mbc:mx+mbc) + common/cdisc/ x0,y0,alf,beta,r0,idisc + common /comic/ hin,hout +c + pi = 4.d0*datan(1.d0) + width = 0.2d0 +c + write(6,*) '+++ mx = ',mx + do 150 i=1,mx + xcell = xlower + (i-0.5d0)*dx + if (xcell .lt. r0) then + h = hin + else + h = hout + endif + q(1,i) = h + q(2,i) = 0.d0 + 150 continue +c + return + end + diff --git a/fvmbook/chap21/radialdam/1drad/setplot.py b/fvmbook/chap21/radialdam/1drad/setplot.py new file mode 100644 index 00000000..32e20a41 --- /dev/null +++ b/fvmbook/chap21/radialdam/1drad/setplot.py @@ -0,0 +1,75 @@ + +""" +Set up the plot figures, axes, and items to be done for each frame. + +This module is imported by the plotting routines and then the +function setplot is called to set the plot parameters. + +""" + +#-------------------------- +def setplot(plotdata): +#-------------------------- + + """ + Specify what is to be plotted at each frame. + Input: plotdata, an instance of clawpack.visclaw.data.ClawPlotData. + Output: a modified version of plotdata. + + """ + + plotdata.clearfigures() # clear any old figures,axes,items data + + + + # Figure for q[0] + plotfigure = plotdata.new_plotfigure(name='q[0]', figno=0) + + # Set up for axes in this figure: + plotaxes = plotfigure.new_plotaxes() + plotaxes.xlimits = 'auto' + plotaxes.ylimits = [0., 2.1] + plotaxes.title = 'q[0]' + + # Set up for item on these axes: + plotitem = plotaxes.new_plotitem(plot_type='1d') + plotitem.plot_var = 0 + plotitem.plotstyle = '-' + plotitem.color = 'b' + plotitem.show = True # show on plot? + + + # Figure for q[1] + plotfigure = plotdata.new_plotfigure(name='q[1]', figno=1) + + # Set up for axes in this figure: + plotaxes = plotfigure.new_plotaxes() + plotaxes.xlimits = 'auto' + plotaxes.ylimits = [-0.3, 0.7] + plotaxes.title = 'q[1]' + + # Set up for item on these axes: + plotitem = plotaxes.new_plotitem(plot_type='1d') + plotitem.plot_var = 1 + plotitem.plotstyle = '-' + plotitem.color = 'b' + plotitem.show = True # show on plot? + + + # Parameters used only when creating html and/or latex hardcopy + # e.g., via clawpack.visclaw.frametools.printframes: + + plotdata.printfigs = True # print figures + plotdata.print_format = 'png' # file format + plotdata.print_framenos = 'all' # list of frames to print + plotdata.print_fignos = 'all' # list of figures to print + plotdata.html = True # create html files of plots? + plotdata.html_homelink = '../README.html' # pointer for top of index + plotdata.latex = True # create latex file of plots? + plotdata.latex_figsperline = 2 # layout of plots + plotdata.latex_framesperline = 1 # layout of plots + plotdata.latex_makepdf = False # also run pdflatex? + + return plotdata + + diff --git a/fvmbook/chap21/radialdam/1drad/setplot1.m b/fvmbook/chap21/radialdam/1drad/setplot1.m new file mode 100644 index 00000000..cef2cddf --- /dev/null +++ b/fvmbook/chap21/radialdam/1drad/setplot1.m @@ -0,0 +1,29 @@ +% SETPLOT1 sets user defined plotting parameters +% +% User defined Matlab script for setting various Clawpack plotting +% parameters. This script is called by PLOTCLAW1. A default +% version of this script can be found in claw/matlab/setplot1.m and +% copied to users working directory and modifed to set things up +% differently. +% +% Parameters that can be set with SETPLOT1 +% +% OutputFlag - set to 'ascii' or 'hdf'. +% PlotStyle - used in plot command for line color and type. +% mq - which component of q to plot +% UserVariable - Set to 1 to specify a user defined variable. +% UserVariableFile - name of m-file mapping data to q +% MappedGrid - set to 1 if mapc2p.m exists for nonuniform +% grid +% MaxFrames - max number of frames +% +% All parameters can be modified by typing 'k' at the PLOTCLAW1 prompt. +% +% See PLOTCLAW1. + +mq = 1:2; % which component(s) of q to plot +UserVariable = 0; % set to 1 to specify a user-defined variable +UserVariableFile = ' '; % name of m-file mapping data to q +MappedGrid = 0; % set to 1 if mapc2p.m exists for nonuniform grid +PlotStyle = setplotstyle('b-'); % used in plot command for line color and type +MaxFrames = 1000; % max number of frames to loop over diff --git a/fvmbook/chap21/radialdam/1drad/setprob.f b/fvmbook/chap21/radialdam/1drad/setprob.f new file mode 100644 index 00000000..eb565426 --- /dev/null +++ b/fvmbook/chap21/radialdam/1drad/setprob.f @@ -0,0 +1,34 @@ + subroutine setprob + implicit double precision (a-h,o-z) + character*12 fname + common /cparam/ grav + common /comsrc/ ndim + common/cdisc/ x0,y0,alf,beta,r0,idisc + common /comic/ hin,hout +c +c # Set the material parameters for the acoustic equations +c # Passed to the Riemann solver rp1.f in a common block +c +c + iunit = 7 + fname = 'setprob.data' +c # open the unit with new routine from Clawpack 4.4 to skip over +c # comment lines starting with #: + call opendatafile(iunit, fname) + +c # ndim = space dimensions (2 = cylindrical symmetry, 3 = spherical) + read(7,*) ndim + +c # gravitational constant: + read(7,*) grav + +c # data for radial dam-break problem: + read(7,*) x0 + read(7,*) y0 + read(7,*) r0 + read(7,*) hin + read(7,*) hout +c + return + end + diff --git a/fvmbook/chap21/radialdam/1drad/setrun.py b/fvmbook/chap21/radialdam/1drad/setrun.py new file mode 100644 index 00000000..0c11d12f --- /dev/null +++ b/fvmbook/chap21/radialdam/1drad/setrun.py @@ -0,0 +1,229 @@ +""" +Module to set up run time parameters for Clawpack -- classic code. + +The values set in the function setrun are then written out to data files +that will be read in by the Fortran code. + +""" + +import os +import numpy as np + +#------------------------------ +def setrun(claw_pkg='classic'): +#------------------------------ + + """ + Define the parameters used for running Clawpack. + + INPUT: + claw_pkg expected to be "classic" for this setrun. + + OUTPUT: + rundata - object of class ClawRunData + + """ + + from clawpack.clawutil import data + + + assert claw_pkg.lower() == 'classic', "Expected claw_pkg = 'classic'" + + num_dim = 1 + rundata = data.ClawRunData(claw_pkg, num_dim) + + #------------------------------------------------------------------ + # Problem-specific parameters to be written to setprob.data: + #------------------------------------------------------------------ + # Sample setup to write one line to setprob.data ... + probdata = rundata.new_UserData(name='probdata',fname='setprob.data') + probdata.add_param('ndim', 2, 'radial symmetry') + probdata.add_param('g', 1.0, 'gravitational constant') + probdata.add_param('x0', 0.0, 'x0') + probdata.add_param('y0', 0.0, 'y0') + probdata.add_param('r0', 0.5, 'r0') + probdata.add_param('hin', 2.0, 'depth for r < r0') + probdata.add_param('hout', 1.0, 'depth for r > r0') + + #------------------------------------------------------------------ + # Standard Clawpack parameters to be written to claw.data: + #------------------------------------------------------------------ + + clawdata = rundata.clawdata # initialized when rundata instantiated + + + # --------------- + # Spatial domain: + # --------------- + + # Number of space dimensions: + clawdata.num_dim = num_dim + + # Lower and upper edge of computational domain: + clawdata.lower[0] = 0.000000e+00 # xlower + clawdata.upper[0] = 2.500000e+00 # xupper + + # Number of grid cells: + clawdata.num_cells[0] = 2000 # mx + + + # --------------- + # Size of system: + # --------------- + + # Number of equations in the system: + clawdata.num_eqn = 2 + + # Number of auxiliary variables in the aux array (initialized in setaux) + clawdata.num_aux = 0 + + # Index of aux array corresponding to capacity function, if there is one: + clawdata.capa_index = 0 + + + # ------------- + # Initial time: + # ------------- + + clawdata.t0 = 0.000000 + + + # Restart from checkpoint file of a previous run? + # Note: If restarting, you must also change the Makefile to set: + # RESTART = True + # If restarting, t0 above should be from original run, and the + # restart_file 'fort.qNNNN' specified below should be in + # the OUTDIR indicated in Makefile. + + clawdata.restart = False # True to restart from prior results + clawdata.restart_file = 'fort.q0006' # File to use for restart data + + + # ------------- + # Output times: + #-------------- + + # Specify at what times the results should be written to fort.q files. + # Note that the time integration stops after the final output time. + + clawdata.output_style = 1 + + if clawdata.output_style==1: + # Output ntimes frames at equally spaced times up to tfinal: + # Can specify num_output_times = 0 for no output + clawdata.num_output_times = 6 + clawdata.tfinal = 1.500000 + clawdata.output_t0 = True # output at initial (or restart) time? + + elif clawdata.output_style == 2: + # Specify a list or numpy array of output times: + # Include t0 if you want output at the initial time. + clawdata.output_times = [0., 0.1] + + elif clawdata.output_style == 3: + # Output every step_interval timesteps over total_steps timesteps: + clawdata.output_step_interval = 2 + clawdata.total_steps = 4 + clawdata.output_t0 = True # output at initial (or restart) time? + + + clawdata.output_format = 'ascii' # 'ascii', 'binary', 'netcdf' + + clawdata.output_q_components = 'all' # could be list such as [True,True] + clawdata.output_aux_components = 'none' # could be list + clawdata.output_aux_onlyonce = True # output aux arrays only at t0 + + + # --------------------------------------------------- + # Verbosity of messages to screen during integration: + # --------------------------------------------------- + + # The current t, dt, and cfl will be printed every time step + # at AMR levels <= verbosity. Set verbosity = 0 for no printing. + # (E.g. verbosity == 2 means print only on levels 1 and 2.) + clawdata.verbosity = 0 + + + + # -------------- + # Time stepping: + # -------------- + + # if dt_variable==True: variable time steps used based on cfl_desired, + # if dt_variable==False: fixed time steps dt = dt_initial always used. + clawdata.dt_variable = True + + # Initial time step for variable dt. + # (If dt_variable==0 then dt=dt_initial for all steps) + clawdata.dt_initial = 5.000000e-01 + + # Max time step to be allowed if variable dt used: + clawdata.dt_max = 1.000000e+99 + + # Desired Courant number if variable dt used + clawdata.cfl_desired = 0.900000 + # max Courant number to allow without retaking step with a smaller dt: + clawdata.cfl_max = 1.000000 + + # Maximum number of time steps to allow between output times: + clawdata.steps_max = 5000 + + + # ------------------ + # Method to be used: + # ------------------ + + # Order of accuracy: 1 => Godunov, 2 => Lax-Wendroff plus limiters + clawdata.order = 2 + + + # Number of waves in the Riemann solution: + clawdata.num_waves = 2 + + # List of limiters to use for each wave family: + # Required: len(limiter) == num_waves + # Some options: + # 0 or 'none' ==> no limiter (Lax-Wendroff) + # 1 or 'minmod' ==> minmod + # 2 or 'superbee' ==> superbee + # 3 or 'vanleer' ==> van Leer + # 4 or 'mc' ==> MC limiter + clawdata.limiter = ['mc', 'mc'] + + clawdata.use_fwaves = False # True ==> use f-wave version of algorithms + + # Source terms splitting: + # src_split == 0 or 'none' ==> no source term (src routine never called) + # src_split == 1 or 'godunov' ==> Godunov (1st order) splitting used, + # src_split == 2 or 'strang' ==> Strang (2nd order) splitting used, not recommended. + clawdata.source_split = 1 + + + # -------------------- + # Boundary conditions: + # -------------------- + + # Number of ghost cells (usually 2) + clawdata.num_ghost = 2 + + # Choice of BCs at xlower and xupper: + # 0 or 'user' => user specified (must modify bcNamr.f to use this option) + # 1 or 'extrap' => extrapolation (non-reflecting outflow) + # 2 or 'periodic' => periodic (must specify this at both boundaries) + # 3 or 'wall' => solid wall for systems where q(2) is normal velocity + + clawdata.bc_lower[0] = 'wall' # at xlower + clawdata.bc_upper[0] = 'extrap' # at xupper + + return rundata + + # end of function setrun + # ---------------------- + + +if __name__ == '__main__': + # Set up run-time parameters and write all data files. + import sys + rundata = setrun(*sys.argv[1:]) + rundata.write() + diff --git a/fvmbook/chap21/radialdam/1drad/src1.f b/fvmbook/chap21/radialdam/1drad/src1.f new file mode 100644 index 00000000..dee4b828 --- /dev/null +++ b/fvmbook/chap21/radialdam/1drad/src1.f @@ -0,0 +1,36 @@ + + +c +c +c ========================================================= + subroutine src1(meqn,mbc,mx,xlower,dx,q,maux,aux,t,dt) +c ========================================================= + implicit real*8(a-h,o-z) + dimension q(meqn,1-mbc:mx+mbc) +c + common /comsrc/ ndim +c +c # source terms for radial symmetry in shallow water equations +c +c # ndim should be set in setprob.f +c # ndim = 2 for cylindrical symmetry +c # ndim = 3 for spherical symmetry +c +c # 2-stage Runge-Kutta method +c +c do i=-1,3 +c write(6,*) 'i, q(1,i), q(2,i): ',i, q(1,i), q(2,i) +c enddo + + do 10 i=1,mx+mbc + xcell = xlower + (i-0.5d0)*dx + qstar1 = q(1,i) - 0.5d0*dt*(ndim-1)/xcell * q(2,i) + qstar2 = q(2,i) - 0.5d0*dt*(ndim-1)/xcell * q(2,i)**2 / q(1,i) +c + q(1,i) = q(1,i) - dt*(ndim-1)/xcell * qstar2 + q(2,i) = q(2,i) - dt*(ndim-1)/xcell * qstar2**2 / qstar1 + 10 continue +c + return + end + diff --git a/fvmbook/chap21/radialdam/Makefile b/fvmbook/chap21/radialdam/Makefile new file mode 100644 index 00000000..354bbb96 --- /dev/null +++ b/fvmbook/chap21/radialdam/Makefile @@ -0,0 +1,65 @@ + +# Makefile for Clawpack code in this directory. +# This version only sets the local files and frequently changed +# options, and then includes the standard makefile pointed to by CLAWMAKE. +CLAWMAKE = $(CLAW)/clawutil/src/Makefile.common + +# See the above file for details and a list of make options, or type +# make .help +# at the unix prompt. + + +# Adjust these variables if desired: +# ---------------------------------- + +CLAW_PKG = classic # Clawpack package to use +EXE = xclaw # Executable to create +SETRUN_FILE = setrun.py # File containing function to make data +OUTDIR = _output # Directory for output +SETPLOT_FILE = setplot.py # File containing function to set plots +PLOTDIR = _plots # Directory for plots + +OVERWRITE ?= True # False ==> make a copy of OUTDIR first +RESTART ?= False # Should = clawdata.restart in setrun + +# Environment variable FC should be set to fortran compiler, e.g. gfortran + +# Compiler flags can be specified here or set as an environment variable +FFLAGS ?= + +# --------------------------------- +# List of sources for this program: +# --------------------------------- + +LIB = $(CLAW)/classic/src/2d + +MODULES = \ + +SOURCES = \ + qinit.f \ + setprob.f \ + fdisc.f \ + $(CLAW)/riemann/src/rpn2_shallow_roe_with_efix.f90 \ + $(CLAW)/riemann/src/rpt2_shallow_roe_with_efix.f90 \ + $(CLAW)/classic/src/2d/cellave.f \ + $(CLAW)/classic/src/2d/setaux.f90 \ + $(CLAW)/classic/src/2d/driver.f90 \ + $(CLAW)/classic/src/2d/claw2ez.f \ + $(CLAW)/classic/src/2d/claw2.f \ + $(CLAW)/classic/src/2d/bc2.f \ + $(CLAW)/classic/src/2d/b4step2.f90 \ + $(CLAW)/classic/src/2d/step2.f90 \ + $(CLAW)/classic/src/2d/step2ds.f90 \ + $(CLAW)/classic/src/2d/dimsp2.f \ + $(CLAW)/classic/src/2d/flux2.f90 \ + $(CLAW)/classic/src/2d/copyq2.f \ + $(CLAW)/classic/src/2d/inlinelimiter.f90 \ + $(CLAW)/classic/src/2d/src2.f90 \ + $(CLAW)/classic/src/2d/out2.f \ + $(CLAW)/classic/src/2d/restart2.f \ + $(CLAW)/classic/src/2d/opendatafile.f + +#------------------------------------------------------------------- +# Include Makefile containing standard definitions and make options: +include $(CLAWMAKE) + diff --git a/fvmbook/chap21/radialdam/README.rst b/fvmbook/chap21/radialdam/README.rst new file mode 100644 index 00000000..618965f2 --- /dev/null +++ b/fvmbook/chap21/radialdam/README.rst @@ -0,0 +1,19 @@ + +.. _fvmbook_chap21/radialdam: + +Radial dam-break problem for 2D shallow water equations +-------------------------------------------------------- + + +Example [book/chap21/radialdam] to accompany the book +`Finite Volume Methods for Hyperbolic Problems +`_ +by R. J. LeVeque. + +Converted to Clawpack 5.0 form in 2016. + + +Subdirectory 1drad contains code to solve 1d radially symmetric equations +on a fine grid. First run that code. + + diff --git a/fvmbook/chap21/radialdam/afterframe.m b/fvmbook/chap21/radialdam/afterframe.m new file mode 100644 index 00000000..7a74607b --- /dev/null +++ b/fvmbook/chap21/radialdam/afterframe.m @@ -0,0 +1,18 @@ +if PlotType ~= 4 + axis([-2.5 2.5 -2.5 2.5]) + axis square + end + +if PlotType==4 + axis([0 2.5 0 2.1]) + dir = './1drad/'; + dim = 1; + [amrdata1d,t1d] = readamrdata(dim,Frame,dir); + if isempty(t1d) + disp('Run xclaw in 1drad to generate 1d reference solution') + else + hold on; + [q1d,x1d] = plotframe1ez(amrdata1d,mq,'r-'); + hold off; + end + end diff --git a/fvmbook/chap21/radialdam/fdisc.f b/fvmbook/chap21/radialdam/fdisc.f new file mode 100644 index 00000000..b5a84da3 --- /dev/null +++ b/fvmbook/chap21/radialdam/fdisc.f @@ -0,0 +1,32 @@ +c +c +c +c ================================================= + function fdisc(x,y) +c ================================================= + implicit double precision (a-h,o-z) + common/cdisc/ x0,y0,alf,beta,r0,idisc +c +c # for computing cell averages for initial data that has a +c # discontinuity along some curve. fdisc should be negative to the +c # left of the curve and positive to the right +c # idisc specifies the nature of the discontinuity for two +c # particular cases (a straight line and circle) but this routine +c # can be modified for any other curve. +c + go to (10,20) idisc +c + 10 continue +c # straight line through (x0,y0) with normal (alf,beta) pointing +c # into right state +c + fdisc = (x-x0)*alf + (y-y0)*beta + return +c + 20 continue +c # circle of radius r0: + fdisc = (x-x0)**2 + (y-y0)**2 - r0**2 +c + return + end + diff --git a/fvmbook/chap21/radialdam/qinit.f b/fvmbook/chap21/radialdam/qinit.f new file mode 100644 index 00000000..fc35aa17 --- /dev/null +++ b/fvmbook/chap21/radialdam/qinit.f @@ -0,0 +1,30 @@ + +c +c +c +c ===================================================== + subroutine qinit(meqn,mbc,mx,my,xlower,ylower, + & dx,dy,q,maux,aux) +c ===================================================== +c +c # Set initial conditions for q. +c # Shallow water with radial dam break problem, h = hin inside +c # circle specified in fdisc.f +c + implicit double precision (a-h,o-z) + dimension q(meqn,1-mbc:mx+mbc,1-mbc:my+mbc) + common /comic/ hin,hout +c + + do 20 i=1,mx + xlow = xlower + (i-1.d0)*dx + do 20 j=1,my + ylow = ylower + (j-1.d0)*dy + call cellave(xlow,ylow,dx,dy,win) + q(1,i,j) = hin*win + hout*(1.d0-win) + q(2,i,j) = 0.d0 + q(3,i,j) = 0.d0 + 20 continue + return + end + diff --git a/fvmbook/chap21/radialdam/setplot.py b/fvmbook/chap21/radialdam/setplot.py new file mode 100644 index 00000000..5c205ff7 --- /dev/null +++ b/fvmbook/chap21/radialdam/setplot.py @@ -0,0 +1,129 @@ + +""" +Set up the plot figures, axes, and items to be done for each frame. + +This module is imported by the plotting routines and then the +function setplot is called to set the plot parameters. + +""" + +#-------------------------- +def setplot(plotdata): +#-------------------------- + + """ + Specify what is to be plotted at each frame. + Input: plotdata, an instance of clawpack.visclaw.data.ClawPlotData. + Output: a modified version of plotdata. + + """ + + + from clawpack.visclaw import colormaps + + plotdata.clearfigures() # clear any old figures,axes,items data + + + # Figure for q[0] + plotfigure = plotdata.new_plotfigure(name='q[0]', figno=0) + + # Set up for axes in this figure: + plotaxes = plotfigure.new_plotaxes() + plotaxes.xlimits = [-2.5, 2.5] + plotaxes.ylimits = [-2.5, 2.5] + plotaxes.title = 'q[0]' + plotaxes.scaled = True + + # Set up for item on these axes: + plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor') + plotitem.plot_var = 0 + plotitem.pcolor_cmap = colormaps.red_yellow_blue + plotitem.pcolor_cmin = 0.5 + plotitem.pcolor_cmax = 1.5 + plotitem.add_colorbar = True + plotitem.show = True # show on plot? + + + # Scatter plot of q[0] + plotfigure = plotdata.new_plotfigure(name='Scatter', figno=10) + + # Set up for axes in this figure: + plotaxes = plotfigure.new_plotaxes() + plotaxes.xlimits = [0., 2.5] + plotaxes.ylimits = [0., 2.1] + plotaxes.title = 'Scatter plot of h' + + # Set up for item on these axes: + plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data') + plotitem.plot_var = 0 + def q_vs_radius(current_data): + from numpy import sqrt + x = current_data.x + y = current_data.y + r = sqrt(x**2 + y**2) + q = current_data.q[0,:,:] + return r,q + plotitem.map_2d_to_1d = q_vs_radius + plotitem.plotstyle = 'o' + + # Plot the 1drad solution on scatter plot: + plotitem = plotaxes.new_plotitem(plot_type='1d_plot') + plotitem.plot_var = 0 + import os + plotitem.outdir = os.path.abspath('1drad/_output') + plotitem.plotstyle = 'r-' + + + # Figure for q[1] + plotfigure = plotdata.new_plotfigure(name='q[1]', figno=1) + + # Set up for axes in this figure: + plotaxes = plotfigure.new_plotaxes() + plotaxes.xlimits = [-2.5, 2.5] + plotaxes.ylimits = [-2.5, 2.5] + plotaxes.title = 'q[1]' + plotaxes.scaled = True + + # Set up for item on these axes: + plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor') + plotitem.plot_var = 1 + plotitem.pcolor_cmap = colormaps.yellow_red_blue + plotitem.add_colorbar = True + plotitem.show = False # show on plot? + + + # Figure for q[2] + plotfigure = plotdata.new_plotfigure(name='q[2]', figno=2) + + # Set up for axes in this figure: + plotaxes = plotfigure.new_plotaxes() + plotaxes.xlimits = [-2.5, 2.5] + plotaxes.ylimits = [-2.5, 2.5] + plotaxes.title = 'q[2]' + plotaxes.scaled = True + + # Set up for item on these axes: + plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor') + plotitem.plot_var = 2 + plotitem.pcolor_cmap = colormaps.yellow_red_blue + plotitem.add_colorbar = True + plotitem.show = False # show on plot? + + + # Parameters used only when creating html and/or latex hardcopy + # e.g., via clawpack.visclaw.frametools.printframes: + + plotdata.printfigs = True # print figures + plotdata.print_format = 'png' # file format + plotdata.print_framenos = 'all' # list of frames to print + plotdata.print_fignos = 'all' # list of figures to print + plotdata.html = True # create html files of plots? + plotdata.html_homelink = '../README.html' # pointer for top of index + plotdata.latex = True # create latex file of plots? + plotdata.latex_figsperline = 2 # layout of plots + plotdata.latex_framesperline = 1 # layout of plots + plotdata.latex_makepdf = False # also run pdflatex? + + return plotdata + + diff --git a/fvmbook/chap21/radialdam/setplot2.m b/fvmbook/chap21/radialdam/setplot2.m new file mode 100644 index 00000000..95cd5763 --- /dev/null +++ b/fvmbook/chap21/radialdam/setplot2.m @@ -0,0 +1,77 @@ + +% SETPLOT2 sets user defined plotting parameters +% +% User defined Matlab script for setting various Clawpack plotting +% parameters. This script is called by PLOTCLAW2. A default +% version of this script can be found in claw/matlab/setplot2.m and +% copied to users working directory and modifed to set things up +% differently. +% +% Parameters that can be set with SETPLOT2 +% +% OutputFlag - set to 'ascii' (default) to read ascii output +% or to 'hdf' to read hdf output files. +% PlotType - type of plot to produce: +% - 1 = pcolor on slices (with optional contours) +% - 2 = contour lines in 2d on white slices +% - 3 = Schlieren plot on slices +% - 4 = scatter plot of q vs. r +% +% mq - which component of q to plot +% UserVariable - Set to 1 to specify a user defined variable. +% UserVariableFile - name of m-file mapping data to q +% MappedGrid - set to 1 if mapc2p.m exists for nonuniform +% grid +% Manifold - set to 1 if mapc2m.m exists for manifold plot. +% MaxFrames - max number of frames +% MaxLevels - max number of AMR levels +% PlotData - Data on refinement level k is plotted only if +% PlotData(k) == 1 +% PlotGrid - PLot grid lines on level k is PlotGrid(k) /= 0 +% PlotGridEdges - Plot 2d patch borders if PlotGridEdges(k) /= 0 +% ContourValues - Set to desired contour values, or [] for no ... +% lines. +% x0,y0 - center for scatter plots. +% ScatterStyle - symbols for scatter plot. +% LineStyle - same as ScatterStyle. +% UserMap1d - set to 1 if 'map1d' file exists. +% +% All parameters can be modified by typing 'k' at the PLOTCLAW2 prompt. +% +% See also PLOTCLAW2, SetPlotGrid, setPlotGridEdges. + +% OutputFlag = 'ascii' % default value. + +PlotType = 2; % type of plot to produce: + % 1 = pseudo-color (pcolor) + % 2 = contour + % 3 = Schlieren + % 4 = scatter plot of q vs. r + +mq = 1; % which component of q to plot +UserVariable = 0; % set to 1 to specify a user-defined variable +UserVariableFile = ' '; % name of m-file mapping data to q +MappedGrid = 0; % set to 1 if mapc2p.m exists for nonuniform grid +Manifold = 0; +MaxFrames = 1000; % max number of frames to loop over +MaxLevels = 6; +PlotData = [1 1 1 1 1 1]; % Data on refinement level k is plotted only if + % k'th component is nonzero +PlotGrid = [0 0 0 0 0 0]; % Plot grid lines on each level? + +PlotGridEdges = [1 1 1 1 1 1]; % Plot edges of patches of each grid at + % this level? + +%--------------------------------- + +ContourValues = 0.61 : 0.02 : 1.31; + % Set to either a scalar, for automatic contours or + % a vector of contour levels. + +%--------------------------------- + +% for scatter plot (PlotType==4): +% plot q(i,j) vs. r(i,j) = (x(i,j)-x0)^2 + (y(i,j)-y0)^2 + x0 = 0; + y0 = 0; + ScatterStyle = setplotstyle('bx','rx','gx'); diff --git a/fvmbook/chap21/radialdam/setprob.f b/fvmbook/chap21/radialdam/setprob.f new file mode 100644 index 00000000..741adad8 --- /dev/null +++ b/fvmbook/chap21/radialdam/setprob.f @@ -0,0 +1,31 @@ + subroutine setprob + implicit double precision (a-h,o-z) + character*12 fname + common /cparam/ grav + + common/cdisc/ x0,y0,alf,beta,r0,idisc + common /comic/ hin,hout +c +c +c + iunit = 7 + fname = 'setprob.data' +c # open the unit with new routine from Clawpack 4.4 to skip over +c # comment lines starting with #: + call opendatafile(iunit, fname) +c +c # gravitational constant: + read(7,*) grav + +c # data for radial dam-break problem: + idisc = 2 + read(7,*) x0 + read(7,*) y0 + read(7,*) r0 + read(7,*) hin + read(7,*) hout +c + + return + end + diff --git a/fvmbook/chap21/radialdam/setrun.py b/fvmbook/chap21/radialdam/setrun.py new file mode 100644 index 00000000..f2aba266 --- /dev/null +++ b/fvmbook/chap21/radialdam/setrun.py @@ -0,0 +1,243 @@ +""" +Module to set up run time parameters for Clawpack -- classic code. + +The values set in the function setrun are then written out to data files +that will be read in by the Fortran code. + +""" + +import os +import numpy as np + +#------------------------------ +def setrun(claw_pkg='classic'): +#------------------------------ + + """ + Define the parameters used for running Clawpack. + + INPUT: + claw_pkg expected to be "classic" for this setrun. + + OUTPUT: + rundata - object of class ClawRunData + + """ + + from clawpack.clawutil import data + + + assert claw_pkg.lower() == 'classic', "Expected claw_pkg = 'classic'" + + num_dim = 2 + rundata = data.ClawRunData(claw_pkg, num_dim) + + #------------------------------------------------------------------ + # Problem-specific parameters to be written to setprob.data: + #------------------------------------------------------------------ + # Sample setup to write one line to setprob.data ... + probdata = rundata.new_UserData(name='probdata',fname='setprob.data') + probdata.add_param('g', 1.0, 'gravitational constant') + probdata.add_param('x0', 0.0, 'x0') + probdata.add_param('y0', 0.0, 'y0') + probdata.add_param('r0', 0.5, 'r0') + probdata.add_param('hin', 2.0, 'depth for r < r0') + probdata.add_param('hout', 1.0, 'depth for r > r0') + + #------------------------------------------------------------------ + # Standard Clawpack parameters to be written to claw.data: + #------------------------------------------------------------------ + + clawdata = rundata.clawdata # initialized when rundata instantiated + + + # --------------- + # Spatial domain: + # --------------- + + # Number of space dimensions: + clawdata.num_dim = num_dim + + # Lower and upper edge of computational domain: + clawdata.lower[0] = -2.500000e+00 # xlower + clawdata.upper[0] = 2.500000e+00 # xupper + clawdata.lower[1] = -2.500000e+00 # ylower + clawdata.upper[1] = 2.500000e+00 # yupper + + # Number of grid cells: + clawdata.num_cells[0] = 125 # mx + clawdata.num_cells[1] = 125 # my + + + # --------------- + # Size of system: + # --------------- + + # Number of equations in the system: + clawdata.num_eqn = 3 + + # Number of auxiliary variables in the aux array (initialized in setaux) + clawdata.num_aux = 0 + + # Index of aux array corresponding to capacity function, if there is one: + clawdata.capa_index = 0 + + + # ------------- + # Initial time: + # ------------- + + clawdata.t0 = 0.000000 + + + # Restart from checkpoint file of a previous run? + # Note: If restarting, you must also change the Makefile to set: + # RESTART = True + # If restarting, t0 above should be from original run, and the + # restart_file 'fort.qNNNN' specified below should be in + # the OUTDIR indicated in Makefile. + + clawdata.restart = False # True to restart from prior results + clawdata.restart_file = 'fort.q0006' # File to use for restart data + + + # ------------- + # Output times: + #-------------- + + # Specify at what times the results should be written to fort.q files. + # Note that the time integration stops after the final output time. + + clawdata.output_style = 1 + + if clawdata.output_style==1: + # Output ntimes frames at equally spaced times up to tfinal: + # Can specify num_output_times = 0 for no output + clawdata.num_output_times = 6 + clawdata.tfinal = 1.500000 + clawdata.output_t0 = True # output at initial (or restart) time? + + elif clawdata.output_style == 2: + # Specify a list or numpy array of output times: + # Include t0 if you want output at the initial time. + clawdata.output_times = [0., 0.1] + + elif clawdata.output_style == 3: + # Output every step_interval timesteps over total_steps timesteps: + clawdata.output_step_interval = 2 + clawdata.total_steps = 4 + clawdata.output_t0 = True # output at initial (or restart) time? + + + clawdata.output_format = 'ascii' # 'ascii', 'binary', 'netcdf' + + clawdata.output_q_components = 'all' # could be list such as [True,True] + clawdata.output_aux_components = 'none' # could be list + clawdata.output_aux_onlyonce = True # output aux arrays only at t0 + + + # --------------------------------------------------- + # Verbosity of messages to screen during integration: + # --------------------------------------------------- + + # The current t, dt, and cfl will be printed every time step + # at AMR levels <= verbosity. Set verbosity = 0 for no printing. + # (E.g. verbosity == 2 means print only on levels 1 and 2.) + clawdata.verbosity = 0 + + + + # -------------- + # Time stepping: + # -------------- + + # if dt_variable==True: variable time steps used based on cfl_desired, + # if dt_variable==False: fixed time steps dt = dt_initial always used. + clawdata.dt_variable = True + + # Initial time step for variable dt. + # (If dt_variable==0 then dt=dt_initial for all steps) + clawdata.dt_initial = 1.000000e-01 + + # Max time step to be allowed if variable dt used: + clawdata.dt_max = 1.000000e+99 + + # Desired Courant number if variable dt used + clawdata.cfl_desired = 0.800000 + # max Courant number to allow without retaking step with a smaller dt: + clawdata.cfl_max = 1.000000 + + # Maximum number of time steps to allow between output times: + clawdata.steps_max = 500 + + + # ------------------ + # Method to be used: + # ------------------ + + # Order of accuracy: 1 => Godunov, 2 => Lax-Wendroff plus limiters + clawdata.order = 2 + + # Use dimensional splitting? (not yet available for AMR) + clawdata.dimensional_split = 'unsplit' + + # For unsplit method, transverse_waves can be + # 0 or 'none' ==> donor cell (only normal solver used) + # 1 or 'increment' ==> corner transport of waves + # 2 or 'all' ==> corner transport of 2nd order corrections too + clawdata.transverse_waves = 2 + + + # Number of waves in the Riemann solution: + clawdata.num_waves = 3 + + # List of limiters to use for each wave family: + # Required: len(limiter) == num_waves + # Some options: + # 0 or 'none' ==> no limiter (Lax-Wendroff) + # 1 or 'minmod' ==> minmod + # 2 or 'superbee' ==> superbee + # 3 or 'vanleer' ==> van Leer + # 4 or 'mc' ==> MC limiter + clawdata.limiter = ['mc', 'mc', 'mc'] + + clawdata.use_fwaves = False # True ==> use f-wave version of algorithms + + # Source terms splitting: + # src_split == 0 or 'none' ==> no source term (src routine never called) + # src_split == 1 or 'godunov' ==> Godunov (1st order) splitting used, + # src_split == 2 or 'strang' ==> Strang (2nd order) splitting used, not recommended. + clawdata.source_split = 0 + + + # -------------------- + # Boundary conditions: + # -------------------- + + # Number of ghost cells (usually 2) + clawdata.num_ghost = 2 + + # Choice of BCs at xlower and xupper: + # 0 or 'user' => user specified (must modify bcNamr.f to use this option) + # 1 or 'extrap' => extrapolation (non-reflecting outflow) + # 2 or 'periodic' => periodic (must specify this at both boundaries) + # 3 or 'wall' => solid wall for systems where q(2) is normal velocity + + clawdata.bc_lower[0] = 'wall' # at xlower + clawdata.bc_upper[0] = 'extrap' # at xupper + + clawdata.bc_lower[1] = 'wall' # at ylower + clawdata.bc_upper[1] = 'extrap' # at yupper + + return rundata + + # end of function setrun + # ---------------------- + + +if __name__ == '__main__': + # Set up run-time parameters and write all data files. + import sys + rundata = setrun(*sys.argv[1:]) + rundata.write() +