Skip to content

Commit

Permalink
Small refactor of PatchFESpaces constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiManyer committed Dec 5, 2023
1 parent 7704503 commit 213c303
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 41 deletions.
41 changes: 23 additions & 18 deletions src/PatchBasedSmoothers/mpi/PatchFESpaces.jl
Original file line number Diff line number Diff line change
@@ -1,43 +1,48 @@

function PatchFESpace(model::GridapDistributed.DistributedDiscreteModel,
reffe::Tuple{<:Gridap.FESpaces.ReferenceFEName,Any,Any},
conformity::Gridap.FESpaces.Conformity,
function PatchFESpace(space::GridapDistributed.DistributedSingleFieldFESpace,
patch_decomposition::DistributedPatchDecomposition,
Vh::GridapDistributed.DistributedSingleFieldFESpace)
reffe::Union{ReferenceFE,Tuple{<:Gridap.ReferenceFEs.ReferenceFEName,Any,Any}};
conformity=nothing)
cell_conformity = _cell_conformity(patch_decomposition.model,reffe;conformity=conformity)
return PatchFESpace(space,patch_decomposition,cell_conformity)
end

function PatchFESpace(space::GridapDistributed.DistributedSingleFieldFESpace,
patch_decomposition::DistributedPatchDecomposition,
cell_conformity::AbstractArray{<:CellConformity})
model = patch_decomposition.model
root_gids = get_face_gids(model,get_patch_root_dim(patch_decomposition))

spaces = map(local_views(model),
spaces = map(local_views(space),
local_views(patch_decomposition),
local_views(Vh),
partition(root_gids)) do model, patch_decomposition, Vh, partition
cell_conformity,
partition(root_gids)) do space, patch_decomposition, cell_conformity, partition
patches_mask = fill(false,local_length(partition))
patches_mask[ghost_to_local(partition)] .= true # Mask ghost patch roots
PatchFESpace(model,reffe,conformity,patch_decomposition,Vh;patches_mask=patches_mask)
PatchFESpace(space,patch_decomposition,cell_conformity;patches_mask=patches_mask)
end

# This PRange has no ghost dofs
local_ndofs = map(num_free_dofs,spaces)
global_ndofs = sum(local_ndofs)
patch_partition = variable_partition(local_ndofs,global_ndofs,false)
gids = PRange(patch_partition)
return GridapDistributed.DistributedSingleFieldFESpace(spaces,gids,get_vector_type(Vh))
return GridapDistributed.DistributedSingleFieldFESpace(spaces,gids,get_vector_type(space))
end

function PatchFESpace(mh::ModelHierarchy,
reffe::Tuple{<:Gridap.FESpaces.ReferenceFEName,Any,Any},
conformity::Gridap.FESpaces.Conformity,
patch_decompositions::AbstractArray{<:DistributedPatchDecomposition},
sh::FESpaceHierarchy)
nlevs = num_levels(mh)
function PatchFESpace(sh::FESpaceHierarchy,
patch_decompositions::AbstractArray{<:DistributedPatchDecomposition})
mh = sh.mh
nlevs = num_levels(mh)
levels = Vector{MultilevelTools.FESpaceHierarchyLevel}(undef,nlevs)
for lev in 1:nlevs-1
parts = get_level_parts(mh,lev)
if i_am_in(parts)
model = get_model(mh,lev)
space = MultilevelTools.get_fe_space(sh,lev)
decomp = patch_decompositions[lev]
patch_space = PatchFESpace(model,reffe,conformity,decomp,space)
levels[lev] = MultilevelTools.FESpaceHierarchyLevel(lev,nothing,patch_space)
cell_conformity = sh.levels[lev].cell_conformity
patch_space = PatchFESpace(space,decomp,cell_conformity)
levels[lev] = MultilevelTools.FESpaceHierarchyLevel(lev,nothing,patch_space,cell_conformity)
end
end
return FESpaceHierarchy(mh,levels)
Expand Down
42 changes: 19 additions & 23 deletions src/PatchBasedSmoothers/seq/PatchFESpaces.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
struct PatchFESpace <: Gridap.FESpaces.SingleFieldFESpace
num_dofs :: Int
patch_cell_dofs_ids :: Gridap.Arrays.Table
Vh :: Gridap.FESpaces.SingleFieldFESpace
patch_decomposition :: PatchDecomposition
dof_to_pdof :: Gridap.Arrays.Table
end

