Skip to content

Commit df579ef

Browse files
committed
added WIP (mostly works modulu bugs) 1d acoustics.
1 parent 73f3e73 commit df579ef

File tree

18 files changed

+2091
-0
lines changed

18 files changed

+2091
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
module ReadDataFile
2+
3+
export Reader, readstr, readbool, readint, readflt, readintarray, readfltarray, close_reader
4+
5+
type Reader
6+
7+
fname::String
8+
istream::IOStream
9+
line::String
10+
lineno::Int
11+
12+
# a constructor: opens a file, sets lineno
13+
function Reader(fname::String)
14+
istream = open(fname, "r")
15+
r = new(fname,istream, "", 0)
16+
finalizer(r, close_reader)
17+
return r
18+
end
19+
end
20+
21+
function readln(r::Reader)
22+
const skip_rexp = r"^\s*(?:#|$)"
23+
const rexp = r"^\s*(.*?)\s*(?:(#|=:)\s*(.*?)\s*$|$)"
24+
25+
while true
26+
r.line = readline(r.istream)
27+
r.lineno += 1
28+
# skip empty lines and comments starting from #
29+
if match(skip_rexp, r.line) == nothing
30+
break
31+
end
32+
end
33+
m = match(rexp, r.line)
34+
r.line = m.captures[1]
35+
end
36+
37+
function readstr(r::Reader)
38+
readln(r)
39+
return r.line
40+
end
41+
42+
function readbool(r::Reader)
43+
readln(r)
44+
if r.line != "T" && r.line != "F"
45+
local fname = r.fname, lineno = r.lineno
46+
error("$fname($lineno): error parsing boolean")
47+
end
48+
return r.line == "T"
49+
end
50+
51+
function readint(r::Reader)
52+
readln(r)
53+
return parse(Int,r.line)
54+
end
55+
56+
function readflt(r::Reader)
57+
readln(r)
58+
return parse(Float64, r.line)
59+
end
60+
61+
function readraw(r::Reader)
62+
readln(r)
63+
return split(r.line)
64+
end
65+
66+
function readarray(r::Reader, parser, len)
67+
buf = readraw(r)
68+
buflen = length(buf)
69+
@assert(buflen == len)
70+
return [parser(buf[i]) for i = 1:buflen]
71+
end
72+
73+
readintarray(r::Reader, len::Int) = readarray(r, x -> parse(Int, x), len)
74+
readfltarray(r::Reader, len::Int) = readarray(r, x -> parse(Float64, x), len)
75+
76+
function close_reader(r::Reader)
77+
Base.close(r.istream)
78+
end
79+
80+
# ```jlcon
81+
# julia> include("ReadDataFile.jl")
82+
#
83+
# julia> using ReadDataFile
84+
#
85+
# julia> r = Reader("claw.data")
86+
# -I- claw.data 6 blank lines were skipped
87+
# Reader("claw.data",IOStream(<file claw.data>),"1",6,r"^\s*(.*?)\s*(?:#\s*(.*?)\s*$|$)")
88+
#
89+
# julia> readint(r)
90+
# 1
91+
#
92+
# julia> readflt(r)
93+
# -1.0
94+
# ```
95+
96+
end # ReadDataFile
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
module SetProb
3+
4+
export
5+
CParam, read_prob_data
6+
7+
type CParam
8+
rho ::Float64
9+
bulk ::Float64
10+
cc ::Float64
11+
zz ::Float64
12+
13+
beta ::Float64
14+
15+
# default constructor
16+
function CParam()
17+
new(0.0, 0.0, 0.0, 0.0, 0.0)
18+
end
19+
end
20+
21+
22+
# Set the material parameters for the acoustic equations
23+
24+
using ReadDataFile
25+
26+
function read_prob_data(parms::CParam)
27+
28+
r = Reader("setprob.data")
29+
30+
# density:
31+
parms.rho = readflt(r)
32+
33+
# bulk modulus:
34+
parms.bulk = readflt(r)
35+
36+
# sound speed:
37+
parms.cc = sqrt(parms.bulk/parms.rho)
38+
39+
# impedance:
40+
parms.zz = parms.cc*parms.rho
41+
42+
# beta for initial conditions:
43+
parms.beta = readflt(r)
44+
45+
close_reader(r)
46+
end # read_prob_data
47+
48+
end # SetProb
49+
50+
using .SetProb
51+
using Base.Test.@test
52+
53+
function test_read_data()
54+
const parms = CParam()
55+
read_prob_data(parms)
56+
println("CParam = $parms")
57+
return true
58+
end
59+
60+
# @test test_read_data()
61+
62+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function b4step1(mbc::Int, mx::Int, meqn::Int, q, xloweri::Float64, dxi::Float64, t::Float64, dt::Float64, mauxi::Int, aux)
2+
#
3+
# ! Called before each call to step1.
4+
# ! Use to set time-dependent aux arrays or perform other tasks.
5+
# !
6+
# ! This default version does nothing.
7+
#
8+
# implicit none
9+
# integer, intent(in) :: mbc,mx,meqn,maux
10+
# real(kind=8), intent(in) :: xlower,dx,t,dt
11+
# real(kind=8), intent(inout) :: q(meqn,1-mbc:mx+mbc)
12+
# real(kind=8), intent(inout) :: aux(maux,1-mbc:mx+mbc)
13+
#
14+
end # subroutine b4step1
15+

