-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementing Explicit Runge Kutta Methods #951
Changes from all commits
10dcb08
c774d9a
b73af29
32e4d2f
94a8021
860a54a
b0a9426
fdf0d76
115e7da
77260d5
a0ec1e5
01e12cd
c4a91cd
b74c834
801c823
4e07d76
6795124
3b67fa9
cebb289
15de64d
d6f8eed
41a7a73
6d52485
e912ceb
046a21b
2f95b08
5e2bebc
eec1acb
9f1a818
d05d095
09c9710
e1d30a6
372ce38
8cd4422
fb27722
4fb59e1
1dc710c
72c733b
7182846
e84a4a6
0bd09cb
8937390
2b4f8d2
bb11b3b
13915bd
2239cd8
4343fc2
156f2b9
e787dba
abddb61
9718544
5375b72
d31c4cf
92fd4f4
47e27cb
b05a77c
6b70420
50afea4
264d701
46caf87
08f045c
7a880fb
5001e0c
98db57c
64c144f
da2d61b
1991e12
45fc322
afe6cb8
f5ec63d
a5a56ca
c3252f7
45c5585
ae6f2b2
e277a94
82914d6
294ad48
f0f7be8
f945230
4af777f
d87313e
abb8b46
4735eef
a5b795d
58273df
0dd6e9d
7f622a1
7881ca1
c179529
9d38d4e
775f82e
804de59
43f6d2a
16f1a64
7cf4112
1d312e5
22c71a2
a98f5a7
34f228b
6da6db9
e60d258
78beb01
94eea87
510235b
f2dbde9
c42a38a
b5dd6d1
5ad8ed3
bbb0786
8f4d54e
058c00f
43e662d
353e8ce
2eb5b9f
defd1d2
af6b5a1
81ce278
8fdc5f3
76a54ae
cb81ce4
37ef83e
93bd409
d62365a
b242b70
b4e3391
45defc6
60d33b7
1d516c9
fe6436d
c33ae46
5161c8f
2c8784a
6b29434
3001807
cf75856
fc627bf
6510314
332a0be
c65061c
7c63398
bc633db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ docs/build/ | |
Manifest.toml | ||
tmp/ | ||
.vscode/ | ||
*.vtu | ||
*.pvd |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using Pkg | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are all these tests related to the ExRK dev? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. started clean branch of master fork. |
||
|
||
Pkg.add(url="https://github.com/tamaratambyah/Gridap.jl", rev="rungekutta") | ||
|
||
using Gridap | ||
|
||
using Test | ||
|
||
# Analytical functions | ||
# u(x,t) = (x[1]+x[2])*t | ||
# u(x,t) = (2*x[1]+x[2])*t | ||
u(x,t) = (1.0-x[1])*x[1]*(1.0-x[2])*x[2]*t | ||
# u(x,t) = (1.0-x[1])*x[1]*t | ||
|
||
u(t) = x -> u(x,t) | ||
∂tu = ∂t(u) | ||
f(t) = x -> ∂t(u)(x,t)-Δ(u(t))(x) | ||
|
||
|
||
|
||
domain = (0,1,0,1) | ||
partition = (2,2) | ||
model = CartesianDiscreteModel(domain,partition) | ||
|
||
order = 2 | ||
|
||
reffe = ReferenceFE(lagrangian,Float64,order) | ||
V0 = FESpace( | ||
model, | ||
reffe, | ||
conformity=:H1, | ||
dirichlet_tags=[1,2,3,4,5,6] | ||
) | ||
U = TransientTrialFESpace(V0,u) | ||
|
||
Ω = Triangulation(model) | ||
degree = 2*order | ||
dΩ = Measure(Ω,degree) | ||
|
||
neumanntags = [7,8] | ||
Γ = BoundaryTriangulation(model,tags=neumanntags) | ||
dΓ = Measure(Γ,degree) | ||
nb = get_normal_vector(Γ) | ||
|
||
# | ||
a(u,v) = ∫(∇(v)⋅∇(u))dΩ | ||
b(v,t) = ∫(v*f(t))dΩ | ||
b_Γ(v,t) = ∫(v*(∇(u(t))⋅nb))dΓ | ||
|
||
lhs(t,u,v) = ∫( v* (u) )dΩ | ||
rhs(t,u,v) = b(v,t) + b_Γ(v,t) - a(u,v) | ||
|
||
jac(t,u,du,v) = ∫(( ∇(v)⊙∇(du) ))dΩ | ||
jac_t(t,u,dut,v) = ∫( dut*v )dΩ | ||
|
||
op = TransientEXRungeKuttaFEOperator(lhs,rhs,jac,jac_t,U,V0) | ||
|
||
t0 = 0.0 | ||
tF = 10.0 | ||
dt = 0.001 | ||
|
||
U0 = U(0.0) | ||
uh0 = interpolate_everywhere(u(0.0),U0) | ||
|
||
ls = LUSolver() | ||
|
||
# ode_solver = EXRungeKutta(ls,dt,:EX_FE_1_0_1) | ||
ode_solver = EXRungeKutta(ls,dt,:EX_SSP_3_0_3) | ||
|
||
sol_t = solve(ode_solver,op,uh0,t0,tF) | ||
|
||
l2(w) = w*w | ||
|
||
tol = 1.0e-6 | ||
|
||
errors_rk_fe = [] | ||
ts_rk_fe = [] | ||
for (uh_tn, tn) in sol_t | ||
e = u(tn) - uh_tn | ||
el2 = sqrt(sum( ∫(l2(e))dΩ )) / ( sqrt( sum( ∫( u(tn) )dΩ )) ) | ||
println(el2) | ||
(@test el2 < tol) | ||
errors_rk_fe = [errors_rk_fe; el2] | ||
ts_rk_fe = [ts_rk_fe; tn] | ||
end | ||
|
||
plot(ts_rk_fe,errors_rk_fe) | ||
plot!( | ||
#shape=:auto, | ||
xlabel="t", | ||
ylabel="relative error", | ||
title="RK-FE" | ||
# yaxis=:log | ||
) | ||
plot!(show=true) | ||
savefig(string("rk_fe_error_boundary")) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
using Pkg | ||
using Test | ||
Pkg.add(url="https://github.com/tamaratambyah/Gridap.jl", rev="rungekutta") | ||
|
||
using Gridap | ||
|
||
|
||
|
||
u(x,t) = (1.0-x[1])*x[1]*(1.0-x[2])*x[2]*t | ||
u(t::Real) = x -> u(x,t) | ||
f(t) = x -> ∂t(u)(x,t)-Δ(u(t))(x) | ||
|
||
L= 1.0 | ||
n = 2 | ||
domain = (0,L,0,L) | ||
partition = (n,n) | ||
model = CartesianDiscreteModel(domain,partition) | ||
|
||
order = 2 | ||
|
||
reffe = ReferenceFE(lagrangian,Float64,order) | ||
V0 = FESpace( | ||
model, | ||
reffe, | ||
conformity=:L2 | ||
) | ||
U = TransientTrialFESpace(V0) | ||
|
||
Ω = Triangulation(model) | ||
degree = 2*order | ||
dΩ = Measure(Ω,degree) | ||
|
||
Γ = BoundaryTriangulation(model) | ||
dΓ = Measure(Γ,degree) | ||
nb = get_normal_vector(Γ) | ||
|
||
Λ = SkeletonTriangulation(model) | ||
dΛ = Measure(Λ,degree) | ||
ns = get_normal_vector(Λ) | ||
|
||
a(u,v) = ∫(∇(v)⋅∇(u))dΩ | ||
b(v,t) = ∫(v*f(t))dΩ | ||
m(u,v) = ∫(v*u)dΩ | ||
|
||
h = 1.0 / n | ||
γ = order*(order+1) | ||
a_Γ(u,v) = ∫( (γ/h)*v*u - v*(∇(u)⋅nb) - (∇(v)⋅nb)*u )dΓ | ||
b_Γ(v,t) = ∫( (γ/h)*v*u(t) - (∇(v)⋅nb)*u(t) )dΓ | ||
|
||
a_Λ(u,v) = ∫( (γ/h)*jump(v*ns)⊙jump(u*ns) - jump(v*ns)⊙mean(∇(u)) - mean(∇(v))⊙jump(u*ns) )dΛ | ||
|
||
lhs(t,u,v) = m(u,v) | ||
rhs(t,u,v) = b(v,t) + b_Γ(v,t) - a(u,v) - a_Γ(u,v) - a_Λ(u,v) | ||
jac(t,u,du,v) = a(du,v) + a_Γ(du,v) + a_Λ(du,v) | ||
jac_t(t,u,dut,v) = m(dut,v) | ||
|
||
op = TransientEXRungeKuttaFEOperator(lhs,rhs,jac,jac_t,U,V0) | ||
|
||
t0 = 0.0 | ||
tF = 10.0 | ||
dt = 0.001 | ||
|
||
U0 = U(0.0) | ||
uh0 = interpolate_everywhere(u(0.0),U0) | ||
|
||
ls = LUSolver() | ||
# ode_solver = EXRungeKutta(ls,dt,:EX_FE_1_0_1) | ||
ode_solver = EXRungeKutta(ls,dt,:EX_SSP_3_0_3) | ||
|
||
sol_t = solve(ode_solver,op,uh0,t0,tF) | ||
|
||
l2(w) = w*w | ||
|
||
tol = 1.0e-6 | ||
|
||
errors_rk_fe = [] | ||
ts_rk_fe = [] | ||
for (uh_tn, tn) in sol_t | ||
|
||
e = u(tn) - uh_tn | ||
el2 = sqrt(sum( ∫(l2(e))dΩ )) #/ ( sqrt(sum( ∫(l2( u(tn) ))dΩ )) ) | ||
println(el2, tn) | ||
@test el2 < tol | ||
|
||
errors_rk_fe = [errors_rk_fe; el2] | ||
ts_rk_fe = [ts_rk_fe; tn] | ||
end | ||
|
||
|
||
|
||
plot(ts_rk_fe,errors_rk_fe) | ||
plot!( | ||
#shape=:auto, | ||
xlabel="t", | ||
ylabel="relative error", | ||
title="RK-FE" | ||
# yaxis=:log | ||
) | ||
plot!(show=true) | ||
savefig(string("rk_fe_error_dG")) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using Pkg | ||
Pkg.add(url="https://github.com/tamaratambyah/Gridap.jl", rev="rungekutta") | ||
|
||
using Gridap | ||
using Plots | ||
using Test | ||
|
||
u(x,t) = x[1]*(1-x[1])*t | ||
u(t) = x -> u(x,t) | ||
∂tu = ∂t(u) | ||
f(t) = x -> ∂t(u)(x,t)-Δ(u(t))(x) | ||
|
||
|
||
domain = (0,1) | ||
partition = (2) | ||
model = CartesianDiscreteModel(domain,partition) | ||
|
||
order = 2 | ||
|
||
reffe = ReferenceFE(lagrangian,Float64,order) | ||
V0 = FESpace( | ||
model, | ||
reffe, | ||
conformity=:H1, | ||
dirichlet_tags="boundary" | ||
) | ||
U = TransientTrialFESpace(V0,u) | ||
|
||
Ω = Triangulation(model) | ||
degree = 2*order | ||
dΩ = Measure(Ω,degree) | ||
|
||
# | ||
lhs(t,u,v) = ∫( v* (u) )dΩ | ||
rhs(t,u,v) = ∫(v*f(t))dΩ - ∫(( ∇(v)⊙∇(u) ))dΩ | ||
jac(t,u,du,v) = ∫(( ∇(v)⊙∇(du) ))dΩ | ||
jac_t(t,u,dut,v) = ∫( dut*v )dΩ | ||
|
||
op = TransientEXRungeKuttaFEOperator(lhs,rhs,jac,jac_t,U,V0) | ||
|
||
t0 = 0.0 | ||
tF = 10.0 | ||
dt = 0.001 | ||
|
||
uh0 = interpolate_everywhere(u(0.0),U(0.0)) | ||
|
||
ls = LUSolver() | ||
# ode_solver = EXRungeKutta(ls,dt,:EX_FE_1_0_1) | ||
# ode_solver = EXRungeKutta(ls,dt,:EX_SSP_3_0_3) | ||
ode_solver = DIRungeKutta(ls,dt,:BE_1_0_1) | ||
sol_t = solve(ode_solver,op,uh0,t0,tF) | ||
|
||
|
||
l2(w) = w*w | ||
|
||
tol = 1.0e-6 | ||
|
||
errors_rk_fe = [] | ||
ts_rk_fe = [] | ||
for (uh_tn, tn) in sol_t | ||
e = interpolate_everywhere(u(tn),U(tn)) - uh_tn | ||
el2 = sqrt(sum( ∫(l2(e))dΩ )) | ||
println(el2) | ||
@test el2< tol | ||
@test ~any( isnan.(get_free_dof_values(uh_tn))) | ||
|
||
errors_rk_fe = [errors_rk_fe; el2] | ||
ts_rk_fe = [ts_rk_fe; tn] | ||
end | ||
|
||
|
||
|
||
plot(ts_rk_fe,errors_rk_fe) | ||
plot!( | ||
#shape=:auto, | ||
xlabel="t", | ||
ylabel="relative error", | ||
title="RK-FE" | ||
# yaxis=:log | ||
) | ||
plot!(show=true) | ||
savefig(string("rk_fe_error")) | ||
|
||
|
||
|
||
sol_t = solve(ode_solver,op,uh0,t0,tF) | ||
createpvd("my_tests/transient_sol/poisson_transient_solution") do pvd | ||
for (uh,t) in sol_t | ||
pvd[t] = createvtk(Ω,"my_tests/transient_sol/poisson_transient_solution_$t"*".vtu",cellfields=["u"=>uh]) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using Pkg | ||
Pkg.add(url="https://github.com/tamaratambyah/Gridap.jl", rev="rungekutta") | ||
|
||
using Gridap | ||
using Plots | ||
using Test | ||
|
||
u(x,t) = (1.0-x[1])*x[1]*(1.0-x[2])*x[2]*t | ||
u(t) = x -> u(x,t) | ||
∂tu = ∂t(u) | ||
f(t) = x -> ∂t(u)(x,t)-Δ(u(t))(x) | ||
|
||
|
||
domain = (0,1,0,1) | ||
partition = (2,2) | ||
model = CartesianDiscreteModel(domain,partition) | ||
|
||
order = 2 | ||
|
||
reffe = ReferenceFE(lagrangian,Float64,order) | ||
V0 = FESpace( | ||
model, | ||
reffe, | ||
conformity=:H1, | ||
dirichlet_tags="boundary" | ||
) | ||
U = TransientTrialFESpace(V0,u) | ||
|
||
Ω = Triangulation(model) | ||
degree = 2*order | ||
dΩ = Measure(Ω,degree) | ||
|
||
# | ||
lhs(t,u,v) = ∫( v* (u) )dΩ | ||
rhs(t,u,v) = ∫(v*f(t))dΩ - ∫(( ∇(v)⊙∇(u) ))dΩ | ||
jac(t,u,du,v) = ∫(( ∇(v)⊙∇(du) ))dΩ | ||
jac_t(t,u,dut,v) = ∫( dut*v )dΩ | ||
|
||
op = TransientEXRungeKuttaFEOperator(lhs,rhs,jac,jac_t,U,V0) | ||
|
||
t0 = 0.0 | ||
tF = 1.0 | ||
dt = 0.001 | ||
|
||
uh0 = interpolate_everywhere(u(0.0),U(0.0)) | ||
|
||
ls = LUSolver() | ||
# ode_solver = EXRungeKutta(ls,dt,:EX_FE_1_0_1) | ||
ode_solver = EXRungeKutta(ls,dt,:EX_SSP_3_0_3) | ||
|
||
sol_t = solve(ode_solver,op,uh0,t0,tF) | ||
|
||
|
||
l2(w) = w*w | ||
|
||
tol = 1.0e-6 | ||
|
||
errors_rk_fe = [] | ||
ts_rk_fe = [] | ||
for (uh_tn, tn) in sol_t | ||
e = u(tn) - uh_tn | ||
el2 = sqrt(sum( ∫(l2(e))dΩ )) | ||
println(el2) | ||
@test el2< tol | ||
|
||
errors_rk_fe = [errors_rk_fe; el2] | ||
ts_rk_fe = [ts_rk_fe; tn] | ||
end | ||
|
||
|
||
plot(ts_rk_fe,errors_rk_fe) | ||
plot!( | ||
#shape=:auto, | ||
xlabel="t", | ||
ylabel="relative error", | ||
title="RK-FE" | ||
# yaxis=:log | ||
) | ||
plot!(show=true) | ||
savefig(string("rk_fe_error_2D")) | ||
|
||
|
||
createpvd("my_tests/transient_sol/poisson_transient_solution") do pvd | ||
for (uh,t) in sol_t | ||
pvd[t] = createvtk(Ω,"my_tests/transient_sol/poisson_transient_solution_$t"*".vtu",cellfields=["u"=>uh]) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole my_tests folder should not be pushed to the main gridap project
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
started clean branch of master fork. my_tests folder is removed