Skip to content

Commit

Permalink
Merge pull request #21 from jpthiele/runic
Browse files Browse the repository at this point in the history
Apply runic formatting and add check to pre-commit
  • Loading branch information
pjaap authored Nov 29, 2024
2 parents c9804a8 + b651d76 commit f0e8853
Show file tree
Hide file tree
Showing 69 changed files with 9,583 additions and 9,549 deletions.
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ repos:
rev: v2.2.4
hooks:
- id: codespell
- repo: https://github.com/fredrikekre/runic-pre-commit
rev: v1.0.0
hooks:
- id: runic
178 changes: 89 additions & 89 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,109 +5,109 @@ using ExtendableFEM

function make_all(; with_examples::Bool = true, modules = :all, run_examples::Bool = true, run_notebooks::Bool = false)

module_examples = []
module_examples = []

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

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

if modules === :all
modules = [
"Example103_BurgersEquation.jl",
"Example105_NonlinearPoissonEquation.jl",
"Example106_NonlinearDiffusion.jl",
"Example108_RobinBoundaryCondition.jl",
"Example201_PoissonProblem.jl",
"Example202_MixedPoissonProblem.jl",
"Example203_PoissonProblemDG.jl",
"Example204_LaplaceEVProblem.jl",
"Example205_HeatEquation.jl",
"Example206_CoupledSubGridProblems.jl",
"Example207_AdvectionUpwindDG.jl",
"Example210_LshapeAdaptivePoissonProblem.jl",
"Example211_LshapeAdaptiveEQPoissonProblem.jl",
"Example220_ReactionConvectionDiffusion.jl",
"Example225_ObstacleProblem.jl",
"Example226_Thermoforming.jl",
"Example230_NonlinearElasticity.jl",
"Example235_StokesIteratedPenalty.jl",
"Example240_SVRTEnrichment.jl",
"Example245_NSEFlowAroundCylinder.jl",
"Example250_NSELidDrivenCavity.jl",
"Example252_NSEPlanarLatticeFlow.jl",
"Example260_AxisymmetricNavierStokesProblem.jl",
"Example265_FlowTransport.jl",
"Example270_NaturalConvectionProblem.jl",
"Example275_OptimalControlStokes.jl",
"Example280_CompressibleStokes.jl",
"Example282_IncompressibleMHD.jl",
"Example284_LevelSetMethod.jl",
"Example285_CahnHilliard.jl",
"Example290_PoroElasticity.jl",
"Example301_PoissonProblem.jl",
"Example310_DivFreeBasis.jl",
"Example330_HyperElasticity.jl",
]
end
if modules === :all
modules = [
"Example103_BurgersEquation.jl",
"Example105_NonlinearPoissonEquation.jl",
"Example106_NonlinearDiffusion.jl",
"Example108_RobinBoundaryCondition.jl",
"Example201_PoissonProblem.jl",
"Example202_MixedPoissonProblem.jl",
"Example203_PoissonProblemDG.jl",
"Example204_LaplaceEVProblem.jl",
"Example205_HeatEquation.jl",
"Example206_CoupledSubGridProblems.jl",
"Example207_AdvectionUpwindDG.jl",
"Example210_LshapeAdaptivePoissonProblem.jl",
"Example211_LshapeAdaptiveEQPoissonProblem.jl",
"Example220_ReactionConvectionDiffusion.jl",
"Example225_ObstacleProblem.jl",
"Example226_Thermoforming.jl",
"Example230_NonlinearElasticity.jl",
"Example235_StokesIteratedPenalty.jl",
"Example240_SVRTEnrichment.jl",
"Example245_NSEFlowAroundCylinder.jl",
"Example250_NSELidDrivenCavity.jl",
"Example252_NSEPlanarLatticeFlow.jl",
"Example260_AxisymmetricNavierStokesProblem.jl",
"Example265_FlowTransport.jl",
"Example270_NaturalConvectionProblem.jl",
"Example275_OptimalControlStokes.jl",
"Example280_CompressibleStokes.jl",
"Example282_IncompressibleMHD.jl",
"Example284_LevelSetMethod.jl",
"Example285_CahnHilliard.jl",
"Example290_PoroElasticity.jl",
"Example301_PoissonProblem.jl",
"Example310_DivFreeBasis.jl",
"Example330_HyperElasticity.jl",
]
end

#notebooks = ["PlutoTemplate.jl"
# "Example with Graphics" => "ExamplePluto.jl"]
#notebooks = ["PlutoTemplate.jl"
# "Example with Graphics" => "ExamplePluto.jl"]

