Skip to content

Commit

Permalink
moved tests to examplejuggler
Browse files Browse the repository at this point in the history
  • Loading branch information
j-fu committed Nov 23, 2023
1 parent db7713f commit bf6fa5d
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 181 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ExtendableGrids"
uuid = "cfc395e8-590f-11e8-1f13-43a2532b2fa8"
authors = ["Juergen Fuhrmann <juergen.fuhrmann@wias-berlin.de>, Christian Merdon <christian.merdon@wias-berlin.de>"]
version = "1.1.0"
version = "1.2.0"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
3 changes: 1 addition & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
ENV["MPLBACKEND"] = "agg"
using Documenter, ExtendableGrids, Literate, GridVisualize, SimplexGridFactory, Gmsh
using Documenter, ExtendableGrids, Literate, GridVisualize, SimplexGridFactory, Gmsh, Test
import CairoMakie, Triangulate

CairoMakie.activate!(; type = "svg", visible = false)
Expand Down
44 changes: 25 additions & 19 deletions examples/examples1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,51 @@ using ExtendableGrids
# ## Interval from vector
#
function interval_from_vector()
X=collect(0:0.05:1)
grid=simplexgrid(X)
X = collect(0:0.05:1)
grid = simplexgrid(X)
end
# ![](interval_from_vector.svg)

#
# ##Interval with local refinement
#
function interval_localref()

XLeft=geomspace(0.0,0.5,0.1, 0.01)
XRight=geomspace(0.5,1.0,0.01,0.1)
X=glue(XLeft, XRight)
grid=simplexgrid(X)
XLeft = geomspace(0.0, 0.5, 0.1, 0.01)
XRight = geomspace(0.5, 1.0, 0.01, 0.1)
X = glue(XLeft, XRight)
grid = simplexgrid(X)
end
# ![](interval_localref.svg)


#
# ## Interval with multiple regions
#
function interval_multiregion()

X=collect(0:0.05:1)
grid=simplexgrid(X)
cellmask!(grid,[0.0],[0.5],3)
bfacemask!(grid,[0.5], [0.5],4)
X = collect(0:0.05:1)
grid = simplexgrid(X)
cellmask!(grid, [0.0], [0.5], 3)
bfacemask!(grid, [0.5], [0.5], 4)
grid
end
# ![](interval_multiregion.svg)
#
# ## Multiple regions and subgrid
#
function interval_subgrid()
X=collect(0:0.01:1)
grid=simplexgrid(X)
bfacemask!(grid,[0.5],[0.5],3)
cellmask!(grid,[0.0],[0.25],2)
cellmask!(grid,[0.20],[0.5],3)
subgrid(grid,[2,3])
X = collect(0:0.01:1)
grid = simplexgrid(X)
bfacemask!(grid, [0.5], [0.5], 3)
cellmask!(grid, [0.0], [0.25], 2)
cellmask!(grid, [0.20], [0.5], 3)
subgrid(grid, [2, 3])
end
# ![](interval_subgrid.svg)

using Test

function runtests()
@test numbers_match(interval_from_vector(), 21, 20, 2)
@test numbers_match(interval_localref(), 27, 26, 2)
@test numbers_match(interval_multiregion(), 21, 20, 3)
@test numbers_match(interval_subgrid(), 51, 50, 2)
end
129 changes: 67 additions & 62 deletions examples/examples2d.jl
Original file line number Diff line number Diff line change
@@ -1,104 +1,109 @@
# 2D Grid examples
# ===============
#
using Triangulate, ExtendableGrids, SimplexGridFactory

# ## Rectangle
function rectangle()
X=collect(0:0.05:1)
Y=collect(0:0.05:1)
simplexgrid(X,X)
X = collect(0:0.05:1)
Y = collect(0:0.05:1)
simplexgrid(X, X)
end
# ![](rectangle.svg)
#
# ## Rectangle with local refinement
#
function rectangle_localref()
hmin=0.01
hmax=0.1
XLeft=geomspace(0.0,0.5,hmax,hmin)
XRight=geomspace(0.5,1.0,hmin,hmax)
X=glue(XLeft, XRight)
simplexgrid(X,X)
hmin = 0.01
hmax = 0.1
XLeft = geomspace(0.0, 0.5, hmax, hmin)
XRight = geomspace(0.5, 1.0, hmin, hmax)
X = glue(XLeft, XRight)
simplexgrid(X, X)
end
# ![](rectangle_localref.svg)