examples/acoustics_1d_example1/bc1.jl

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
using OffsetArrays
2+
3+
#
4+
#
5+
#=========================================================================#
6+
function bc1(meqn::Int, mbc::Int, mx::Int, xlower::Float64, dx::Float64,
7+
q::OffsetArray{Float64,2}, maux::Int, aux::OffsetArray{Float64,2},
8+
t::Float64, dt::Float64, mthbc::Array{Int,1})
9+
#=========================================================================#
10+
#
11+
# # Standard boundary condition choices for claw2
12+
#
13+
# # At each boundary k = 1 (left), 2 (right):
14+
# # mthbc(k) = 0 for user-supplied BC's (must be inserted!)
15+
# # = 1 for zero-order extrapolation
16+
# # = 2 for periodic boundary coniditions
17+
# # = 3 for solid walls, assuming this can be implemented
18+
# # by reflecting the data about the boundary and then
19+
# # negating the 2'nd component of q.
20+
# ------------------------------------------------
21+
#
22+
# # Extend the data from the computational region
23+
# # i = 1, 2, ..., mx2
24+
# # to the virtual cells outside the region, with
25+
# # i = 1-ibc and i = mx+ibc for ibc=1,...,mbc
26+
#
27+
## implicit double precision (a-h,o-z)
28+
## dimension q(meqn,1-mbc:mx+mbc)
29+
## dimension aux(maux,1-mbc:mx+mbc)
30+
##
31+
## dimension mthbc(2)
32+
33+
#
34+
#
35+
#-------------------------------------------------------
36+
# # left boundary:
37+
#-------------------------------------------------------
38+
# go to (100,110,120,130) mthbc(1)+1
39+
#
40+
if mthbc[1] == 0
41+
# 100 continue
42+
43+
# user-specified boundary conditions go here in place of error output
44+
println("*** ERROR *** mthbc(1)=0 and no BCs specified in bc1")
45+
46+
elseif mthbc[1] == 1
47+
48+
# 110 continue
49+
# zero-order extrapolation:
50+
for ibc=1:mbc
51+
for m=1:meqn
52+
q[m,1-ibc] = q[m,1]
53+
end
54+
end
55+
# go to 199
56+
57+
elseif mthbc[1] == 2
58+
# 120 continue
59+
# periodic:
60+
for ibc=1:mbc
61+
for m=1:meqn
62+
q[m,1-ibc] = q[m,mx+1-ibc]
63+
end
64+
end
65+
# go to 199
66+
67+
elseif mthbc[1] == 3
68+
# 130 continue
69+
# # solid wall (assumes 2'nd component is velocity or momentum in x):
70+
for ibc=1:mbc
71+
for m=1:meqn
72+
q[m,1-ibc] = q[m,ibc]
73+
end
74+
q[2,1-ibc] = -q[2,ibc]
75+
end
76+
# # negate the normal velocity:
77+
# go to 199
78+
79+
# 199 continue
80+
end # if mthbc[1] == ...
81+
82+
#
83+
#-------------------------------------------------------
84+
# # right boundary:
85+
#-------------------------------------------------------
86+
# go to (200,210,220,230) mthbc(2)+1
87+
#
88+
if mthbc[2] == 0
89+
# 200 continue
90+
# user-specified boundary conditions go here in place of error output
91+
println("*** ERROR *** mthbc(2)=0 and no BCs specified in bc2")
92+
# go to 299
93+
94+
elseif mthbc[2] == 1
95+
# 210 continue
96+
# zero-order extrapolation:
97+
for ibc=1:mbc
98+
for m=1:meqn
99+
q[m,mx+ibc] = q[m,mx]
100+
end
101+
end
102+
# go to 299
103+
104+
elseif mthbc[2] == 2
105+
# 220 continue
106+
# # periodic:
107+
for ibc=1:mbc
108+
for m=1:meqn
109+
q[m,mx+ibc] = q[m,ibc]
110+
end
111+
end
112+
# go to 299
113+
114+
elseif mthbc[2] == 3
115+
# 230 continue
116+
# # solid wall (assumes 2'nd component is velocity or momentum in x):
117+
for ibc=1:mbc
118+
for m=1:meqn
119+
q[m,mx+ibc] = q[m,mx+1-ibc]
120+
end
121+
q[2,mx+ibc] = -q[2,mx+1-ibc]
122+
end
123+
# go to 299
124+
125+
end # if mthbc[2] == ...
126+
# 299 continue
127+
#
128+
129+
end
130+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
########################################################
2+
### DO NOT EDIT THIS FILE: GENERATED AUTOMATICALLY ####
3+
### To modify data, edit setrun.py ####
4+
### and then "make .data" ####
5+
########################################################
6+
7+
1 =: num_dim
8+
-1.0 =: lower
9+
1.0 =: upper
10+
400 =: num_cells
11+
12+
2 =: num_eqn
13+
2 =: num_waves
14+
0 =: num_aux
15+
16+
0.0 =: t0
17+
18+
1 =: output_style
19+
16 =: num_output_times
20+
0.8 =: tfinal
21+
T =: output_t0
22+
23+
1 =: output_format
24+
1 1 =: iout_q
25+
26+
0.1 =: dt_initial
27+
1e+99 =: dt_max
28+
1.0 =: cfl_max
29+
0.9 =: cfl_desired
30+
500 =: steps_max
31+
32+
T =: dt_variable
33+
2 =: order
34+
0 =: verbosity
35+
0 =: source_split
36+
0 =: capa_index
37+
F =: use_fwaves
38+
39+
4 4 =: limiter
40+
41+
2 =: num_ghost
42+
1 =: bc_lower
43+
1 =: bc_upper
44+
45+
F =: restart
46+
'fort.q0006' =: restart_file
47+
0 =: checkpt_style
48+

0 commit comments

Comments
 (0)