cleanexamples()
cleanexamples()

module_examples = @docmodules(example_dir, modules, Plotter = CairoMakie)
#html_examples = @docplutonotebooks(example_dir, notebooks, iframe=false)
#pluto_examples = @docplutonotebooks(example_dir, notebooks, iframe=true)
end
module_examples = @docmodules(example_dir, modules, Plotter = CairoMakie)
#html_examples = @docplutonotebooks(example_dir, notebooks, iframe=false)
#pluto_examples = @docplutonotebooks(example_dir, notebooks, iframe=true)
end

makedocs(
modules = [ExtendableFEM],
sitename = "ExtendableFEM.jl",
authors = "Christian Merdon, Jan Philipp Thiele",
format = Documenter.HTML(; repolink = "https://github.com/WIAS-PDELib/ExtendableFEM.jl", mathengine = MathJax3()),
clean = false,
checkdocs = :none,
warnonly = false,
doctest = true,
pages = [
"Home" => "index.md",
"Index" => "package_index.md",
"Problem Description" => [
"problemdescription.md",
makedocs(
modules = [ExtendableFEM],
sitename = "ExtendableFEM.jl",
authors = "Christian Merdon, Jan Philipp Thiele",
format = Documenter.HTML(; repolink = "https://github.com/WIAS-PDELib/ExtendableFEM.jl", mathengine = MathJax3()),
clean = false,
checkdocs = :none,
warnonly = false,
doctest = true,
pages = [
"Home" => "index.md",
"Index" => "package_index.md",
"Problem Description" => [
"problemdescription.md",
"tensordescription.md",
"nonlinearoperator.md",
"bilinearoperator.md",
"linearoperator.md",
"interpolateboundarydata.md",
"homogeneousdata.md",
"fixdofs.md",
"combinedofs.md",
"callbackoperator.md",
"allindex.md",
],
"Solving" => Any[
"pdesolvers.md",
"pdesolvers_dt.md",
"parallel_assembly.md"
],
"Postprocessing" => Any[
"postprocessing.md",
"itemintegrators.md",
"faceinterpolator.md",
],
#"Tutorial Notebooks" => notebooks,
"Examples" => module_examples,
],
)
"nonlinearoperator.md",
"bilinearoperator.md",
"linearoperator.md",
"interpolateboundarydata.md",
"homogeneousdata.md",
"fixdofs.md",
"combinedofs.md",
"callbackoperator.md",
"allindex.md",
],
"Solving" => Any[
"pdesolvers.md",
"pdesolvers_dt.md",
"parallel_assembly.md",
],
"Postprocessing" => Any[
"postprocessing.md",
"itemintegrators.md",
"faceinterpolator.md",
],
#"Tutorial Notebooks" => notebooks,
"Examples" => module_examples,
],
)

cleanexamples()
return cleanexamples()

end

#make_all(; with_examples = true, run_examples = true, run_notebooks = true)
make_all(; with_examples = false, run_examples = false, run_notebooks = false)

deploydocs(
repo = "github.com/WIAS-PDELib/ExtendableFEM.jl",
repo = "github.com/WIAS-PDELib/ExtendableFEM.jl",
)
135 changes: 68 additions & 67 deletions examples/Example103_BurgersEquation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,84 +28,85 @@ using Test #hide

## nonlinear kernel, i.e. f(u)
function f!(result, input, qpinfo)
result[1] = input[1]^2 / 2
return result[1] = input[1]^2 / 2
end

## initial condition
function uinit!(result, qpinfo)
result[1] = abs(qpinfo.x[1]) < 0.5 ? 1 : 0
return result[1] = abs(qpinfo.x[1]) < 0.5 ? 1 : 0
end

## everything is wrapped in a main function
function main(;
ν = 0.01,
h = 0.005,
T = 2,
order = 2,
τ = 0.01,
Plotter = nothing,
use_diffeq = true,
solver = Rosenbrock23(autodiff = false),
kwargs...)

## load mesh and exact solution
xgrid = simplexgrid(-2:h:2)

## generate empty PDEDescription for three unknowns (h, u)
PD = ProblemDescription("Burger's Equation")
u = Unknown("u"; name = "u")
assign_unknown!(PD, u)
assign_operator!(PD, NonlinearOperator(f!, [grad(u)], [id(u)]; bonus_quadorder = 2))
assign_operator!(PD, BilinearOperator([grad(u)]; store = true, factor = ν))
assign_operator!(PD, CombineDofs(u, u, [1], [num_nodes(xgrid)], [1.0]; kwargs...))

