@@ -25,15 +25,15 @@ bcs = [u(0,x) ~ cos(x),
2525
2626# Space and time domains
2727domains = [t ∈ IntervalDomain (0.0 ,1.0 ),
28- x ∈ IntervalDomain (0.0 ,1.0 )]
28+ x ∈ IntervalDomain (0.0 ,1.0 )]
2929
3030# PDE system
31- pdesys = PDESystem (eq,bcs,domains,[t,x],[u])
31+ pdesys = PDESystem (eq,bcs,domains,[t,x],[u (t,x) ])
3232
3333# Method of lines discretization
3434dx = 0.1
3535order = 2
36- discretization = MOLFiniteDifference (dx,order )
36+ discretization = MOLFiniteDifference ([x => dx],t )
3737
3838# Convert the PDE problem into an ODE problem
3939prob = discretize (pdesys,discretization)
@@ -43,16 +43,18 @@ using OrdinaryDiffEq
4343sol = solve (prob,Tsit5 (),saveat= 0.2 )
4444
4545# Plot results and compare with exact solution
46- x = prob . space[ 2 ]
46+ x = ( 0 : dx : 1 )[ 2 : end - 1 ]
4747t = sol. t
4848
4949using Plots
5050plt = plot ()
51+
5152for i in 1 : length (t)
52- plot! (x,Array (prob . extrapolation[ 1 ](t[i]) * sol. u[i]) ,label= " Numerical, t=$(t[i]) " )
53+ plot! (x,sol. u[i],label= " Numerical, t=$(t[i]) " )
5354 scatter! (x, u_exact (x, t[i]),label= " Exact, t=$(t[i]) " )
5455end
5556display (plt)
57+ savefig (" plot.png" )
5658```
5759### Neumann boundary conditions
5860
@@ -79,13 +81,13 @@ domains = [t ∈ IntervalDomain(0.0,1.0),
7981 x ∈ IntervalDomain (0.0 ,1.0 )]
8082
8183# PDE system
82- pdesys = PDESystem (eq,bcs,domains,[t,x],[u])
84+ pdesys = PDESystem (eq,bcs,domains,[t,x],[u (t,x) ])
8385
8486# Method of lines discretization
8587# Need a small dx here for accuracy
8688dx = 0.01
8789order = 2
88- discretization = MOLFiniteDifference (dx,order )
90+ discretization = MOLFiniteDifference ([x => dx],t )
8991
9092# Convert the PDE problem into an ODE problem
9193prob = discretize (pdesys,discretization)
@@ -95,16 +97,18 @@ using OrdinaryDiffEq
9597sol = solve (prob,Tsit5 (),saveat= 0.2 )
9698
9799# Plot results and compare with exact solution
98- x = prob . space[ 2 ]
100+ x = ( 0 : dx : 1 )[ 2 : end - 1 ]
99101t = sol. t
100102
101103using Plots
102104plt = plot ()
105+
103106for i in 1 : length (t)
104- plot! (x,Array (prob . extrapolation[ 1 ](t[i]) * sol. u[i]) ,label= " Numerical, t=$(t[i]) " )
107+ plot! (x,sol. u[i],label= " Numerical, t=$(t[i]) " ,lw = 12 )
105108 scatter! (x, u_exact (x, t[i]),label= " Exact, t=$(t[i]) " )
106109end
107110display (plt)
111+ savefig (" plot.png" )
108112```
109113
110114### Robin boundary conditions
@@ -132,13 +136,13 @@ domains = [t ∈ IntervalDomain(0.0,1.0),
132136 x ∈ IntervalDomain (- 1.0 ,1.0 )]
133137
134138# PDE system
135- pdesys = PDESystem (eq,bcs,domains,[t,x],[u])
139+ pdesys = PDESystem (eq,bcs,domains,[t,x],[u (t,x) ])
136140
137141# Method of lines discretization
138142# Need a small dx here for accuracy
139143dx = 0.05
140144order = 2
141- discretization = MOLFiniteDifference (dx,order )
145+ discretization = MOLFiniteDifference ([x => dx],t )
142146
143147# Convert the PDE problem into an ODE problem
144148prob = discretize (pdesys,discretization)
@@ -148,14 +152,16 @@ using OrdinaryDiffEq
148152sol = solve (prob,Tsit5 (),saveat= 0.2 )
149153
150154# Plot results and compare with exact solution
151- x = prob . space[ 2 ]
155+ x = ( 0 : dx : 1 )[ 2 : end - 1 ]
152156t = sol. t
153157
154158using Plots
155159plt = plot ()
160+
156161for i in 1 : length (t)
157- plot! (x,Array (prob . extrapolation[ 1 ](t[i]) * sol. u[i]) ,label= " Numerical, t=$(t[i]) " )
162+ plot! (x,sol. u[i],label= " Numerical, t=$(t[i]) " )
158163 scatter! (x, u_exact (x, t[i]),label= " Exact, t=$(t[i]) " )
159164end
160165display (plt)
166+ savefig (" plot.png" )
161167```
0 commit comments