Skip to content

Commit

Permalink
Adding uniform refinement in the vertical direction
Browse files Browse the repository at this point in the history
  • Loading branch information
amartinhuertas committed Mar 6, 2024
1 parent a5fa023 commit c57a21c
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 5 deletions.
75 changes: 75 additions & 0 deletions src/AnisotropicallyAdapted3DDistributedDiscreteModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,81 @@ function vertically_adapt(model::OctreeDistributedDiscreteModel{Dc,Dp},
return ref_model, adaptivity_glue
end

function _vertically_uniformly_refine!(model::OctreeDistributedDiscreteModel{Dc,Dp}) where {Dc,Dp}
pXest_type = model.pXest_type
function refine_layer_callback(p6est::Ptr{p6est_t},
which_tree::p4est_topidx_t,
column::Ptr{p4est_quadrant_t},
layer::Ptr{p2est_quadrant_t})
Cint(1)
end

refine_layer_fn_callback_c = @cfunction($refine_layer_callback, Cint,
(Ptr{p6est_t}, p4est_topidx_t, Ptr{p4est_quadrant_t}, Ptr{p2est_quadrant_t}))

# # Copy input p4est, refine and balance
ptr_new_pXest = pXest_copy(pXest_type, model.ptr_pXest)
p6est_vertically_refine!(ptr_new_pXest,
refine_layer_fn_callback_c,
C_NULL)
ptr_new_pXest
end

function vertically_uniformly_refine(model::OctreeDistributedDiscreteModel)
ptr_new_pXest = _vertically_uniformly_refine!(model)

# Extract ghost and lnodes
ptr_pXest_ghost = setup_pXest_ghost(model.pXest_type, ptr_new_pXest)
ptr_pXest_lnodes = setup_pXest_lnodes_nonconforming(model.pXest_type, ptr_new_pXest, ptr_pXest_ghost)

# Build fine-grid mesh
fmodel,non_conforming_glue = setup_non_conforming_distributed_discrete_model(model.pXest_type,
model.parts,
model.coarse_model,
model.ptr_pXest_connectivity,
ptr_new_pXest,
ptr_pXest_ghost,
ptr_pXest_lnodes)

pXest_ghost_destroy(model.pXest_type,ptr_pXest_ghost)
pXest_lnodes_destroy(model.pXest_type,ptr_pXest_lnodes)

pXest_refinement_rule_type = PXestVerticalRefinementRuleType()
_refinement_and_coarsening_flags = map(partition(get_cell_gids(model))) do indices
flags = Vector{Cint}(undef,length(local_to_global(indices)))
flags .= refine_flag
end

stride = pXest_stride_among_children(model.pXest_type,pXest_refinement_rule_type,model.ptr_pXest)
adaptivity_glue = _compute_fine_to_coarse_model_glue(model.pXest_type,
pXest_refinement_rule_type,
model.parts,
model.dmodel,
fmodel,
_refinement_and_coarsening_flags,
stride)
adaptive_models = map(local_views(model),
local_views(fmodel),
adaptivity_glue) do model, fmodel, glue
Gridap.Adaptivity.AdaptedDiscreteModel(fmodel,model,glue)
end
fmodel = GridapDistributed.GenericDistributedDiscreteModel(adaptive_models,get_cell_gids(fmodel))
ref_model = OctreeDistributedDiscreteModel(3,3,
model.parts,
fmodel,
non_conforming_glue,
model.coarse_model,
model.ptr_pXest_connectivity,
ptr_new_pXest,
model.pXest_type,
model.pXest_refinement_rule_type,
false,
model)
return ref_model, adaptivity_glue
end



function setup_non_conforming_distributed_discrete_model(pXest_type::P6estType,
parts,
coarse_discrete_model,
Expand Down
1 change: 1 addition & 0 deletions src/GridapP4est.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module GridapP4est
export AnisotropicallyAdapted3DDistributedDiscreteModel
export vertically_adapt
export horizontally_adapt
export vertically_uniformly_refine
export nothing_flag, refine_flag, coarsen_flag
export FixedFractionAdaptiveFlagsMarkingStrategy
export update_adaptivity_flags!
Expand Down
2 changes: 1 addition & 1 deletion src/OctreeDistributedDiscreteModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function Init(a::OctreeDistributedDiscreteModel)
end

function Finalize(a::OctreeDistributedDiscreteModel)
# octree_distributed_discrete_model_free!(a)
octree_distributed_discrete_model_free!(a)
return nothing
end

Expand Down
8 changes: 4 additions & 4 deletions test/PoissonAnisotropicOctreeModelsTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ module PoissonAnisotropicOctreeModelsTests
rdmodel=dmodel
for i=1:num_amr_steps
rdmodel=test_transfer_ops_and_redistribute(ranks,rdmodel,order,T)
if i==1
rdmodel,_=vertically_uniformly_refine(dmodel)
end
end
end

Expand All @@ -271,11 +274,8 @@ module PoissonAnisotropicOctreeModelsTests
end
for perm in (1,2), order in (1,4), scalar_or_vector in (:vector,)
test(ranks,perm,order,_field_type(Val{3}(),scalar_or_vector))
end
for order=1:1, scalar_or_vector in (:scalar,:vector)
test_3d(ranks,order,_field_type(Val{3}(),scalar_or_vector), num_amr_steps=4)
end
for order=1:1, scalar_or_vector in (:scalar,)
for order=1:1, scalar_or_vector in (:scalar,:vector)
test_3d(ranks,order,_field_type(Val{3}(),scalar_or_vector), num_amr_steps=4)
end
end
Expand Down

0 comments on commit c57a21c

Please sign in to comment.