diff --git a/src/extendablegrid.jl b/src/extendablegrid.jl index 82cd56a3..42373db7 100644 --- a/src/extendablegrid.jl +++ b/src/extendablegrid.jl @@ -12,9 +12,9 @@ $(TYPEDEF) Grid type wrapping Dict """ -mutable struct ExtendableGrid{Tc,Ti} - components::Dict{Type{<:AbstractGridComponent},Any} - ExtendableGrid{Tc,Ti}() where{Tc,Ti} =new(Dict{Type{<:AbstractGridComponent},Any}()) +mutable struct ExtendableGrid{Tc, Ti} + components::Dict{Type{<:AbstractGridComponent}, Any} + ExtendableGrid{Tc, Ti}() where {Tc, Ti} = new(Dict{Type{<:AbstractGridComponent}, Any}()) end """ @@ -30,8 +30,7 @@ are created on demand. Due to the fact that components are stored as Any the return value triggers type instability. To prevent this, specialized methods must be (and are) defined. """ -Base.getindex( grid::ExtendableGrid, T::Type{<:AbstractGridComponent} ) = get!(grid,T) - +Base.getindex(grid::ExtendableGrid, T::Type{<:AbstractGridComponent}) = get!(grid, T) """ ```` @@ -42,8 +41,7 @@ Union type for element information arrays. If all elements have the same information, it can be stored in an economical form as a [`VectorOfConstants`](@ref). """ -const ElementInfo{T}=Union{Vector{T},VectorOfConstants{T}} - +const ElementInfo{T} = Union{Vector{T}, VectorOfConstants{T}} """ $(TYPEDEF) @@ -51,8 +49,9 @@ $(TYPEDEF) """ abstract type AbstractGridFloatArray1D <: AbstractGridComponent end -function Base.getindex( grid::ExtendableGrid{Tc,Ti}, T::Type{<:AbstractGridFloatArray1D} )::Array{Tc,1} where{Tc,Ti} get!(grid,T) end - +function Base.getindex(grid::ExtendableGrid{Tc, Ti}, T::Type{<:AbstractGridFloatArray1D})::Array{Tc, 1} where {Tc, Ti} + get!(grid, T) +end """ $(TYPEDEF) @@ -60,7 +59,9 @@ $(TYPEDEF) """ abstract type AbstractGridFloatArray2D <: AbstractGridComponent end -function Base.getindex( grid::ExtendableGrid{Tc,Ti}, T::Type{<:AbstractGridFloatArray2D} )::Array{Tc,2} where{Tc,Ti} get!(grid,T) end +function Base.getindex(grid::ExtendableGrid{Tc, Ti}, T::Type{<:AbstractGridFloatArray2D})::Array{Tc, 2} where {Tc, Ti} + get!(grid, T) +end """ $(TYPEDEF) @@ -68,9 +69,9 @@ $(TYPEDEF) """ abstract type AbstractGridIntegerArray1D <: AbstractGridComponent end -function Base.getindex( grid::ExtendableGrid{Tc,Ti}, T::Type{<:AbstractGridIntegerArray1D} )::Array{Ti,1} where{Tc,Ti} get!(grid,T) end - - +function Base.getindex(grid::ExtendableGrid{Tc, Ti}, T::Type{<:AbstractGridIntegerArray1D})::Array{Ti, 1} where {Tc, Ti} + get!(grid, T) +end """ $(TYPEDEF) @@ -78,8 +79,9 @@ $(TYPEDEF) """ abstract type AbstractGridIntegerArray2D <: AbstractGridComponent end -function Base.getindex( grid::ExtendableGrid{Tc,Ti}, T::Type{<:AbstractGridIntegerArray2D} )::Array{Ti,1} where{Tc,Ti} get!(grid,T) end - +function Base.getindex(grid::ExtendableGrid{Tc, Ti}, T::Type{<:AbstractGridIntegerArray2D})::Array{Ti, 1} where {Tc, Ti} + get!(grid, T) +end """ $(TYPEDEF) @@ -87,8 +89,9 @@ Integer number """ abstract type AbstractGridIntegerConstant <: AbstractGridComponent end -function Base.getindex( grid::ExtendableGrid{Tc,Ti}, T::Type{<:AbstractGridIntegerConstant})::Ti where{Tc,Ti} get!(grid,T) end - +function Base.getindex(grid::ExtendableGrid{Tc, Ti}, T::Type{<:AbstractGridIntegerConstant})::Ti where {Tc, Ti} + get!(grid, T) +end """ $(TYPEDEF) @@ -96,7 +99,9 @@ Floating point number """ abstract type AbstractGridFloatConstant <: AbstractGridComponent end -function Base.getindex( grid::ExtendableGrid{Tc,Ti}, T::Type{<:AbstractGridFloatConstant} )::Tc where{Tc,Ti} get!(grid,T) end +function Base.getindex(grid::ExtendableGrid{Tc, Ti}, T::Type{<:AbstractGridFloatConstant})::Tc where {Tc, Ti} + get!(grid, T) +end """ $(TYPEDEF) @@ -105,7 +110,9 @@ Any kind of adjacency between grid components """ abstract type AbstractGridAdjacency <: AbstractGridComponent end -function Base.getindex( grid::ExtendableGrid{Tc,Ti}, T::Type{<:AbstractGridAdjacency} )::Adjacency{Ti} where{Tc,Ti} get!(grid,T) end +function Base.getindex(grid::ExtendableGrid{Tc, Ti}, T::Type{<:AbstractGridAdjacency})::Adjacency{Ti} where {Tc, Ti} + get!(grid, T) +end """ $(TYPEDEF) @@ -114,10 +121,10 @@ Array of element geometry information. """ abstract type AbstractElementGeometries <: AbstractGridComponent end -function Base.getindex( grid::ExtendableGrid{Tc,Ti}, T::Type{<:AbstractElementGeometries} )::ElementInfo{ElementGeometries} where{Tc,Ti} get!(grid,T) end - - - +function Base.getindex(grid::ExtendableGrid{Tc, Ti}, + T::Type{<:AbstractElementGeometries})::ElementInfo{ElementGeometries} where {Tc, Ti} + get!(grid, T) +end """ $(TYPEDEF) @@ -126,8 +133,9 @@ Array of element region number information. """ abstract type AbstractElementRegions <: AbstractGridComponent end -function Base.getindex( grid::ExtendableGrid{Tc,Ti}, T::Type{<:AbstractElementRegions} )::ElementInfo{Ti} where{Tc,Ti} get!(grid,T) end - +function Base.getindex(grid::ExtendableGrid{Tc, Ti}, T::Type{<:AbstractElementRegions})::ElementInfo{Ti} where {Tc, Ti} + get!(grid, T) +end """ $(TYPEDEF) @@ -136,9 +144,9 @@ Coordinate system """ abstract type CoordinateSystem <: AbstractGridComponent end -function Base.getindex( grid::ExtendableGrid{Tc,Ti}, T::Type{CoordinateSystem} )::CoordinateSystems where{Tc,Ti} get!(grid,T) end - - +function Base.getindex(grid::ExtendableGrid{Tc, Ti}, T::Type{CoordinateSystem})::CoordinateSystems where {Tc, Ti} + get!(grid, T) +end ################################################################## # Component key types: for these, access is type stable @@ -164,7 +172,6 @@ Adjacency describing nodes per grid boundary face """ abstract type BFaceNodes <: AbstractGridAdjacency end - """ $(TYPEDEF) @@ -221,8 +228,6 @@ Number of boundary edge regions """ abstract type NumBEdgeRegions <: AbstractGridIntegerConstant end - - ############################################################ # Generic component methods @@ -235,24 +240,21 @@ and possibly transform components to be added to the grid via `setindex!`. The default method just passes data through. """ -veryform(grid::ExtendableGrid,v,::Type{<:AbstractGridComponent})=v - +veryform(grid::ExtendableGrid, v, ::Type{<:AbstractGridComponent}) = v """ $(TYPEDSIGNATURES) Set new grid component """ -Base.setindex!(grid::ExtendableGrid,v,T::Type{<:AbstractGridComponent})= grid.components[T]=veryform(grid,v,T) +Base.setindex!(grid::ExtendableGrid, v, T::Type{<:AbstractGridComponent}) = grid.components[T] = veryform(grid, v, T) """ $(TYPEDSIGNATURES) Remove grid component """ -Base.delete!(grid::ExtendableGrid,T::Type{<:AbstractGridComponent})= delete!(grid.components,T) - - +Base.delete!(grid::ExtendableGrid, T::Type{<:AbstractGridComponent}) = delete!(grid.components, T) """ $(TYPEDSIGNATURES) @@ -260,8 +262,8 @@ $(TYPEDSIGNATURES) To be called by getindex. This triggers lazy creation of non-existing gridcomponents """ -Base.get!(grid::ExtendableGrid,T::Type{<:AbstractGridComponent})= get!( ()->veryform(grid,instantiate(grid,T),T), grid.components,T) - +Base.get!(grid::ExtendableGrid, T::Type{<:AbstractGridComponent}) = get!(() -> veryform(grid, instantiate(grid, T), T), + grid.components, T) """ $(TYPEDSIGNATURES) @@ -270,9 +272,6 @@ $(TYPEDSIGNATURES) """ function instantiate end - - - ############################################################ # Verfication of inserted data @@ -283,14 +282,8 @@ veryform(grid::ExtendableGrid{Tc,Ti},v,T::Type{<:AbstractGridAdjacency}) where{T Check proper type of adjacencies upon insertion """ -veryform(grid::ExtendableGrid{Tc,Ti},v,T::Type{<:AbstractGridAdjacency}) where{Tc,Ti}= typeof(v)<:Adjacency{Ti} ? v : throw("Type mismatch") - - - - - - - +veryform(grid::ExtendableGrid{Tc, Ti}, v, T::Type{<:AbstractGridAdjacency}) where {Tc, Ti} = typeof(v) <: Adjacency{Ti} ? v : + throw("Type mismatch") ############################################################ # Instantiation methods @@ -300,32 +293,29 @@ $(TYPEDSIGNATURES) Instantiate number of cell regions """ -instantiate(grid, ::Type{NumCellRegions})=maximum(grid[CellRegions]) +instantiate(grid, ::Type{NumCellRegions}) = maximum(grid[CellRegions]) """ $(TYPEDSIGNATURES) Instantiate number of bface regions """ -instantiate(grid, ::Type{NumBFaceRegions})=maximum(grid[BFaceRegions]) - +instantiate(grid, ::Type{NumBFaceRegions}) = maximum(grid[BFaceRegions]) """ $(TYPEDSIGNATURES) Instantiate number of boundary edge regions """ -instantiate(grid, ::Type{NumBEdgeRegions})=maximum(grid[BEdgeRegions]) +instantiate(grid, ::Type{NumBEdgeRegions}) = maximum(grid[BEdgeRegions]) function prepare_bedgeregions!(grid::ExtendableGrid) - bedges = grid[BEdgeNodes] - bedgeregions = zeros(Int32, num_bedges(grid)) + bedges = grid[BEdgeNodes] + bedgeregions = zeros(Int32, num_bedges(grid)) grid[BEdgeRegions] = bedgeregions end - -instantiate(grid, ::Type{BEdgeRegions})=prepare_bedgeregions!(grid) - +instantiate(grid, ::Type{BEdgeRegions}) = prepare_bedgeregions!(grid) ############################################################# # General methods @@ -335,112 +325,97 @@ $(TYPEDSIGNATURES) Print the hierarchy of grid component key types (subtypes of [`AbstractGridComponent`](@ref). This includes additionally user defined subptypes. """ -gridcomponents()=AbstractTrees.print_tree(AbstractGridComponent) - - +gridcomponents() = AbstractTrees.print_tree(AbstractGridComponent) """ $(TYPEDSIGNATURES) Keys in grid """ -Base.keys(g::ExtendableGrid)=Base.keys(g.components) - +Base.keys(g::ExtendableGrid) = Base.keys(g.components) """ $(TYPEDSIGNATURES) Check if key is in grid """ -Base.haskey(g::ExtendableGrid,k) = Base.haskey(g.components,k) - +Base.haskey(g::ExtendableGrid, k) = Base.haskey(g.components, k) """ $(SIGNATURES) Space dimension of grid """ -dim_space(grid::ExtendableGrid)= size(grid[Coordinates],1) - +dim_space(grid::ExtendableGrid) = size(grid[Coordinates], 1) """ $(SIGNATURES) Grid dimension dimension of grid (larges element dimension) """ -dim_grid(grid::ExtendableGrid)= dim_element(grid[CellGeometries][1]) - +dim_grid(grid::ExtendableGrid) = dim_element(grid[CellGeometries][1]) """ $(SIGNATURES) Number of nodes in grid """ -num_nodes(grid::ExtendableGrid)::Int= size(grid[Coordinates],2) - +num_nodes(grid::ExtendableGrid)::Int = size(grid[Coordinates], 2) """ $(TYPEDSIGNATURES) Number of cells in grid """ -num_cells(grid::ExtendableGrid)= num_sources(grid[CellNodes]) - +num_cells(grid::ExtendableGrid) = num_sources(grid[CellNodes]) """ $(TYPEDSIGNATURES) Number of boundary faces in grid. """ -num_bfaces(grid::ExtendableGrid)= haskey(grid,BFaceNodes) ? num_sources(grid[BFaceNodes]) : 0 +num_bfaces(grid::ExtendableGrid) = haskey(grid, BFaceNodes) ? num_sources(grid[BFaceNodes]) : 0 """ $(TYPEDSIGNATURES) Number of boundary edges in grid. """ -num_bedges(grid::ExtendableGrid)= haskey(grid,BEdgeNodes) ? num_sources(grid[BEdgeNodes]) : 0 - - +num_bedges(grid::ExtendableGrid) = haskey(grid, BEdgeNodes) ? num_sources(grid[BEdgeNodes]) : 0 """ $(TYPEDSIGNATURES) Maximum cell region number """ -num_cellregions(grid::ExtendableGrid)=grid[NumCellRegions] - +num_cellregions(grid::ExtendableGrid) = grid[NumCellRegions] """ $(TYPEDSIGNATURES) Maximum boundary face region numbers """ -num_bfaceregions(grid::ExtendableGrid)=grid[NumBFaceRegions] - +num_bfaceregions(grid::ExtendableGrid) = grid[NumBFaceRegions] """ $(TYPEDSIGNATURES) Maximum boundary edge region numbers """ -num_bedgeregions(grid::ExtendableGrid)=grid[NumBEdgeRegions] - - - +num_bedgeregions(grid::ExtendableGrid) = grid[NumBEdgeRegions] """ $(SIGNATURES) Type of coordinates in grid """ -coord_type(grid::ExtendableGrid{Tc, Ti}) where {Tc,Ti}=Tc +coord_type(grid::ExtendableGrid{Tc, Ti}) where {Tc, Ti} = Tc """ $(SIGNATURES) Type of indices """ -index_type(grid::ExtendableGrid{Tc, Ti}) where {Tc,Ti}=Ti +index_type(grid::ExtendableGrid{Tc, Ti}) where {Tc, Ti} = Ti """ $(TYPEDSIGNATURES) @@ -448,45 +423,116 @@ $(TYPEDSIGNATURES) Map a function onto node coordinates of grid """ function Base.map(f::Function, grid::ExtendableGrid) - coord=grid[Coordinates] - dim=dim_space(grid) - if dim==1 - @views Base.map(f,coord[1,:]) - elseif dim==2 - @views Base.map(f,coord[1,:], coord[2,:]) + coord = grid[Coordinates] + dim = dim_space(grid) + if dim == 1 + @views Base.map(f, coord[1, :]) + elseif dim == 2 + @views Base.map(f, coord[1, :], coord[2, :]) else - @views Base.map(f,coord[1,:], coord[2,:], coord[3,:]) + @views Base.map(f, coord[1, :], coord[2, :], coord[3, :]) end end - -function Base.show(io::IO,grid::ExtendableGrid) - if num_edges(grid)>0 - str=@sprintf("%s;\ndim: %d nodes: %d cells: %d bfaces: %d, edges: %d\n", - typeof(grid),dim_space(grid),num_nodes(grid), num_cells(grid), num_bfaces(grid), num_edges(grid)) +function Base.show(io::IO, grid::ExtendableGrid) + if num_edges(grid) > 0 + str = @sprintf("%s;\ndim: %d nodes: %d cells: %d bfaces: %d, edges: %d\n", + typeof(grid), dim_space(grid), num_nodes(grid), num_cells(grid), num_bfaces(grid), num_edges(grid)) else - str=@sprintf("%s;\ndim: %d nodes: %d cells: %d bfaces: %d\n", - typeof(grid),dim_space(grid),num_nodes(grid), num_cells(grid), num_bfaces(grid)) + str = @sprintf("%s;\ndim: %d nodes: %d cells: %d bfaces: %d\n", + typeof(grid), dim_space(grid), num_nodes(grid), num_cells(grid), num_bfaces(grid)) end - println(io,str) + println(io, str) +end + +### Tests for the gmsh extension: + +function multidimsort(A) + i1 = sortperm(A[1, :]) + A1 = A[:, i1] + for j = 2:size(A, 1) + cm = countmap(A1[j - 1, :]) + for (key, val) in cm + if val > 1 #if there only is one entry with this key, the reordering is not necessary + inds = findall(z -> z == key, A1[j - 1, :]) #indices of that key in A1 + sorted_inds = sortperm(A1[j, inds]) + A1[:, inds] = A1[:, inds[sorted_inds]] #reorder + end + end + end + return A1 end """ -$(SIGNATURES) + seemingly_equal(grid1, grid2; sort=false, confidence=:full Recursively check seeming equality of two grids. Seemingly means -that long arrays are only compared via random samples -""" -function seemingly_equal(grid1::ExtendableGrid, grid2::ExtendableGrid) - for key in keys(grid1) - if !haskey(grid2,key) - return false +that long arrays are only compared via random samples. + +Keyword args: + +- `sort`: if true, sort grid points +- `confidence`: Confidence level: + - :low : Point numbers etc are the same + - :full : all arrays are equal (besides the coordinate array, the arrays only have to be equal up to permutations) +""" +function seemingly_equal(grid1::ExtendableGrid, grid2::ExtendableGrid; sort = false, confidence = :full) + if !sort + for key in keys(grid1) + if !haskey(grid2, key) + return false + end + if !seemingly_equal(grid1[key], grid2[key]) + return false + end end - if !seemingly_equal(grid1[key],grid2[key]) - return false + return true + end + + if confidence == :full + for key in keys(grid1) + if !haskey(grid2, key) + return false + end + if !isa(grid1[key], AbstractArray) + !seemingly_equal(grid1[key], grid2[key]) && return false + continue + end + + s1 = size(grid1[key]) + s2 = size(grid2[key]) + + if length(s1) == 0 + if length(s1) == 1 + if eltype(grid1[key]) <: Number + ind1 = sortperm(grid1[key]) + ind2 = sortperm(grid2[key]) + sa1 = grid1[key][ind1] + sa2 = grid2[key][ind2] + !seemingly_equal(sa1, sa2) && return false + else + !seemingly_equal(grid1[key], grid2[key]) && return false + end + else + if eltype(grid1[key]) <: Number && key != Coordinates + sa1 = multidimsort(sort(grid1[key]; dims = 1)) + sa2 = multidimsort(sort(grid2[key]; dims = 1)) + !seemingly_equal(sa1, sa2) && return false + else + !seemingly_equal(grid1[key], grid2[key]) && return false + end + end + end end + return true + elseif confidence == :low + grid1_data = (num_nodes(grid1), num_cells(grid1), num_bfaces(grid1)) + grid2_data = (num_nodes(grid2), num_cells(grid2), num_bfaces(grid2)) + return grid1_data == grid2_data + else + error("Confidence level $(confidence) not implemented") + return false end - return true end """ @@ -495,30 +541,30 @@ $(SIGNATURES) Check for seeming equality of two arrays by random sample. """ function seemingly_equal(array1::AbstractArray, array2::AbstractArray) - if size(array1)!=size(array2) + if size(array1) != size(array2) return false end - l=length(array1) - ntests=Float64(min(l,50)) - p=min(0.5,ntests/l) - for i in randsubseq( 1:l,p) - if !seemingly_equal(array1[i],array2[i]) + l = length(array1) + ntests = Float64(min(l, 50)) + p = min(0.5, ntests / l) + for i in randsubseq(1:l, p) + if !seemingly_equal(array1[i], array2[i]) return false end end true end -seemingly_equal(a1::VariableTargetAdjacency, a2::VariableTargetAdjacency)=seemingly_equal(a1.colentries,a2.colentries)&& seemingly_equal(a1.colstart, a2.colstart) -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 seemingly_equal(a1::VariableTargetAdjacency, a2::VariableTargetAdjacency) + seemingly_equal(a1.colentries, a2.colentries) && seemingly_equal(a1.colstart, a2.colstart) +end +seemingly_equal(x1::Type, x2::Type) = (x1 == x2) +seemingly_equal(x1::Number, x2::Number) = (x1 ≈ x2) +seemingly_equal(x1::Any, x2::Any) = (x1 == x2) -Base.extrema(grid::ExtendableGrid)=Base.extrema(grid[Coordinates],dims=2) +Base.extrema(grid::ExtendableGrid) = Base.extrema(grid[Coordinates]; dims = 2) function bbox(grid) - e=extrema(grid) - map(a->a[1],e),map(a->a[2],e) + e = extrema(grid) + map(a -> a[1], e), map(a -> a[2], e) end - diff --git a/test/runtests.jl b/test/runtests.jl index 92074063..b15236a4 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,4 @@ -ENV["MPLBACKEND"]="agg" - +ENV["MPLBACKEND"] = "agg" using Test, ExtendableGrids, GridVisualize, SHA, SimplexGridFactory, Triangulate import StatsBase @@ -8,584 +7,445 @@ using StatsBase: countmap import CairoMakie -CairoMakie.activate!(type="svg",visible=false) - - -### Tests for the gmsh extension: - - - -function multidimsort(A) - i1 = sortperm(A[1,:]) - A1 = A[:,i1] - for j=2:size(A,1) - cm = countmap(A1[j-1,:]) - for (key,val) in cm - if val > 1 #if there only is one entry with this key, the reordering is not necessary - inds = findall(z->z==key, A1[j-1,:]) #indices of that key in A1 - sorted_inds = sortperm(A1[j, inds]) - A1[:,inds] = A1[:,inds[sorted_inds]] #reorder - end - end - end - return A1 - -end - -#= -Confidence level: -- :low : Point numbers etc are the same -- :full : all arrays are equal (besides the coordinate array, the arrays only have to be equal up to permutations) -=# - - -function seemingly_equal_with_sort(grid1::ExtendableGrid, grid2::ExtendableGrid; confidence=:full) - if confidence==:full - for key in keys(grid1) - #@warn key - if !haskey(grid2,key) - return false - end - - if key == Coordinates - #@warn "now checking coords" - if !seemingly_equal(grid1[key],grid2[key]) - return false - end - else - try - #@warn "1" - sorted = false - s1 = size(grid1[key]) - s2 = size(grid2[key]) - - - #@warn "2" - - if length(s1) == 1 - #@warn "l(s) = 1" - ind1 = sortperm(grid1[key]) - ind2 = sortperm(grid2[key]) - sa1 = grid1[key][ind1] - sa2 = grid2[key][ind2] - else - #@warn "l(s) > 1" - sa1 = multidimsort(sort(grid1[key], dims=1)) - sa2 = multidimsort(sort(grid2[key], dims=1)) - - end - - - if !seemingly_equal(sa1,sa2) - return false - end - - catch - #@warn "doesn't have a size" #"not a sortable array") - if !seemingly_equal(grid1[key],grid2[key]) - return false - end - end - end - - end - return true - elseif confidence==:low - grid1_data=(num_nodes(grid1),num_cells(grid1), num_bfaces(grid1)) - grid2_data=(num_nodes(grid2),num_cells(grid2), num_bfaces(grid2)) - return grid1_data==grid2_data - else - error("Confidence level $(confidence) not implemented") - return false - end -end - - - - - +CairoMakie.activate!(; type = "svg", visible = false) @testset "Read/write simplex gmsh 2d / 3d" begin - gmsh.initialize() gmsh.option.setNumber("General.Terminal", 0) - gmsh.option.setNumber("General.Verbosity", 0) - - path = "" - + gmsh.option.setNumber("General.Verbosity", 0) + + path = "" + X = collect(0:0.02:2) Y = collect(0:2:4) grid1 = simplexgrid(X, Y) #ExtendableGrids.simplexgrid_from_gmsh(path*"sto_2d.msh") - - ExtendableGrids.load_simplexgrid_to_gmsh(grid1; filename=path*"testfile.msh") - grid2 = ExtendableGrids.simplexgrid_from_gmsh(path*"testfile.msh"; Tc=Float32, Ti=Int64) + ExtendableGrids.load_simplexgrid_to_gmsh(grid1; filename = path * "testfile.msh") + grid2 = ExtendableGrids.simplexgrid_from_gmsh(path * "testfile.msh"; Tc = Float32, Ti = Int64) #gmsh.finalize() - - @test seemingly_equal_with_sort(grid2, grid1;confidence=:low) - @test seemingly_equal_with_sort(grid2, grid1;confidence=:full) - + @test seemingly_equal(grid2, grid1; sort = true, confidence = :low) + @test seemingly_equal(grid2, grid1; sort = true, confidence = :full) + gmsh.clear() - - - grid1 = ExtendableGrids.simplexgrid_from_gmsh(path*"sto_2d.msh"; Tc=Float64, Ti=Int64) + + grid1 = ExtendableGrids.simplexgrid_from_gmsh(path * "sto_2d.msh"; Tc = Float64, Ti = Int64) gmsh.clear() - ExtendableGrids.load_simplexgrid_to_gmsh(grid1; filename=path*"testfile.msh") - grid2 = ExtendableGrids.simplexgrid_from_gmsh(path*"testfile.msh"; Tc=Float64, Ti=Int64) + ExtendableGrids.load_simplexgrid_to_gmsh(grid1; filename = path * "testfile.msh") + grid2 = ExtendableGrids.simplexgrid_from_gmsh(path * "testfile.msh"; Tc = Float64, Ti = Int64) #gmsh.finalize() - - @test seemingly_equal_with_sort(grid1, grid2;confidence=:low) - @test seemingly_equal_with_sort(grid1, grid2;confidence=:full) - + + @test seemingly_equal(grid1, grid2; sort = true, confidence = :low) + @test seemingly_equal(grid1, grid2; sort = true, confidence = :full) + gmsh.clear() - - grid1 = ExtendableGrids.simplexgrid_from_gmsh(path*"sto_3d.msh"; Tc=Float32, Ti=Int64) + + grid1 = ExtendableGrids.simplexgrid_from_gmsh(path * "sto_3d.msh"; Tc = Float32, Ti = Int64) gmsh.clear() - ExtendableGrids.load_simplexgrid_to_gmsh(grid1; filename=path*"testfile.msh") - grid2 = ExtendableGrids.simplexgrid_from_gmsh(path*"testfile.msh"; Tc=Float64, Ti=Int32) + ExtendableGrids.load_simplexgrid_to_gmsh(grid1; filename = path * "testfile.msh") + grid2 = ExtendableGrids.simplexgrid_from_gmsh(path * "testfile.msh"; Tc = Float64, Ti = Int32) #gmsh.finalize() - - @test seemingly_equal_with_sort(grid1, grid2;confidence=:low) - @test seemingly_equal_with_sort(grid1, grid2;confidence=:full) - + + @test seemingly_equal(grid1, grid2; sort = true, confidence = :low) + @test seemingly_equal(grid1, grid2; sort = true, confidence = :full) + gmsh.clear() - - grid1 = ExtendableGrids.simplexgrid_from_gmsh(path*"sto_2d.msh") + + grid1 = ExtendableGrids.simplexgrid_from_gmsh(path * "sto_2d.msh") gmsh.clear() - #grid2 = + #grid2 = #simplexgrid([0, 1, 2], [3, 4, 5]) - grid2 = ExtendableGrids.simplexgrid_from_gmsh(path*"sto_3d.msh"; Tc=Float32, Ti=Int32) + grid2 = ExtendableGrids.simplexgrid_from_gmsh(path * "sto_3d.msh"; Tc = Float32, Ti = Int32) #gmsh.finalize() - - @test !seemingly_equal_with_sort(grid1, grid2;confidence=:low) - @test !seemingly_equal_with_sort(grid1, grid2;confidence=:full) - + + @test !seemingly_equal(grid1, grid2; sort = true, confidence = :low) + @test !seemingly_equal(grid1, grid2; sort = true, confidence = :full) + + gmsh.clear() + + grid1 = ExtendableGrids.simplexgrid_from_gmsh("testmesh.gmsh"; incomplete = true) + ExtendableGrids.seal!(grid1; encode = false) gmsh.clear() - - grid1 = ExtendableGrids.simplexgrid_from_gmsh("testmesh.gmsh"; incomplete=true) - ExtendableGrids.seal!(grid1; encode=false) - gmsh.clear() - ExtendableGrids.load_simplexgrid_to_gmsh(grid1; filename="completed_testfile.msh") + ExtendableGrids.load_simplexgrid_to_gmsh(grid1; filename = "completed_testfile.msh") grid2 = ExtendableGrids.simplexgrid_from_gmsh("completed_testfile.msh") - - gmsh.clear() - - grid3 = ExtendableGrids.simplexgrid_from_gmsh("testmesh.gmsh"; incomplete=true) - ExtendableGrids.seal!(grid3; encode=true) - - gmsh.clear() - - @test seemingly_equal_with_sort(grid1, grid2;confidence=:low) - @test seemingly_equal_with_sort(grid1, grid2;confidence=:full) - @test seemingly_equal_with_sort(grid1, grid3;confidence=:low) - @test seemingly_equal_with_sort(grid1, grid3;confidence=:full) - - x = collect(LinRange(0,1,50)) - grid1 = simplexgrid(x,x) + + gmsh.clear() + + grid3 = ExtendableGrids.simplexgrid_from_gmsh("testmesh.gmsh"; incomplete = true) + ExtendableGrids.seal!(grid3; encode = true) + + gmsh.clear() + + @test seemingly_equal(grid1, grid2; sort = true, confidence = :low) + @test seemingly_equal(grid1, grid2; sort = true, confidence = :full) + @test seemingly_equal(grid1, grid3; sort = true, confidence = :low) + @test seemingly_equal(grid1, grid3; sort = true, confidence = :full) + + x = collect(LinRange(0, 1, 50)) + grid1 = simplexgrid(x, x) grid1[BFaceRegions] = ones(Int32, length(grid1[BFaceRegions])) #num_faces(grid1)) - grid2 = simplexgrid(x,x) - grid3 = simplexgrid(x,x) + grid2 = simplexgrid(x, x) + grid3 = simplexgrid(x, x) ExtendableGrids.seal!(grid2) - ExtendableGrids.seal!(grid3; encode=false) - + ExtendableGrids.seal!(grid3; encode = false) + gmsh.finalize() - - @test seemingly_equal_with_sort(grid2, grid1;confidence=:low) - @test seemingly_equal_with_sort(grid2, grid1;confidence=:full) - @test seemingly_equal_with_sort(grid3, grid1;confidence=:low) - @test seemingly_equal_with_sort(grid3, grid1;confidence=:full) - - + + @test seemingly_equal(grid2, grid1; sort = true, confidence = :low) + @test seemingly_equal(grid2, grid1; sort = true, confidence = :full) + @test seemingly_equal(grid3, grid1; sort = true, confidence = :low) + @test seemingly_equal(grid3, grid1; sort = true, confidence = :full) end @testset "Read/write mixed gmsh 2d" begin - gmsh.initialize() gmsh.option.setNumber("General.Terminal", 0) - gmsh.option.setNumber("General.Verbosity", 0) - - path = "" - grid1 = ExtendableGrids.mixedgrid_from_gmsh(path*"mixedgrid_2d.msh"; Tc=Float64, Ti=Int64) + gmsh.option.setNumber("General.Verbosity", 0) + + path = "" + grid1 = ExtendableGrids.mixedgrid_from_gmsh(path * "mixedgrid_2d.msh"; Tc = Float64, Ti = Int64) gmsh.clear() - ExtendableGrids.load_mixedgrid_to_gmsh(grid1; filename=path*"testfile.msh") - grid2 = ExtendableGrids.mixedgrid_from_gmsh(path*"testfile.msh"; Tc=Float32, Ti=UInt64) + ExtendableGrids.load_mixedgrid_to_gmsh(grid1; filename = path * "testfile.msh") + grid2 = ExtendableGrids.mixedgrid_from_gmsh(path * "testfile.msh"; Tc = Float32, Ti = UInt64) gmsh.finalize() - - @test seemingly_equal_with_sort(grid1, grid2;confidence=:low) - @test seemingly_equal_with_sort(grid1, grid2;confidence=:full) - -end - - - - + @test seemingly_equal(grid1, grid2; sort = true, confidence = :low) + @test seemingly_equal(grid1, grid2; sort = true, confidence = :full) +end ### Original tests: - @testset "Geomspace" begin function test_geomspace() - X1=geomspace(2.0,3.0,0.2,0.2) - X2=collect(2:0.2:3) - @assert X1 ≈ X2 - X1=geomspace(2.0,3.0,0.1,0.2) - X2=geomspace(2.0,3.0,0.2,0.1) - - - X1=geomspace(2.0,3.0,1.0e-5,0.2) - X2=geomspace(2.0,3.0,0.2,1.0e-5) - (X1[2]-X1[1]) ≈ (X2[end]-X2[end-1]) && - (X2[2]-X2[1]) ≈ (X1[end]-X1[end-1]) + X1 = geomspace(2.0, 3.0, 0.2, 0.2) + X2 = collect(2:0.2:3) + @assert X1 ≈ X2 + X1 = geomspace(2.0, 3.0, 0.1, 0.2) + X2 = geomspace(2.0, 3.0, 0.2, 0.1) + + X1 = geomspace(2.0, 3.0, 1.0e-5, 0.2) + X2 = geomspace(2.0, 3.0, 0.2, 1.0e-5) + (X1[2] - X1[1]) ≈ (X2[end] - X2[end - 1]) && + (X2[2] - X2[1]) ≈ (X1[end] - X1[end - 1]) end - function test_geomspace1(n,h0,h1) - for i=1:n - X=geomspace(0,1,h0*rand(),h1*rand()) + function test_geomspace1(n, h0, h1) + for i = 1:n + X = geomspace(0, 1, h0 * rand(), h1 * rand()) end true end - - @test test_geomspace() - @test test_geomspace1(100,0.01,0.01) - @test test_geomspace1(100,0.01,0.1) - @test test_geomspace1(100,0.1,0.01) - @test test_geomspace1(100,0.001,0.1) - - - @test length(geomspace(0,1,0.01,0.1))==27 - @test length(geomspace(0,1,0.001,0.1))==47 - @test length(geomspace(0,1,0.0001,0.1))==68 - @test length(geomspace(0,1,0.00001,0.1))==90 + @test test_geomspace() + @test test_geomspace1(100, 0.01, 0.01) + @test test_geomspace1(100, 0.01, 0.1) + @test test_geomspace1(100, 0.1, 0.01) + @test test_geomspace1(100, 0.001, 0.1) + + @test length(geomspace(0, 1, 0.01, 0.1)) == 27 + @test length(geomspace(0, 1, 0.001, 0.1)) == 47 + @test length(geomspace(0, 1, 0.0001, 0.1)) == 68 + @test length(geomspace(0, 1, 0.00001, 0.1)) == 90 end @testset "Basic" begin + function test_prepare_edges() + ## Compared with pdelib; have more of these + 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]' - - function test_prepare_edges() - ## Compared with pdelib; have more of these - 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) - - grid[CellEdges]==Int32[1 2; 2 4; 3 5] && - grid[FaceNodes]==Int32[1 2 3 3 4; 2 3 1 4 2] && - grid[EdgeCells]==Int32[1 1 1 2 2; 0 2 0 0 0] + bfacemat = [1, 1] + grid = simplexgrid(nodes, cells, cellmat, bfaces, bfacemat) + + grid[CellEdges] == Int32[1 2; 2 4; 3 5] && + grid[FaceNodes] == Int32[1 2 3 3 4; 2 3 1 4 2] && + grid[EdgeCells] == Int32[1 1 1 2 2; 0 2 0 0 0] end @test test_prepare_edges() - @test let - g=simplexgrid(0:10) - bfc=g[BFaceCells] - bfc[1,1]==1 && bfc[1,2]==10 + g = simplexgrid(0:10) + bfc = g[BFaceCells] + bfc[1, 1] == 1 && bfc[1, 2] == 10 end @test let - g=simplexgrid(0:10) - bfn=g[BFaceNormals] - bfn==[-1.0 1.0] + g = simplexgrid(0:10) + bfn = g[BFaceNormals] + bfn == [-1.0 1.0] end - @test let - g=simplexgrid(0:2, 0:2) - bfn=g[BFaceNormals] - bfn==[0.0 -1.0; - -1.0 0.0; - 0.0 -1.0; - 1.0 0.0; - 0.0 1.0; - -1.0 0.0; - 1.0 0.0; - 0.0 1.0]' + g = simplexgrid(0:2, 0:2) + bfn = g[BFaceNormals] + bfn == [0.0 -1.0; + -1.0 0.0; + 0.0 -1.0; + 1.0 0.0; + 0.0 1.0; + -1.0 0.0; + 1.0 0.0; + 0.0 1.0]' end @test let - g=simplexgrid(0:2, 0:2) - bfc=g[BFaceCells] - tryfix(bfc)==[1 2 3 3 6 6 7 8;] + g = simplexgrid(0:2, 0:2) + bfc = g[BFaceCells] + tryfix(bfc) == [1 2 3 3 6 6 7 8;] end @test let - X=[0 0; 2 0 ; 1 2; 1 0.5]' - C=[ 1 2 4 ; 2 3 4 ; 3 1 4]' - CR=ones(Int,3) - F=[ 1 2 ; 2 3 ; 3 1]' - FR=[1,2,3] - g=simplexgrid(X,C,CR,F,FR) - bfc=g[BFaceCells] - tryfix(bfc)==[1 2 3;] + X = [0 0; 2 0; 1 2; 1 0.5]' + C = [1 2 4; 2 3 4; 3 1 4]' + CR = ones(Int, 3) + F = [1 2; 2 3; 3 1]' + FR = [1, 2, 3] + g = simplexgrid(X, C, CR, F, FR) + bfc = g[BFaceCells] + tryfix(bfc) == [1 2 3;] end - - end - - - -function testrw(grid,format;confidence=:full) +function testrw(grid, format; confidence = :full) #@warn format - ftmp=tempname()*"."*format - write(ftmp,grid) - grid1=simplexgrid(ftmp) - seemingly_equal_with_sort(grid1,grid;confidence=confidence) + ftmp = tempname() * "." * format + write(ftmp, grid) + grid1 = simplexgrid(ftmp) + seemingly_equal(grid1, grid; confidence = confidence) end @testset "Read/Write sg" begin - X=collect(0:0.05:1) - @test testrw(simplexgrid(X),"sg") - @test testrw(simplexgrid(X,X),"sg") - @test testrw(simplexgrid(X,X,X),"sg") + X = collect(0:0.05:1) + @test testrw(simplexgrid(X), "sg") + @test testrw(simplexgrid(X, X), "sg") + @test testrw(simplexgrid(X, X, X), "sg") end - -function testgrid(grid,testdata) - (num_nodes(grid),num_cells(grid), num_bfaces(grid))==testdata +function testgrid(grid, testdata) + (num_nodes(grid), num_cells(grid), num_bfaces(grid)) == testdata end -examples1d=joinpath(@__DIR__,"..","examples","examples1d.jl") +examples1d = joinpath(@__DIR__, "..", "examples", "examples1d.jl") include(examples1d) -examples2d=joinpath(@__DIR__,"..","examples","examples2d.jl") +examples2d = joinpath(@__DIR__, "..", "examples", "examples2d.jl") include(examples2d) -examples3d=joinpath(@__DIR__,"..","examples","examples3d.jl") +examples3d = joinpath(@__DIR__, "..", "examples", "examples3d.jl") include(examples3d) - - - @testset "1D" begin function rect1d() - X=collect(0:0.1:1) - g=simplexgrid(X) - rect!(g, [0.3],[0.6], region=2,bregions=[3,4]) + X = collect(0:0.1:1) + g = simplexgrid(X) + rect!(g, [0.3], [0.6]; region = 2, bregions = [3, 4]) end - - @test testgrid(interval_from_vector(),(21,20,2)) - @test testgrid(interval_localref(), (27,26,2)) - @test testgrid(interval_multiregion(),(21,20,3)) - @test testgrid(interval_subgrid(),(51,50,2)) - @test testgrid(rect1d(),(11,10,4)) + + @test testgrid(interval_from_vector(), (21, 20, 2)) + @test testgrid(interval_localref(), (27, 26, 2)) + @test testgrid(interval_multiregion(), (21, 20, 3)) + @test testgrid(interval_subgrid(), (51, 50, 2)) + @test testgrid(rect1d(), (11, 10, 4)) end @testset "2D" begin function rect2d() - X=collect(0:0.1:1) - g=simplexgrid(X,X) - rect!(g, [0.3, 0.3],[0.6,0.6], region=2,bregions=[3,4,5,6]) + X = collect(0:0.1:1) + g = simplexgrid(X, X) + rect!(g, [0.3, 0.3], [0.6, 0.6]; region = 2, bregions = [3, 4, 5, 6]) end - @test testgrid(rectangle(),(441,800,80)) - @test testgrid(rectangle_localref(),(729, 1352, 104)) - @test testgrid(rectangle_multiregion(),(441,800,100)) - @test testgrid(rectangle_subgrid(),(360, 600, 120)) - @test testgrid(rect2d(),(121,200,52)) - @test testgrid(rect2d_bregion_function(),(79,112,44)) - - g,sg,sf=sorted_subgrid() - @test testgrid(g,(187,306,66)) - @test testgrid(sg,(17,16,0)) - @test issorted(view(sg[Coordinates],1,:)) - + @test testgrid(rectangle(), (441, 800, 80)) + @test testgrid(rectangle_localref(), (729, 1352, 104)) + @test testgrid(rectangle_multiregion(), (441, 800, 100)) + @test testgrid(rectangle_subgrid(), (360, 600, 120)) + @test testgrid(rect2d(), (121, 200, 52)) + @test testgrid(rect2d_bregion_function(), (79, 112, 44)) + + g, sg, sf = sorted_subgrid() + @test testgrid(g, (187, 306, 66)) + @test testgrid(sg, (17, 16, 0)) + @test issorted(view(sg[Coordinates], 1, :)) end @testset "3D" begin - function subgen(;h=0.2) - X=collect(-1:h:2) - Y=collect(0:h:1) - Z=collect(0:h:2) - g=simplexgrid(X,Y,Z) + function subgen(; h = 0.2) + X = collect(-1:h:2) + Y = collect(0:h:1) + Z = collect(0:h:2) + g = simplexgrid(X, Y, Z) # Mark all boundaries as region 1 - bfacemask!(g,[-1,0,0], [2,1,2],1, allow_new=false) - + bfacemask!(g, [-1, 0, 0], [2, 1, 2], 1; allow_new = false) + # Default cell region is 1 # Mark cut-out regions as 2 - cellmask!(g, [-1,0,0], [0,1,1], 2) - cellmask!(g, [1,0,0], [2,1,1], 2) - + cellmask!(g, [-1, 0, 0], [0, 1, 1], 2) + cellmask!(g, [1, 0, 0], [2, 1, 1], 2) + # add new interface elements - bfacemask!(g, [-1,0,1], [2,1,1],3,allow_new=true) - bfacemask!(g, [0,0,0], [0,1,1],3,allow_new=true) - bfacemask!(g, [1,0,0], [1,1,1],3,allow_new=true) - + bfacemask!(g, [-1, 0, 1], [2, 1, 1], 3; allow_new = true) + bfacemask!(g, [0, 0, 0], [0, 1, 1], 3; allow_new = true) + bfacemask!(g, [1, 0, 0], [1, 1, 1], 3; allow_new = true) + # return subgrid of region 1 - subgrid(g,[1]) + subgrid(g, [1]) end function rect3d() - X=collect(0:0.1:1) - g=simplexgrid(X,X,X) - rect!(g, [0.3, 0.3,0.4],[0.6,0.6,0.7], region=2,bregion=8) + X = collect(0:0.1:1) + g = simplexgrid(X, X, X) + rect!(g, [0.3, 0.3, 0.4], [0.6, 0.6, 0.7]; region = 2, bregion = 8) g end - - - @test testgrid(quadrilateral(),(330,1200,440)) + @test testgrid(quadrilateral(), (330, 1200, 440)) @test mask_bedges() - X=collect(0:0.25:1) - gxy=simplexgrid(X,X) - gxyz=simplexgrid(gxy,X) - g=simplexgrid(X,X,X) - @test testgrid(gxyz,(125,384,192)) - @test g[Coordinates]≈gxyz[Coordinates] - @test testgrid(subgen(),(756,3000,950)) - @test testgrid(rect3d(),(1331,6000,1308)) - @test testgrid(cross3d(),(189,480,344)) + X = collect(0:0.25:1) + gxy = simplexgrid(X, X) + gxyz = simplexgrid(gxy, X) + g = simplexgrid(X, X, X) + @test testgrid(gxyz, (125, 384, 192)) + @test g[Coordinates] ≈ gxyz[Coordinates] + @test testgrid(subgen(), (756, 3000, 950)) + @test testgrid(rect3d(), (1331, 6000, 1308)) + @test testgrid(cross3d(), (189, 480, 344)) end - @testset "plotting examples" begin include("../docs/makeplots.jl") - picdir=mktempdir() - - @test makeplot("interval_from_vector",picdir; Plotter=CairoMakie) - @test makeplot("interval_localref",picdir; Plotter=CairoMakie) - @test makeplot("interval_multiregion",picdir; Plotter=CairoMakie) - @test makeplot("interval_subgrid",picdir; Plotter=CairoMakie) - @test makeplot("rectangle",picdir; Plotter=CairoMakie) - @test makeplot("rectangle_localref",picdir; Plotter=CairoMakie) - @test makeplot("rectangle_multiregion",picdir; Plotter=CairoMakie) - @test makeplot("rectangle_subgrid",picdir; Plotter=CairoMakie) - @test makeplot("quadrilateral",picdir; Plotter=CairoMakie) - @test makeplotx("sorted_subgrid",picdir; Plotter=CairoMakie) + picdir = mktempdir() + + @test makeplot("interval_from_vector", picdir; Plotter = CairoMakie) + @test makeplot("interval_localref", picdir; Plotter = CairoMakie) + @test makeplot("interval_multiregion", picdir; Plotter = CairoMakie) + @test makeplot("interval_subgrid", picdir; Plotter = CairoMakie) + @test makeplot("rectangle", picdir; Plotter = CairoMakie) + @test makeplot("rectangle_localref", picdir; Plotter = CairoMakie) + @test makeplot("rectangle_multiregion", picdir; Plotter = CairoMakie) + @test makeplot("rectangle_subgrid", picdir; Plotter = CairoMakie) + @test makeplot("quadrilateral", picdir; Plotter = CairoMakie) + @test makeplotx("sorted_subgrid", picdir; Plotter = CairoMakie) end +function tglue(; dim = 2, breg = 0) + X1 = linspace(0, 1, 5) + Y1 = linspace(0, 1, 5) + Z1 = linspace(0, 1, 5) -function tglue(;dim=2,breg=0) - X1=linspace(0,1,5) - Y1=linspace(0,1,5) - Z1=linspace(0,1,5) - - X2=linspace(1,2,5) - Y2=linspace(0,0.5,3) - Z2=linspace(0,0.5,3) + X2 = linspace(1, 2, 5) + Y2 = linspace(0, 0.5, 3) + Z2 = linspace(0, 0.5, 3) - if dim==1 - g1=simplexgrid(X1) - g2=simplexgrid(X2) + if dim == 1 + g1 = simplexgrid(X1) + g2 = simplexgrid(X2) end - - if dim==2 - g1=simplexgrid(X1,Y1) - g2=simplexgrid(X2,Y2) + + if dim == 2 + g1 = simplexgrid(X1, Y1) + g2 = simplexgrid(X2, Y2) end - - if dim==3 - g1=simplexgrid(X1,Y1,Z1) - g2=simplexgrid(X2,Y2,Z2) + + if dim == 3 + g1 = simplexgrid(X1, Y1, Z1) + g2 = simplexgrid(X2, Y2, Z2) end - - glue(g1,g2,interface=breg) + + glue(g1, g2; interface = breg) end @testset "Glue" begin - @test testgrid(tglue(;dim=1,breg=0),(9,8,2)) - @test testgrid(tglue(;dim=1,breg=1),(9,8,3)) - @test testgrid(tglue(;dim=2,breg=0),(37, 48, 24)) - @test testgrid(tglue(;dim=2,breg=1),(37, 48, 26)) - @test testgrid(tglue(;dim=3,breg=0),(161, 480, 256)) - @test testgrid(tglue(;dim=3,breg=1),(161, 480, 264)) + @test testgrid(tglue(; dim = 1, breg = 0), (9, 8, 2)) + @test testgrid(tglue(; dim = 1, breg = 1), (9, 8, 3)) + @test testgrid(tglue(; dim = 2, breg = 0), (37, 48, 24)) + @test testgrid(tglue(; dim = 2, breg = 1), (37, 48, 26)) + @test testgrid(tglue(; dim = 3, breg = 0), (161, 480, 256)) + @test testgrid(tglue(; dim = 3, breg = 1), (161, 480, 264)) end - - function voronoitest() - g=simplexgrid(0:0.1:1) - @test g[VoronoiFaceCenters]≈[0.05 0.15 0.25 0.35 0.45 0.55 0.65 0.75 0.85 0.95] - g=simplexgrid(0:0.5:1,0:0.5:1) - @test g[VoronoiFaceCenters]≈[0.25 0.5 0.25 0.25 0.0 0.75 1.0 0.75 0.75 0.5 0.25 0.25 0.0 1.0 0.75 0.75; - 0.0 0.25 0.25 0.5 0.25 0.0 0.25 0.25 0.5 0.75 0.75 1.0 0.75 0.75 0.75 1.0] + g = simplexgrid(0:0.1:1) + @test g[VoronoiFaceCenters] ≈ [0.05 0.15 0.25 0.35 0.45 0.55 0.65 0.75 0.85 0.95] + g = simplexgrid(0:0.5:1, 0:0.5:1) + @test g[VoronoiFaceCenters] ≈ [0.25 0.5 0.25 0.25 0.0 0.75 1.0 0.75 0.75 0.5 0.25 0.25 0.0 1.0 0.75 0.75; + 0.0 0.25 0.25 0.5 0.25 0.0 0.25 0.25 0.5 0.75 0.75 1.0 0.75 0.75 0.75 1.0] end @testset "Voronoi" begin voronoitest() end - + @testset "Grid Stuff" begin include("test_gridstuff.jl") run_grid_tests() -end +end @testset "Interpolations" begin X_from = collect(0:0.1:1) X_to = collect(0:0.02:1) - grid_from=simplexgrid(X_from) - grid_to=simplexgrid(X_to) - u_from=map((x)->x,grid_from) - u_to_exact=map((x)->x,grid_to) - u_to=interpolate(grid_to,u_from,grid_from) - @test u_to≈u_to_exact - - u_from=Matrix(hcat(u_from,u_from)') - u_to_exact=Matrix(hcat(u_to_exact,u_to_exact)') - u_to=interpolate(grid_to,u_from,grid_from) - @test u_to≈u_to_exact - - grid_from=simplexgrid(X_from,X_from) - grid_to=simplexgrid(X_to,X_to) - u_from=map((x,y)->x+y,grid_from) - u_to_exact=map((x,y)->x+y,grid_to) - u_to=interpolate(grid_to,u_from,grid_from) - @test u_to≈u_to_exact - - u_from=Matrix(hcat(u_from,u_from)') - u_to_exact=Matrix(hcat(u_to_exact,u_to_exact)') - u_to=interpolate(grid_to,u_from,grid_from) - @test u_to≈u_to_exact - - grid_from=simplexgrid(X_from,X_from,X_from) - grid_to=simplexgrid(X_to,X_to,X_to) - u_from=map((x,y,z)->x+y+z,grid_from) - u_to_exact=map((x,y,z)->x+y+z,grid_to) - u_to=interpolate(grid_to,u_from,grid_from) - @test u_to≈u_to_exact - - u_from=Matrix(hcat(u_from,u_from)') - u_to_exact=Matrix(hcat(u_to_exact,u_to_exact)') - u_to=interpolate(grid_to,u_from,grid_from) - @test u_to≈u_to_exact - + grid_from = simplexgrid(X_from) + grid_to = simplexgrid(X_to) + u_from = map((x) -> x, grid_from) + u_to_exact = map((x) -> x, grid_to) + u_to = interpolate(grid_to, u_from, grid_from) + @test u_to ≈ u_to_exact + + u_from = Matrix(hcat(u_from, u_from)') + u_to_exact = Matrix(hcat(u_to_exact, u_to_exact)') + u_to = interpolate(grid_to, u_from, grid_from) + @test u_to ≈ u_to_exact + + grid_from = simplexgrid(X_from, X_from) + grid_to = simplexgrid(X_to, X_to) + u_from = map((x, y) -> x + y, grid_from) + u_to_exact = map((x, y) -> x + y, grid_to) + u_to = interpolate(grid_to, u_from, grid_from) + @test u_to ≈ u_to_exact + + u_from = Matrix(hcat(u_from, u_from)') + u_to_exact = Matrix(hcat(u_to_exact, u_to_exact)') + u_to = interpolate(grid_to, u_from, grid_from) + @test u_to ≈ u_to_exact + + grid_from = simplexgrid(X_from, X_from, X_from) + grid_to = simplexgrid(X_to, X_to, X_to) + u_from = map((x, y, z) -> x + y + z, grid_from) + u_to_exact = map((x, y, z) -> x + y + z, grid_to) + u_to = interpolate(grid_to, u_from, grid_from) + @test u_to ≈ u_to_exact + + u_from = Matrix(hcat(u_from, u_from)') + u_to_exact = Matrix(hcat(u_to_exact, u_to_exact)') + u_to = interpolate(grid_to, u_from, grid_from) + @test u_to ≈ u_to_exact end @testset "writeVTK" begin X = collect(-1:1.0:1) Y = collect(-1:1.0:1) Z = collect(-2:1.0:2) - g = simplexgrid(X,Y,Z) + g = simplexgrid(X, Y, Z) nx = num_nodes(g) nc = num_cells(g) # ensure calculation of these data is free of roundoff errors - point_data = map((x,y,z) -> (x+y+z), g) + point_data = map((x, y, z) -> (x + y + z), g) field_data = [1.0, 2, 3, 4, 5, 6] - writeVTK("testfile_writevtk.vtu", g; - cellregions = g[CellRegions], - point_data = point_data, - field_data = field_data) + writeVTK("testfile_writevtk.vtu", g; + cellregions = g[CellRegions], + point_data = point_data, + field_data = field_data) sha_code = open("testfile_writevtk.vtu") do f sha256(f) @@ -593,23 +453,3 @@ end @test sha_code == "93a31139ccb3ae3017351d7cef0c2639c5def97c9744699543fe8bc58e1ebcea" end - - - - - - - - - - - - - - - - - - - -