Skip to content

Commit

Permalink
Added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiManyer committed Jan 23, 2023
1 parent ae14c98 commit 623b651
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
29 changes: 8 additions & 21 deletions src/Adaptivity/EdgeBasedRefinement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,24 @@ function refine(::EdgeBasedRefinement,model::UnstructuredDiscreteModel{Dc,Dp};ce

# Create new model
rrules, faces_list = setup_edge_based_rrules(model.grid_topology,cells_to_refine)
topo = refine_unstructured_topology(model.grid_topology,rrules,faces_list)
topo = _refine_unstructured_topology(model.grid_topology,rrules,faces_list)
reffes = map(p->LagrangianRefFE(Float64,p,1),get_polytopes(topo))
grid = UnstructuredGrid(get_vertex_coordinates(topo),get_faces(topo,Dc,0),reffes,get_cell_type(topo),OrientationStyle(topo))
labels = FaceLabeling(topo)
ref_model = UnstructuredDiscreteModel(grid,topo,labels)

# Create ref glue
glue = get_refinement_glue(topo,model.grid_topology,rrules)
glue = _get_refinement_glue(topo,model.grid_topology,rrules)

return AdaptedDiscreteModel(ref_model,model,glue)
end

function refine_unstructured_topology(topo::UnstructuredGridTopology{Dc},
function _refine_unstructured_topology(topo::UnstructuredGridTopology{Dc},
rrules::AbstractVector{<:RefinementRule},
faces_list::Tuple) where {Dc}
coords_new = get_new_coordinates_from_faces(topo,faces_list)
c2n_map_new = get_refined_cell_to_vertex_map(topo,rrules,faces_list)
polys_new, cell_type_new = get_refined_polytopes(rrules)
polys_new, cell_type_new = get_cell_polytopes(rrules)

# We can guarantee the new topology is oriented if
# 1 - the old topology was oriented
Expand All @@ -69,22 +69,9 @@ function refine_unstructured_topology(topo::UnstructuredGridTopology{Dc},
return UnstructuredGridTopology(coords_new,c2n_map_new,cell_type_new,polys_new,orientation)
end

function get_refined_polytopes(rrules::AbstractArray{<:RefinementRule})
rr_polys = lazy_map(rr->get_polytopes(rr.ref_grid),rrules)

# NOTE: The innermost `unique` is to optimize for CompressedArrays
polys_new = unique(reduce(vcat,unique(rr_polys)))

rr_cell_type = lazy_map(rr->get_cell_type(rr.ref_grid),rrules)
rr2new_cell_type = lazy_map(vp->map(p->findfirst(x->x==p,polys_new),vp),rr_polys)
cell_type_new = reduce(vcat,lazy_map((gids,lids)->lazy_map(Reindex(gids),lids),rr2new_cell_type,rr_cell_type))

return polys_new, cell_type_new
end

function get_refinement_glue(ftopo ::UnstructuredGridTopology{Dc},
ctopo ::UnstructuredGridTopology{Dc},
rrules::AbstractVector{<:RefinementRule}) where {Dc}
function _get_refinement_glue(ftopo ::UnstructuredGridTopology{Dc},
ctopo ::UnstructuredGridTopology{Dc},
rrules::AbstractVector{<:RefinementRule}) where {Dc}
nC_old = num_faces(ctopo,Dc)
nC_new = num_faces(ftopo,Dc)

Expand Down Expand Up @@ -166,7 +153,7 @@ function setup_edge_based_rrules(topo::UnstructuredGridTopology{Dc},cells_to_ref
p = cell_types[nbor]
ref_edge = nbor_ref_edges[1]
cell_color[nbor] = GREEN + Int8(green_offsets[p]-1+ref_edge-1)
else # > 1, can't be 0
else # > 1, can't be 0 (queue invariant)
cell_color[nbor] = RED + Int8(cell_types[nbor]-1)
is_red[nbor] = true
is_refined[nbor_edges] .= true
Expand Down
13 changes: 13 additions & 0 deletions src/Adaptivity/RefinementRules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ function get_cell_polytopes(rr::RefinementRule)
return CompressedArray(polys,cell_types)
end

function get_cell_polytopes(rrules::AbstractArray{<:RefinementRule})
rr_polys = lazy_map(rr->get_polytopes(rr.ref_grid),rrules)

# NOTE: The innermost `unique` is to optimize for CompressedArrays
polys_new = unique(reduce(vcat,unique(rr_polys)))

rr_cell_type = lazy_map(rr->get_cell_type(rr.ref_grid),rrules)
rr2new_cell_type = lazy_map(vp->map(p->findfirst(x->x==p,polys_new),vp),rr_polys)
cell_type_new = reduce(vcat,lazy_map((gids,lids)->lazy_map(Reindex(gids),lids),rr2new_cell_type,rr_cell_type))

return polys_new, cell_type_new
end

x_to_cell(rr::RefinementRule,x::Point) = CellData._point_to_cell!(rr.p2c_cache,x)

function bundle_points_by_subcell(rr::RefinementRule,x::AbstractArray{<:Point})
Expand Down
1 change: 1 addition & 0 deletions test/AdaptivityTests/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ end

@testset "GridTransfer" begin
include("GridTransferTests.jl")
include("FineToCoarseFieldsTests.jl")
end

@testset "CompositeQuadratures" begin
Expand Down

0 comments on commit 623b651

Please sign in to comment.