Skip to content

Commit a5bfc91

Browse files
Merge pull request #480 from SciML/fix_damped_wave
Update damped wave docs
2 parents 70c9080 + d3b7cfb commit a5bfc91

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

docs/src/pinn/wave.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ with grid discretization `dx = 0.05` and physics-informed neural networks. Here
9898
```julia
9999
using NeuralPDE, Flux, ModelingToolkit, GalacticOptim, Optim, DiffEqFlux
100100
using Plots, Printf
101-
using Quadrature,Cubature, Cuba
102101
import ModelingToolkit: Interval, infimum, supremum
103102

104103
@parameters t, x
@@ -136,13 +135,18 @@ domains = [t ∈ Interval(0.0, L),
136135
x Interval(0.0, L)]
137136

138137
# Neural network
139-
chain = [[FastChain(FastDense(2, 16, Flux.tanh), FastDense(16, 16, Flux.tanh), FastDense(16, 16, Flux.tanh), FastDense(16, 1)) for _ in 1:3];
140-
[FastChain(FastDense(2, 6, Flux.tanh), FastDense(6, 1)) for _ in 1:2];]
138+
inn = 25
139+
innd = 4
140+
chain = [[FastChain(FastDense(2, inn, Flux.tanh),
141+
FastDense(inn, inn, Flux.tanh),
142+
FastDense(inn, inn, Flux.tanh),
143+
FastDense(inn, 1)) for _ in 1:3];
144+
[FastChain(FastDense(2, innd, Flux.tanh), FastDense(innd, 1)) for _ in 1:2];]
141145

142146
initθ = map(c -> Float64.(c), DiffEqFlux.initial_params.(chain))
143147

144-
dx = 0.05
145-
strategy = GridTraining(dx)
148+
strategy = GridTraining(0.02)
149+
146150
discretization = PhysicsInformedNN(chain, strategy; init_params=initθ)
147151

148152
@named pde_system = PDESystem(eq, bcs, domains, [t, x], [u(t, x), Dxu(t, x), Dtu(t, x), O1(t, x), O2(t, x)])
@@ -159,15 +163,14 @@ cb = function (p, l)
159163
return false
160164
end
161165

162-
# Optimizer
163-
res = GalacticOptim.solve(prob, BFGS(); cb=cb, maxiters=1000)
166+
res = GalacticOptim.solve(prob, BFGS();cb=cb, maxiters=2000)
164167
prob = remake(prob, u0=res.minimizer)
165-
res = GalacticOptim.solve(prob, BFGS(); cb=cb, maxiters=3000)
168+
res = GalacticOptim.solve(prob, BFGS();cb=cb, maxiters=2000)
166169

167170
phi = discretization.phi[1]
168171

169172
# Analysis
170-
ts, xs = [infimum(d.domain):dx:supremum(d.domain) for d in domains]
173+
ts, xs = [infimum(d.domain):0.05:supremum(d.domain) for d in domains]
171174

172175
μ_n(k) = (v * sqrt(4 * k^2 * π^2 - b^2 * L^2 * v^2)) / (2 * L)
173176
b_n(k) = 2 / L * -(L^2 * ((2 * π * L - π) * k * sin* k) + ((π^2 - π^2 * L) * k^2 + 2 * L) * cos* k) - 2 * L)) /^3 * k^3) # vegas((x, ϕ) -> ϕ[1] = sin(k * π * x[1]) * f(x[1])).integral[1]
@@ -186,6 +189,7 @@ end
186189
gif(anim, "1Dwave_damped_adaptive.gif", fps=200)
187190

188191
# Surface plot
192+
ts, xs = [infimum(d.domain):0.01:supremum(d.domain) for d in domains]
189193
u_predict = reshape([first(phi([t,x], res.minimizer)) for t in ts for x in xs], (length(ts), length(xs)))
190194
u_real = reshape([analytic_sol_func(t, x) for t in ts for x in xs], (length(ts), length(xs)))
191195

@@ -198,8 +202,8 @@ plot(p1,p2,p3)
198202

199203
We can see the results here:
200204

201-
![Damped_wave_sol_adaptive_u](https://user-images.githubusercontent.com/26853713/128976158-2cf113c9-cec8-4e81-94a8-4c5a814d57c2.png)
205+
![Damped_wave_sol_adaptive_u](https://user-images.githubusercontent.com/12683885/149665332-d4daf7d0-682e-4933-a2b4-34f403881afb.png)
202206

203207
Plotted as a line one can see the analytical solution and the prediction here:
204208

205-
![1Dwave_damped_adaptive](https://user-images.githubusercontent.com/26853713/128976095-e772be8f-eb92-4ddf-a3bb-32700e9e2112.gif)
209+
![1Dwave_damped_adaptive](https://user-images.githubusercontent.com/12683885/149665327-69d04c01-2240-45ea-981e-a7b9412a3b58.gif)

0 commit comments

Comments
 (0)