#
# ## Rectangle with multiple regions
#
function rectangle_multiregion()
X=collect(0:0.05:1)
Y=collect(0:0.05:1)
grid=simplexgrid(X,Y)
cellmask!(grid,[0.0,0.0],[1.0,0.5],3)
bfacemask!(grid,[0.0,0.0],[0.0,0.5],5)
bfacemask!(grid,[1.0,0.0],[1.0,0.5],6)
bfacemask!(grid,[0.0,0.5],[1.0,0.5],7)
X = collect(0:0.05:1)
Y = collect(0:0.05:1)
grid = simplexgrid(X, Y)
cellmask!(grid, [0.0, 0.0], [1.0, 0.5], 3)
bfacemask!(grid, [0.0, 0.0], [0.0, 0.5], 5)
bfacemask!(grid, [1.0, 0.0], [1.0, 0.5], 6)
bfacemask!(grid, [0.0, 0.5], [1.0, 0.5], 7)
end
# ![](rectangle_multiregion.svg)



#
# ## Subgrid from rectangle
#
function rectangle_subgrid()
X=collect(0:0.05:1)
Y=collect(0:0.05:1)
grid=simplexgrid(X,Y)
rect!(grid,[0.25,0.25],[0.75,0.75];region=2, bregion=5)
subgrid(grid,[1])
X = collect(0:0.05:1)
Y = collect(0:0.05:1)
grid = simplexgrid(X, Y)
rect!(grid, [0.25, 0.25], [0.75, 0.75]; region = 2, bregion = 5)
subgrid(grid, [1])
end
# ![](rectangle_subgrid.svg)


#
# ## Rect2d with bregion function
#
# Here, we use function as bregion parameter - this allows to
# have no bfaces at the interface between the two rects.
function rect2d_bregion_function()
X=collect(0:0.5:10)
Y=collect(0:0.5:10)
grid=simplexgrid(X,Y)
rect!(grid,[5,4],[9,6];region=2, bregions=[5,5,5,5])
X = collect(0:0.5:10)
Y = collect(0:0.5:10)
grid = simplexgrid(X, Y)
rect!(grid, [5, 4], [9, 6]; region = 2, bregions = [5, 5, 5, 5])

rect!(grid, [4, 2], [5, 8]; region = 2, bregion = cur -> cur == 5 ? 0 : 8)

rect!(grid,[4,2],[5,8];region=2, bregion= cur-> cur == 5 ? 0 : 8 )

subgrid(grid,[2])

subgrid(grid, [2])
end
# ![](rect2d_bregion_function.svg)




function sorted_subgrid(; maxvolume=0.01)

builder=SimplexGridBuilder(Generator=Triangulate)

p1=point!(builder,0,0)
p2=point!(builder,1,0)
p3=point!(builder,1,2)
p4=point!(builder,0,1)
p5=point!(builder,-1,2)

facetregion!(builder,1)
facet!(builder,p1,p2)
facetregion!(builder,2)
facet!(builder,p2,p3)
facetregion!(builder,3)
facet!(builder,p3,p4)
facetregion!(builder,4)
facet!(builder,p4,p5)
facetregion!(builder,5)
facet!(builder,p5,p1)

g=simplexgrid(builder;maxvolume)
sg=subgrid(g,[2],boundary=true,transform=(a,b)->a[1]=b[2])
f=map( (x,y)->sin(3x)*cos(3y),g)
sf=view(f,sg)
g,sg,sf
function sorted_subgrid(; maxvolume = 0.01)
builder = SimplexGridBuilder(; Generator = Triangulate)

p1 = point!(builder, 0, 0)
p2 = point!(builder, 1, 0)
p3 = point!(builder, 1, 2)
p4 = point!(builder, 0, 1)
p5 = point!(builder, -1, 2)

facetregion!(builder, 1)
facet!(builder, p1, p2)
facetregion!(builder, 2)
facet!(builder, p2, p3)
facetregion!(builder, 3)
facet!(builder, p3, p4)
facetregion!(builder, 4)
facet!(builder, p4, p5)
facetregion!(builder, 5)
facet!(builder, p5, p1)

g = simplexgrid(builder; maxvolume)
sg = subgrid(g, [2]; boundary = true, transform = (a, b) -> a[1] = b[2])
f = map((x, y) -> sin(3x) * cos(3y), g)
sf = view(f, sg)
g, sg, sf
end
# ![](sorted_subgrid.svg)

