From 0bc91844ae3144890601fb211970b1da35be2d4e Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Tue, 17 Sep 2024 15:10:32 +1000 Subject: [PATCH 01/19] 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 c2b09475..5bb0dff6 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 00000000..f0bbcea5 --- /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Ω) + From a3309eef48b97bef3f9e5f3517a2716f86339b04 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Tue, 1 Oct 2024 10:12:33 +1000 Subject: [PATCH 02/19] Minor --- test/ConstantFESpacesTests.jl | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/test/ConstantFESpacesTests.jl b/test/ConstantFESpacesTests.jl index f0bbcea5..8a66568b 100644 --- a/test/ConstantFESpacesTests.jl +++ b/test/ConstantFESpacesTests.jl @@ -2,19 +2,22 @@ using Gridap using GridapDistributed, PartitionedArrays -using Gridap.FESpaces +using Gridap.FESpaces, Gridap.Arrays, Gridap.Algebra np = (2,2) -ranks = with_debug() do distribute +ranks = with_mpi() do distribute distribute(LinearIndices((prod(np),))) end -model = CartesianDiscreteModel(ranks,np,(0,1,0,1),(4,4)) +model = CartesianDiscreteModel(ranks,np,(0,1,0,1),(10,10)) Ω = Triangulation(model) dΩ = Measure(Ω,2) +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) @@ -25,3 +28,19 @@ own_to_local(gids) uh = zero(V) sum(∫(uh)dΩ) +map(ranks) do r + println("flag 1 from ", r) +end + +a((u,λ),(v,μ)) = ∫(u*v + λ*v + μ*u)dΩ +A = assemble_matrix(a,X,X) + +map(ranks) do r + println("flag 2 from ", r) +end + +x = allocate_in_domain(A) + +map(ranks) do r + println("done from ", r) +end From 272dc6f9492cce113171f712d4a87954b771173d Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Tue, 1 Oct 2024 10:46:32 +1000 Subject: [PATCH 03/19] Added local-constant fespaces --- src/FESpaces.jl | 18 ++++++++++-- test/ConstantFESpacesTests.jl | 52 +++++++++++++++-------------------- 2 files changed, 37 insertions(+), 33 deletions(-) diff --git a/src/FESpaces.jl b/src/FESpaces.jl index 5bb0dff6..43c7d8dc 100644 --- a/src/FESpaces.jl +++ b/src/FESpaces.jl @@ -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) diff --git a/test/ConstantFESpacesTests.jl b/test/ConstantFESpacesTests.jl index 8a66568b..76239811 100644 --- a/test/ConstantFESpacesTests.jl +++ b/test/ConstantFESpacesTests.jl @@ -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) -dΩ = Measure(Ω,2) + Ω = Triangulation(model) + dΩ = 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 From 58f84345e0804b2acf1be108b2d3437b97a81085 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Tue, 1 Oct 2024 10:56:17 +1000 Subject: [PATCH 04/19] Added tests --- test/ConstantFESpacesTests.jl | 4 ++-- test/mpi/runtests_np4_body.jl | 5 +++++ test/sequential/ConstantFESpacesTests.jl | 10 ++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 test/sequential/ConstantFESpacesTests.jl diff --git a/test/ConstantFESpacesTests.jl b/test/ConstantFESpacesTests.jl index 76239811..df65eb99 100644 --- a/test/ConstantFESpacesTests.jl +++ b/test/ConstantFESpacesTests.jl @@ -1,3 +1,5 @@ +module ConstantFESpacesTests + using Test using Gridap using GridapDistributed, PartitionedArrays @@ -33,6 +35,4 @@ function main(distribute,np) A2 = assemble_matrix(a,X2,X2) end -with_debug() do distribute - main(distribute,(2,2)) end diff --git a/test/mpi/runtests_np4_body.jl b/test/mpi/runtests_np4_body.jl index 355f6627..fe5e4759 100644 --- a/test/mpi/runtests_np4_body.jl +++ b/test/mpi/runtests_np4_body.jl @@ -54,5 +54,10 @@ function all_tests(distribute,parts) TestApp.BlockSparseMatrixAssemblersTests.main(distribute,parts) PArrays.toc!(t,"BlockSparseMatrixAssemblers") + if prod(parts) == 4 + TestApp.ConstantFESpacesTests.main(distribute,parts) + PArrays.toc!(t,"ConstantFESpaces") + end + display(t) end diff --git a/test/sequential/ConstantFESpacesTests.jl b/test/sequential/ConstantFESpacesTests.jl new file mode 100644 index 00000000..66ae51d2 --- /dev/null +++ b/test/sequential/ConstantFESpacesTests.jl @@ -0,0 +1,10 @@ +module ConstantFESpacesTestsSeq + +using PartitionedArrays +include("../ConstantFESpacesTests.jl") + +with_debug() do distribute + ConstantFESpacesTests.main(distribute,(2,2)) +end + +end From 52fbaddef70a3844d9ae13c905b8023ce97d35a3 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Tue, 1 Oct 2024 10:57:30 +1000 Subject: [PATCH 05/19] Minor --- src/FESpaces.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/FESpaces.jl b/src/FESpaces.jl index 43c7d8dc..959c498b 100644 --- a/src/FESpaces.jl +++ b/src/FESpaces.jl @@ -876,7 +876,8 @@ function FESpaces.ConstantFESpace( ) @assert constraint_type ∈ [:global,:local] if constraint_type == :global - @warn "ConstantFESpace is NOT scalable in parallel. For testing purposes only." + msg = "ConstantFESpace is NOT scalable in parallel. For testing purposes only." + @warn msg end spaces = map(local_views(model)) do model From 17f8de2f391ab15e7b6a80493c26ef6286ab686e Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Tue, 1 Oct 2024 11:05:20 +1000 Subject: [PATCH 06/19] Added constraint --- src/FESpaces.jl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/FESpaces.jl b/src/FESpaces.jl index 959c498b..319e2182 100644 --- a/src/FESpaces.jl +++ b/src/FESpaces.jl @@ -870,6 +870,22 @@ function _compute_new_distributed_fixedval( return c end +""" + ConstantFESpace( + model::DistributedDiscreteModel; + constraint_type=:global, + kwargs... + ) + +Distributed equivalent to `ConstantFESpace(model;kwargs...)`. + +With `constraint_type=:global`, a single dof is shared by all processors. +This creates a global constraint, which is NOT scalable in parallel. Use at your own peril. + +With `constraint_type=:local`, a single dof is owned by each processor and shared with no one else. +This space is locally-constant in each processor, and therefore scalable (but not equivalent +to its serial counterpart). +""" function FESpaces.ConstantFESpace( model::DistributedDiscreteModel; constraint_type=:global,kwargs... From 5d1fd16da8a71604ed30660157457cf49b6a5faf Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Mon, 7 Oct 2024 14:17:43 +1100 Subject: [PATCH 07/19] DistributedAdaptedDiscreteModels now keep the parent gids --- src/Adaptivity.jl | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/Adaptivity.jl b/src/Adaptivity.jl index 1ce6bb91..a302e6bd 100644 --- a/src/Adaptivity.jl +++ b/src/Adaptivity.jl @@ -3,6 +3,12 @@ const DistributedAdaptedDiscreteModel{Dc,Dp} = GenericDistributedDiscreteModel{Dc,Dp,<:AbstractArray{<:AdaptedDiscreteModel{Dc,Dp}}} +struct DistributedAdaptedDiscreteModelCache{A,B,C} + model_matedata::A + parent_metadata::B + parent_gids::C +end + function DistributedAdaptedDiscreteModel( model :: DistributedDiscreteModel, parent :: DistributedDiscreteModel, @@ -12,7 +18,9 @@ function DistributedAdaptedDiscreteModel( AdaptedDiscreteModel(model,parent,glue) end gids = get_cell_gids(model) - metadata = hasproperty(model,:metadata) ? model.metadata : nothing + metadata = DistributedAdaptedDiscreteModelCache( + model.metadata,parent.metadata,get_cell_gids(parent) + ) return GenericDistributedDiscreteModel(models,gids;metadata) end @@ -20,15 +28,16 @@ function Adaptivity.get_model(model::DistributedAdaptedDiscreteModel) GenericDistributedDiscreteModel( map(get_model,local_views(model)), get_cell_gids(model); - metadata = hasproperty(model,:metadata) ? model.metadata : nothing + metadata = model.metadata.model_metadata ) end function Adaptivity.get_parent(model::DistributedAdaptedDiscreteModel) - msg = " Error: Cannot get global parent model. \n - We do not keep the global ids of the parent model within the children.\n - You can extract the local parents with map(get_parent,local_views(model))" - @notimplemented msg + GenericDistributedDiscreteModel( + map(get_parent,local_views(model)), + model.metadata.parent_gids; + metadata = model.metadata.parent_metadata + ) end function Adaptivity.get_adaptivity_glue(model::DistributedAdaptedDiscreteModel) @@ -48,7 +57,7 @@ function Adaptivity.refine( fmodel = GenericDistributedDiscreteModel( map(get_model,local_views(_fmodel)), get_cell_gids(_fmodel); - metadata=_fmodel.metadata + metadata=_fmodel.metadata.model_metadata ) glues = get_adaptivity_glue(_fmodel) return DistributedAdaptedDiscreteModel(fmodel,cmodel,glues) @@ -592,7 +601,9 @@ function Adaptivity.refine( end fgids = get_cell_gids(fmodel) - metadata = fmodel.metadata + metadata = DistributedAdaptedDiscreteModelCache( + fmodel.metadata,cmodel.metadata,get_cell_gids(cmodel) + ) return GenericDistributedDiscreteModel(fmodels,fgids;metadata) end @@ -909,7 +920,10 @@ function Adaptivity.refine( ) where Dc fmodels, f_own_to_local = refine_local_models(cmodel,args...;kwargs...) fgids = refine_cell_gids(cmodel,fmodels,f_own_to_local) - return GenericDistributedDiscreteModel(fmodels,fgids) + metadata = DistributedAdaptedDiscreteModelCache( + nothing,cmodel.metadata,get_cell_gids(cmodel) + ) + return GenericDistributedDiscreteModel(fmodels,fgids;metadata) end """ From bc8b461984b9a7d2df3637af569364bfb08cd29f Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Mon, 7 Oct 2024 14:25:09 +1100 Subject: [PATCH 08/19] Minor --- src/Adaptivity.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Adaptivity.jl b/src/Adaptivity.jl index a302e6bd..92533b18 100644 --- a/src/Adaptivity.jl +++ b/src/Adaptivity.jl @@ -4,7 +4,7 @@ const DistributedAdaptedDiscreteModel{Dc,Dp} = GenericDistributedDiscreteModel{Dc,Dp,<:AbstractArray{<:AdaptedDiscreteModel{Dc,Dp}}} struct DistributedAdaptedDiscreteModelCache{A,B,C} - model_matedata::A + model_metadata::A parent_metadata::B parent_gids::C end From 96b036ad58e5099986cb749e40c6eb08b9af6775 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Mon, 7 Oct 2024 14:30:54 +1100 Subject: [PATCH 09/19] Added is_child --- src/Adaptivity.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Adaptivity.jl b/src/Adaptivity.jl index 92533b18..ffb43f8b 100644 --- a/src/Adaptivity.jl +++ b/src/Adaptivity.jl @@ -44,6 +44,10 @@ function Adaptivity.get_adaptivity_glue(model::DistributedAdaptedDiscreteModel) return map(Adaptivity.get_adaptivity_glue,local_views(model)) end +function Adaptivity.is_child(m1::DistributedDiscreteModel,m2::DistributedDiscreteModel) + reduce(&,map(Adaptivity.is_child,local_views(m1),local_views(m2))) +end + function Adaptivity.refine( cmodel::DistributedAdaptedDiscreteModel{Dc},args...;kwargs... ) where Dc From 89a2c498399168bac8f02d2bc24b2b41dea71ba9 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Wed, 9 Oct 2024 09:16:35 +1100 Subject: [PATCH 10/19] Minor fix in Interpolables --- src/CellData.jl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/CellData.jl b/src/CellData.jl index 6befc88e..aba2f093 100644 --- a/src/CellData.jl +++ b/src/CellData.jl @@ -362,10 +362,9 @@ struct DistributedInterpolable{Tx,Ty,A} <: Function interps::A function DistributedInterpolable(interps::AbstractArray{<:Interpolable}) Tx,Ty = map(interps) do I - fi = I.uh - trian = get_triangulation(fi) + trian = get_triangulation(I.uh) x = mean(testitem(get_cell_coordinates(trian))) - return typeof(x), return_type(fi,x) + return typeof(x), return_type(I,x) end |> tuple_of_arrays Tx = getany(Tx) Ty = getany(Ty) From fccf216794f8f41f795eeb33771dbbc1e8163409 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Wed, 9 Oct 2024 11:13:36 +1100 Subject: [PATCH 11/19] Minor --- src/CellData.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CellData.jl b/src/CellData.jl index aba2f093..0c82a000 100644 --- a/src/CellData.jl +++ b/src/CellData.jl @@ -417,7 +417,7 @@ function Arrays.evaluate!(cache,I::DistributedInterpolable{Tx,Ty},x::AbstractVec end if inside ids[k] = i - vals[k] = yi + vals[k] = copy(yi) k += 1 end end From 1e09e3f7f904350ebe836138005cf782b097460d Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Mon, 14 Oct 2024 10:39:17 +1100 Subject: [PATCH 12/19] Minor --- src/Adaptivity.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Adaptivity.jl b/src/Adaptivity.jl index ffb43f8b..b41fb4bf 100644 --- a/src/Adaptivity.jl +++ b/src/Adaptivity.jl @@ -520,7 +520,7 @@ end # Cartesian Model uniform refinement function Adaptivity.refine( - cmodel::DistributedDiscreteModel{Dc}, + cmodel::DistributedCartesianDiscreteModel{Dc}, refs::Integer = 2 ) where Dc Adaptivity.refine(cmodel,Tuple(fill(refs,Dc))) From 293dccdded7cc50062051bb0b91619a5ea5c1321 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Mon, 14 Oct 2024 10:54:17 +1100 Subject: [PATCH 13/19] Minor bugfix --- src/Adaptivity.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Adaptivity.jl b/src/Adaptivity.jl index b41fb4bf..8f774d11 100644 --- a/src/Adaptivity.jl +++ b/src/Adaptivity.jl @@ -996,7 +996,9 @@ function refine_local_models( # Filter out local models filtered_fmodels = map(fmodels,f_own_or_ghost_ids) do fmodel,f_own_or_ghost_ids - model = DiscreteModelPortion(get_model(fmodel),f_own_or_ghost_ids).model + model = UnstructuredDiscreteModel( # Necessary to keep the same type + DiscreteModelPortion(get_model(fmodel),f_own_or_ghost_ids) + ) parent = get_parent(fmodel) _glue = get_adaptivity_glue(fmodel) From a2941bb560ebb917720122f609a52b4bf864d985 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Wed, 30 Oct 2024 18:18:14 +1100 Subject: [PATCH 14/19] Added Boundary and Skeleton for DistributedTriangulations --- src/Geometry.jl | 32 ++++++++++++++++++++++++++++++++ test/GeometryTests.jl | 13 ++++++++++--- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/Geometry.jl b/src/Geometry.jl index 4c788242..517dd596 100644 --- a/src/Geometry.jl +++ b/src/Geometry.jl @@ -491,11 +491,21 @@ function Geometry.BoundaryTriangulation( BoundaryTriangulation(no_ghost,model;kwargs...) end +function Geometry.BoundaryTriangulation( + trian::DistributedTriangulation;kwargs...) + BoundaryTriangulation(no_ghost,trian;kwargs...) +end + function Geometry.SkeletonTriangulation( model::DistributedDiscreteModel;kwargs...) SkeletonTriangulation(no_ghost,model;kwargs...) end +function Geometry.SkeletonTriangulation( + trian::DistributedTriangulation;kwargs...) + SkeletonTriangulation(no_ghost,trian;kwargs...) +end + function Geometry.Triangulation( portion,::Type{ReferenceFE{Dt}},model::DistributedDiscreteModel{Dm};kwargs...) where {Dt,Dm} # Generate global ordering for the faces of dimension Dt (if needed) @@ -515,6 +525,17 @@ function Geometry.BoundaryTriangulation( DistributedTriangulation(trians,model) end +function Geometry.BoundaryTriangulation( + portion,trian::DistributedTriangulation;kwargs... +) + model = get_background_model(trian) + gids = get_cell_gids(model) + trians = map(local_views(trian),partition(gids)) do trian, gids + BoundaryTriangulation(portion,gids,trian;kwargs...) + end + DistributedTriangulation(trians,model) +end + function Geometry.SkeletonTriangulation( portion,model::DistributedDiscreteModel{Dc};kwargs...) where Dc gids = get_face_gids(model,Dc) @@ -524,6 +545,17 @@ function Geometry.SkeletonTriangulation( DistributedTriangulation(trians,model) end +function Geometry.SkeletonTriangulation( + portion,trian::DistributedTriangulation;kwargs... +) + model = get_background_model(trian) + gids = get_cell_gids(model) + trians = map(local_views(trian),partition(gids)) do trian, gids + SkeletonTriangulation(portion,gids,trian;kwargs...) + end + DistributedTriangulation(trians,model) +end + function Geometry.Triangulation( portion,gids::AbstractLocalIndices, args...;kwargs...) trian = Triangulation(args...;kwargs...) diff --git a/test/GeometryTests.jl b/test/GeometryTests.jl index beeae4d2..9c51068d 100644 --- a/test/GeometryTests.jl +++ b/test/GeometryTests.jl @@ -92,14 +92,21 @@ function main(distribute,parts) add_tag!(labels,"fluid",[fluid]) cell_to_entity end - cell_gids=get_cell_gids(model) - vcache=PartitionedArrays.p_vector_cache(cell_to_entity,partition(cell_gids)) - assemble!((a,b)->b, cell_to_entity, map(reverse,vcache) ) |> wait # Make tags consistent + cell_gids = get_cell_gids(model) + consistent!(PVector(cell_to_entity,partition(cell_gids))) |> wait # Make tags consistent + #vcache = PartitionedArrays.p_vector_cache(cell_to_entity,partition(cell_gids)) + #assemble!((a,b)->b, cell_to_entity, map(reverse,vcache) ) |> wait # Make tags consistent Ωs = Interior(model,tags="solid") Ωf = Interior(model,tags="fluid") Γfs = Interface(Ωf,Ωs) + # CompositeTriangulations + Γf = Boundary(Ωf) + Λf = Skeleton(Ωf) + Λs = Skeleton(Ωs) + Γs = Boundary(Ωs) + end function test_local_part_face_labelings_consistency(lmodel::CartesianDiscreteModel{D},gids,gmodel) where {D} From 9cf35c2575e833d35d0df26c7ca336c6473f3d63 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Wed, 30 Oct 2024 23:31:47 +1100 Subject: [PATCH 15/19] Bugfix --- src/Geometry.jl | 10 +++++++--- test/GeometryTests.jl | 2 -- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Geometry.jl b/src/Geometry.jl index 517dd596..d54c1949 100644 --- a/src/Geometry.jl +++ b/src/Geometry.jl @@ -581,8 +581,8 @@ function Geometry.InterfaceTriangulation( end function Geometry.InterfaceTriangulation(a::DistributedTriangulation,b::DistributedTriangulation) - trians = map(InterfaceTriangulation,a.trians,b.trians) @assert a.model === b.model + trians = map(InterfaceTriangulation,a.trians,b.trians) DistributedTriangulation(trians,a.model) end @@ -642,7 +642,10 @@ function remove_ghost_cells(trian::Triangulation,gids) remove_ghost_cells(glue,trian,gids) end -function remove_ghost_cells(trian::Union{SkeletonTriangulation,BoundaryTriangulation},gids) +function remove_ghost_cells( + trian::Union{SkeletonTriangulation,BoundaryTriangulation,Geometry.CompositeTriangulation}, + gids +) model = get_background_model(trian) Dm = num_cell_dims(model) glue = get_glue(trian,Val(Dm)) @@ -650,7 +653,8 @@ function remove_ghost_cells(trian::Union{SkeletonTriangulation,BoundaryTriangula end function remove_ghost_cells( - trian::AdaptedTriangulation{Dc,Dp,<:Union{SkeletonTriangulation,BoundaryTriangulation}},gids) where {Dc,Dp} + trian::AdaptedTriangulation{Dc,Dp,<:Union{SkeletonTriangulation,BoundaryTriangulation}},gids +) where {Dc,Dp} remove_ghost_cells(trian.trian,gids) end diff --git a/test/GeometryTests.jl b/test/GeometryTests.jl index 9c51068d..6d911da4 100644 --- a/test/GeometryTests.jl +++ b/test/GeometryTests.jl @@ -94,8 +94,6 @@ function main(distribute,parts) end cell_gids = get_cell_gids(model) consistent!(PVector(cell_to_entity,partition(cell_gids))) |> wait # Make tags consistent - #vcache = PartitionedArrays.p_vector_cache(cell_to_entity,partition(cell_gids)) - #assemble!((a,b)->b, cell_to_entity, map(reverse,vcache) ) |> wait # Make tags consistent Ωs = Interior(model,tags="solid") Ωf = Interior(model,tags="fluid") From 2f755d8208eacd0378342dd47720db5e87b79c77 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Mon, 11 Nov 2024 23:22:47 +1100 Subject: [PATCH 16/19] Fixed tests --- test/AdaptivityCartesianTests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/AdaptivityCartesianTests.jl b/test/AdaptivityCartesianTests.jl index 0a199fd1..418d0b3d 100644 --- a/test/AdaptivityCartesianTests.jl +++ b/test/AdaptivityCartesianTests.jl @@ -152,7 +152,7 @@ function main(distribute,ncells,isperiodic) fine_adaptivity_glue = get_adaptivity_glue(redist_child_1) # Redistribute by dispatching on the DistributedCartesianDescriptor - pdesc = redist_child_1.metadata + pdesc = redist_child_1.metadata.model_metadata redist_child_2, redist_glue_child = redistribute(child,pdesc) # Tests From f28b6516f62d5448415d2797177125639b06b1db Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Wed, 13 Nov 2024 17:12:52 +1100 Subject: [PATCH 17/19] Minor bugfix --- src/Adaptivity.jl | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Adaptivity.jl b/src/Adaptivity.jl index 8f774d11..3ee6fcc4 100644 --- a/src/Adaptivity.jl +++ b/src/Adaptivity.jl @@ -145,11 +145,7 @@ end function redistribute(model::DistributedAdaptedDiscreteModel,args...;kwargs...) # Local cmodels are AdaptedDiscreteModels. To correctly dispatch, we need to # extract the underlying models, then redistribute. - _model = GenericDistributedDiscreteModel( - map(get_model,local_views(model)), - get_cell_gids(model); - metadata=model.metadata - ) + _model = get_model(model) return redistribute(_model,args...;kwargs...) end From f330f074a51b2cd72c876176ed2894424086d4e0 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Thu, 14 Nov 2024 00:07:08 +1100 Subject: [PATCH 18/19] Minor --- src/Geometry.jl | 40 +++++++++++++++++++++---------------- test/TestApp/src/TestApp.jl | 1 + 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/Geometry.jl b/src/Geometry.jl index 5b5dca5b..026ea937 100644 --- a/src/Geometry.jl +++ b/src/Geometry.jl @@ -475,7 +475,8 @@ function Geometry.get_background_model(a::DistributedTriangulation) end function Geometry.num_cells(a::DistributedTriangulation{Df}) where Df - gids = get_face_gids(a.model,Df) + model = get_background_model(a) + gids = get_face_gids(model,Df) n_loc_ocells = map(local_views(a),partition(gids)) do a, gids glue = get_glue(a,Val(Df)) @assert isa(glue,FaceToFaceGlue) @@ -538,17 +539,6 @@ function Geometry.BoundaryTriangulation( DistributedTriangulation(trians,model) end -function Geometry.BoundaryTriangulation( - portion,trian::DistributedTriangulation;kwargs... -) - model = get_background_model(trian) - gids = get_cell_gids(model) - trians = map(local_views(trian),partition(gids)) do trian, gids - BoundaryTriangulation(portion,gids,trian;kwargs...) - end - DistributedTriangulation(trians,model) -end - function Geometry.SkeletonTriangulation( portion,model::DistributedDiscreteModel{Dc};kwargs...) where Dc gids = get_face_gids(model,Dc) @@ -558,12 +548,28 @@ function Geometry.SkeletonTriangulation( DistributedTriangulation(trians,model) end +# NOTE: The following constructors require adding back the ghost cells: +# Potentially, the input `trian` has had some/all of its ghost cells removed. If we do not +# add them back, some skeleton facets might look like boundary facets to the local constructors... +function Geometry.BoundaryTriangulation( + portion,trian::DistributedTriangulation;kwargs... +) + model = get_background_model(trian) + gids = get_cell_gids(model) + ghosted_trian = add_ghost_cells(trian) + trians = map(local_views(ghosted_trian),partition(gids)) do trian, gids + BoundaryTriangulation(portion,gids,trian;kwargs...) + end + DistributedTriangulation(trians,model) +end + function Geometry.SkeletonTriangulation( portion,trian::DistributedTriangulation;kwargs... ) - model = get_background_model(trian) - gids = get_cell_gids(model) - trians = map(local_views(trian),partition(gids)) do trian, gids + model = get_background_model(trian) + gids = get_cell_gids(model) + ghosted_trian = add_ghost_cells(trian) + trians = map(local_views(ghosted_trian),partition(gids)) do trian, gids SkeletonTriangulation(portion,gids,trian;kwargs...) end DistributedTriangulation(trians,model) @@ -715,7 +721,7 @@ function _find_owned_skeleton_facets(glue,gids) end function add_ghost_cells(dtrian::DistributedTriangulation) - dmodel = dtrian.model + dmodel = get_background_model(dtrian) add_ghost_cells(dmodel,dtrian) end @@ -765,7 +771,7 @@ function add_ghost_cells( end function generate_cell_gids(dtrian::DistributedTriangulation) - dmodel = dtrian.model + dmodel = get_background_model(dtrian) generate_cell_gids(dmodel,dtrian) end diff --git a/test/TestApp/src/TestApp.jl b/test/TestApp/src/TestApp.jl index 5a8390e6..b60c6deb 100644 --- a/test/TestApp/src/TestApp.jl +++ b/test/TestApp/src/TestApp.jl @@ -19,4 +19,5 @@ module TestApp include("../../BlockSparseMatrixAssemblersTests.jl") include("../../VisualizationTests.jl") include("../../AutodiffTests.jl") + include("../../ConstantFESpacesTests.jl") end \ No newline at end of file From d2fb4c60e17f0c76f847f5624038e8efbbfeca4b Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Thu, 14 Nov 2024 08:25:02 +1100 Subject: [PATCH 19/19] Updated NEWS --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 0e13b454..12280fa6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added support for automatic differentiation with ForwardDiff. Since PR[#167](https://github.com/gridap/GridapDistributed.jl/pull/167). +- Added ConstantFESpaces. Since PR[#166](https://github.com/gridap/GridapDistributed.jl/pull/166). ## [0.4.5] 2024-10-08