From 5e289dd97832116c01b7e05a13648d084b3944ea Mon Sep 17 00:00:00 2001 From: Yueh-Hua Tu Date: Sun, 17 Jul 2022 15:43:41 +0800 Subject: [PATCH] fem complete update README and format --- example/Burgers_FEM/Project.toml | 17 ++++++++++ example/Burgers_FEM/README.md | 9 +++++ example/Burgers_FEM/src/Burgers_FEM.jl | 46 ++++++++++++++++++++++++++ example/Burgers_FEM/test/runtests.jl | 6 ++++ test/runtests.jl | 1 + 5 files changed, 79 insertions(+) create mode 100644 example/Burgers_FEM/Project.toml create mode 100644 example/Burgers_FEM/README.md create mode 100644 example/Burgers_FEM/src/Burgers_FEM.jl create mode 100644 example/Burgers_FEM/test/runtests.jl diff --git a/example/Burgers_FEM/Project.toml b/example/Burgers_FEM/Project.toml new file mode 100644 index 00000000..492413f0 --- /dev/null +++ b/example/Burgers_FEM/Project.toml @@ -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"] diff --git a/example/Burgers_FEM/README.md b/example/Burgers_FEM/README.md new file mode 100644 index 00000000..abb1e741 --- /dev/null +++ b/example/Burgers_FEM/README.md @@ -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() +``` diff --git a/example/Burgers_FEM/src/Burgers_FEM.jl b/example/Burgers_FEM/src/Burgers_FEM.jl new file mode 100644 index 00000000..54d0e83c --- /dev/null +++ b/example/Burgers_FEM/src/Burgers_FEM.jl @@ -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 diff --git a/example/Burgers_FEM/test/runtests.jl b/example/Burgers_FEM/test/runtests.jl new file mode 100644 index 00000000..7ea9e5e8 --- /dev/null +++ b/example/Burgers_FEM/test/runtests.jl @@ -0,0 +1,6 @@ +using Burgers_FEM +using Test + +@testset "Burgers_FEM.jl" begin + # Write your tests here. +end diff --git a/test/runtests.jl b/test/runtests.jl index 6ffe561a..4fd870cf 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -27,3 +27,4 @@ end  l、゙ ~ヽ  じしf_, )ノ =# +# Want some fish?