Skip to content
This repository has been archived by the owner on Sep 28, 2024. It is now read-only.

Burgers' equation resolved by FEM #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions example/Burgers_FEM/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name = "Burgers_FEM"
uuid = "e5170f7b-8a26-429b-971b-688deff48327"
authors = ["Yueh-Hua Tu"]
version = "0.1.0"

[deps]
FEniCS = "186dfeec-b415-5c13-8e76-5fbf19f56f9b"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"

[compat]
julia = "1.6"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
9 changes: 9 additions & 0 deletions example/Burgers_FEM/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Burgers' equation resolved by finite element method

This example exhibits PDE problem for Burgers' equation resolved by finite element method. Change directory to `example/Burgers_FEM` and use following commend to solve the problem:

```julia
$ julia --proj

julia> using Burgers_FEM; Burgers_FEM.run_fem()
```
46 changes: 46 additions & 0 deletions example/Burgers_FEM/src/Burgers_FEM.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module Burgers_FEM

using FEniCS

function run_fem(ν = 1 / 1000)
# parameters
s = 1024 # x
steps = 200 # t

DT = Constant(1 / steps)
dt = 1 / steps

mesh = UnitIntervalMesh(s)
V = FunctionSpace(mesh, "CG", 1)

bc = DirichletBC(V, 0.0, "on_boundary")

u_init = Expression("x[0]", degree = 1)
u = TrialFunction(V)
u_old = FeFunction(V)
v = TestFunction(V)

u = interpolate(u_init, V)
assign(u_old, u)

f = Expression("0.0", degree = 0)

F = (dot(u - u_old, v) / DT
+ ν * inner(grad(u), grad(v))
+ inner(u * directional_derivative(u, 0), v)
-
dot(f, v)) * dx

us = Vector{Float64}[]
t = 0.0
for n in 1:steps
t = t + dt
nlvsolve(F, u, bc)
push!(us, get_array(u))
assign(u_old, u)
end

return us
end

end
6 changes: 6 additions & 0 deletions example/Burgers_FEM/test/runtests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using Burgers_FEM
using Test

@testset "Burgers_FEM.jl" begin
# Write your tests here.
Copy link
Contributor

Choose a reason for hiding this comment

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

any test for this?

end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ end
 l、゙ ~ヽ
 じしf_, )ノ
=#
# Want some fish?
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# Want some fish?