Skip to content

Commit

Permalink
Merge branch 'main' of github.com:gridap/GridapP4est.jl into uniform-3d
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiManyer committed Dec 6, 2023
2 parents cd5770a + db171dd commit 3b24516
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
version:
- '1.8'
os:
- ubuntu-20.04
- ubuntu-latest
arch:
- x64
steps:
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 = "GridapP4est"
uuid = "c2c8e14b-f5fd-423d-9666-1dd9ad120af9"
authors = ["Alberto F. Martin <[email protected]>"]
version = "0.3.2"
version = "0.3.3"

[deps]
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
Expand Down
59 changes: 33 additions & 26 deletions src/FESpaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -889,37 +889,45 @@ function fe_space_with_linear_constraints_cell_dof_ids(Uc::FESpaceWithLinearCons
Gridap.Arrays.Table(Uc_cell_dof_ids_data, U_cell_dof_ids.ptrs)
end

function _is_conforming(model::OctreeDistributedDiscreteModel)
is_local_conforming=map(model.non_conforming_glue) do ncglue
all(x->x==0, ncglue.num_hanging_faces)
end
reduction(&,is_local_conforming,init=true,destination=:all).item_ref[]
end

function _add_constraints(model::GridapDistributed.DistributedDiscreteModel{Dc},
reffe,
spaces_wo_constraints;
conformity=nothing,
kwargs...) where {Dc}
if (conformity==nothing || conformity!=:L2)
ref_constraints = _build_constraint_coefficients_matrix_in_ref_space(Dc, reffe)

face_subface_ldof_to_cell_ldof = Vector{Vector{Vector{Vector{Int32}}}}(undef, Dc-1)
face_subface_ldof_to_cell_ldof[Dc-1] = _generate_face_subface_ldof_to_cell_ldof(Dc-1, Dc, reffe)
if (Dc == 3)
face_subface_ldof_to_cell_ldof[1] =
_generate_face_subface_ldof_to_cell_ldof(1, Dc, reffe)
end
sDOF_to_dof, sDOF_to_dofs, sDOF_to_coeffs =
generate_constraints(model, spaces_wo_constraints, reffe, ref_constraints, face_subface_ldof_to_cell_ldof)
spaces_w_constraints = map(spaces_wo_constraints,
sDOF_to_dof,
sDOF_to_dofs,
sDOF_to_coeffs) do V, sDOF_to_dof, sDOF_to_dofs, sDOF_to_coeffs
@debug "[$(MPI.Comm_rank(MPI.COMM_WORLD))]: fe_space_wo_constraints_cell_dof_ids=$(get_cell_dof_ids(V))"
Vc = FESpaceWithLinearConstraints(sDOF_to_dof, sDOF_to_dofs, sDOF_to_coeffs, V)
end
local_cell_dof_ids = map(spaces_w_constraints,sDOF_to_dof) do Vc,sDOF_to_dof
result = fe_space_with_linear_constraints_cell_dof_ids(Vc,sDOF_to_dof)
@debug "[$(MPI.Comm_rank(MPI.COMM_WORLD))]: fe_space_with_linear_constraints_cell_dof_ids=$(result)"
result
end

if (_is_conforming(model) || conformity==:L2 )
spaces_w_constraints=spaces_wo_constraints
local_cell_dof_ids=map(get_cell_dof_ids,spaces_w_constraints)
else
spaces_w_constraints=spaces_wo_constraints
local_cell_dof_ids=map(get_cell_dof_ids,spaces_w_constraints)
@assert conformity==nothing || conformity!=:L2
ref_constraints = _build_constraint_coefficients_matrix_in_ref_space(Dc, reffe)
face_subface_ldof_to_cell_ldof = Vector{Vector{Vector{Vector{Int32}}}}(undef, Dc-1)
face_subface_ldof_to_cell_ldof[Dc-1] = _generate_face_subface_ldof_to_cell_ldof(Dc-1, Dc, reffe)
if (Dc == 3)
face_subface_ldof_to_cell_ldof[1] =
_generate_face_subface_ldof_to_cell_ldof(1, Dc, reffe)
end
sDOF_to_dof, sDOF_to_dofs, sDOF_to_coeffs =
generate_constraints(model, spaces_wo_constraints, reffe, ref_constraints, face_subface_ldof_to_cell_ldof)
spaces_w_constraints = map(spaces_wo_constraints,
sDOF_to_dof,
sDOF_to_dofs,
sDOF_to_coeffs) do V, sDOF_to_dof, sDOF_to_dofs, sDOF_to_coeffs
@debug "[$(MPI.Comm_rank(MPI.COMM_WORLD))]: fe_space_wo_constraints_cell_dof_ids=$(get_cell_dof_ids(V))"
Vc = FESpaceWithLinearConstraints(sDOF_to_dof, sDOF_to_dofs, sDOF_to_coeffs, V)
end
local_cell_dof_ids = map(spaces_w_constraints,sDOF_to_dof) do Vc,sDOF_to_dof
result = fe_space_with_linear_constraints_cell_dof_ids(Vc,sDOF_to_dof)
@debug "[$(MPI.Comm_rank(MPI.COMM_WORLD))]: fe_space_with_linear_constraints_cell_dof_ids=$(result)"
result
end
end
nldofs = map(num_free_dofs,spaces_w_constraints)
cell_gids = get_cell_gids(model)
Expand All @@ -932,7 +940,6 @@ function _add_constraints(model::GridapDistributed.DistributedDiscreteModel{Dc},
GridapDistributed.DistributedSingleFieldFESpace(spaces_w_constraints,gids,vector_type)
end


# Generates a new DistributedSingleFieldFESpace composed
# by local FE spaces with linear multipoint constraints added
function Gridap.FESpaces.FESpace(model::OctreeDistributedDiscreteModel{Dc},
Expand Down
10 changes: 7 additions & 3 deletions src/OctreeDistributedDiscreteModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1432,12 +1432,16 @@ function _refine_coarsen_balance!(model::OctreeDistributedDiscreteModel{Dc,Dp},
end

function Gridap.Adaptivity.adapt(model::OctreeDistributedDiscreteModel{Dc,Dp},
refinement_and_coarsening_flags::MPIArray{<:Vector};
refinement_and_coarsening_flags::MPIArray{<:Vector{<:Integer}};
parts=nothing) where {Dc,Dp}

Gridap.Helpers.@notimplementedif parts!=nothing

_refinement_and_coarsening_flags = map(refinement_and_coarsening_flags) do flags
convert(Vector{Cint},flags)
end

ptr_new_pXest = _refine_coarsen_balance!(model, refinement_and_coarsening_flags)
ptr_new_pXest = _refine_coarsen_balance!(model, _refinement_and_coarsening_flags)

# Extract ghost and lnodes
ptr_pXest_ghost = setup_pXest_ghost(Val{Dc}, ptr_new_pXest)
Expand All @@ -1457,7 +1461,7 @@ function Gridap.Adaptivity.adapt(model::OctreeDistributedDiscreteModel{Dc,Dp},
adaptivity_glue = _compute_fine_to_coarse_model_glue(model.parts,
model.dmodel,
fmodel,
refinement_and_coarsening_flags)
_refinement_and_coarsening_flags)
adaptive_models = map(local_views(model),
local_views(fmodel),
adaptivity_glue) do model, fmodel, glue
Expand Down
4 changes: 2 additions & 2 deletions test/PoissonNonConformingOctreeModelsTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module PoissonNonConformingOctreeModelsTests
reffe=ReferenceFE(lagrangian,T,order)
VH=FESpace(dmodel,reffe;dirichlet_tags="boundary")
UH=TrialFESpace(VH,u)
ref_coarse_flags=map(ranks,partition(get_cell_gids(dmodel.dmodel))) do rank,indices
ref_coarse_flags=map(ranks,partition(get_cell_gids(dmodel.dmodel))) do rank,indices
flags=zeros(Cint,length(indices))
flags.=nothing_flag

Expand Down Expand Up @@ -176,7 +176,7 @@ module PoissonNonConformingOctreeModelsTests

degree = 2*order+1
ref_coarse_flags=map(ranks,partition(get_cell_gids(dmodel.dmodel))) do rank,indices
flags=zeros(Cint,length(indices))
flags=zeros(Int,length(indices))
flags.=nothing_flag
if (rank==1)
flags[1:2^Dc].=coarsen_flag
Expand Down

0 comments on commit 3b24516

Please sign in to comment.