Skip to content

Commit 6232e9a

Browse files
committed
time-varying Neumann
1 parent 624eaa8 commit 6232e9a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

examples/collocation.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,27 @@ sol = solve(prob, Rodas5(), reltol = 1e-8, abstol = 1e-8)
4646
t = range(0,1,100)
4747
contourf(t, x₂, hcat(sol.(t)...))
4848

49+
# We can also solve heat with a more complicated boundary condition like `u_x(t,1) = \sin t^2`,
50+
# using zero Dirichlet for the left condition.
51+
# To fit into the mass matrix model we differentiate wrt `t` to get the condition
52+
# `u_{xt}(t,1) = 2 t \cos t^2`.
53+
54+
55+
function heat_rneumann!(du, u, D₂, t)
56+
du[1] = 0 # left bc
57+
mul!(@view(du[2:end-1]), D₂, u)
58+
du[end] = 2*t*cos(t^2) # right bc
59+
end
60+
61+
u₀ = x -> (1-x^2)^2 * exp(x) # initial condition
62+
63+
N_r = diff(T)[1,1:n]' / V # Right Neumann condition
64+
prob = ODEProblem(ODEFunction(heat_rneumann!, mass_matrix = [B_l; R; N_r]), u₀.(x₂), (0., 1.), D₂)
65+
sol = solve(prob, Rodas5(), reltol = 1e-8, abstol = 1e-8)
66+
67+
t = range(0,1,100)
68+
contourf(t, x₂, hcat(sol.(t)...))
69+
4970

5071
####
5172
# Burgers equation

0 commit comments

Comments
 (0)