Skip to content

Commit

Permalink
Changed examples to use gridplot (#10)
Browse files Browse the repository at this point in the history
* Update to IterativeSolvers 0.9

* All examples changed to gridplot

Working witht PyPlot, GLMakie
Plots (of course) works only for structured 2D and not for 3D due
to missing support for triangulations.
  • Loading branch information
j-fu authored Jan 9, 2021
1 parent 6c89121 commit 53ee3b5
Show file tree
Hide file tree
Showing 21 changed files with 123 additions and 207 deletions.
12 changes: 6 additions & 6 deletions 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 = ["Juergen Fuhrmann <[email protected]>"]
version = "0.9.2"
version = "0.10.0"

[deps]
DiffResults = "163ba53b-c6d8-5494-b064-1a9d43ac40c5"
Expand All @@ -21,12 +21,12 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
DiffResults = "1"
DocStringExtensions = "^0.8.0"
ExtendableGrids = "^0.6"
DocStringExtensions = "^0.8"
ExtendableGrids = "^0.7.1"
ExtendableSparse = "^0.3.4"
ForwardDiff = "^0.10.0"
IterativeSolvers = "^0.8.0"
ForwardDiff = "^0.10"
IterativeSolvers = "^0.9"
SparseDiffTools = "1"
SparsityDetection = "^0.3"
StaticArrays = "1"
SparsityDetection = "^0.3.3"
julia = "^1.3"
15 changes: 6 additions & 9 deletions examples/Example102_StationaryConvectionDiffusion1D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ the impact on the qualitative properties of the solution.
module Example102_StationaryConvectionDiffusion1D
using Printf
using VoronoiFVM
using ExtendableGrids

## Central difference flux. The velocity term is discretized using the
## average of the solution in the endpoints of the grid. If the local Peclet
Expand Down Expand Up @@ -116,16 +117,12 @@ function main(;n=10,Plotter=nothing,verbose=false,D=0.01,v=1.0)
solution_upwind=calculate(grid,data,upwind_flux!,verbose)
solution_central=calculate(grid,data,central_flux!,verbose)

if isplots(Plotter)
Plots=Plotter
coord=coordinates(grid)
p=Plots.plot(title="Convection-Diffusion",grid=true)
Plots.plot!(p,coord[1,:],solution_exponential[1,:],label="exponential")
Plots.plot!(p,coord[1,:],solution_upwind[1,:],label="upwind")
Plots.plot!(p,coord[1,:],solution_central[1,:],label="central")
Plots.plot!(p,show=true)
end

p=GridPlotContext(Plotter=Plotter,layout=(3,1))
gridplot!(p[1,1],grid,solution_exponential[1,:],title="exponential")
gridplot!(p[2,1],grid,solution_upwind[1,:],title="upwind")
gridplot!(p[3,1],grid,solution_central[1,:],title="centered",show=true)

## Return test value
return sum(solution_exponential)+sum(solution_upwind)+sum(solution_central)
end
Expand Down
11 changes: 3 additions & 8 deletions examples/Example105_NonlinearPoisson1D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Such equation occur e.g. in simulations of electrochemical systems and semicondu
module Example105_NonlinearPoisson1D
using Printf
using VoronoiFVM
using ExtendableGrids

function main(;n=10,Plotter=nothing,verbose=false, unknown_storage=:sparse)

Expand Down Expand Up @@ -87,14 +88,8 @@ function main(;n=10,Plotter=nothing,verbose=false, unknown_storage=:sparse)
## Stationary solution of the problem
solve!(solution,inival,sys, control=control)

if isplots(Plotter)
coord=coordinates(grid)
Plotter.plot(coord[1,:],solution[1,:],
label="",
title="Nonlinear Poisson",
grid=true,show=true)
end

gridplot(grid,solution[1,:],title="Nonlinear Poisson", Plotter=Plotter)

return sum(solution)
end

Expand Down
20 changes: 5 additions & 15 deletions examples/Example106_NonlinearDiffusion1D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ We initialize this problem with the exact solution for $t=t_0=0.001$.
module Example106_NonlinearDiffusion1D
using Printf
using VoronoiFVM

using ExtendableGrids

function barenblatt(x,t,m)
tx=t^(-1.0/(m+1.0))
Expand Down Expand Up @@ -82,24 +82,14 @@ function main(;n=20,m=2,Plotter=nothing,verbose=false, unknown_storage=:sparse,t
control=VoronoiFVM.NewtonControl()
control.verbose=verbose
time=t0
p=GridPlotContext(Plotter=Plotter,layout=(2,1),fast=true)
while time<tend
time=time+tstep
solve!(solution,inival,sys,control=control,tstep=tstep)
inival.=solution
if verbose
@printf("time=%g\n",time)
end
if isplots(Plotter)
p=Plotter.plot(X,
solution[1,:],
label="numerical",
title=@sprintf("Nonlinear Diffusion t=%.5f",time),
grid=true)
Plotter.plot!(p,X,
map(x->barenblatt(x,time,m),X),
label="exact",
show=true)
end
gridplot!(p[1,1],grid,solution[1,:],title=@sprintf("numerical, t=%.3g",time))
gridplot!(p[2,1],grid,map(x->barenblatt(x,time,m),grid),title=@sprintf("exact, t=%.3g",time))
reveal(p)
end
return sum(solution)
end
Expand Down
21 changes: 6 additions & 15 deletions examples/Example107_NonlinearStorage1D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ example.
module Example107_NonlinearStorage1D
using Printf
using VoronoiFVM

using ExtendableGrids

function barenblatt(x,t,m)
tx=t^(-1.0/(m+1.0))
Expand Down Expand Up @@ -81,24 +81,15 @@ function main(;n=20,m=2.0,Plotter=nothing,verbose=false, unknown_storage=:sparse
control=VoronoiFVM.NewtonControl()
control.verbose=verbose
time=t0
p=GridPlotContext(Plotter=Plotter,layout=(2,1))
while time<tend
time=time+tstep
solve!(solution,inival,sys,control=control,tstep=tstep)
inival.=solution
if verbose
@printf("time=%g\n",time)
end
if isplots(Plotter)
p=Plotter.plot(X,
solution[1,:],
label="numerical",
title=@sprintf("Nonlinear Diffusion t=%.5f",time),
grid=true)
Plotter.plot!(p,X,
map(x->barenblatt(x,time,m)^m,X),
label="exact",
show=true)
end
gridplot!(p[1,1],grid,solution[1,:],title=@sprintf("numerical, t=%.5f",time),clear=true)
gridplot!(p[2,1],grid,map(x->barenblatt(x,time,m)^m,grid),title=@sprintf("exact, t=%.4f",time),clear=true)
sleep(1.0e-5)
# yield()
end
return sum(solution)
end
Expand Down
12 changes: 5 additions & 7 deletions examples/Example110_ReactionDiffusion1D_TwoSpecies.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Example110_ReactionDiffusion1D_TwoSpecies

using Printf
using VoronoiFVM

using ExtendableGrids

function main(;n=100,Plotter=nothing,verbose=false,unknown_storage=:sparse)
h=1/n
Expand Down Expand Up @@ -73,16 +73,14 @@ function main(;n=100,Plotter=nothing,verbose=false,unknown_storage=:sparse)
control.verbose=verbose
control.damp_initial=0.1
u5=0
p=GridPlotContext(Plotter=Plotter,layout=(2,1))
for xeps in [1.0,0.5,0.25,0.1,0.05,0.025,0.01]
eps=[xeps,xeps]
solve!(U,inival,sys,control=control)
inival.=U
if isplots(Plotter)
coord=coordinates(grid)
p=Plotter.plot(coord[1,:],U[1,:], grid=true)
Plotter.plot!(p,coord[1,:],U[2,:],show=true, title=@sprintf("\$\\varepsilon=%8.3f\$",xeps)),
Plotter.sleep(0.2)
end
gridplot!(p[1,1],grid,U[1,:],clear=true,title="U1, eps=$(xeps)")
gridplot!(p[2,1],grid,U[2,:],clear=true,title="U2, eps=$(xeps)",reveal=true)
sleep(0.2)
u5=U[5]
end
return u5
Expand Down
17 changes: 6 additions & 11 deletions examples/Example115_HeterogeneousCatalysis1D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ R_{BC}(u_C, u_B)&=k_{BC}^+ u_B(1-u_C) - k_{BC}^-u_C\\
module Example115_HeterogeneousCatalysis1D
using Printf
using VoronoiFVM
using ExtendableGrids

function main(;n=10,Plotter=nothing,verbose=false,tend=1, unknown_storage=:sparse)

Expand Down Expand Up @@ -157,6 +158,7 @@ function main(;n=10,Plotter=nothing,verbose=false,tend=1, unknown_storage=:spars
T=zeros(0)
u_C=zeros(0)

p=GridPlotContext(Plotter=Plotter,layout=(3,1))
while time<tend
time=time+tstep
solve!(U,inival,sys,tstep=tstep)
Expand All @@ -168,17 +170,10 @@ function main(;n=10,Plotter=nothing,verbose=false,tend=1, unknown_storage=:spars
push!(T,time)
push!(u_C,U[iC,1])

if isplots(Plotter)
Plots=Plotter
coord=coordinates(grid)
p1=Plots.plot(coord[1,:],U[iA,:], grid=true, label="[A]")
Plots.plot!(p1,coord[1,:],U[iB,:], label="[B]",
title=@sprintf("max_A=%.5f max_B=%.5f u_C=%.5f\n",maximum(U[iA,:]),maximum(U[iB,:]),u_C[end]),
ylabel="[A], [B]", xlabel="x",legend=:topright,framestyle=:full)
p2=Plots.plot(T,u_C,ylabel="[C]",xlabel="t",framestyle=:full, label="[C]")
p=Plots.plot(p1,p2,layout=(2,1))
Plots.gui(p)
end
gridplot!(p[1,1],grid,U[iA,:],clear=true,title=@sprintf("[A]: (%.3f,%.3f)",extrema(U[iA,:])...))
gridplot!(p[2,1],grid,U[iB,:],clear=true,title=@sprintf("[B]: (%.3f,%.3f)",extrema(U[iA,:])...))
gridplot!(p[3,1],simplexgrid(copy(T)),copy(u_C),clear=true,title=@sprintf("[C]: %.3f",u_C[end]),show=true)
yield()
end
return U[iC,1]
end
Expand Down
39 changes: 18 additions & 21 deletions examples/Example120_ThreeRegions1D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using ExtendableGrids



function main(;n=30,Plotter=nothing,plot_grid=false, verbose=false,unknown_storage=:sparse)
function main(;n=30,Plotter=nothing,plot_grid=false, verbose=false,unknown_storage=:sparse,tend=10)
h=3.0/(n-1)
X=collect(0:h:3.0)
grid=VoronoiFVM.Grid(X)
Expand All @@ -21,10 +21,8 @@ function main(;n=30,Plotter=nothing,plot_grid=false, verbose=false,unknown_stora
subgrid2=subgrid(grid,[1,2,3])
subgrid3=subgrid(grid,[3])

if isplots(Plotter)&&plot_grid
p=Plotter.plot()
VoronoiFVM.plot(Plotter,grid,p=p)
Plotter.gui(p)
if plot_grid
plotgrid(grid,Plotter=Plotter)
return
end

Expand Down Expand Up @@ -87,36 +85,35 @@ function main(;n=30,Plotter=nothing,plot_grid=false, verbose=false,unknown_stora
tstep=0.01
time=0.0
istep=0
tend=10
testval=0
p=GridPlotContext(Plotter=Plotter,layout=(1,1))
while time<tend
time=time+tstep
solve!(U,inival,sys,control=control,tstep=tstep)
inival.=U
if verbose
@printf("time=%g\n",time)
end
tstep*=1.0
tstep*=1.1
istep=istep+1
testval=U[2,15]
if isplots(Plotter)
Plots=Plotter
p=Plots.plot()
U1=view(U[1,:],subgrid1)
U2=view(U[2,:],subgrid2)
U3=view(U[3,:],subgrid3)
plot(subgrid1, U1,label="spec1", color=(0.5,0,0),p=p,show=false, Plotter=Plots)
plot(subgrid2, U2,label="spec2", color=(0.0,0.5,0),p=p,show=false, Plotter=Plots)
plot(subgrid3, U3,label="spec3", color=(0.0,0.0,0.5),p=p,show=false, Plotter=Plots)
Plots.gui(p)
end
testval=U[2,5]

U1=view(U[1,:],subgrid1)
U2=view(U[2,:],subgrid2)
U3=view(U[3,:],subgrid3)

gridplot!(p[1,1],subgrid1, U1,label="spec1", color=(0.5,0,0),xlimits=(0,3),flimits=(0,1e-3),
title=@sprintf("three regions t=%.3g",time))
gridplot!(p[1,1],subgrid2, U2,label="spec2", color=(0.0,0.5,0),clear=false)
gridplot!(p[1,1],subgrid3, U3,label="spec3", color=(0.0,0.0,0.5),clear=false,show=true)
end
return testval
end

function test()
main(unknown_storage=:sparse) 0.00039500514567080265 &&
main(unknown_storage=:dense) 0.00039500514567080265
testval=0.0005954993329548969
main(unknown_storage=:sparse) testval &&
main(unknown_storage=:dense) testval
end

end
12 changes: 5 additions & 7 deletions examples/Example125_TestFunctions1D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
module Example125_TestFunctions1D
using Printf
using VoronoiFVM

using ExtendableGrids


function main(;n=100,Plotter=nothing,verbose=false,unknown_storage=:sparse)
Expand Down Expand Up @@ -55,18 +55,16 @@ function main(;n=100,Plotter=nothing,verbose=false,unknown_storage=:sparse)
control.verbose=verbose
control.damp_initial=0.1
I1=0
p=GridPlotContext(Plotter=Plotter,layout=(2,1))
for xeps in [1.0,0.1,0.01]
eps=[xeps,xeps]
solve!(U,inival,sys,control=control)
I1=integrate(sys,tf1,U)
coord=coordinates(grid)
inival.=U
if isplots(Plotter)
p=Plotter.plot()
Plotter.plot!(p,coord[1,:],U[1,:])
Plotter.plot!(p,coord[1,:],U[2,:])
Plotter.gui(p)
end
gridplot!(p[1,1],grid,U[1,:])
gridplot!(p[2,1],grid,U[2,:])
reveal(p)
u5=U[5]
end
return I1[1]
Expand Down
13 changes: 5 additions & 8 deletions examples/Example150_Impedance1D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module Example150_Impedance1D

using Printf
using VoronoiFVM
using ExtendableGrids

function main(;nref=0,Plotter=nothing,verbose=false, unknown_storage=:sparse)

Expand Down Expand Up @@ -155,14 +156,10 @@ function main(;nref=0,Plotter=nothing,verbose=false, unknown_storage=:sparse)
ω=ω*1.2

end

if isplots(Plotter)
p=Plotter.plot(grid=true)
Plotter.plot!(p,real(allIL),imag(allIL),label="calc")
Plotter.plot!(p,real(allIxL),imag(allIxL),label="exact")
Plotter.gui(p)
end
#return test value

p=GridPlotContext(Plotter=Plotter)
gridplot!(p,real(allIL),imag(allIL),label="calc",color=:red)
gridplot!(p,real(allIxL),imag(allIxL),label="exact",show=true,clear=false,color=:blue)
return imag(allIL[5])
end

Expand Down
Loading

2 comments on commit 53ee3b5

@j-fu
Copy link
Member Author

@j-fu j-fu commented on 53ee3b5 Jan 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/27634

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.10.0 -m "<description of version>" 53ee3b58cf505a259393c7cf4f953d0c4cc13d67
git push origin v0.10.0

Please sign in to comment.