Skip to content

Commit

Permalink
updated version requirements, several small improvements, pngs instea…
Browse files Browse the repository at this point in the history
…d of svgs in examples, version bump
  • Loading branch information
chmerdon committed Jun 24, 2024
1 parent 242e0f3 commit d5d7ae8
Show file tree
Hide file tree
Showing 15 changed files with 192 additions and 76 deletions.
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ExtendableFEMBase"
uuid = "12fb9182-3d4c-4424-8fd1-727a0899810c"
authors = ["Christian Merdon <[email protected]>"]
version = "0.4"
version = "0.5"

[deps]
DiffResults = "163ba53b-c6d8-5494-b064-1a9d43ac40c5"
Expand All @@ -20,8 +20,8 @@ UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
[compat]
DiffResults = "1"
DocStringExtensions = "0.8,0.9"
ExtendableGrids = "1.3"
ExtendableSparse = "^1.2"
ExtendableGrids = "1.8"
ExtendableSparse = "^1.4"
ForwardDiff = "^0.10.35"
Term = "2"
UnicodePlots = "^3.6"
Expand Down
Binary file added assets/example280.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 12 additions & 19 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.svg)
![](example200.png)
=#

Expand Down Expand Up @@ -61,10 +61,10 @@ function main(; maxnref = 8, order = 2, Plotter = nothing)
sol, time_assembly, time_solve = solve_poisson_lowlevel(FES, μ, f)

## plot statistics
println(stdout, barplot(["Grid", "FaceNodes", "CellDofs", "Assembly", "Solve"], [time_grid, time_facenodes, time_dofmap, time_assembly, time_solve], title = "Runtimes"))
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)))
scalarplot!(plt[1,1], xgrid, view(sol.entries, 1:num_nodes(xgrid)), limits = (-0.0125,0.0125))
end

return sol, plt
Expand All @@ -82,16 +82,10 @@ function solve_poisson_lowlevel(FES, μ, f)

## fix boundary dofs
begin
BFaceDofs::Adjacency{Int32} = FES[ExtendableFEMBase.BFaceDofs]
nbfaces::Int = num_sources(BFaceDofs)
AM::ExtendableSparseMatrix{Float64, Int64} = A.entries
dof_j::Int = 0
for bface 1:nbfaces
for j 1:num_targets(BFaceDofs, 1)
dof_j = BFaceDofs[j, bface]
AM[dof_j, dof_j] = 1e60
b.entries[dof_j] = 0
end
bdofs = boundarydofs(FES)
for dof in bdofs
A.entries[dof, dof] = 1e60
b.entries[dof] = 0
end
end
ExtendableSparse.flush!(A.entries)
Expand Down Expand Up @@ -122,13 +116,12 @@ function assemble!(A::ExtendableSparseMatrix, b::Vector, FES, f, μ = 1)
∇vals = FEBasis_∇.cvals
FEBasis_id = FEEvaluator(FES, Identity, qf)
idvals = FEBasis_id.cvals
CellDofs = FES[ExtendableFEMBase.CellDofs]
celldofs = FES[CellDofs]

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

ndofs4cell::Int = get_ndofs(ON_CELLS, FEType, EG)
Aloc = zeros(Float64, ndofs4cell, ndofs4cell)
ncells::Int = num_cells(xgrid)
Expand All @@ -152,9 +145,9 @@ function assemble!(A::ExtendableSparseMatrix, b::Vector, FES, f, μ = 1)

