From b8f555d562aa5ebd141e8f18dd4b669a9ea3656d Mon Sep 17 00:00:00 2001 From: Eric Neiva Date: Fri, 14 Jun 2024 17:07:43 +0200 Subject: [PATCH 01/10] Fix type instability in `local_aggregates` `gcell_to_cell` is a `PartitionedArrays.VectorFromDict{Tk,Tv}` storing a `Dict{Tk,Tv}`. Apparently, its getindex specialisation does not return a value of type `Tv`. --- src/Distributed/DistributedAgFEM.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Distributed/DistributedAgFEM.jl b/src/Distributed/DistributedAgFEM.jl index b4f0961..718b350 100644 --- a/src/Distributed/DistributedAgFEM.jl +++ b/src/Distributed/DistributedAgFEM.jl @@ -457,8 +457,9 @@ function _local_aggregates(cell_to_gcellin,gids::PRange) end function _local_aggregates(cell_to_gcellin,gcell_to_cell) + T = eltype(cell_to_gcellin) map(cell_to_gcellin) do gcin - iszero(gcin) ? gcin : gcell_to_cell[ gcin ] + iszero(gcin) ? gcin : T(gcell_to_cell[ gcin ]) end end From b487bd0b4feb2df98400ea20cc59b8d65848ac1a Mon Sep 17 00:00:00 2001 From: Eric Neiva Date: Fri, 14 Jun 2024 18:11:15 +0200 Subject: [PATCH 02/10] Added failing test --- test/DistributedTests/sequential/PoissonTests.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/DistributedTests/sequential/PoissonTests.jl b/test/DistributedTests/sequential/PoissonTests.jl index d52e007..8a7c4d6 100644 --- a/test/DistributedTests/sequential/PoissonTests.jl +++ b/test/DistributedTests/sequential/PoissonTests.jl @@ -2,7 +2,8 @@ module PoissonTestsSeq using PartitionedArrays include("../PoissonTests.jl") with_debug() do distribute - PoissonTests.main(distribute,(2,2)) - PoissonTests.main(distribute,(4,1),cells=(12,12),geometry=:remotes) + PoissonTests.main(distribute,(2,2)) # Passes test + PoissonTests.main(distribute,(2,4)) # Fails test (L2 and H1 errors above tolerances) + # PoissonTests.main(distribute,(4,1),cells=(12,12),geometry=:remotes) end end From 784e28fabf7acd67645e97518707f6384a3f4695 Mon Sep 17 00:00:00 2001 From: Pere Antoni Martorell Date: Wed, 3 Jul 2024 10:19:07 +0200 Subject: [PATCH 03/10] [Distributed] Merge nodes in models with remote aggregates by GID --- src/Distributed/Distributed.jl | 2 ++ src/Distributed/DistributedAgFEM.jl | 35 ++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/Distributed/Distributed.jl b/src/Distributed/Distributed.jl index aadb4d5..a86e5f9 100644 --- a/src/Distributed/Distributed.jl +++ b/src/Distributed/Distributed.jl @@ -11,6 +11,8 @@ using Gridap.Geometry using Gridap.Helpers using Gridap.ReferenceFEs +using PartitionedArrays: VectorFromDict + using GridapEmbedded.CSG using GridapEmbedded.LevelSetCutters using GridapEmbedded.Interfaces diff --git a/src/Distributed/DistributedAgFEM.jl b/src/Distributed/DistributedAgFEM.jl index 718b350..d91f7e4 100644 --- a/src/Distributed/DistributedAgFEM.jl +++ b/src/Distributed/DistributedAgFEM.jl @@ -296,6 +296,39 @@ function _get_cell_measure(trian1::Triangulation,trian2::Triangulation) end end +function merge_nodes(model::DistributedDiscreteModel) + node_gids = get_face_gids(model,0) + cell_gids = get_cell_gids(model) + models = map(local_views(model),local_views(node_gids)) do model,node_ids + merge_nodes(model,node_ids) + end + DistributedDiscreteModel(models,cell_gids) +end + +function merge_nodes(model::DiscreteModel,ids) + l_to_g = local_to_global(ids) + n_global = length(global_to_local(ids)) + n_local = length(l_to_g) + g_to_l = VectorFromDict(reverse(l_to_g),reverse(1:length(l_to_g)),n_global) + l_to_lparent = g_to_l[l_to_g] + lnew_to_l = findall(map(==,l_to_lparent,1:n_local)) + l_to_lnew = zeros(Int,n_local) + l_to_lnew[lnew_to_l] = 1:length(lnew_to_l) + g_to_lnew = map(l->iszero(l) ? l : l_to_lnew[l], g_to_l) + l_to_lnew = g_to_lnew[l_to_g] + + grid = get_grid(model) + coords = get_node_coordinates(grid) + conn = get_cell_node_ids(grid) + reffes = get_reffes(grid) + ctypes = get_cell_type(grid) + + coords = coords[lnew_to_l] + conn = map(Broadcasting(Reindex(l_to_lnew)),conn) |> Table + grid = UnstructuredGrid(coords,conn,reffes,ctypes) + UnstructuredDiscreteModel(grid) +end + function add_remote_cells(model::DistributedDiscreteModel,remote_cells,remote_parts) # Send remote gids to owners snd_ids = remote_parts @@ -343,7 +376,7 @@ function add_remote_cells(model::DistributedDiscreteModel,remote_cells,remote_pa grids = map(lazy_append,lgrids,rgrids) models = map(UnstructuredDiscreteModel,grids) agids = add_remote_ids(gids,remote_cells,remote_parts) - DistributedDiscreteModel(models,agids) + DistributedDiscreteModel(models,agids) |> merge_nodes end function add_remote_aggregates(model::DistributedDiscreteModel,aggregates,aggregate_owner) From a70008559edae363bede08c1831a7871abead9e1 Mon Sep 17 00:00:00 2001 From: Pere Antoni Martorell Date: Wed, 3 Jul 2024 10:21:25 +0200 Subject: [PATCH 04/10] Fix constraint criterion for DOFs --- src/AgFEM/AgFEMSpaces.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AgFEM/AgFEMSpaces.jl b/src/AgFEM/AgFEMSpaces.jl index 4c0f0c4..2ad1ce6 100644 --- a/src/AgFEM/AgFEMSpaces.jl +++ b/src/AgFEM/AgFEMSpaces.jl @@ -76,9 +76,9 @@ function _setup_agfem_constraints( if dof > 0 fdof = dof acell_dof = fdof_to_acell[fdof] + fdof_to_isagg[fdof] &= iscut if acell_dof == 0 || gcell > acell_to_gcell[acell_dof] fdof_to_acell[fdof] = acell - fdof_to_isagg[fdof] = iscut && fdof_to_isagg[fdof] fdof_to_ldof[fdof] = ldof end end From d733619e1fb92085410478a6dedcf7c359f8cd78 Mon Sep 17 00:00:00 2001 From: Pere Antoni Martorell Date: Wed, 3 Jul 2024 10:25:17 +0200 Subject: [PATCH 05/10] [distributed] fix unsorted local DOFs issues --- src/Distributed/Distributed.jl | 1 + src/Distributed/DistributedAgFEM.jl | 31 ++++++++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/Distributed/Distributed.jl b/src/Distributed/Distributed.jl index a86e5f9..444e27a 100644 --- a/src/Distributed/Distributed.jl +++ b/src/Distributed/Distributed.jl @@ -27,6 +27,7 @@ using GridapEmbedded.AgFEM: AggregateCutCellsByThreshold using GridapEmbedded.MomentFittedQuadratures: MomentFitted using Gridap.Geometry: AppendedTriangulation using Gridap.Geometry: get_face_to_parent_face +using Gridap.FESpaces: FESpaceWithLinearConstraints using GridapDistributed: DistributedDiscreteModel using GridapDistributed: DistributedTriangulation using GridapDistributed: DistributedFESpace diff --git a/src/Distributed/DistributedAgFEM.jl b/src/Distributed/DistributedAgFEM.jl index d91f7e4..1441c2a 100644 --- a/src/Distributed/DistributedAgFEM.jl +++ b/src/Distributed/DistributedAgFEM.jl @@ -18,9 +18,7 @@ function AgFEMSpace( trian = add_ghost_cells(trian) trian_gids = generate_cell_gids(trian) cell_to_cellin = _active_aggregates(bgcell_to_bgcellin) - cell_to_ldofs = map(get_cell_dof_ids,spaces) - cell_to_ldofs = map(i->map(sort,i),cell_to_ldofs) - _remove_improper_cell_ldofs!(cell_to_ldofs,cell_to_cellin) + cell_to_ldofs = cell_ldof_to_mdof(spaces,cell_to_cellin) nldofs = map(num_free_dofs,spaces) gids = generate_gids(trian_gids,cell_to_ldofs,nldofs) vector_type = _find_vector_type(spaces,gids) @@ -469,13 +467,32 @@ function _active_aggregates(bgcell_to_bgcellin) bgcell_to_acell[ acell_to_bgcellin ] end -function _remove_improper_cell_ldofs!( - cell_to_ldofs::AbstractVector{<:AbstractVector{<:AbstractVector}}, - bgcell_to_bgcellin::AbstractVector{<:AbstractVector}) +function cell_ldof_to_mdof( + spaces::AbstractArray{<:FESpace}, + cell_to_cellin::AbstractArray{<:AbstractVector}) - map(_remove_improper_cell_ldofs!,cell_to_ldofs,bgcell_to_bgcellin) + map(cell_ldof_to_mdof,spaces,cell_to_cellin) end +function cell_ldof_to_mdof( + space::FESpaceWithLinearConstraints, + cell_to_cellin::AbstractVector) + + DOF_to_mDOFs = space.DOF_to_mDOFs + cell_ldof_to_dof = space.cell_to_ldof_to_dof + cell_ldof_to_mdof = map(cell_ldof_to_dof) do ldof_to_dof + map(ldof_to_dof) do dof + mDOFs = DOF_to_mDOFs[dof] + length(mDOFs) == 1 ? mDOFs[1] : zero(eltype(mDOFs)) + end + end + for (cell,ldof_to_mdof) in enumerate(cell_ldof_to_mdof) + if cell_to_cellin[cell] != cell + empty!(ldof_to_mdof) + end + end + cell_ldof_to_mdof +end function _remove_improper_cell_ldofs!(cell_to_ldofs,cell_to_cellin) for cell in 1:length(cell_to_ldofs) From 211781461c3f03bf4686a319c3c1d92a7b63746f Mon Sep 17 00:00:00 2001 From: Pere Antoni Martorell Date: Wed, 3 Jul 2024 10:26:16 +0200 Subject: [PATCH 06/10] edit tests --- test/DistributedTests/PoissonTests.jl | 2 +- test/DistributedTests/sequential/PoissonTests.jl | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/test/DistributedTests/PoissonTests.jl b/test/DistributedTests/PoissonTests.jl index 4c736c3..feb6e9b 100644 --- a/test/DistributedTests/PoissonTests.jl +++ b/test/DistributedTests/PoissonTests.jl @@ -103,7 +103,7 @@ function main(distribute,parts; "gid"=>own_to_global(gids)])#, # cellfields=["uh"=>uh]) - writevtk(Ω,"trian_O",cellfields=["uh"=>uh]) + writevtk(Ω,"trian_O",cellfields=["uh"=>uh,"eh"=>e]) writevtk(Γ,"trian_G") @test el2/ul2 < 1.e-8 @test eh1/uh1 < 1.e-7 diff --git a/test/DistributedTests/sequential/PoissonTests.jl b/test/DistributedTests/sequential/PoissonTests.jl index 8a7c4d6..32c0967 100644 --- a/test/DistributedTests/sequential/PoissonTests.jl +++ b/test/DistributedTests/sequential/PoissonTests.jl @@ -2,8 +2,9 @@ module PoissonTestsSeq using PartitionedArrays include("../PoissonTests.jl") with_debug() do distribute - PoissonTests.main(distribute,(2,2)) # Passes test - PoissonTests.main(distribute,(2,4)) # Fails test (L2 and H1 errors above tolerances) - # PoissonTests.main(distribute,(4,1),cells=(12,12),geometry=:remotes) + PoissonTests.main(distribute,(2,2)) + PoissonTests.main(distribute,(1,4),cells=(4,8)) + PoissonTests.main(distribute,(2,4),cells=(8,8)) + PoissonTests.main(distribute,(4,1),cells=(12,12),geometry=:remotes) end end From fde7577114a222fcecaa2a9f8541e731185e7a48 Mon Sep 17 00:00:00 2001 From: Eric Neiva Date: Thu, 4 Jul 2024 18:19:02 +0200 Subject: [PATCH 07/10] [distributed] fix unsorted local DOFs issues when Dirichlet BCs Todo: figure out how to remove duplication of _dof_to_DOF and _DOF_to_dof --- src/Distributed/DistributedAgFEM.jl | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Distributed/DistributedAgFEM.jl b/src/Distributed/DistributedAgFEM.jl index 1441c2a..7691792 100644 --- a/src/Distributed/DistributedAgFEM.jl +++ b/src/Distributed/DistributedAgFEM.jl @@ -474,16 +474,35 @@ function cell_ldof_to_mdof( map(cell_ldof_to_mdof,spaces,cell_to_cellin) end +function _dof_to_DOF(dof,n_fdofs) + if dof > 0 + DOF = dof + else + DOF = n_fdofs - dof + end +end + +function _DOF_to_dof(DOF,n_fdofs) + if DOF > n_fdofs + dof = -(DOF-n_fdofs) + else + dof = DOF + end +end + function cell_ldof_to_mdof( space::FESpaceWithLinearConstraints, cell_to_cellin::AbstractVector) DOF_to_mDOFs = space.DOF_to_mDOFs cell_ldof_to_dof = space.cell_to_ldof_to_dof + n_fdofs = space.n_fdofs + n_fmdofs = space.n_fmdofs cell_ldof_to_mdof = map(cell_ldof_to_dof) do ldof_to_dof map(ldof_to_dof) do dof - mDOFs = DOF_to_mDOFs[dof] - length(mDOFs) == 1 ? mDOFs[1] : zero(eltype(mDOFs)) + DOF = _dof_to_DOF(dof,n_fdofs) + mDOFs = DOF_to_mDOFs[DOF] + length(mDOFs) == 1 ? _DOF_to_dof(mDOFs[1],n_fmdofs) : zero(eltype(mDOFs)) end end for (cell,ldof_to_mdof) in enumerate(cell_ldof_to_mdof) From a5ab7d444895418fa4dd9e9a229c4a485c73e6a1 Mon Sep 17 00:00:00 2001 From: Eric Neiva Date: Fri, 5 Jul 2024 17:47:33 +0200 Subject: [PATCH 08/10] Import aux funs for cell_ldof_to_mdof --- src/Distributed/Distributed.jl | 1 + src/Distributed/DistributedAgFEM.jl | 16 ---------------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/src/Distributed/Distributed.jl b/src/Distributed/Distributed.jl index 444e27a..c68af9a 100644 --- a/src/Distributed/Distributed.jl +++ b/src/Distributed/Distributed.jl @@ -28,6 +28,7 @@ using GridapEmbedded.MomentFittedQuadratures: MomentFitted using Gridap.Geometry: AppendedTriangulation using Gridap.Geometry: get_face_to_parent_face using Gridap.FESpaces: FESpaceWithLinearConstraints +using Gridap.FESpaces: _dof_to_DOF, _DOF_to_dof using GridapDistributed: DistributedDiscreteModel using GridapDistributed: DistributedTriangulation using GridapDistributed: DistributedFESpace diff --git a/src/Distributed/DistributedAgFEM.jl b/src/Distributed/DistributedAgFEM.jl index 7691792..88d57b9 100644 --- a/src/Distributed/DistributedAgFEM.jl +++ b/src/Distributed/DistributedAgFEM.jl @@ -474,22 +474,6 @@ function cell_ldof_to_mdof( map(cell_ldof_to_mdof,spaces,cell_to_cellin) end -function _dof_to_DOF(dof,n_fdofs) - if dof > 0 - DOF = dof - else - DOF = n_fdofs - dof - end -end - -function _DOF_to_dof(DOF,n_fdofs) - if DOF > n_fdofs - dof = -(DOF-n_fdofs) - else - dof = DOF - end -end - function cell_ldof_to_mdof( space::FESpaceWithLinearConstraints, cell_to_cellin::AbstractVector) From e88e5c84ed04f67a91d55e114d6736aa37138a36 Mon Sep 17 00:00:00 2001 From: Eric Neiva Date: Fri, 5 Jul 2024 17:47:53 +0200 Subject: [PATCH 09/10] Delete obsolete function --- src/Distributed/DistributedAgFEM.jl | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Distributed/DistributedAgFEM.jl b/src/Distributed/DistributedAgFEM.jl index 88d57b9..89c6ab2 100644 --- a/src/Distributed/DistributedAgFEM.jl +++ b/src/Distributed/DistributedAgFEM.jl @@ -497,14 +497,6 @@ function cell_ldof_to_mdof( cell_ldof_to_mdof end -function _remove_improper_cell_ldofs!(cell_to_ldofs,cell_to_cellin) - for cell in 1:length(cell_to_ldofs) - cell_to_cellin[cell] != cell || continue - cell_to_ldofs[cell] = empty!(cell_to_ldofs[cell]) - end - cell_to_ldofs -end - function _local_aggregates(cell_to_gcellin,gids::PRange) map(_local_aggregates,cell_to_gcellin,global_to_local(gids)) end From 4a623dc238f29cbbd9561838e1e04882769afd56 Mon Sep 17 00:00:00 2001 From: Eric Neiva Date: Fri, 5 Jul 2024 17:51:19 +0200 Subject: [PATCH 10/10] Update NEWS.md --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index d1852b9..8fe85a9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Unused `name` keywork argument in `square` and `quadrilateral` analytical geometries. Since PR [#86](https://github.com/gridap/GridapEmbedded.jl/pull/86). +- Gluing of the remote root cells to the local+ghost mesh. Since PR [#91](https://github.com/gridap/GridapEmbedded.jl/pull/91). ## [0.9.3] - 2024-05-20