Skip to content

Commit

Permalink
Merge pull request #1013 from gridap/adaptivity
Browse files Browse the repository at this point in the history
Adaptivity 2.0
  • Loading branch information
JordiManyer authored Jul 11, 2024
2 parents 9079dd1 + c8e13a5 commit 8749df2
Show file tree
Hide file tree
Showing 9 changed files with 567 additions and 181 deletions.
6 changes: 4 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [0.18.3] - 2024-07-11

### Added

- Added more features to Adaptivity. Notably: 3D uniform edge-based refinement for HEX and TETs. Barycentric refinement for simplices. Simplexify as a new refinement strategy. Since PR[#1013](https://github.com/gridap/Gridap.jl/pull/1013).

- Define `GeneralPolytope` that represents general polytopes in 2 and 3 dimensions. Since PR[#1006](https://github.com/gridap/Gridap.jl/pull/1006).

## [0.18.2] - 2024-05-02
## [0.18.2] - 2024-05-02

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Gridap"
uuid = "56d4f2e9-7ea1-5844-9cf6-b9c51ca7ce8e"
authors = ["Santiago Badia <[email protected]>", "Francesc Verdugo <[email protected]>", "Alberto F. Martin <[email protected]>"]
version = "0.18.2"
version = "0.18.3"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
4 changes: 3 additions & 1 deletion src/Adaptivity/AdaptedDiscreteModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ end
function string_to_refinement(refinement_method::String, model)
refinement_method == "red_green" && return RedGreenRefinement()
refinement_method == "nvb" && return NVBRefinement(model)
refinement_method == "barycentric" && return BarycentricRefinement()
refinement_method == "simplexify" && return SimplexifyRefinement()
error("refinement_method $refinement_method not recognized")
end

Expand Down Expand Up @@ -134,7 +136,7 @@ function refine(model::CartesianDiscreteModel{Dc}, cell_partition::Tuple) where
coarse_labels = get_face_labeling(model)
coarse_topo = get_grid_topology(model)
fine_topo = get_grid_topology(_model_ref)
fine_labels = _refine_face_labeling(coarse_labels,glue,coarse_topo,fine_topo)
fine_labels = refine_face_labeling(coarse_labels,glue,coarse_topo,fine_topo)

model_ref = CartesianDiscreteModel(get_grid(_model_ref),fine_topo,fine_labels)
return AdaptedDiscreteModel(model_ref,model,glue)
Expand Down
1 change: 1 addition & 0 deletions src/Adaptivity/Adaptivity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ include("AdaptedDiscreteModels.jl")
include("AdaptedTriangulations.jl")
include("CompositeQuadratures.jl")
include("EdgeBasedRefinement.jl")
include("SimplexifyRefinement.jl")

end # module
48 changes: 39 additions & 9 deletions src/Adaptivity/AdaptivityGlues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ function get_o2n_faces_map(ncell_to_ocell::Vector{T}) where {T<:Integer}
iC = ncell_to_ocell[iF]
ptrs[iC+1] += 1
end
length_to_ptrs!(ptrs)
Arrays.length_to_ptrs!(ptrs)

cnts = fill(0,nC)
data = fill(zero(T),ptrs[end])
for iF in 1:nF
iC = ncell_to_ocell[iF]
data[ptrs[iC]+cnts[iC]] = iF
cnts[iC] += 1
data[ptrs[iC]] = iF
ptrs[iC] += 1
end
Arrays.rewind_ptrs!(ptrs)

ocell_to_ncell = Table(data,ptrs)
return ocell_to_ncell
Expand Down Expand Up @@ -219,6 +219,7 @@ function get_d_to_fface_to_cface(glue::AdaptivityGlue{<:RefinementGlue},
rrules = get_old_cell_refinement_rules(glue)
ccell_to_d_to_faces = lazy_map(rr->map(d->Geometry.get_faces(get_grid_topology(rr.ref_grid),Dc,d),0:Dc),rrules)
ccell_to_d_to_fface_to_parent_face = lazy_map(get_d_to_face_to_parent_face,rrules)
fcell_to_child_id = glue.n2o_cell_to_child_id

# Global data, concerning the complete meshes
ccell_to_fcell = glue.o2n_faces_map
Expand All @@ -234,7 +235,8 @@ function get_d_to_fface_to_cface(glue::AdaptivityGlue{<:RefinementGlue},
local_d_to_fface_to_parent_dim = ccell_to_d_to_fface_to_parent_face[ccell]
# For each fine subcell:
# child_id -> Local Id of the fine cell within the refinement rule (ccell)
for (child_id,fcell) in enumerate(ccell_to_fcell[ccell])
for fcell in ccell_to_fcell[ccell]
child_id = fcell_to_child_id[fcell]
# For each fine face on the fine subcell:
# d -> Dimension of the fine face
# iF -> Local Id of the fine face within the fine cell
Expand All @@ -244,7 +246,7 @@ function get_d_to_fface_to_cface(glue::AdaptivityGlue{<:RefinementGlue},
# Local Id of the fine face within the refinement rule
fface_child_id = ccell_to_d_to_faces[ccell][d+1][child_id][iF]
# Local Id of the coarse parent face within the coarse cell
parent = local_d_to_fface_to_parent_face[d+1][fface_child_id]
parent = local_d_to_fface_to_parent_face[d+1][fface_child_id]

# Global Id of the coarse parent face, and it's dimension
cface_dim = local_d_to_fface_to_parent_dim[d+1][fface_child_id]
Expand All @@ -261,17 +263,17 @@ end

# FaceLabeling refinement

function _refine_face_labeling(coarse_labeling::FaceLabeling,
function refine_face_labeling(coarse_labeling::FaceLabeling,
glue :: AdaptivityGlue,
ctopo :: GridTopology,
ftopo :: GridTopology)
d_to_fface_to_cface,
d_to_fface_to_cface_dim = get_d_to_fface_to_cface(glue,ctopo,ftopo)

return _refine_face_labeling(coarse_labeling,d_to_fface_to_cface,d_to_fface_to_cface_dim)
return refine_face_labeling(coarse_labeling,d_to_fface_to_cface,d_to_fface_to_cface_dim)
end

function _refine_face_labeling(coarse_labeling::FaceLabeling,
function refine_face_labeling(coarse_labeling::FaceLabeling,
d_to_fface_to_cface,
d_to_fface_to_cface_dim)
tag_to_name = copy(coarse_labeling.tag_to_name)
Expand All @@ -295,4 +297,32 @@ function _refine_face_labeling(coarse_labeling::FaceLabeling,
end

return Geometry.FaceLabeling(d_to_dface_to_entity,tag_to_entities,tag_to_name)
end

"""
blocked_refinement_glue(rrules::AbstractVector{<:RefinementRule})
Given an array of RefinementRules for each coarse cell, returns an AdaptivityGlue
where children from the same parent are placed in contiguous blocks.
"""
function blocked_refinement_glue(
rrules::AbstractVector{<:RefinementRule{<:Polytope{Dc}}}
) where Dc
nC_old = length(rrules)
nC_new = sum(num_subcells,rrules)

f2c_cell_map = Vector{Int}(undef,nC_new)
fcell_to_child_id = Vector{Int}(undef,nC_new)

k = 1
for iC = 1:nC_old
rr = rrules[iC]
range = k:k+num_subcells(rr)-1
f2c_cell_map[range] .= iC
fcell_to_child_id[range] .= collect(1:num_subcells(rr))
k += num_subcells(rr)
end

f2c_faces_map = [(d==Dc) ? f2c_cell_map : Int[] for d in 0:Dc]
return AdaptivityGlue(f2c_faces_map,fcell_to_child_id,rrules)
end
Loading

0 comments on commit 8749df2

Please sign in to comment.