Skip to content

Commit

Permalink
runic format testt, docs, ext
Browse files Browse the repository at this point in the history
  • Loading branch information
j-fu committed Nov 27, 2024
1 parent bfbace8 commit f722d0e
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 178 deletions.
73 changes: 40 additions & 33 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@ using ExtendableGrids, GridVisualize, LinearAlgebra, RecursiveArrayTools, SciMLB

using ExtendableFEMBase, ExtendableFEM

using OrdinaryDiffEqBDF, OrdinaryDiffEqLowOrderRK, OrdinaryDiffEqRosenbrock, OrdinaryDiffEqSDIRK, OrdinaryDiffEqTsit5
using OrdinaryDiffEqBDF, OrdinaryDiffEqLowOrderRK, OrdinaryDiffEqRosenbrock, OrdinaryDiffEqSDIRK, OrdinaryDiffEqTsit5

function make(; with_examples = true,
with_notebooks = true)
function make(;
with_examples = true,
with_notebooks = true
)

bib = CitationBibliography(
joinpath(@__DIR__, "..", "CITATIONS.bib");
style=:numeric
style = :numeric
)

ExampleJuggler.verbose!(true)

cleanexamples()
notebookdir = joinpath(@__DIR__, "..", "pluto-examples")
exampledir = joinpath(@__DIR__, "..", "examples")

size_threshold_ignore=[]
size_threshold_ignore = []

pages = [
"Home" => "index.md",
Expand All @@ -36,16 +38,17 @@ function make(; with_examples = true,
"internal.md",
"allindex.md",
"devel.md",
"extensions.md"]
"extensions.md",
],
]


