diff --git a/src/FESpaces.jl b/src/FESpaces.jl index c2b0947..5bb0dff 100644 --- a/src/FESpaces.jl +++ b/src/FESpaces.jl @@ -869,3 +869,22 @@ function _compute_new_distributed_fixedval( c = reduce(+,c_i,init=zero(eltype(c_i))) return c end + +function FESpaces.ConstantFESpace(model::DistributedDiscreteModel;kwargs...) + @warn "ConstantFESpace is NOT scalable in parallel. For testing purposes only." + spaces = map(local_views(model)) do model + ConstantFESpace(model;kwargs...) + end + + # Single dof, owned by processor 1 (ghost for all other processors) + cell_gids = get_cell_gids(model) + indices = map(partition(cell_gids)) do cell_indices + me = part_id(cell_indices) + LocalIndices(1,me,Int[1],Int32[1]) + end + gids = PRange(indices) + + trian = DistributedTriangulation(map(get_triangulation,spaces),model) + vector_type = _find_vector_type(spaces,gids) + return DistributedSingleFieldFESpace(spaces,gids,trian,vector_type) +end diff --git a/test/ConstantFESpacesTests.jl b/test/ConstantFESpacesTests.jl new file mode 100644 index 0000000..f0bbcea --- /dev/null +++ b/test/ConstantFESpacesTests.jl @@ -0,0 +1,27 @@ + +using Gridap +using GridapDistributed, PartitionedArrays + +using Gridap.FESpaces + +np = (2,2) +ranks = with_debug() do distribute + distribute(LinearIndices((prod(np),))) +end + +model = CartesianDiscreteModel(ranks,np,(0,1,0,1),(4,4)) + +Ω = Triangulation(model) +dΩ = Measure(Ω,2) + +V = ConstantFESpace(model) + +gids = get_free_dof_ids(V) +local_to_global(gids) +local_to_owner(gids) +ghost_to_local(gids) +own_to_local(gids) + +uh = zero(V) +sum(∫(uh)dΩ) +