## add local matrix to global matrix
for j 1:ndofs4cell
dof_j = CellDofs[j, cell]
dof_j = celldofs[j, cell]
for k j:ndofs4cell
dof_k = CellDofs[k, cell]
dof_k = celldofs[k, cell]
if abs(Aloc[j, k]) > 1e-15
## write into sparse matrix, only lines with allocations
rawupdateindex!(A, +, Aloc[j, k], dof_j, dof_k)
Expand All @@ -178,7 +171,7 @@ function assemble!(A::ExtendableSparseMatrix, b::Vector, FES, f, μ = 1)
temp += weights[qp] * idvals[1, j, qp] * f(x)
end
## write into global vector
dof_j = CellDofs[j, cell]
dof_j = celldofs[j, cell]
b[dof_j] += temp * cellvolumes[cell]
end
end
Expand All @@ -191,7 +184,7 @@ end
function generateplots(dir = pwd(); Plotter = nothing, kwargs...)
~, plt = main(; Plotter = Plotter, kwargs...)
scene = GridVisualize.reveal(plt)
GridVisualize.save(joinpath(dir, "example200.svg"), scene; Plotter = Plotter)
GridVisualize.save(joinpath(dir, "example200.png"), scene; Plotter = Plotter)
end

function runtests(; order = 2, kwargs...) #hide
Expand Down
20 changes: 8 additions & 12 deletions examples/Example205_LowLevelSpaceTimePoisson.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on the unit square domain ``\Omega`` on a given grid
with space-time finite element methods based on
tensorized ansatz functions.
![](example205.svg)
![](example205.png)
=#

Expand Down Expand Up @@ -99,23 +99,19 @@ function solve_poisson_lowlevel(FES_time, FES_space, μ, f)
loop_allocations = assemble!(A, b, FES_time, FES_space, f, μ)

## fix homogeneous boundary dofs
bfacedofs::Adjacency{Int32} = FES_space[ExtendableFEMBase.BFaceDofs]
nbfaces::Int = num_sources(bfacedofs)
dof::Int = 0
for bface 1:nbfaces
bdofs = boundarydofs(FES_space)
for sdof in bdofs
for dof_t = 1 : ndofs_time
for j 1:num_targets(bfacedofs, 1)
dof = (dof_t-1)*ndofs_space + bfacedofs[j, bface]
A[dof, dof] = 1e60
b[dof] = 0
end
dof = (dof_t-1)*ndofs_space + sdof
A[dof, dof] = 1e60
b[dof] = 0
end
end

## fix initial value by zero
for j=1:ndofs_space
A[j,j] = 1e60
b[dof] = 0
b[j] = 0
end
ExtendableSparse.flush!(A)
end
Expand Down Expand Up @@ -311,7 +307,7 @@ end
function generateplots(dir = pwd(); Plotter = nothing, kwargs...)
~, plt = main(; Plotter = Plotter, kwargs...)
scene = GridVisualize.reveal(plt)
GridVisualize.save(joinpath(dir, "example205.svg"), scene; Plotter = Plotter)
GridVisualize.save(joinpath(dir, "example205.png"), scene; Plotter = Plotter)
end

end #module
19 changes: 4 additions & 15 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.svg)
![](example210.png)
=#

module Example210_LowLevelNavierStokes
Expand Down Expand Up @@ -162,18 +162,7 @@ function solve_stokes_lowlevel(FES; teval = 0)
@time begin
u_init = FEVector(FES)
interpolate!(u_init[1], u!; time = teval)

fixed_dofs = [size(A.entries, 1)] # fix one pressure dof = last dof
BFaceDofs::Adjacency{Int32} = FES[1][ExtendableFEMBase.BFaceDofs]
nbfaces::Int = num_sources(BFaceDofs)
AM::ExtendableSparseMatrix{Float64, Int64} = A.entries
dof_j::Int = 0
for bface 1:nbfaces
for j 1:num_targets(BFaceDofs, 1)
dof_j = BFaceDofs[j, bface]
push!(fixed_dofs, dof_j)
end
end
fixed_dofs = boundarydofs(FES[1])
push!(fixed_dofs, FES[1].ndofs + 1) ## fix one pressure dof
end

Expand All @@ -200,7 +189,7 @@ function solve_stokes_lowlevel(FES; teval = 0)

