Skip to content

Commit

Permalink
Merge branch 'master' into distributed_discrete_geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
zjwegert authored Jul 9, 2024
2 parents 0fcedea + d579786 commit 9cabe09
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 24 deletions.
4 changes: 2 additions & 2 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GridapEmbedded.jl Copyright and License
==

Copyright (c) 2020 by [Francesc Verdugo](mailto:[email protected]), [Eric Neiva](mailto:[email protected]) and [Santiago Badia](mailto:[email protected]).
Copyright (c) 2020 by [Francesc Verdugo](mailto:[email protected]), [Eric Neiva](mailto:[email protected]), [Pere Antoni Martorell](mailto:[email protected]) and [Santiago Badia](mailto:[email protected]).

GridapEmbedded.jl is licensed under the MIT Expat License

Expand Down Expand Up @@ -106,4 +106,4 @@ By making a contribution to this project, I certify that:
Contact
==

Please, contact the project administrators, [Francesc Verdugo](mailto:[email protected]), [Eric Neiva](mailto:[email protected]) and [Santiago Badia](mailto:[email protected]), for further questions about licenses and terms of use.
Please, contact the project administrators, [Francesc Verdugo](mailto:[email protected]), [Eric Neiva](mailto:[email protected]), [Pere Antoni Martorell](mailto:[email protected]) and [Santiago Badia](mailto:[email protected]), for further questions about licenses and terms of use.
7 changes: 6 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
## [0.9.4] - 2024-07-09

