Skip to content

Commit

Permalink
Merge pull request #61 from j-fu/handle_incomplete
Browse files Browse the repository at this point in the history
Make parts of simplexgrid constructor optional
  • Loading branch information
j-fu authored Sep 29, 2024
2 parents c9144ca + 0bf96c8 commit 8a97c23
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/extendablegrid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ $(TYPEDSIGNATURES)
Instantiate number of bface regions
"""
instantiate(grid, ::Type{NumBFaceRegions}) = maximum(grid[BFaceRegions])
instantiate(grid, ::Type{NumBFaceRegions}) = length(grid[BFaceRegions])> 0 ? maximum(grid[BFaceRegions]) : 0

"""
$(TYPEDSIGNATURES)
Expand Down
18 changes: 9 additions & 9 deletions src/simplexgrid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
````
function simplexgrid(coord::Array{Tc,2},
cellnodes::Array{Ti,2},
cellregions,
bfacenodes,
bfaceregions
cellregions=ones(Ti, size(coord,2)),
bfacenodes=zeros(Ti,size(coord,1),0),
bfaceregions=zeros(Ti,length(bfacenodes))
) where {Tc,Ti}
````
Create d-dimensional simplex grid from five arrays.
- coord: d ``\\times`` n_points matrix of coordinates
- cellnodes: d+1 ``\\times`` n_tri matrix of triangle - point incidence
- cellregions: n_tri vector of cell region markers
- bfacenodes: d ``\\times`` n_bf matrix of boundary facet - point incidences
- bfaceregions: n_bf vector of boundary facet region markers
- cellregions: (optional) n_tri vector of cell region markers
- bfacenodes: (optional) d ``\\times`` n_bf matrix of boundary facet - point incidences
- bfaceregions: (optional) n_bf vector of boundary facet region markers
Coordinate type `Tc` index type `Ti` are detected from the first two parameters.
`cellregions`, `bfaceregions`, `bfacenodes` are converted to have the same element type as `cellnodes`.
"""
function simplexgrid(coord::AbstractArray{Tc,2},
cellnodes::AbstractArray{Ti,2},
cellregions,
bfacenodes,
bfaceregions
cellregions=ones(Ti, size(cellnodes,2)),
bfacenodes=zeros(Ti,size(coord,1),0),
bfaceregions=zeros(Ti,length(bfacenodes))
) where {Tc,Ti}
@assert size(coord,2)>0
dim=size(coord,1)
Expand Down
52 changes: 33 additions & 19 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ using Test, Aqua
using ExampleJuggler

using ExtendableGrids, SHA
using ExtendableGrids: seal!

using AbstractTrees, StatsBase

Expand Down Expand Up @@ -51,26 +52,39 @@ end
end

@testset "Basic" begin
@test let
nodes = [0.0 1;
1 0;
0 1;
1 1]'

cells = [1 2 3;
2 3 4]'

cellmat = [1, 1]
bfaces = [1 2;
1 3;
2 4]'

bfacemat = [1, 1]

grid = simplexgrid(nodes, cells, cellmat, bfaces, bfacemat)
isconsistent(grid)
end
nodes = [0.0 1;
1 0;
0 1;
1 1]'

cells = [1 2 3;
2 3 4]'

cellmat = [1, 1]
bfaces = [1 2;
1 3;
2 4]'

bfacemat = [1, 1]

grid = simplexgrid(nodes, cells, cellmat, bfaces, bfacemat)
@test isconsistent(grid)

grid = simplexgrid(nodes, cells, cellmat, bfaces)
@test isconsistent(grid)
seal!(grid)
@test isconsistent(grid)

grid = simplexgrid(nodes, cells, cellmat)
@test isconsistent(grid)
seal!(grid)
@test isconsistent(grid)

grid = simplexgrid(nodes, cells)
@test isconsistent(grid)
seal!(grid)
@test isconsistent(grid)

@test let
nodes = [0.0 1;
1 0;
Expand Down

0 comments on commit 8a97c23

Please sign in to comment.