-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_1d.jl
219 lines (180 loc) · 6.26 KB
/
app_1d.jl
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
### A Pluto.jl notebook ###
# v0.19.42
using Markdown
using InteractiveUtils
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local iv = try Base.loaded_modules[Base.PkgId(Base.UUID("6e696c72-6542-2067-7265-42206c756150"), "AbstractPlutoDingetjes")].Bonds.initial_value catch; b -> missing; end
local el = $(esc(element))
global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : iv(el)
el
end
end
# ╔═╡ d5e4988a-09a0-11ef-2eb9-97277c169c65
begin
import Pkg
# activate the shared project environment
Pkg.activate(Base.current_project())
Pkg.status()
# instantiate, i.e. make sure that all packages are downloaded
Pkg.instantiate()
using WaveSim
using Plots
theme(:dracula)
using PlutoUI
end
# ╔═╡ 206b9281-0aab-435d-8592-6e5169449832
md"""
# Activate Local Environment
"""
# ╔═╡ ed6ee4ce-fcd8-403a-9061-d688737f87be
function select(options, UItype)
return PlutoUI.combine() do Child
inputs = [
md""" $(name): $(
Child(name, ui)
)"""
for (name, ui) in zip(options, UItype)
]
md"""
$(inputs)
"""
end
end;
# ╔═╡ b56e0a7c-c0a2-43f3-ba46-7f5c38d1cf97
md"""
# Problem Setting
"""
# ╔═╡ 8ab95f04-2dad-4274-a7b5-69c23d5c2bb1
md"""
## Space and Time Discretization
"""
# ╔═╡ ce9660d5-a355-464c-9142-1bfd084fc658
@bind space select(["Length of the String (in meters)", "Number of points in x dimension"], [PlutoUI.Select(100:100), PlutoUI.Select(101:1000:11001)])
# ╔═╡ 241fc0e7-8b6c-4d61-b7c8-95f331469dc4
begin
x_max, nx = space
dx = (x_max)/(nx-1);
md"""
**Space Discretization Step Size (in meters): $(round(dx, digits=2))**
"""
end
# ╔═╡ ba518ad0-391d-45ca-8617-73fcc80bc8f4
md"""
## Time Discretization
"""
# ╔═╡ 36b894da-0428-459c-92ff-0f3e34943769
@bind time select(["How long to run the simulation (in seconds)", "Number of points in t dimension"], [PlutoUI.Select(1:10, default=2), PlutoUI.Select(1001:1000:11001, default=2001)])
# ╔═╡ 17fe1153-8514-4876-b5b7-7ba0bd2d1d89
begin
t_max, nt = time;
dt = (t_max)/(nt-1);
md"""
**Time Discretization Step Size (in seconds): $(round(dt, digits=10))**
"""
end
# ╔═╡ d9417b50-b232-47cc-8d78-506aca36fbca
md"""
## Source Function
"""
# ╔═╡ bd5d0e35-4bdd-488f-b8a5-bea04c27d764
@bind source select(["Pick a source function", "Source Frequency (in Hz)", "Source Initiation Time (in seconds)", "Plot Source Function"], [PlutoUI.Select(["Derivative of Gaussian", "Gaussian"]), PlutoUI.Select(5:5:30, default=5), PlutoUI.Slider(0.1:0.01:round(t_max/2, digits=2), show_value=true), PlutoUI.Select([true, false])])
# ╔═╡ c6d58808-b224-46f9-91f4-965c02dd32ec
begin
func_name, f0, t0, plt = source
# Space Discretization
x = range(start=0, stop=x_max, length=nx)
# Time Discretization
t = range(start=0, stop=t_max, length=nt)
# Source Function
if func_name == "Derivative of Gaussian"
src = -8. .* (t .- t0) .* f0 .* (exp.(-1.0 .* (4*f0)^2 .* (t .- t0).^2)) / ((x_max-0)/(nx-1))
elseif func_name == "Gaussian"
src = exp.(-1.0 .* (4*f0)^2 .* (t .- t0).^2) / ((x_max-0)/(nx-1))
end
if plt
# Plotting source Function
p = scatter(t, src, title="Source Function", label="Source Function", markersize=1, dpi=1000)
xlabel!("t")
ylabel!("Amplitude")
end
end
# ╔═╡ 2985d0e2-ae9b-41f3-996a-b8422c17ded8
md"""
# Finite Difference Simulation
"""
# ╔═╡ f18d9481-13ae-49eb-b6fb-5501d00c2f4a
@bind fdm_details select(["Source location from x=0 (in meters)",
"Medium velocity (in m/s)",
"FD scheme (3 point or 5 point)",
"Boundary condition"],[
PlutoUI.Select([25,x_max/2,x_max-25], default=x_max/2),
PlutoUI.Select(50.:50:500.),
PlutoUI.Select([3, 5]),
PlutoUI.Select(["zero", "neumann", "absorbing"]),])
# ╔═╡ b9dd9d24-bff2-4e84-b188-6dec8e865d60
begin
isrc, c, op, boundary = fdm_details
# Space Discretization
x_details = Dict("x_min" => 0, "x_max" => x_max, "nx" => nx)
# Time Discretization
t_details = Dict("t_min" => 0, "t_max" => t_max, "nt" => nt)
# Source Details
src_details = Dict("isrc" => isrc, "src" => src)
md"""
### CFL criteria: $(round(c*dt/dx, digits=3))
"""
end
# ╔═╡ e090a86d-7ed8-4428-b777-06383d62f492
begin
p_sols = wave_sim_1d(x_details, t_details, src_details, c, op, boundary);
@bind it PlutoUI.Slider(range(start=1, stop=nt, length=min(nt, 60*(t_max)*10)), show_value=false)
end
# ╔═╡ cf0e9ff0-dd7e-40e2-8544-e8d18ffa9e25
begin
# Plotting
t_val = round(it*(t_max)/(nt-1), digits=2)
plot(x, p_sols[Int(floor(it)),:], ylims=(min(1.25*minimum(p_sols), -1.5*maximum(p_sols)), 1.5*maximum(p_sols)), label="Wave (c=$(c) m/s)", dpi=1000)
xlabel!("x(meters)")
ylabel!("u(x,t=$(t_val))")
title!("Wave at t=$(t_val) secs")
end
# ╔═╡ 5f829cd4-1bca-4473-a8a7-aca6a91cbd91
# ╠═╡ disabled = true
#=╠═╡
begin
# Animation
anim = @animate for it in range(start=1, stop=nt, length=min(nt, 60*(t_max)*10))
t_val = round(it*(t_max)/(nt-1), digits=2)
plot(x, p_sols[Int(floor(it)),:],
ylims=(1.25*minimum(p_sols), 1.25*maximum(p_sols)),
label="Wave (c=$(c) m/s)", dpi=300)
xlabel!("x(meters)")
ylabel!("u(x,t=$(t_val))")
title!("Wave at t=$(t_val) secs")
end
# gif(anim, "anims/1D.gif", fps=60)
mp4(anim, "anims/1D_zb.mp4", fps=60)
end
╠═╡ =#
# ╔═╡ Cell order:
# ╟─206b9281-0aab-435d-8592-6e5169449832
# ╟─d5e4988a-09a0-11ef-2eb9-97277c169c65
# ╟─ed6ee4ce-fcd8-403a-9061-d688737f87be
# ╟─b56e0a7c-c0a2-43f3-ba46-7f5c38d1cf97
# ╟─8ab95f04-2dad-4274-a7b5-69c23d5c2bb1
# ╟─ce9660d5-a355-464c-9142-1bfd084fc658
# ╟─241fc0e7-8b6c-4d61-b7c8-95f331469dc4
# ╟─ba518ad0-391d-45ca-8617-73fcc80bc8f4
# ╟─36b894da-0428-459c-92ff-0f3e34943769
# ╟─17fe1153-8514-4876-b5b7-7ba0bd2d1d89
# ╟─d9417b50-b232-47cc-8d78-506aca36fbca
# ╟─bd5d0e35-4bdd-488f-b8a5-bea04c27d764
# ╟─c6d58808-b224-46f9-91f4-965c02dd32ec
# ╟─2985d0e2-ae9b-41f3-996a-b8422c17ded8
# ╟─f18d9481-13ae-49eb-b6fb-5501d00c2f4a
# ╟─b9dd9d24-bff2-4e84-b188-6dec8e865d60
# ╟─e090a86d-7ed8-4428-b777-06383d62f492
# ╟─cf0e9ff0-dd7e-40e2-8544-e8d18ffa9e25
# ╟─5f829cd4-1bca-4473-a8a7-aca6a91cbd91