### Added
- Missing distributed functions. Since PR [#92](https://github.com/gridap/GridapEmbedded.jl/pull/92).
- Background models extended with remote ghosts inherit Cartesian labels. Since PR [#93](https://github.com/gridap/GridapEmbedded.jl/pull/93).

### 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

Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GridapEmbedded"
uuid = "8838a6a3-0006-4405-b874-385995508d5d"
authors = ["Francesc Verdugo <[email protected]>", "Eric Neiva <[email protected]>", "Pere Antoni Martorell <pmartorell@cimne.upc.edu>", "Santiago Badia <[email protected]>"]
version = "0.9.3"
authors = ["Francesc Verdugo <[email protected]>", "Eric Neiva <[email protected]>", "Pere Antoni Martorell <pere.antoni.martorell@upc.edu>", "Santiago Badia <[email protected]>"]
version = "0.9.4"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
4 changes: 2 additions & 2 deletions src/AgFEM/AgFEMSpaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function AgFEMSpace(
glue = get_glue(trian_a,Val(D))
acell_to_bgcell = glue.tface_to_mface
bgcell_to_acell = glue.mface_to_tface
acell_to_bgcellin = lazy_map(Reindex(bgcell_to_bgcellin),acell_to_bgcell)
acell_to_bgcellin = collect(lazy_map(Reindex(bgcell_to_bgcellin),acell_to_bgcell))
acell_to_acellin = collect(lazy_map(Reindex(bgcell_to_acell),acell_to_bgcellin))
acell_to_gcell = lazy_map(Reindex(bgcell_to_gcell),acell_to_bgcell)

Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/Distributed/Distributed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ using Gridap.Helpers
using Gridap.ReferenceFEs
using Gridap.FESpaces

using PartitionedArrays: VectorFromDict

using GridapEmbedded.CSG
using GridapEmbedded.LevelSetCutters
using GridapEmbedded.Interfaces
Expand All @@ -27,6 +29,8 @@ using GridapEmbedded.MomentFittedQuadratures: MomentFitted
using Gridap.Geometry: AppendedTriangulation
using Gridap.Geometry: get_face_to_parent_face
using Gridap.Arrays: find_inverse_index_map, testitem, return_type
using Gridap.FESpaces: FESpaceWithLinearConstraints
using Gridap.FESpaces: _dof_to_DOF, _DOF_to_dof
using GridapDistributed: DistributedDiscreteModel
using GridapDistributed: DistributedTriangulation
using GridapDistributed: DistributedFESpace
Expand Down
129 changes: 113 additions & 16 deletions src/Distributed/DistributedAgFEM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -296,6 +294,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
Expand Down Expand Up @@ -340,12 +371,63 @@ function add_remote_cells(model::DistributedDiscreteModel,remote_cells,remote_pa

# Build appended model
lgrids = map(get_grid,local_views(model))
grids = map(lazy_append,lgrids,rgrids)
models = map(UnstructuredDiscreteModel,grids)
_grids = map(lazy_append,lgrids,rgrids)
_models = map(UnstructuredDiscreteModel,_grids)
agids = add_remote_ids(gids,remote_cells,remote_parts)
amodel = DistributedDiscreteModel(_models,agids) |> merge_nodes

D = num_cell_dims(model)
grids = map(get_grid,local_views(amodel))
topos = map(get_grid_topology,local_views(amodel))
d_to_dface_to_entity = map(topos) do topo
[ fill(Int32(UNSET),num_faces(topo,d)) for d in 0:D ]
end
oldtopos = map(get_grid_topology,local_views(model))
oldlabels = map(get_face_labeling,local_views(model))
for d in 0:D
_fill_labels!(d_to_dface_to_entity,
oldlabels,
oldtopos,
topos,
ncells,
d,D,
snd_lids,
rgraph)
end
labels = map(d_to_dface_to_entity,oldlabels) do d_to_dface_to_entity,ol
FaceLabeling(d_to_dface_to_entity,ol.tag_to_entities,ol.tag_to_name)
end
models = map(UnstructuredDiscreteModel,grids,topos,labels)
DistributedDiscreteModel(models,agids)
end

function _fill_labels!(d_to_dface_to_entity,llabels,ltopos,ntopos,nremotes,
d::Int,D::Int,snd_lids,rgraph)
snd_labels = map(ltopos,llabels,snd_lids) do topo,labels,lids
dface_to_entity = get_face_entity(labels,d)
T = eltype(eltype(dface_to_entity))
labels = map(lids) do lids
faces = map(Reindex(get_faces(topo,D,d)),lids)
labels = map(Reindex(dface_to_entity),faces)
reduce(append!,labels,init=T[])
end
Vector{Vector{T}}(labels)
end
rcv_labels = allocate_exchange(snd_labels,rgraph)
exchange!(rcv_labels,snd_labels,rgraph) |> wait
rlabels = map(PartitionedArrays.getdata,rcv_labels)
map(d_to_dface_to_entity,llabels) do d_to_dface_to_entity,l
l_face_entity = get_face_entity(l,d)
d_to_dface_to_entity[d+1][1:length(l_face_entity)] = l_face_entity
end
map(d_to_dface_to_entity,ntopos,nremotes,rlabels) do d_to_dface_to_entity,nt,nr,r
nr > 0 && begin
rf = reduce(vcat,get_faces(nt,D,d)[end-nr+1:end])
d_to_dface_to_entity[d+1][rf] = r
end
end
end

function add_remote_aggregates(model::DistributedDiscreteModel,aggregates,aggregate_owner)
gids = get_cell_gids(model)
remote_cells,remote_parts = _extract_remote_cells(gids,aggregates,aggregate_owner)
Expand Down Expand Up @@ -436,29 +518,44 @@ 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 _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])
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
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)
if cell_to_cellin[cell] != cell
empty!(ldof_to_mdof)
end
end
cell_to_ldofs
cell_ldof_to_mdof
end

function _local_aggregates(cell_to_gcellin,gids::PRange)
map(_local_aggregates,cell_to_gcellin,global_to_local(gids))
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

Expand Down
20 changes: 20 additions & 0 deletions src/Distributed/DistributedDiscretizations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ function compute_bgcell_to_inoutcut(cutgeo::DistributedEmbeddedDiscretization,ar
end
end

function compute_bgfacet_to_inoutcut(cutgeo::DistributedEmbeddedDiscretization,args...)
map(local_views(cutgeo)) do cutgeo
compute_bgfacet_to_inoutcut(cutgeo,args...)
end
end

function remove_ghost_cells(trian::DistributedTriangulation)
model = get_background_model(trian)
gids = get_cell_gids(model)
Expand Down Expand Up @@ -224,6 +230,20 @@ function change_bgmodel(
DistributedEmbeddedDiscretization(cuts,model)
end

function change_bgmodel(
cutgeo::DistributedEmbeddedDiscretization{<:AbstractArray{<:EmbeddedFacetDiscretization}},
model::DistributedDiscreteModel,
args...)

D = map(num_dims,local_views(model)) |> PartitionedArrays.getany
cuts = _change_bgmodels(cutgeo,model,args...)
gids = get_face_gids(model,D-1)
ls_to_facet_to_inoutcut = map(c->c.ls_to_facet_to_inoutcut,cuts)
_consistent!(ls_to_facet_to_inoutcut,gids)
DistributedEmbeddedDiscretization(cuts,model)
end


function _change_bgmodels(
cutgeo::DistributedEmbeddedDiscretization,
model::DistributedDiscreteModel,
Expand Down
2 changes: 1 addition & 1 deletion test/DistributedTests/PoissonTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/DistributedTests/sequential/PoissonTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ using PartitionedArrays
include("../PoissonTests.jl")
with_debug() do distribute
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

0 comments on commit 9cabe09

Please sign in to comment.