# INPUT
# [[1, 2]]
# [[1, 2], [2, 3]]
Expand Down Expand Up @@ -39,32 +31,42 @@ end
# [[6, 7], [7, -2]]
# [[8, -2]]

struct PatchFESpace <: Gridap.FESpaces.SingleFieldFESpace
Vh :: Gridap.FESpaces.SingleFieldFESpace
patch_decomposition :: PatchDecomposition
num_dofs :: Int
patch_cell_dofs_ids :: Gridap.Arrays.Table
dof_to_pdof :: Gridap.Arrays.Table
end

# Issue: I have to pass model, reffe, and conformity, so that I can
# build the cell_conformity instance. I would have liked to
# avoid that, given that these were already used in order to
# build Vh. However, I cannot extract this info out of Vh!!! :-(
function PatchFESpace(model::DiscreteModel,
reffe::Tuple{<:Gridap.FESpaces.ReferenceFEName,Any,Any},
conformity::Gridap.FESpaces.Conformity,
function PatchFESpace(Vh::Gridap.FESpaces.SingleFieldFESpace,
patch_decomposition::PatchDecomposition,
Vh::Gridap.FESpaces.SingleFieldFESpace;
reffe::Union{ReferenceFE,Tuple{<:Gridap.ReferenceFEs.ReferenceFEName,Any,Any}};
conformity=nothing,
patches_mask=Fill(false,num_patches(patch_decomposition)))
cell_conformity = _cell_conformity(patch_decomposition.model,reffe;conformity=conformity)
return PatchFESpace(Vh,patch_decomposition,cell_conformity;patches_mask=patches_mask)
end

cell_reffe = setup_cell_reffe(model,reffe)
cell_conformity = CellConformity(cell_reffe,conformity)
function PatchFESpace(Vh::Gridap.FESpaces.SingleFieldFESpace,
patch_decomposition::PatchDecomposition,
cell_conformity::CellConformity;
patches_mask=Fill(false,num_patches(patch_decomposition)))

cell_dofs_ids = get_cell_dof_ids(Vh)
patch_cell_dofs_ids, num_dofs =
generate_patch_cell_dofs_ids(get_grid_topology(model),
generate_patch_cell_dofs_ids(get_grid_topology(patch_decomposition.model),
patch_decomposition.patch_cells,
patch_decomposition.patch_cells_overlapped,
patch_decomposition.patch_cells_faces_on_boundary,
cell_dofs_ids,cell_conformity,patches_mask)

dof_to_pdof = generate_dof_to_pdof(Vh,patch_decomposition,patch_cell_dofs_ids)

return PatchFESpace(num_dofs,patch_cell_dofs_ids,Vh,patch_decomposition,dof_to_pdof)
return PatchFESpace(Vh,patch_decomposition,num_dofs,patch_cell_dofs_ids,dof_to_pdof)
end

Gridap.FESpaces.get_dof_value_type(a::PatchFESpace) = Gridap.FESpaces.get_dof_value_type(a.Vh)
Expand Down Expand Up @@ -118,12 +120,6 @@ end

# Construction of the patch cell dofs ids

function setup_cell_reffe(model::DiscreteModel,reffe::Tuple{<:Gridap.FESpaces.ReferenceFEName,Any,Any}; kwargs...)
basis, reffe_args,reffe_kwargs = reffe
cell_reffe = ReferenceFE(model,basis,reffe_args...;reffe_kwargs...)
return cell_reffe
end

function generate_patch_cell_dofs_ids(topology,
patch_cells,
patch_cells_overlapped,
Expand Down

0 comments on commit 213c303

Please sign in to comment.