## prepare solution vector and initial data
FES = FESpace{H1Pk{1, 1, order}}(xgrid)
sol = FEVector(FES; tags = PD.unknowns)
interpolate!(sol[u], uinit!)

## init plotter and plot u0
plt = plot([id(u), id(u)], sol; Plotter = Plotter, title_add = " (t = 0)")

## generate mass matrix
M = FEMatrix(FES)
assemble!(M, BilinearOperator([id(1)]; lump = 2))

if (use_diffeq)
## generate DifferentialEquations.ODEProblem
prob = ExtendableFEM.generate_ODEProblem(PD, FES, (0.0, T); init = sol, mass_matrix = M)

## solve ODE problem
de_sol = DifferentialEquations.solve(prob, solver, abstol = 1e-6, reltol = 1e-3, dt = τ, dtmin = 1e-6, adaptive = true)
@info "#tsteps = $(length(de_sol))"

## extract final solution
sol.entries .= de_sol[end]
else
## add backward Euler time derivative
assign_operator!(PD, BilinearOperator(M, [u]; factor = 1 / τ, kwargs...))
assign_operator!(PD, LinearOperator(M, [u], [u]; factor = 1 / τ, kwargs...))

## generate solver configuration
SC = SolverConfiguration(PD, FES; init = sol, maxiterations = 1, kwargs...)

## iterate tspan
t = 0
for it 1:Int(floor(T / τ))
t += τ
ExtendableFEM.solve(PD, FES, SC; time = t)
end
end

## plot final state
plot!(plt, [id(u)], sol; keep = 1, title_add = " (t = $T)")

return sol, plt
ν = 0.01,
h = 0.005,
T = 2,
order = 2,
τ = 0.01,
Plotter = nothing,
use_diffeq = true,
solver = Rosenbrock23(autodiff = false),
kwargs...
)

## load mesh and exact solution
xgrid = simplexgrid(-2:h:2)

## generate empty PDEDescription for three unknowns (h, u)
PD = ProblemDescription("Burger's Equation")
u = Unknown("u"; name = "u")
assign_unknown!(PD, u)
assign_operator!(PD, NonlinearOperator(f!, [grad(u)], [id(u)]; bonus_quadorder = 2))
assign_operator!(PD, BilinearOperator([grad(u)]; store = true, factor = ν))
assign_operator!(PD, CombineDofs(u, u, [1], [num_nodes(xgrid)], [1.0]; kwargs...))

## prepare solution vector and initial data
FES = FESpace{H1Pk{1, 1, order}}(xgrid)
sol = FEVector(FES; tags = PD.unknowns)
interpolate!(sol[u], uinit!)

## init plotter and plot u0
plt = plot([id(u), id(u)], sol; Plotter = Plotter, title_add = " (t = 0)")

## generate mass matrix
M = FEMatrix(FES)
assemble!(M, BilinearOperator([id(1)]; lump = 2))

if (use_diffeq)
## generate DifferentialEquations.ODEProblem
prob = ExtendableFEM.generate_ODEProblem(PD, FES, (0.0, T); init = sol, mass_matrix = M)

## solve ODE problem
de_sol = DifferentialEquations.solve(prob, solver, abstol = 1.0e-6, reltol = 1.0e-3, dt = τ, dtmin = 1.0e-6, adaptive = true)
@info "#tsteps = $(length(de_sol))"

## extract final solution
sol.entries .= de_sol[end]
else
## add backward Euler time derivative
assign_operator!(PD, BilinearOperator(M, [u]; factor = 1 / τ, kwargs...))
assign_operator!(PD, LinearOperator(M, [u], [u]; factor = 1 / τ, kwargs...))

## generate solver configuration
SC = SolverConfiguration(PD, FES; init = sol, maxiterations = 1, kwargs...)

## iterate tspan
t = 0
for it in 1:Int(floor(T / τ))
t += τ
ExtendableFEM.solve(PD, FES, SC; time = t)
end
end

## plot final state
plot!(plt, [id(u)], sol; keep = 1, title_add = " (t = $T)")

return sol, plt
end

generateplots = ExtendableFEM.default_generateplots(Example103_BurgersEquation, "example103.png") #hide
function runtests() #hide
sol, plt = main(; h = 0.01, τ = 0.1, T = 1, use_diffeq = false) #hide
@test maximum(sol.entries) 0.9380540612507218 #hide
sol, plt = main(; h = 0.01, τ = 0.1, T = 1, use_diffeq = false) #hide
return @test maximum(sol.entries) 0.9380540612507218 #hide
end #hide
end
Loading

0 comments on commit f0e8853

Please sign in to comment.