Skip to content

Commit 5c3725e

Browse files
committed
fixes from review
1 parent f9b72d9 commit 5c3725e

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

docs/src/tutorials/dgm.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ u(t, 1) & = 0
4747
```
4848

4949
### Copy- Pasteable code
50-
```julia
50+
```@example
5151
using NeuralPDE
5252
using ModelingToolkit, Optimization, OptimizationOptimisers
5353
import Lux: tanh, identity
@@ -58,15 +58,15 @@ using MethodOfLines, OrdinaryDiffEq
5858
@parameters x t
5959
@variables u(..)
6060
61-
Dt= Differential(t)
62-
Dx= Differential(x)
63-
Dxx= Dx^2
64-
α = 0.05;
61+
Dt = Differential(t)
62+
Dx = Differential(x)
63+
Dxx = Dx^2
64+
α = 0.05
6565
# Burger's equation
66-
eq= Dt(u(t,x)) + u(t,x) * Dx(u(t,x)) - α * Dxx(u(t,x)) ~ 0
66+
eq = Dt(u(t,x)) + u(t,x) * Dx(u(t,x)) - α * Dxx(u(t,x)) ~ 0
6767
6868
# boundary conditions
69-
bcs= [
69+
bcs = [
7070
u(0.0, x) ~ - sin(π*x),
7171
u(t, -1.0) ~ 0.0,
7272
u(t, 1.0) ~ 0.0
@@ -75,7 +75,7 @@ bcs= [
7575
domains = [t ∈ Interval(0.0, 1.0), x ∈ Interval(-1.0, 1.0)]
7676
7777
# MethodOfLines, for FD solution
78-
dx= 0.01
78+
dx = 0.01
7979
order = 2
8080
discretization = MOLFiniteDifference([x => dx], t, saveat = 0.01)
8181
@named pde_system = PDESystem(eq, bcs, domains, [t, x], [u(t,x)])
@@ -87,13 +87,13 @@ xs = sol[x]
8787
u_MOL = sol[u(t,x)]
8888
8989
# NeuralPDE, using Deep Galerkin Method
90-
strategy = QuasiRandomTraining(256, minibatch= 32);
91-
discretization= DeepGalerkin(2, 1, 50, 5, tanh, tanh, identity, strategy);
92-
@named pde_system = PDESystem(eq, bcs, domains, [t, x], [u(t,x)]);
93-
prob = discretize(pde_system, discretization);
94-
global iter = 0;
90+
strategy = QuasiRandomTraining(256, minibatch= 32)
91+
discretization = DeepGalerkin(2, 1, 50, 5, tanh, tanh, identity, strategy)
92+
@named pde_system = PDESystem(eq, bcs, domains, [t, x], [u(t,x)])
93+
prob = discretize(pde_system, discretization)
94+
global iter = 0
9595
callback = function (p, l)
96-
global iter += 1;
96+
global iter += 1
9797
if iter%20 == 0
9898
println("$iter => $l")
9999
end
@@ -103,11 +103,11 @@ end
103103
res = Optimization.solve(prob, Adam(0.1); callback = callback, maxiters = 100)
104104
prob = remake(prob, u0 = res.u)
105105
res = Optimization.solve(prob, Adam(0.01); callback = callback, maxiters = 500)
106-
phi = discretization.phi;
106+
phi = discretization.phi
107107
108108
u_predict= [first(phi([t, x], res.minimizer)) for t in ts, x in xs]
109109
110-
diff_u = abs.(u_predict .- u_MOL);
110+
diff_u = abs.(u_predict .- u_MOL)
111111
112112
using Plots
113113
p1 = plot(tgrid, xgrid, u_MOL', linetype = :contourf, title = "FD");

0 commit comments

Comments
 (0)