## fix boundary dofs
for dof in fixed_dofs
AM[dof, dof] = 1e60
A.entries[dof, dof] = 1e60
b.entries[dof] = 1e60 * u_init.entries[dof]
end
ExtendableSparse.flush!(A.entries)
Expand Down Expand Up @@ -400,6 +389,6 @@ end
function generateplots(dir = pwd(); Plotter = nothing, kwargs...)
~, plt = main(; Plotter = Plotter, kwargs...)
scene = GridVisualize.reveal(plt)
GridVisualize.save(joinpath(dir, "example210.svg"), scene; Plotter = Plotter)
GridVisualize.save(joinpath(dir, "example210.png"), scene; Plotter = Plotter)
end
end #module
6 changes: 4 additions & 2 deletions examples/Example280_BasisPlotter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
([source code](SOURCE_URL))
This example plots all the basis functions of a H1 finite element on Edge1D or Triangle2D
as unicode plots
as unicode plots. This is the result with the default parameters (dim = 1, order = 3):
![](https://github.com/chmerdon/ExtendableFEMBase.jl/blob/master/docs/src/assets/example280.png?raw=true")
=#

Expand All @@ -14,7 +16,7 @@ using ExtendableFEMBase
using ExtendableGrids

## everything is wrapped in a main function
function main(; dim = 1, order = 2)
function main(; dim = 1, order = 3)

## generate two grids
@assert dim in [1, 2] "dim must be 1 or 2"
Expand Down
10 changes: 5 additions & 5 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.svg)
![](example281.png)
=#

module Example281_DiscontinuousPlot
Expand All @@ -35,7 +35,7 @@ function main(; broken = false, nrefs = 3, abs = false, Plotter = nothing)
## generate two grids
xgrid = grid_unitsquare(Triangle2D)

## mark a second region
## mark first two triangles to be in second region
xgrid[CellRegions][1:2] .= 2

## refine
Expand All @@ -53,8 +53,8 @@ function main(; broken = false, nrefs = 3, abs = false, Plotter = nothing)
subgrid2 = subgrid(xgrid, [2])

## get parent nodes for each subgrid
subnodes1 = subgrid1[ExtendableGrids.NodeInParent]
subnodes2 = subgrid2[ExtendableGrids.NodeInParent]
subnodes1 = subgrid1[NodeParents]
subnodes2 = subgrid2[NodeParents]

## compute nodevalues for nodes of each subgrid
nodevals4nodes1 = nodevalues(FEFunction[1], Identity; abs = abs, regions = [1], nodes = subnodes1)
Expand All @@ -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.svg"), scene; Plotter = Plotter)
GridVisualize.save(joinpath(dir, "example281.png"), 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.svg)
![](example290.png)
=#

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.svg"), scene; Plotter = Plotter)
GridVisualize.save(joinpath(dir, "example290.png"), scene; Plotter = Plotter)
end

end
3 changes: 2 additions & 1 deletion src/ExtendableFEMBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ export NeededDerivative4Operator, Length4Operator, QuadratureOrderShift4Operator
export OperatorPair, OperatorTriple


include("finiteelements.jl")
include("finiteelements.jl") # also includes dofmaps.jl and feevaluator*.jl
export DofMap
export CellDofs, FaceDofs, EdgeDofs, BFaceDofs, BEdgeDofs
export CellDofsParent, FaceDofsParent, EdgeDofsParent, BFaceDofsParent, BEdgeDofsParent
export DofMapTypes
export Dofmap4AssemblyType, ItemGeometries4DofMap, EffAT4AssemblyType, ParentDofmap4Dofmap
export AbstractFiniteElement
export FESpace, FESpaces, get_AT, get_FEType
export boundarydofs, ndofs, broken

export AbstractH1FiniteElement
export H1BUBBLE, L2P0, H1P1, H1P2, H1P2B, H1MINI, H1CR, H1P3, H1Pk
Expand Down
Loading

0 comments on commit d5d7ae8

Please sign in to comment.