20
20
# is completely correct, or that it will work for your purposes.
21
21
# Use the software at your own risk.
22
22
# ***********************************************************************
23
-
23
+ __precompile__ ()
24
24
using OffsetArrays
25
+ using DocOpt
25
26
26
27
include (" consts.jl" )
27
28
@@ -32,16 +33,13 @@ include("linearad.jl")
32
33
include (" consdiff.jl" )
33
34
include (" upwind.jl" )
34
35
35
- function main ()
36
- # const ncells = 100
37
- const ncells = 10000
36
+ function do_computation (ncells, nsteps, verbose, print_solution)
38
37
39
38
u = OffsetArray (Float64, - 2 : ncells+ 1 )
40
39
x = OffsetArray (Float64, 0 : ncells)
41
40
flux = OffsetArray (Float64, 0 : ncells)
42
41
dfdu = OffsetArray (Float64, - 2 : ncells+ 1 )
43
42
44
- const nsteps = 10000
45
43
const tmax = 0.8
46
44
const cfl = 0.9
47
45
@@ -57,7 +55,10 @@ function main()
57
55
58
56
initsl (ncells,fc,lc,fm,lm,ifirst,ilast, u,x)
59
57
60
- # println("x : $x u : $u")
58
+ if verbose
59
+ println (" x : $x u : $u " )
60
+ end
61
+
61
62
bcmesh (fm,lm,ncells, x)
62
63
bccells (fc,lc,ncells, u)
63
64
fluxderv (fc,lc,fc,lc, u, dfdu)
@@ -76,17 +77,53 @@ function main()
76
77
end
77
78
78
79
# write final results (plot later)
79
- @unsafe for ic= 0 : ncells- 1
80
- # for ic=0:ncells-1
81
- xc = (x[ic]+ x[ic+ 1 ])* 0.5
82
- uc = u[ic]
83
- # @printf("%e %e\n",xc,uc)
80
+ if print_solution
81
+ @unsafe for ic= 0 : ncells- 1
82
+ xc = (x[ic]+ x[ic+ 1 ])* 0.5
83
+ uc = u[ic]
84
+ @printf (" %e %e\n " ,xc,uc)
85
+ end
86
+ end
87
+
88
+ end
89
+
90
+ function main ()
91
+ const script_name = basename (Base. source_path ())
92
+ const doc = """ $script_name
93
+
94
+ Usage:
95
+ $script_name -h | --help
96
+ $script_name [-v | --verbose] [-p | --print] [--cells=<cells>] [--steps=<steps>] [--runs=<runs>]
97
+
98
+ Options:
99
+ -h --help Show this screen.
100
+ -v --verbose Adds verbosity.
101
+ -p --print Print solution.
102
+ --cells=<cells> Specify a number of cells [default: 100].
103
+ --steps=<steps> Specify a number of steps [default: 10000].
104
+ --runs=<runs> Specify a number of runs [default: 2].
105
+ """
106
+
107
+ arguments = docopt (doc)
108
+
109
+ verbose = arguments[" --verbose" ]
110
+ print_sol = arguments[" --print" ]
111
+ ncells = parse (Int, arguments[" --cells" ])
112
+ nsteps = parse (Int, arguments[" --steps" ])
113
+ nruns = parse (Int, arguments[" --runs" ])
114
+
115
+ if verbose
116
+ println (" ncells: $ncells " )
117
+ println (" nsteps: $nsteps " )
84
118
end
85
119
120
+ for r = 1 : nruns
121
+ @time do_computation (ncells, nsteps, verbose, print_sol)
122
+ end
86
123
87
124
end # main
88
125
89
- @time main ()
90
- @time main ()
126
+ main ()
127
+
91
128
92
129
0 commit comments