From 0bc91844ae3144890601fb211970b1da35be2d4e Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Tue, 17 Sep 2024 15:10:32 +1000 Subject: [PATCH] Added ConstantFESpaces --- src/FESpaces.jl | 19 +++++++++++++++++++ test/ConstantFESpacesTests.jl | 27 +++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 test/ConstantFESpacesTests.jl 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Ω) +