1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
using Printf
using FFTW
include("navier_stokes.jl")
include("driving.jl")
include("print.jl")
function main()
## defaults
delta=0.0001220703125
nsteps=10000000
nu=0.00048828125
print_freq=1000
K1=16
K2=K1
N1=4*K1+1
N2=4*K2+1
# read cli arguments
(params,driving,command)=read_args(ARGS)
# whether N was set in parameters
setN1=false
setN2=false
# read params
if params!=""
for param in split(params,";")
terms=split(param,"=")
if length(terms)!=2
print(stderr,"error: could not read parameter '",param,"'.\n")
exit(-1)
end
lhs=string(terms[1])
rhs=string(terms[2])
if lhs=="K1"
K1=parse(Int64,rhs)
elseif lhs=="K2"
K2=parse(Int64,rhs)
elseif lhs=="K"
K1=parse(Int64,rhs)
K2=K1
elseif lhs=="N1"
N1=parse(Int64,rhs)
setN1=true
elseif lhs=="N2"
N2=parse(Int64,rhs)
setN2=true
elseif lhs=="N"
N1=parse(Int64,rhs)
N2=N1
setN1=true
setN2=true
elseif lhs=="nsteps"
nsteps=parse(Int64,rhs)
elseif lhs=="nu"
nu=parse(Float64,rhs)
elseif lhs=="delta"
delta=parse(Float64,rhs)
elseif lhs=="print_freq"
print_freq=parse(Int64,rhs)
else
print(stderr,"unrecognized parameter '",lhs,"'.\n")
exit(-1)
end
end
end
## read driving
if driving=="test"
g=(kx,ky)->g_test(kx,ky)
end
## set parameters
if ! setN1
N1=4*K1+1
end
if ! setN2
N2=4*K2+1
end
## run command
if command=="uk"
navier_stokes_uk(nsteps,nu,g,N1,N2,K1,K2,delta,print_freq)
elseif command=="alpha"
navier_stokes_alpha(nsteps,nu,g,N1,N2,K1,K2,delta,print_freq)
else
print(stderr,"unrecognized command '",command,"'.\n")
exit(-1)
end
end
# read cli arguments
function read_args(ARGS)
# flag
flag=""
# output strings
command=""
params=""
# default driving force
driving="test"
# loop over arguments
for arg in ARGS
# argument that starts with a dash
if arg[1]=='-'
# go through characters after dash
for char in arg[2:length(arg)]
# set params
if char=='p'
# raise flag
flag="params"
elseif char=='g'
# raise flag
flag="driving"
else
print_usage()
exit(-1)
end
end
# arguments that do not start with a dash
else
if flag=="params"
params=arg
elseif flag=="driving"
driving=arg
else
command=arg
end
# reset flag
flag=""
end
end
if command==""
print_usage()
exit(-1)
end
return (params,driving,command)
end
# usage
function print_usage()
print(stderr,"usage: nstrophy [-p params] [-g driving] <command>\n")
end
main()
|