using Test
function runtests()
@test numbers_match(rectangle(), 441, 800, 80)
@test numbers_match(rectangle_localref(), 729, 1352, 104)
@test numbers_match(rectangle_multiregion(), 441, 800, 100)
@test numbers_match(rectangle_subgrid(), 360, 600, 120)
@test numbers_match(rect2d_bregion_function(), 79, 112, 44)

g, sg, sf = sorted_subgrid()
@test numbers_match(g, 187, 306, 66)
@test numbers_match(sg, 17, 16, 0)
@test issorted(view(sg[Coordinates], 1, :))
end
38 changes: 20 additions & 18 deletions examples/examples3d.jl
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
# 3D Grid examples
# ===============
#
using ExtendableGrids

# ## Quadrilateral
function quadrilateral(;hx=0.25, hy=0.2, hz=0.1)
X=collect(0:hx:1)
Y=collect(0:hy:1)
Z=collect(0:hz:1)
simplexgrid(X,Y,Z)
function quadrilateral(; hx = 0.25, hy = 0.2, hz = 0.1)
X = collect(0:hx:1)
Y = collect(0:hy:1)
Z = collect(0:hz:1)
simplexgrid(X, Y, Z)
end
# ![](quadrilateral.svg)

# ## Cross3d
function cross3d()
X=collect(0:1:10)
Y=collect(0:1:10)
Z=collect(0:1:10)
grid=simplexgrid(X,Y,Z)
X = collect(0:1:10)
Y = collect(0:1:10)
Z = collect(0:1:10)
grid = simplexgrid(X, Y, Z)

rect!(grid, (0,4,0), (10,6,2), region=2, bregions=[1,1,1,1,2,3])
rect!(grid, (0, 4, 0), (10, 6, 2); region = 2, bregions = [1, 1, 1, 1, 2, 3])

rect!(grid, (4,0,2), (6,10,4), region=2, bregions=[ 4,4,4,4, (cur)-> cur == 3 ? 0 : 5 , 6] )

subgrid(grid,[2])
rect!(grid, (4, 0, 2), (6, 10, 4); region = 2, bregions = [4, 4, 4, 4, (cur) -> cur == 3 ? 0 : 5, 6])

subgrid(grid, [2])
end
# ![](cross3d.svg)





function mask_bedges()
grid = quadrilateral(hx=0.25, hy=0.25, hz=0.25)
grid = quadrilateral(; hx = 0.25, hy = 0.25, hz = 0.25)

bedgemask!(grid, [0.0, 0.0, 0.0], [0.0, 0.0, 1.0], 1)
bedgemask!(grid, [0.0, 0.0, 0.0], [0.0, 1.0, 0.0], 2)
Expand All @@ -43,4 +39,10 @@ function mask_bedges()
true
end

using Test

function runtests()
@test numbers_match(quadrilateral(), 330, 1200, 440)
@test mask_bedges()
@test numbers_match(cross3d(), 189, 480, 344)
end
2 changes: 1 addition & 1 deletion src/ExtendableGrids.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export dim_space, dim_grid
export num_nodes, num_cells, num_bfaces, num_bedges
export num_cellregions, num_bfaceregions, num_bedgeregions
export gridcomponents
export seemingly_equal
export seemingly_equal, numbers_match

include("subgrid.jl")
export subgrid
Expand Down
6 changes: 6 additions & 0 deletions src/extendablegrid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,12 @@ seemingly_equal(x1::Type, x2::Type) = (x1 == x2)
seemingly_equal(x1::Number, x2::Number) = (x1 x2)
seemingly_equal(x1::Any, x2::Any) = (x1 == x2)

function numbers_match(grid, nn, nc, nb)
num_nodes(grid) == nn &&
num_cells(grid) == nc &&
num_bfaces(grid) == nb
end

Base.extrema(grid::ExtendableGrid) = Base.extrema(grid[Coordinates]; dims = 2)

function bbox(grid)
Expand Down
7 changes: 4 additions & 3 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[deps]
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
ExampleJuggler = "3bbe58f8-ed81-4c4e-a134-03e85fcf4a1a"
Gmsh = "705231aa-382f-11e9-3f0c-b7cb4346fdeb"
GridVisualize = "5eed8a63-0fb0-45eb-886d-8d5a387d12b8"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
SimplexGridFactory = "57bfcd06-606e-45d6-baf4-4ba06da0efd5"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Triangulate = "f7e6ffb2-c36d-4f8f-a77e-16e897189344"

[compat]
ExampleJuggler = "0.4"
Loading

0 comments on commit bf6fa5d

Please sign in to comment.