diff --git a/test/example-poisson-source.jl b/test/example-poisson-source.jl new file mode 100644 index 0000000000000000000000000000000000000000..48cbc973e7399d02b72016ce3505691ebb0a232e --- /dev/null +++ b/test/example-poisson-source.jl @@ -0,0 +1,31 @@ +using LinearAlgebra: dot, norm +using SemiSmoothNewton +using SemiSmoothNewton: vtk_mesh, vtk_append!, vtk_save + +# simple 2d unit square triangulation +mesh = init_grid(32, 32) + +# scalar piecewise linear continuous elements +space = FeSpace(mesh, P1(), (1,)) +u = FeFunction(space, name = "u") + +# inhomogenity +const p = (0.25, 0.5) +f(x) = 5 * exp(-5 * norm(x .- p)^2) +# parameter +const lambda = 19.7 + +# weak formulation +a(x, u, d_u, phi, d_phi) = + dot(d_u, d_phi) + lambda^2 * dot(u, phi) +l(x, phi, d_phi) = + dot(f(x), phi) + +# solve u +A, b = assemble(space, a, l) +u.data .= A \ b + +# vtk output +vtk = vtk_mesh("output.vtu", mesh) +vtk_append!(vtk, u) +vtk_save(vtk)