Skip to content

Commit

Permalink
trying again with SVG images, added test for Example200
Browse files Browse the repository at this point in the history
  • Loading branch information
chmerdon committed Dec 19, 2023
1 parent e5293c3 commit 0c05fe4
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 12 deletions.
2 changes: 2 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ function make_all(; with_examples::Bool = true)
pluto_examples = []

if with_examples

DocMeta.setdocmeta!(ExampleJuggler, :DocTestSetup, :(using ExampleJuggler); recursive = true)

example_dir = joinpath(@__DIR__, "..", "examples")
pluto_example_dir = joinpath(@__DIR__, "..", "pluto-examples")
Expand Down
8 changes: 8 additions & 0 deletions docs/src/fems.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,11 @@ HCURLN0
HCURLN1
```


## Incomplete finite elements without approximation power

```@docs
H1BUBBLE
```


32 changes: 26 additions & 6 deletions examples/Example200_LowLevelPoisson.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ for different refinement levels.
The computed solution for the default parameters looks like this:
![](example200.jpg)
![](example200.svg)
=#

Expand All @@ -28,6 +28,7 @@ using ExtendableGrids
using ExtendableSparse
using GridVisualize
using UnicodePlots
using Test #

## data for Poisson problem
const μ = 1.0
Expand All @@ -46,6 +47,7 @@ function main(; maxnref = 8, order = 2, Plotter = nothing)

## loop over uniform refinements + timings
plt = GridVisualizer(; Plotter = Plotter, layout = (1, 1), clear = true, resolution = (500, 500))
loop_allocations = 0
for level 1:maxnref
X = LinRange(0, 1, 2^level + 1)
time_grid = @elapsed xgrid = simplexgrid(X, X)
Expand All @@ -62,7 +64,7 @@ function main(; maxnref = 8, order = 2, Plotter = nothing)
println(stdout, barplot(["Grid", "FaceNodes", "CellDofs", "Assembly", "Solve"], [time_grid, time_facenodes, time_dofmap, time_assembly, time_solve], title = "Runtimes"))

## plot
scalarplot!(plt[1,1], xgrid, view(sol.entries, 1:num_nodes(xgrid)), levels = 5)
scalarplot!(plt[1,1], xgrid, view(sol.entries, 1:num_nodes(xgrid)))
end

return sol, plt
Expand All @@ -76,7 +78,7 @@ function solve_poisson_lowlevel(FES, μ, f)
b = FEVector(FES)
println("Assembling...")
time_assembly = @elapsed @time begin
assemble!(A.entries, b.entries, FES, f, μ)
loop_allocations = assemble!(A.entries, b.entries, FES, f, μ)

## fix boundary dofs
begin
Expand Down Expand Up @@ -123,6 +125,7 @@ function assemble!(A::ExtendableSparseMatrix, b::Vector, FES, f, μ = 1)
CellDofs = FES[ExtendableFEMBase.CellDofs]

## ASSEMBLY LOOP
loop_allocations = 0
function barrier(EG, L2G::L2GTransformer)
## barrier function to avoid allocations by type dispatch

Expand All @@ -132,7 +135,7 @@ function assemble!(A::ExtendableSparseMatrix, b::Vector, FES, f, μ = 1)
dof_j::Int, dof_k::Int = 0, 0
x::Vector{Float64} = zeros(Float64, 2)

for cell 1:ncells
loop_allocations += @allocated for cell 1:ncells
## update FE basis evaluators
FEBasis_∇.citem[] = cell
update_basis!(FEBasis_∇)
Expand Down Expand Up @@ -182,12 +185,29 @@ function assemble!(A::ExtendableSparseMatrix, b::Vector, FES, f, μ = 1)
end
barrier(EG, L2G)
flush!(A)
return loop_allocations
end

function generateplots(dir = pwd(); Plotter = nothing, kwargs...)
~, plt = main(; Plotter = Plotter, kwargs...)
~, plt, ~ = main(; Plotter = Plotter, kwargs...)
scene = GridVisualize.reveal(plt)
GridVisualize.save(joinpath(dir, "example200.jpg"), scene; Plotter = Plotter)
GridVisualize.save(joinpath(dir, "example200.svg"), scene; Plotter = Plotter)
end

function runtests(; order = 2, kwargs...) #hide
FEType = H1Pk{1, 2, order}
X = LinRange(0, 1, 64)
xgrid = simplexgrid(X, X)
FES = FESpace{FEType}(xgrid)
A = FEMatrix(FES, FES)
b = FEVector(FES)
@info "ndofs = $(FES.ndofs)"
## first assembly causes allocations when filling sparse matrix
loop_allocations = assemble!(A.entries, b.entries, FES, f, μ)
@info "allocations in 1st assembly: $loop_allocations"
## second assebly in same matrix should have allocation-free inner loop
loop_allocations = assemble!(A.entries, b.entries, FES, f, μ)
@info "allocations in 2nd assembly: $loop_allocations"
@test loop_allocations == 0
end #hide
end #module
4 changes: 2 additions & 2 deletions examples/Example210_LowLevelNavierStokes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Newton's method with automatic differentation is used to handle the nonlinear co
The computed solution for the default parameters looks like this:
![](example210.png)
![](example210.svg)
=#

module Example210_LowLevelNavierStokes
Expand Down Expand Up @@ -400,6 +400,6 @@ end
function generateplots(dir = pwd(); Plotter = nothing, kwargs...)
~, plt = main(; Plotter = Plotter, kwargs...)
scene = GridVisualize.reveal(plt)
GridVisualize.save(joinpath(dir, "example210.png"), scene; Plotter = Plotter)
GridVisualize.save(joinpath(dir, "example210.svg"), scene; Plotter = Plotter)
end
end #module
4 changes: 2 additions & 2 deletions examples/Example281_DiscontinuousPlot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on a grid with two regions by region-wise nodal values and plotting.
The computed solution for the default parameters looks like this:
![](example281.png)
![](example281.svg)
=#

module Example281_DiscontinuousPlot
Expand Down Expand Up @@ -71,6 +71,6 @@ end
function generateplots(dir = pwd(); Plotter = nothing, kwargs...)
plt = main(; Plotter = Plotter, kwargs...)
scene = GridVisualize.reveal(plt)
GridVisualize.save(joinpath(dir, "example281.png"), scene; Plotter = Plotter)
GridVisualize.save(joinpath(dir, "example281.svg"), scene; Plotter = Plotter)
end
end
4 changes: 2 additions & 2 deletions examples/Example290_InterpolationBetweenMeshes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ this P2 function on two uniform refinements into some P1 function. Then, both fi
The computed solution for the default parameters looks like this:
![](example290.png)
![](example290.svg)
=#

module Example290_InterpolationBetweenMeshes
Expand Down Expand Up @@ -62,7 +62,7 @@ end
function generateplots(dir = pwd(); Plotter = nothing, kwargs...)
plt = main(; Plotter = Plotter, kwargs...)
scene = GridVisualize.reveal(plt)
GridVisualize.save(joinpath(dir, "example290.png"), scene; Plotter = Plotter)
GridVisualize.save(joinpath(dir, "example290.svg"), scene; Plotter = Plotter)
end

end
4 changes: 4 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
[deps]
ExtendableFEMBase = "12fb9182-3d4c-4424-8fd1-727a0899810c"
ExtendableSparse = "95c220a8-a1cf-11e9-0c77-dbfce5f500b3"
ExtendableGrids = "cfc395e8-590f-11e8-1f13-43a2532b2fa8"
ExampleJuggler = "3bbe58f8-ed81-4c4e-a134-03e85fcf4a1a"
GridVisualize = "5eed8a63-0fb0-45eb-886d-8d5a387d12b8"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
16 changes: 16 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Test
using ExtendableGrids
using ExtendableFEMBase
using ExampleJuggler

include("test_quadrature.jl")
include("test_interpolators.jl")
Expand All @@ -9,6 +10,20 @@ include("test_febasis.jl")
include("test_segmentintegrator.jl")
include("test_pointevaluator.jl")

function run_examples()
ExampleJuggler.verbose!(true)

example_dir = joinpath(@__DIR__, "..", "examples")

modules = [
"Example200_LowLevelPoisson.jl",
]

@testset "module examples" begin
@testmodules(example_dir, modules)
end
end

function testgrid(::Type{Edge1D})
return uniform_refine(simplexgrid([0.0,1//4,2//3,1.0]),1)
end
Expand Down Expand Up @@ -105,6 +120,7 @@ end

function run_all_tests()
begin
run_examples()
run_febasis_tests()
run_operator_tests()
run_quadrature_tests()
Expand Down

0 comments on commit 0c05fe4

Please sign in to comment.