@@ -51,6 +51,7 @@ using ModelingToolkit: Differential
5151 r_space_x = x_min: dx: x_max
5252 r_space_y = y_min: dy: y_max
5353 asf = reshape ([analytic_sol_func (t_max,r_space_x[i],r_space_y[j]) for j in 1 : Ny for i in 1 : Nx],(Nx,Ny))
54+ asf[1 ,1 ] = asf[1 , end ] = asf[end , 1 ] = asf[end , end ] = 0.
5455 # Method of lines discretization
5556 discretization = MOLFiniteDifference ([x=> dx,y=> dy],t;approx_order= order)
5657 prob = ModelingToolkit. discretize (pdesys,discretization)
121122 r_space_x = x_min: dx: x_max
122123 r_space_y = y_min: dy: y_max
123124 asf = reshape ([analytic_sol_func (t_max,r_space_x[i],r_space_y[j]) for j in 1 : Ny for i in 1 : Nx],(Nx,Ny))
125+ asf[1 ,1 ] = asf[1 , end ] = asf[end , 1 ] = asf[end , end ] = 0.
126+
124127 m = max (asf... )
125128 @test asf / m ≈ sol′ / m atol= 0.4 # TODO : use lower atol when g(x) is improved in MOL_discretize.jl
126129
130133 # savefig("MOL_NonLinear_Diffusion_2D_Test01.png")
131134
132135end
133-
134- @testset " Test 01: Dt(u(t,x,y)) ~ Dx( a(x,y,u) * Dx(u(t,x,y))) + Dy( a(x,y,u) * Dy(u(t,x,y))), Neumann BCs" begin
135-
136- # Variables, parameters, and derivatives
137- @parameters t x y
138- @variables u (.. )
139- Dx = Differential (x)
140- Dy = Differential (y)
141- Dt = Differential (t)
142- t_min= 0.
143- t_max = 2.0
144- x_min = 0.
145- x_max = 2.
146- y_min = 0.
147- y_max = 2.
148-
149- # Analytic solution
150- analytic_sol_func (t,x,y) = exp (x+ y)* cos (x+ y+ 4 t)
151- analytic_deriv_func (t,x,y) = exp (x+ y)* cos (x+ y+ 4 t) + exp (x+ y)* sin (x+ y+ 4 t)
152-
153- # Equation
154- eq = Dt (u (t,x,y)) ~ Dx ( (u (t,x,y)^ 2 / exp (x+ y)^ 2 + sin (x+ y+ 4 t)^ 2 )^ 0.5 * Dx (u (t,x,y))) +
155- Dy ( (u (t,x,y)^ 2 / exp (x+ y)^ 2 + sin (x+ y+ 4 t)^ 2 )^ 0.5 * Dy (u (t,x,y)))
156-
157- # Initial and boundary conditions
158- bcs = [u (t_min,x,y) ~ analytic_sol_func (t_min,x,y),
159- Dx (u (t,x_min,y)) ~ analytic_deriv_func (t,x_min,y),
160- Dx (u (t,x_max,y)) ~ analytic_deriv_func (t,x_max,y),
161- Dy (u (t,x,y_min)) ~ analytic_deriv_func (t,x,y_min),
162- Dy (u (t,x,y_max)) ~ analytic_deriv_func (t,x,y_max)]
163-
164- # Space and time domains
165- domains = [t ∈ Interval (t_min,t_max),
166- x ∈ Interval (x_min,x_max),
167- y ∈ Interval (y_min,y_max)]
168-
169- # Space and time domains
170- @named pdesys = PDESystem ([eq],bcs,domains,[t,x,y],[u (t,x,y)])
171-
172- # Method of lines discretization
173- dx = 0.1 ; dy = 0.2
174- discretization = MOLFiniteDifference ([x=> dx,y=> dy],t; approx_order= 4 )
175- prob = ModelingToolkit. discretize (pdesys,discretization)
176-
177- # Solution of the ODE system
178- sol = solve (prob,Rosenbrock23 ())
179-
180- # Test against exact solution
181- Nx = floor (Int64, (x_max - x_min) / dx) + 1
182- Ny = floor (Int64, (y_max - y_min) / dy) + 1
183- @variables u[1 : Nx,1 : Ny](t)
184- sol′ = [sol[u[(i- 1 )* Ny+ j]][end ] for i in 1 : Nx, j in 1 : Ny]
185- r_space_x = x_min: dx: x_max
186- r_space_y = y_min: dy: y_max
187- asf = [analytic_sol_func (t_max,r_space_x[i],r_space_y[j]) for j in 1 : Ny, i in 1 : Nx]
188- m = max (asf... )
189- @test asf / m ≈ sol′ / m atol= 0.4 # TODO : use lower atol when g(x) is improved in MOL_discretize.jl
190-
191- # Plot
192- # using Plots
193- # heatmap(sol′)
194- # savefig("MOL_NonLinear_Diffusion_2D_Test01.png")
195-
196- end
197-
198-
0 commit comments