Skip to content

Commit

Permalink
Examplejuggler (#86)
Browse files Browse the repository at this point in the history
* notebook build with PlutoStaticHTML works

* PlutoVista -> CairoMakie in notebooks

* HTML configuration for Documenter (size threshold, mathjax3)

* Use ExampleJuggler to handle tests and docs
  • Loading branch information
j-fu authored Nov 21, 2023
1 parent c90325e commit 21ffd78
Show file tree
Hide file tree
Showing 60 changed files with 8,534 additions and 3,461 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "VoronoiFVM"
uuid = "82b139dc-5afc-11e9-35da-9b9bdfd336f3"
authors = ["Jürgen Fuhrmann <juergen.fuhrmann@wias-berlin.de>", "Dilara Abdel", "Jan Weidner", "Alexander Seiler", "Patricio Farrell", "Matthias Liero"]
version = "1.13.3"
version = "1.13.4"

[deps]
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
Expand Down
22 changes: 17 additions & 5 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
[deps]
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
DiffResults = "163ba53b-c6d8-5494-b064-1a9d43ac40c5"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
ExampleJuggler = "3bbe58f8-ed81-4c4e-a134-03e85fcf4a1a"
ExtendableGrids = "cfc395e8-590f-11e8-1f13-43a2532b2fa8"
ExtendableSparse = "95c220a8-a1cf-11e9-0c77-dbfce5f500b3"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
GridVisualize = "5eed8a63-0fb0-45eb-886d-8d5a387d12b8"
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
HypertextLiteral = "ac1192a8-f4b3-4bfe-ba22-af5b92cd3ab2"
ILUZero = "88f59080-6952-5380-9ea5-54057fb9a43f"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Pluto = "c3e4b0f8-55cb-11ea-2926-15256bba5781"
PlutoSliderServer = "2fc8631c-6f24-4c5b-bca7-cbb509c42db4"
PlutoUI = "7f904dfe-b85e-4ff6-b463-dae2292396a8"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
SimplexGridFactory = "57bfcd06-606e-45d6-baf4-4ba06da0efd5"
SparseDiffTools = "47a9eef4-7e08-11e9-0b38-333d64bd3804"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
StrideArraysCore = "7792a7ef-975c-4747-a70f-980b88e8d1da"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Triangulate = "f7e6ffb2-c36d-4f8f-a77e-16e897189344"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
VoronoiFVM = "82b139dc-5afc-11e9-35da-9b9bdfd336f3"

[compat]
Literate = ">=0.2.7"
Pluto = ">=0.17.4"
Documenter = "1"
ExampleJuggler = "0.3.2"
225 changes: 58 additions & 167 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,175 +1,66 @@
using Documenter,
VoronoiFVM, Literate, PlutoSliderServer, ExtendableGrids, GridVisualize, Pkg
using LinearAlgebra

#
# Replace SOURCE_URL marker with github url of source
#
function replace_source_url(input, source_url)
lines_in = collect(eachline(IOBuffer(input)))
lines_out = IOBuffer()
for line in lines_in
println(lines_out, replace(line, "SOURCE_URL" => source_url))
end
return String(take!(lines_out))
end




function make_all(; with_examples = true, run_notebooks = true, example = nothing)

generated_examples = []
notebooks = []
notebooks = []
example_jl_dir = joinpath(@__DIR__, "..", "examples")
example_md_dir = joinpath(@__DIR__, "src", "examples")
notebook_html_dir = joinpath(@__DIR__, "src", "nbhtml")

with_examples && rm(example_md_dir, recursive = true, force = true)
run_notebooks && rm(notebook_html_dir, recursive = true, force = true)

if run_notebooks
notebookenv = joinpath(@__DIR__, "..", "pluto-examples")
Pkg.activate(notebookenv)
Pkg.develop(path = joinpath(@__DIR__, ".."))
Pkg.instantiate()

ENV["PLUTO_PROJECT"] = notebookenv
notebooks = [
"Outflow boundary conditions" => "outflow.jl",
"Obtaining vector fields" => "flux-reconstruction.jl",
"Internal interfaces (1D)" => "interfaces1d.jl",
"A case for caution" => "problemcase.jl",
"Nonlinear solver control" => "nonlinear-solvers.jl",
"API Updates" => "api-update.jl",
]

notebookjl = last.(notebooks)
notebookmd = []

# function rendernotebook(name)
# base=split(name,".")[1]
# input=joinpath(@__DIR__,"..","pluto-examples",base*".jl")
# output=joinpath(@__DIR__,"src","nbhtml",base*".html")
# session = Pluto.ServerSession();
# html_contents=PlutoStaticHTML.notebook2html(input;session)
# write(output, html_contents)
# end


# for notebook in notebookjl
# @info "Converting $(notebook)"
# rendernotebook(notebook)
# end



export_directory(
joinpath(@__DIR__, "..", "pluto-examples"),
notebook_paths = notebookjl,
Export_output_dir = joinpath(notebook_html_dir),
Export_offer_binder = false,
)

# generate frame markdown for each notebook
for notebook in notebookjl
base = split(notebook, ".")[1]
mdstring = """
##### [$(base).jl](@id $(base))
[Download](https://github.com/j-fu/VoronoiFVM.jl/blob/master/pluto-examples/$(notebook))
this [Pluto.jl](https://plutojl.org) this notebook.
```@raw html
<iframe style="height:20000px" width="100%" src="../$(base).html"> </iframe>
```
"""
# <iframe sandbox="allow-same-origin" onload="this.style.height=(this.contentWindow.document.body.scrollHeight+20)+'px';" width="100%" src="../$(base).html"> </iframe>
mdname = base * ".md"
push!(notebookmd, joinpath("nbhtml", mdname))
io = open(joinpath(notebook_html_dir, mdname), "w")
write(io, mdstring)
close(io)
end

notebooks = first.(notebooks) .=> notebookmd
pushfirst!(notebooks, "About the notebooks" => "notebooks.md")
end


if with_examples
#
# Generate Markdown pages from examples
#
if example == nothing
example_sources = readdir(example_jl_dir)
else
example_sources = [example]
end
for example_source in example_sources
base, ext = splitext(example_source)
if ext == ".jl"
source_url =
"https://github.com/j-fu/VoronoiFVM.jl/raw/master/examples/" *
example_source
preprocess(buffer) = replace_source_url(buffer, source_url)
Literate.markdown(
joinpath(@__DIR__, "..", "examples", example_source),
example_md_dir,
documenter = false,
info = false,
preprocess = preprocess,
)
end
end


generated_examples =
vcat(["runexamples.md"], joinpath.("examples", readdir(example_md_dir)))
end

makedocs(
sitename = "VoronoiFVM.jl",
modules = [VoronoiFVM, VoronoiFVM.SolverStrategies],
checkdocs = :all,
clean = false,
doctest = true,
warnonly = true,
authors = "J. Fuhrmann",
repo = "https://github.com/j-fu/VoronoiFVM.jl",
pages = [
"Home" => "index.md",
"changes.md",
"method.md",
"API Documentation" => [
"system.md",
"physics.md",
"solutions.md",
"solver.md",
"post.md",
"quantities.md",
"misc.md",
"internal.md",
"allindex.md",
"devel.md",
],
"Tutorial Notebooks" => notebooks,
"Examples" => generated_examples,
],
)

with_examples && rm(example_md_dir, recursive = true, force = true)
run_notebooks && rm(notebook_html_dir, recursive = true, force = true)
using Documenter, ExampleJuggler, VoronoiFVM, ExtendableGrids

function make_all(; with_examples = true, with_notebooks = true, example = nothing)
ExampleJuggler.verbose!(true)

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

notebooks = [
"Outflow boundary conditions" => "outflow.jl",
"Obtaining vector fields" => "flux-reconstruction.jl",
"Internal interfaces (1D)" => "interfaces1d.jl",
"A case for caution" => "problemcase.jl",
"Nonlinear solver control" => "nonlinear-solvers.jl",
"API Updates" => "api-update.jl",
]
notebook_examples = @docplutonotebooks(notebookdir, notebooks, iframe=false)
notebook_examples = vcat(["About the notebooks" => "notebooks.md"], notebook_examples)

modules = filter(ex -> splitext(ex)[2] == ".jl", basename.(readdir(exampledir)))
module_examples = @docmodules(exampledir, modules)
module_examples = vcat(["About the examples" => "runexamples.md"], module_examples)

makedocs(; sitename = "VoronoiFVM.jl",
modules = [VoronoiFVM, VoronoiFVM.SolverStrategies],
checkdocs = :all,
clean = false,
doctest = false,
warnonly = true,
authors = "J. Fuhrmann",
repo = "https://github.com/j-fu/VoronoiFVM.jl",
format = Documenter.HTML(; size_threshold_ignore = last.(notebook_examples),
mathengine = MathJax3()),
pages = [
"Home" => "index.md",
"changes.md",
"method.md",
"API Documentation" => [
"system.md",
"physics.md",
"solutions.md",
"solver.md",
"post.md",
"quantities.md",
"misc.md",
"internal.md",
"allindex.md",
"devel.md",
],
"Tutorial Notebooks" => notebook_examples,
"Examples" => module_examples,
])

cleanexamples()

if !isinteractive()
deploydocs(repo = "github.com/j-fu/VoronoiFVM.jl.git")
deploydocs(; repo = "github.com/j-fu/VoronoiFVM.jl.git")
end
end

if isinteractive()
make_all(with_examples = false, run_notebooks = false)
make_all(; with_examples = false, with_notebooks = false)
else
make_all(with_examples = true, run_notebooks = true)
make_all(; with_examples = true, with_notebooks = true)
end

35 changes: 19 additions & 16 deletions examples/Example001_Solvers.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#=
# 001: New linear solver API
([source code](SOURCE_URL))
([source code](@__SOURCE_URL__))
=#

module Example001_Solvers

# under development
## under development

using Printf
using VoronoiFVM
Expand All @@ -15,14 +15,14 @@ using LinearSolve
using ExtendableSparse
using LinearAlgebra

function main(; n = 10, Plotter = nothing, assembly=:edgwwise, kwargs...)
function main(; n = 10, Plotter = nothing, assembly = :edgwwise, kwargs...)
h = 1.0 / convert(Float64, n)
X = collect(0.0:h:1.0)
Y = collect(0.0:h:1.0)

grid = VoronoiFVM.Grid(X, Y)
nn=num_nodes(grid)
nn = num_nodes(grid)

eps = 1.0e-2

function reaction(f, u, node)
Expand Down Expand Up @@ -78,20 +78,22 @@ function main(; n = 10, Plotter = nothing, assembly=:edgwwise, kwargs...)
precon_linear = ILUZeroPreconditioner(),
kwargs...)