if with_notebooks
notebooks = [
"OrdinaryDiffEq.jl nonlinear diffusion" => "ode-diffusion1d.jl",
"OrdinaryDiffEq.jl 1D wave equation" => "ode-wave1d.jl",
"OrdinaryDiffEq.jl changing mass matrix" => "ode-nlstorage1d.jl",
"OrdinaryDiffEq.jl brusselator" => "ode-brusselator.jl",
"OrdinaryDiffEq.jl nonlinear diffusion" => "ode-diffusion1d.jl",
"OrdinaryDiffEq.jl 1D wave equation" => "ode-wave1d.jl",
"OrdinaryDiffEq.jl changing mass matrix" => "ode-nlstorage1d.jl",
"OrdinaryDiffEq.jl brusselator" => "ode-brusselator.jl",
"Coupling with Catalyst.jl" => "heterogeneous-catalysis.jl",
"Outflow boundary conditions" => "outflow.jl",
"Obtaining vector fields" => "flux-reconstruction.jl",
Expand All @@ -55,40 +58,44 @@ function make(; with_examples = true,
"Bernoulli function test" => "bernoulli.jl",
"API Updates" => "api-update.jl",
]
notebook_examples = @docplutonotebooks(notebookdir, notebooks, iframe=false)
notebook_examples = @docplutonotebooks(notebookdir, notebooks, iframe = false)
notebook_examples = vcat(["About the notebooks" => "notebooks.md"], notebook_examples)
size_threshold_ignore = last.(notebook_examples)
push!(pages, "Tutorial Notebooks" => notebook_examples)
end

if with_examples
modules = filter(ex -> splitext(ex)[2] == ".jl", basename.(readdir(exampledir)))
module_examples = @docmodules(exampledir, modules, use_module_titles=true)
module_examples = @docmodules(exampledir, modules, use_module_titles = true)
module_examples = vcat(["About the examples" => "runexamples.md"], module_examples)
push!(pages, "Examples" => module_examples)
end

makedocs(; sitename="VoronoiFVM.jl",
modules=[
VoronoiFVM,
# define extension modules manually: https://github.com/JuliaDocs/Documenter.jl/issues/2124#issuecomment-1557473415
Base.get_extension(VoronoiFVM, :VoronoiFVMExtendableFEMBaseExt)
],
plugins=[bib],
checkdocs=:all,
clean = false,
doctest = false,
authors = "J. Fuhrmann",
repo = "https://github.com/WIAS-PDELib/VoronoiFVM.jl",
format = Documenter.HTML(; size_threshold_ignore,
assets=String["assets/citations.css"],
mathengine = MathJax3()),
pages)


makedocs(;
sitename = "VoronoiFVM.jl",
modules = [
VoronoiFVM,
# define extension modules manually: https://github.com/JuliaDocs/Documenter.jl/issues/2124#issuecomment-1557473415
Base.get_extension(VoronoiFVM, :VoronoiFVMExtendableFEMBaseExt),
],
plugins = [bib],
checkdocs = :all,
clean = false,
doctest = false,
authors = "J. Fuhrmann",
repo = "https://github.com/WIAS-PDELib/VoronoiFVM.jl",
format = Documenter.HTML(;
size_threshold_ignore,
assets = String["assets/citations.css"],
mathengine = MathJax3()
),
pages
)


cleanexamples()

if !isinteractive()
return if !isinteractive()
deploydocs(; repo = "github.com/WIAS-PDELib/VoronoiFVM.jl.git")
end
end
Expand Down
55 changes: 28 additions & 27 deletions ext/VoronoiFVMExtendableFEMBaseExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ using DocStringExtensions: DocStringExtensions, SIGNATURES
id(u) = (u, Identity)


dist(p1,p2) = sqrt( (p1[1] - p2[1] )^2 + (p1[2] -p2[2])^2 )
dist(p1, p2) = sqrt((p1[1] - p2[1])^2 + (p1[2] - p2[2])^2)

function iscloser(pint, p1, p2, eps)
return dist(pint,p2) < dist(p2,p1) - eps
return dist(pint, p2) < dist(p2, p1) - eps
end

#This is the FEVectorBlock with lots of info from ExtendableFEMBase
Expand All @@ -48,7 +48,6 @@ end
function AugmentedFEVectorBlock(vel, seg_integrator, point_evaluator, cf, flowgrid)



bp1 = zeros(Float64, 3)
bp2 = zeros(Float64, 3)
result = zeros(Float64, 2)
Expand All @@ -58,14 +57,16 @@ function AugmentedFEVectorBlock(vel, seg_integrator, point_evaluator, cf, flowgr
bary = [1 / 3, 1 / 3, 1 / 3]


AugmentedFEVectorBlock(vel, seg_integrator, point_evaluator, cf, flowgrid,
bp1,
bp2,
result,
summand,
pint,
bpint,
bary)
return AugmentedFEVectorBlock(
vel, seg_integrator, point_evaluator, cf, flowgrid,
bp1,
bp2,
result,
summand,
pint,
bpint,
bary
)


end
Expand All @@ -76,7 +77,7 @@ function multiply_r(result, input, qpinfo)
return nothing
end

function prepare_segment_integration(vel; axisymmetric=false, reconst=false, kwargs...)
function prepare_segment_integration(vel; axisymmetric = false, reconst = false, kwargs...)
flowgrid = vel.FES.xgrid

# reference mappings not implemented for other coord types
Expand All @@ -86,7 +87,7 @@ function prepare_segment_integration(vel; axisymmetric=false, reconst=false, kwa
if reconst
seg_integrator = SegmentIntegrator(Edge1D, [id(1)])
else
seg_integrator = SegmentIntegrator(Edge1D, multiply_r, [id(1)]; bonus_quadorder=1)
seg_integrator = SegmentIntegrator(Edge1D, multiply_r, [id(1)]; bonus_quadorder = 1)
end
else
seg_integrator = SegmentIntegrator(Edge1D, [id(1)])
Expand Down Expand Up @@ -148,29 +149,29 @@ end
# We need two explicitly type-annotated methods for a working method specialization.
# This one...
function VoronoiFVM.integrate(::Type{<:Cartesian2D}, p1, p2, hnormal, aug_vec_block::AugmentedFEVectorBlock; kwargs...)
_integrate_along_segments(p1, p2, hnormal, aug_vec_block; kwargs...)
return _integrate_along_segments(p1, p2, hnormal, aug_vec_block; kwargs...)
end

# ... and that one.
function VoronoiFVM.integrate(::Type{<:Cylindrical2D}, p1, p2, hnormal, aug_vec_block::AugmentedFEVectorBlock; kwargs...)
_integrate_along_segments(p1, p2, hnormal, aug_vec_block; kwargs...)
return _integrate_along_segments(p1, p2, hnormal, aug_vec_block; kwargs...)
end

# compute the path integral for the velocity in aug_vec_block between p1 and p2 by
# incrementally walking through each cell in the grid between p1 and p2
# and summing up each cell's contribution
function _integrate_along_segments(p1, p2, hnormal, aug_vec_block::AugmentedFEVectorBlock{TVB, TSE, TPE, TCF, TFG}; interpolate_eps=1.0e-12, axisymmetric=false, kwargs...) where {TVB, TSE, TPE, TCF, TFG}
edge_length = dist(p1,p2)
function _integrate_along_segments(p1, p2, hnormal, aug_vec_block::AugmentedFEVectorBlock{TVB, TSE, TPE, TCF, TFG}; interpolate_eps = 1.0e-12, axisymmetric = false, kwargs...) where {TVB, TSE, TPE, TCF, TFG}
edge_length = dist(p1, p2)
avg_r = (p1[1] + p2[1]) / 2
(; bp1, result, summand, bp2, pint, bpint, bary)= aug_vec_block
(; bp1, result, summand, bp2, pint, bpint, bary) = aug_vec_block


if axisymmetric && avg_r < eps()
return 0
end

CF = aug_vec_block.cellfinder
icell::Int = gFindLocal!(bp1, CF, p1; eps=interpolate_eps)
icell::Int = gFindLocal!(bp1, CF, p1; eps = interpolate_eps)
if edge_length interpolate_eps
point_evaluator = aug_vec_block.point_evaluator
evaluate_bary!(p2, point_evaluator, bp1, icell)
Expand Down Expand Up @@ -200,15 +201,15 @@ function _integrate_along_segments(p1, p2, hnormal, aug_vec_block::AugmentedFEVe
p1_temp3 = @MVector zeros(3)

function calc_barycentric_coords!(bp, p)
for j = 1:2
for j in 1:2
cx[j] = p[j] - L2Gb[j]
end

fill!(bp, 0)
for j = 1:2, k = 1:2
for j in 1:2, k in 1:2
bp[k] += invA[j, k] * cx[j]
end
postprocess_xreftest!(bp, CF.xCellGeometries[icell])
return postprocess_xreftest!(bp, CF.xCellGeometries[icell])
end

while (true)
Expand All @@ -232,7 +233,7 @@ function _integrate_along_segments(p1, p2, hnormal, aug_vec_block::AugmentedFEVe
# a cell containing p1 in the direction of (p2-p1)
if count(<=(interpolate_eps), bp1) == 2 # 10^(-13)
@. p1_temp2 = p1 + 10 * interpolate_eps * (p2 - p1)
icell_new = gFindLocal!(bp1, CF, p1_temp2; eps=10 * interpolate_eps, icellstart=icell) #!!! allocates
icell_new = gFindLocal!(bp1, CF, p1_temp2; eps = 10 * interpolate_eps, icellstart = icell) #!!! allocates
if icell_new == 0
# TODO: test the following
# icell_new = gFindBruteForce!(bp1, CF, p1_temp[1:2])
Expand Down Expand Up @@ -280,8 +281,8 @@ function _integrate_along_segments(p1, p2, hnormal, aug_vec_block::AugmentedFEVe
p1_temp3 .= 0

while !iscloser(pint, p1, p2, interpolate_eps) ||
(any(x->x<= -interpolate_eps, bpint) || any(x->x>= 1 + interpolate_eps, bpint)) ||
dist(bpint,bp1) <= interpolate_eps #!!! .< allocates a temp vector
(any(x -> x <= -interpolate_eps, bpint) || any(x -> x >= 1 + interpolate_eps, bpint)) ||
dist(bpint, bp1) <= interpolate_eps #!!! .< allocates a temp vector
# check if pint takes us closer to p2 and if bpint is inside the cell *and* if we actually moved with pint from p1
imin += 1
if imin == 4
Expand All @@ -292,9 +293,9 @@ function _integrate_along_segments(p1, p2, hnormal, aug_vec_block::AugmentedFEVe
t = bp1[imin] / (bp1[imin] - bp2[imin])
bpint = bp1 + t * (bp2 - bp1)
eval_trafo!(pint, L2G, bpint)
if dist(pint,p2) < closestdist && ((all(x->x>= -interpolate_eps, bpint) && all(x->x<= 1 + interpolate_eps, bpint)))
if dist(pint, p2) < closestdist && ((all(x -> x >= -interpolate_eps, bpint) && all(x -> x <= 1 + interpolate_eps, bpint)))
closestimin = imin
closestdist = dist(pint,p2)
closestdist = dist(pint, p2)
p1_temp3 .= bpint
end
end
Expand Down
24 changes: 12 additions & 12 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ function run_tests_from_directory(testdir, prefix)
@info "Directory $(testdir):"
examples = filter(ex -> length(ex) >= length(prefix) && ex[1:length(prefix)] == prefix, basename.(readdir(testdir)))
@info examples
@testmodules(testdir, examples)
return @testmodules(testdir, examples)
end

function run_all_tests(; run_notebooks = false, notebooksonly = false)
if !notebooksonly
@testset "basictest" begin
run_tests_from_directory(@__DIR__, "test_")
end

@testset "Development Examples" begin
run_tests_from_directory(joinpath(@__DIR__, "..", "examples"), "Example0")
end
Expand All @@ -45,7 +45,7 @@ function run_all_tests(; run_notebooks = false, notebooksonly = false)
end

if run_notebooks
ENV["VORONOIFVM_RUNTESTS"]="1"
ENV["VORONOIFVM_RUNTESTS"] = "1"
notebooks = [
"nbproto.jl",
"ode-diffusion1d.jl",
Expand All @@ -59,7 +59,7 @@ function run_all_tests(; run_notebooks = false, notebooksonly = false)
"nonlinear-solvers.jl",
"api-update.jl",
"heterogeneous-catalysis.jl",
]
]
@testset "Notebooks" begin
@testscripts(joinpath(@__DIR__, "..", "pluto-examples"), notebooks)
end
Expand All @@ -71,28 +71,28 @@ function run_all_tests(; run_notebooks = false, notebooksonly = false)
end

@testset "Aqua" begin
Aqua.test_ambiguities(VoronoiFVM, broken=true)
Aqua.test_ambiguities(VoronoiFVM, broken = true)
Aqua.test_unbound_args(VoronoiFVM)
Aqua.test_undefined_exports(VoronoiFVM)
Aqua.test_project_extras(VoronoiFVM)
Aqua.test_stale_deps(VoronoiFVM)
Aqua.test_deps_compat(VoronoiFVM)
Aqua.test_piracies(VoronoiFVM, broken=true)
Aqua.test_piracies(VoronoiFVM, broken = true)
Aqua.test_persistent_tasks(VoronoiFVM)
end
if isdefined(Docs,:undocumented_names) # >=1.11

return if isdefined(Docs, :undocumented_names) # >=1.11
@testset "UndocumentedNames" begin
@test isempty(Docs.undocumented_names(VoronoiFVM))
end
end
end

# Don't run notebooks on 1.12: https://github.com/fonsp/Pluto.jl/issues/2939
if haskey(ENV,"EXAMPLES_ONLY")
if haskey(ENV, "EXAMPLES_ONLY")
run_all_tests(; run_notebooks = false, notebooksonly = false)
elseif haskey(ENV,"NOTEBOOKS_ONLY")
run_all_tests(; run_notebooks=true, notebooksonly = true)
elseif haskey(ENV, "NOTEBOOKS_ONLY")
run_all_tests(; run_notebooks = true, notebooksonly = true)
else
run_all_tests(; run_notebooks = VERSION < v"1.12.0-DEV.0" , notebooksonly = false)
run_all_tests(; run_notebooks = VERSION < v"1.12.0-DEV.0", notebooksonly = false)
end
4 changes: 2 additions & 2 deletions test/test_bernoulli.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using Test
function runtests()
function B_Big(x)
bx = BigFloat(x)
Float64(bx / (exp(bx) - one(bx)))
return Float64(bx / (exp(bx) - one(bx)))
end
smallrange = -1:1.00001e-5:1
largerange = -100:1.00001e-3:100
Expand All @@ -19,7 +19,7 @@ function runtests()
@test maxerror(smallrange, x -> B_Big(-x), (x) -> fbernoulli_pm(x)[2]) < 1.0e-14
@test maxerror(largerange, x -> B_Big(-x), (x) -> fbernoulli_pm(x)[2]) < 1.0e-14

true
return true
end

end
16 changes: 8 additions & 8 deletions test/test_checkdelaunay.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ using ExtendableGrids: Coordinates, simplexgrid
using VoronoiFVM: nondelaunay

function runtests()
X=0:0.1:10
g=simplexgrid(X,X)
X = 0:0.1:10
g = simplexgrid(X, X)
@test length(nondelaunay(g)) == 0

coord=g[Coordinates]
for i=1:size(coord,2)
coord[1,i]+=0.01*(rand()-0.5)
coord[2,i]+=0.01*(rand()-0.5)

coord = g[Coordinates]
for i in 1:size(coord, 2)
coord[1, i] += 0.01 * (rand() - 0.5)
coord[2, i] += 0.01 * (rand() - 0.5)
end

@test length(nondelaunay(g))>0
return @test length(nondelaunay(g)) > 0
end

end
Loading

0 comments on commit f722d0e

Please sign in to comment.