Skip to content

Commit

Permalink
Added local-constant fespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiManyer committed Oct 1, 2024
1 parent a3309ee commit 272dc6f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 33 deletions.
18 changes: 15 additions & 3 deletions src/FESpaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -870,17 +870,29 @@ function _compute_new_distributed_fixedval(
return c
end

function FESpaces.ConstantFESpace(model::DistributedDiscreteModel;kwargs...)
@warn "ConstantFESpace is NOT scalable in parallel. For testing purposes only."
function FESpaces.ConstantFESpace(
model::DistributedDiscreteModel;
constraint_type=:global,kwargs...
)
@assert constraint_type [:global,:local]
if constraint_type == :global
@warn "ConstantFESpace is NOT scalable in parallel. For testing purposes only."
end

spaces = map(local_views(model)) do model
ConstantFESpace(model;kwargs...)
end

# Single dof, owned by processor 1 (ghost for all other processors)
nranks = length(spaces)
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])
if constraint_type == :global
LocalIndices(1,me,Int[1],Int32[1])
else
LocalIndices(nranks,me,Int[me],Int32[me])
end
end
gids = PRange(indices)

Expand Down
52 changes: 22 additions & 30 deletions test/ConstantFESpacesTests.jl
Original file line number Diff line number Diff line change
@@ -1,46 +1,38 @@

using Test
using Gridap
using GridapDistributed, PartitionedArrays

using Gridap.FESpaces, Gridap.Arrays, Gridap.Algebra

np = (2,2)
ranks = with_mpi() do distribute
distribute(LinearIndices((prod(np),)))
end
function main(distribute,np)
@assert prod(np) == 4
ranks = distribute(LinearIndices((prod(np),)))

model = CartesianDiscreteModel(ranks,np,(0,1,0,1),(10,10))
model = CartesianDiscreteModel(ranks,np,(0,1,0,1),(10,10))

Ω = Triangulation(model)
= Measure(Ω,2)
Ω = Triangulation(model)
= Measure(Ω,2)

reffe = ReferenceFE(lagrangian, Float64, 1)
U = FESpace(model,reffe)
V = ConstantFESpace(model)
X = MultiFieldFESpace([U,V])
reffe = ReferenceFE(lagrangian, Float64, 1)
U = FESpace(model,reffe)
V = ConstantFESpace(model)
X = MultiFieldFESpace([U,V])

gids = get_free_dof_ids(V)
local_to_global(gids)
local_to_owner(gids)
ghost_to_local(gids)
own_to_local(gids)
gids = get_free_dof_ids(V)
@test length(gids) == 1

uh = zero(V)
sum((uh)dΩ)
a((u,λ),(v,μ)) = (u*v + λ*v + μ*u)dΩ
A = assemble_matrix(a,X,X)

map(ranks) do r
println("flag 1 from ", r)
end
V2 = ConstantFESpace(model;constraint_type=:local)
X2 = MultiFieldFESpace([U,V2])

a((u,λ),(v,μ)) = (u*v + λ*v + μ*u)dΩ
A = assemble_matrix(a,X,X)
gids = get_free_dof_ids(V2)
@test length(gids) == 4

map(ranks) do r
println("flag 2 from ", r)
A2 = assemble_matrix(a,X2,X2)
end

x = allocate_in_domain(A)

map(ranks) do r
println("done from ", r)
with_debug() do distribute
main(distribute,(2,2))
end

0 comments on commit 272dc6f

Please sign in to comment.