@show [1:nn÷2, (nn÷2+1):nn]
@show [1:(nn ÷ 2), (nn ÷ 2 + 1):nn]
@info "Krylov-block1"
kryb1_sol = solve(sys;
inival = 0.5,
method_linear = KrylovJL_BICGSTAB(),
precon_linear = BlockPreconditioner(partitioning=[1:nn÷2, (nn÷2+1):nn],factorization=ILU0Preconditioner()),
kwargs...)
inival = 0.5,
method_linear = KrylovJL_BICGSTAB(),
precon_linear = BlockPreconditioner(; partitioning = [1:(nn ÷ 2), (nn ÷ 2 + 1):nn],
factorization = ILU0Preconditioner()),
kwargs...)

@info "Krylov-block2"
kryb2_sol = solve(sys;
inival = 0.5,
method_linear = KrylovJL_BICGSTAB(),
precon_linear = BlockPreconditioner(partitioning=[1:2:nn, 2:2:nn],factorization=UMFPACKFactorization()),
kwargs...)
inival = 0.5,
method_linear = KrylovJL_BICGSTAB(),
precon_linear = BlockPreconditioner(; partitioning = [1:2:nn, 2:2:nn],
factorization = UMFPACKFactorization()),
kwargs...)

@info "Krylov - delayed factorization:"
krydel_sol = solve(sys;
Expand All @@ -117,7 +119,8 @@ function main(; n = 10, Plotter = nothing, assembly=:edgwwise, kwargs...)
norm(kryjac_sol - umf_sol, Inf) < 1.0e-7
end

function test()
main(assembly=:edgewise) && main(assembly=:cellwise)
using Test
function runtests()
@test main(; assembly = :edgewise) && main(; assembly = :cellwise)
end
end
Loading

0 comments on commit 21ffd78

Please sign in to comment.