@@ -98,7 +98,6 @@ with grid discretization `dx = 0.05` and physics-informed neural networks. Here
98
98
``` julia
99
99
using NeuralPDE, Flux, ModelingToolkit, GalacticOptim, Optim, DiffEqFlux
100
100
using Plots, Printf
101
- using Quadrature,Cubature, Cuba
102
101
import ModelingToolkit: Interval, infimum, supremum
103
102
104
103
@parameters t, x
@@ -136,13 +135,18 @@ domains = [t ∈ Interval(0.0, L),
136
135
x ∈ Interval (0.0 , L)]
137
136
138
137
# 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 ];]
141
145
142
146
initθ = map (c -> Float64 .(c), DiffEqFlux. initial_params .(chain))
143
147
144
- dx = 0.05
145
- strategy = GridTraining (dx)
148
+ strategy = GridTraining ( 0.02 )
149
+
146
150
discretization = PhysicsInformedNN (chain, strategy; init_params= initθ)
147
151
148
152
@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)
159
163
return false
160
164
end
161
165
162
- # Optimizer
163
- res = GalacticOptim. solve (prob, BFGS (); cb= cb, maxiters= 1000 )
166
+ res = GalacticOptim. solve (prob, BFGS ();cb= cb, maxiters= 2000 )
164
167
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 )
166
169
167
170
phi = discretization. phi[1 ]
168
171
169
172
# 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]
171
174
172
175
μ_n (k) = (v * sqrt (4 * k^ 2 * π^ 2 - b^ 2 * L^ 2 * v^ 2 )) / (2 * L)
173
176
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
189
gif (anim, " 1Dwave_damped_adaptive.gif" , fps= 200 )
187
190
188
191
# Surface plot
192
+ ts, xs = [infimum (d. domain): 0.01 : supremum (d. domain) for d in domains]
189
193
u_predict = reshape ([first (phi ([t,x], res. minimizer)) for t in ts for x in xs], (length (ts), length (xs)))
190
194
u_real = reshape ([analytic_sol_func (t, x) for t in ts for x in xs], (length (ts), length (xs)))
191
195
@@ -198,8 +202,8 @@ plot(p1,p2,p3)
198
202
199
203
We can see the results here:
200
204
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 )
202
206
203
207
Plotted as a line one can see the analytical solution and the prediction here:
204
208
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