Skip to content
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

Closed
wants to merge 141 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
10dcb08
adding initial explicit rk infrastructure
tamaratambyah Oct 11, 2023
c774d9a
updating FE tableau
tamaratambyah Oct 11, 2023
b73af29
updating exports
tamaratambyah Oct 11, 2023
32e4d2f
updating ex tableau constructor
tamaratambyah Oct 11, 2023
94a8021
updating EXTransientRKFEOP
tamaratambyah Oct 11, 2023
860a54a
changing gi to fi
tamaratambyah Oct 11, 2023
b0a9426
fixing weak form op
tamaratambyah Oct 11, 2023
fdf0d76
removing explicit rhs
tamaratambyah Oct 11, 2023
115e7da
first stage forward euler
tamaratambyah Oct 12, 2023
77260d5
updating jacobian
tamaratambyah Oct 12, 2023
a0ec1e5
removing forward euler stage 1
tamaratambyah Oct 12, 2023
01e12cd
removing implicit residual
tamaratambyah Oct 12, 2023
c4a91cd
adding FE table
tamaratambyah Oct 12, 2023
b74c834
puting back residual
tamaratambyah Oct 12, 2023
801c823
updating FE table
tamaratambyah Oct 12, 2023
4e07d76
fixing some comments
tamaratambyah Oct 12, 2023
6795124
ignoring vtu,pvd files
tamaratambyah Oct 12, 2023
3b67fa9
initial test problem for RK methods (tutorial 17)
tamaratambyah Oct 12, 2023
cebb289
modifying RungeKutta to remove aij=0 condition
tamaratambyah Oct 12, 2023
15de64d
removing update func
tamaratambyah Oct 13, 2023
d6f8eed
adding ssprk3 table
tamaratambyah Oct 13, 2023
41a7a73
adding if statement back to rungekutta method
tamaratambyah Oct 15, 2023
6d52485
updating sum to be i-1
tamaratambyah Oct 18, 2023
e912ceb
changing jac functions to be same as RungeKutta
tamaratambyah Oct 18, 2023
046a21b
fixing typo
tamaratambyah Oct 18, 2023
2f95b08
fixing
tamaratambyah Oct 18, 2023
5e2bebc
fixing
tamaratambyah Oct 18, 2023
eec1acb
minor changes
tamaratambyah Oct 18, 2023
9f1a818
updating my tests
tamaratambyah Oct 19, 2023
d05d095
removing
tamaratambyah Oct 19, 2023
09c9710
accounting for non linear f
tamaratambyah Oct 19, 2023
e1d30a6
fixing
tamaratambyah Oct 19, 2023
372ce38
minor updates
tamaratambyah Oct 19, 2023
8cd4422
minor changes to rhs! functions
tamaratambyah Oct 19, 2023
fb27722
updating rungekutta for nonlinear f
tamaratambyah Oct 19, 2023
4fb59e1
changing werid 2 input to 1
tamaratambyah Oct 20, 2023
1dc710c
changing werid 2 input to 1
tamaratambyah Oct 20, 2023
72c733b
minor comments
tamaratambyah Oct 20, 2023
7182846
stepping through rk method
tamaratambyah Oct 20, 2023
e84a4a6
adding manufactured soln
tamaratambyah Oct 20, 2023
0bd09cb
gutting RK and starting with FE
tamaratambyah Oct 21, 2023
8937390
fixing constructor
tamaratambyah Oct 21, 2023
2b4f8d2
minor update
tamaratambyah Oct 22, 2023
bb11b3b
modifying allocate_residual + jacobian
tamaratambyah Oct 22, 2023
13915bd
adding back in ui
tamaratambyah Oct 23, 2023
2239cd8
adding back in ui
tamaratambyah Oct 23, 2023
4343fc2
adding ti back in
tamaratambyah Oct 23, 2023
156f2b9
minor changes
tamaratambyah Oct 23, 2023
e787dba
minor changes
tamaratambyah Oct 23, 2023
abddb61
minor
tamaratambyah Oct 23, 2023
9718544
removing ui
tamaratambyah Oct 23, 2023
5375b72
adding ui back in
tamaratambyah Oct 23, 2023
d31c4cf
adding ui back in
tamaratambyah Oct 23, 2023
92fd4f4
adding final update as linear combination
tamaratambyah Oct 23, 2023
47e27cb
fixing indexing error
tamaratambyah Oct 23, 2023
b05a77c
trying the old rk code
tamaratambyah Oct 25, 2023
6b70420
fixing typo
tamaratambyah Oct 25, 2023
50afea4
fixing inputs
tamaratambyah Oct 25, 2023
264d701
fixing jac
tamaratambyah Oct 25, 2023
46caf87
updating scripts
tamaratambyah Oct 26, 2023
08f045c
updating res and jac
tamaratambyah Oct 30, 2023
7a880fb
fixing comments
tamaratambyah Oct 31, 2023
5001e0c
editing fi
tamaratambyah Oct 31, 2023
98db57c
updating EX FE Op
tamaratambyah Oct 31, 2023
64c144f
fixing typo
tamaratambyah Oct 31, 2023
da2d61b
editing get fi
tamaratambyah Oct 31, 2023
1991e12
editing get fi
tamaratambyah Oct 31, 2023
45fc322
editing get fi
tamaratambyah Oct 31, 2023
afe6cb8
editing get fi
tamaratambyah Oct 31, 2023
f5ec63d
updating fi
tamaratambyah Oct 31, 2023
a5a56ca
updating residual
tamaratambyah Oct 31, 2023
c3252f7
adding lhs function
tamaratambyah Oct 31, 2023
45c5585
updating lhs
tamaratambyah Oct 31, 2023
ae6f2b2
fixing .=
tamaratambyah Oct 31, 2023
e277a94
updating lhs
tamaratambyah Oct 31, 2023
82914d6
adding print statement
tamaratambyah Oct 31, 2023
294ad48
updating allocate residual
tamaratambyah Oct 31, 2023
f0f7be8
updating operator
tamaratambyah Nov 1, 2023
f945230
changing fi to ki
tamaratambyah Nov 1, 2023
4af777f
editing jacobian:
tamaratambyah Nov 1, 2023
d87313e
editing jacobian:
tamaratambyah Nov 1, 2023
abb8b46
updates to residual
tamaratambyah Nov 1, 2023
4735eef
updated cache
tamaratambyah Nov 1, 2023
a5b795d
updated cache
tamaratambyah Nov 1, 2023
58273df
updating residual
tamaratambyah Nov 1, 2023
0dd6e9d
updating residual
tamaratambyah Nov 1, 2023
7f622a1
updating residual
tamaratambyah Nov 1, 2023
7881ca1
updating residual
tamaratambyah Nov 1, 2023
c179529
updating residual
tamaratambyah Nov 1, 2023
9d38d4e
updating residual
tamaratambyah Nov 1, 2023
775f82e
works for first time step
tamaratambyah Nov 1, 2023
804de59
adding back rhs
tamaratambyah Nov 1, 2023
43f6d2a
adding back rhs
tamaratambyah Nov 2, 2023
16f1a64
updating residual
tamaratambyah Nov 2, 2023
7cf4112
updating residual
tamaratambyah Nov 2, 2023
1d312e5
updating EX RK - works for FE
tamaratambyah Nov 2, 2023
22c71a2
tidying
tamaratambyah Nov 2, 2023
a98f5a7
adding cache back
tamaratambyah Nov 2, 2023
34f228b
working fe
tamaratambyah Nov 2, 2023
6da6db9
store M and use in jacobian
tamaratambyah Nov 2, 2023
e60d258
store M and use in jacobian
tamaratambyah Nov 2, 2023
78beb01
fixing cache
tamaratambyah Nov 2, 2023
94eea87
fixing input types
tamaratambyah Nov 2, 2023
510235b
adding more testing
tamaratambyah Nov 3, 2023
f2dbde9
updating
tamaratambyah Nov 3, 2023
c42a38a
updating
tamaratambyah Nov 3, 2023
b5dd6d1
testing residual
tamaratambyah Nov 6, 2023
5ad8ed3
testing residual
tamaratambyah Nov 6, 2023
bbb0786
fixing dependency
tamaratambyah Nov 6, 2023
8f4d54e
fixing dependency
tamaratambyah Nov 6, 2023
058c00f
tidying
tamaratambyah Nov 6, 2023
43e662d
residual and jac
tamaratambyah Nov 6, 2023
353e8ce
using M in jac
tamaratambyah Nov 6, 2023
2eb5b9f
going back to jacobians
tamaratambyah Nov 6, 2023
defd1d2
going back to M for jac
tamaratambyah Nov 6, 2023
af6b5a1
updating tests
tamaratambyah Nov 7, 2023
81ce278
first attempt at multistage
tamaratambyah Nov 7, 2023
8fdc5f3
fixing dt
tamaratambyah Nov 7, 2023
76a54ae
updating for multi stage ssprk3
tamaratambyah Nov 7, 2023
cb81ce4
attempt to optimise multi stage
tamaratambyah Nov 7, 2023
37ef83e
fixing update
tamaratambyah Nov 7, 2023
93bd409
editing residual
tamaratambyah Nov 7, 2023
d62365a
changing residual back
tamaratambyah Nov 7, 2023
b242b70
going back to FE
tamaratambyah Nov 7, 2023
b4e3391
multi stage
tamaratambyah Nov 7, 2023
45defc6
fixing residual
tamaratambyah Nov 7, 2023
60d33b7
adding linear wave equation test
tamaratambyah Nov 7, 2023
1d516c9
removing Fe function build
tamaratambyah Nov 8, 2023
fe6436d
removing eval
tamaratambyah Nov 8, 2023
c33ae46
returning dofs
tamaratambyah Nov 8, 2023
5161c8f
initial commit of DIRK
tamaratambyah Nov 8, 2023
2c8784a
fixing bt
tamaratambyah Nov 8, 2023
6b29434
fixing bt
tamaratambyah Nov 8, 2023
3001807
fixing export
tamaratambyah Nov 8, 2023
cf75856
fixing i
tamaratambyah Nov 8, 2023
fc627bf
removing M from cache
tamaratambyah Nov 8, 2023
6510314
printing iters
tamaratambyah Nov 8, 2023
332a0be
updating tests
tamaratambyah Nov 8, 2023
c65061c
updating packages
tamaratambyah Nov 8, 2023
7c63398
updating comments
tamaratambyah Nov 8, 2023
bc633db
updating to include coriolis
tamaratambyah Nov 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ docs/build/
Manifest.toml
tmp/
.vscode/
*.vtu
*.pvd
97 changes: 97 additions & 0 deletions my_tests/TransientFEsTests/BoundaryHeatEquationTests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using Pkg
Copy link
Member

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

Copy link
Collaborator Author

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


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all these tests related to the ExRK dev?
If not, we do not need these tests here.
I do recommend to start from a fresh Gridap fork, add the ExRK dev, and we start again

Copy link
Collaborator Author

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.


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"))
100 changes: 100 additions & 0 deletions my_tests/TransientFEsTests/DGHeatEquationTests.jl
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"))
91 changes: 91 additions & 0 deletions my_tests/TransientFEsTests/HeatEquationTest_1D.jl
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
87 changes: 87 additions & 0 deletions my_tests/TransientFEsTests/HeatEquationTest_2D.jl
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
Loading