From 2d41f86cba02ac70f3bee1b60742645b7b27b72d Mon Sep 17 00:00:00 2001 From: "Alberto F. Martin" Date: Mon, 10 Nov 2025 16:04:57 +1100 Subject: [PATCH 1/3] Adding a new specialized FESpace constructor for Raviart-Thomas spaces for the case in which one wants to set up it from a distributed triangulation Modified existing specialized FESpace constructors for discrete models such that they become compliant with the ones in GridapDistributed --- src/DivConformingFESpaces.jl | 53 ++++++++++++++++++++++++++++++++---- test/DivConformingTests.jl | 17 ++++++++---- 2 files changed, 59 insertions(+), 11 deletions(-) diff --git a/src/DivConformingFESpaces.jl b/src/DivConformingFESpaces.jl index c814e75e..599fe24a 100644 --- a/src/DivConformingFESpaces.jl +++ b/src/DivConformingFESpaces.jl @@ -1,25 +1,66 @@ function FESpaces.FESpace(model::DistributedDiscreteModel, reffe::Tuple{RaviartThomas,Any,Any}; - conformity=nothing,kwargs...) + conformity=nothing, + split_own_and_ghost=false, + constraint=nothing, + kwargs...) cell_reffes = map(local_views(model)) do m basis,reffe_args,reffe_kwargs = reffe cell_reffe = ReferenceFE(m,basis,reffe_args...;reffe_kwargs...) end - _common_fe_space_constructor(model,cell_reffes;conformity,kwargs...) + _common_fe_space_constructor(model,cell_reffes;conformity,split_own_and_ghost,kwargs...) end function FESpace(model::DistributedDiscreteModel, reffe::GenericRefFE{RaviartThomas}; - conformity=nothing, kwargs...) + conformity=nothing, + split_own_and_ghost=false, + constraint=nothing, + kwargs...) cell_reffes = map(local_views(model)) do m Fill(reffe,num_cells(m)) end - _common_fe_space_constructor(model,cell_reffes;conformity,kwargs...) + _common_fe_space_constructor(model,cell_reffes;conformity,split_own_and_ghost,kwargs...) end -function _common_fe_space_constructor(model,cell_reffes;conformity,kwargs...) +function _setup_dmodel(_trian::DistributedTriangulation) + trian = add_ghost_cells(_trian) + models = map(local_views(trian)) do t + get_active_model(t) + end + GenericDistributedDiscreteModel(models, generate_cell_gids(trian)) +end + + + +function FESpace( + _trian::DistributedTriangulation, + reffe::Tuple{RaviartThomas,Any,Any}; + conformity=nothing, + split_own_and_ghost=false, + constraint=nothing,kwargs... +) + dmodel = _setup_dmodel(_trian) + FESpace(dmodel, reffe; conformity=conformity, + split_own_and_ghost=split_own_and_ghost, + constraint=constraint, kwargs...) +end + +function FESpace(_trian::DistributedTriangulation, + reffe::GenericRefFE{RaviartThomas}; + conformity=nothing, + split_own_and_ghost=false, + constraint=nothing, + kwargs...) + dmodel = _setup_dmodel(_trian) + FESpace(dmodel, reffe; conformity=conformity, + split_own_and_ghost=split_own_and_ghost, + constraint=constraint, kwargs...) +end + +function _common_fe_space_constructor(model,cell_reffes;conformity,split_own_and_ghost,kwargs...) sign_flips=_generate_sign_flips(model,cell_reffes) spaces = map(local_views(model),sign_flips,cell_reffes) do m,sign_flip,cell_reffe conf = Conformity(testitem(cell_reffe),conformity) @@ -28,7 +69,7 @@ function _common_fe_space_constructor(model,cell_reffes;conformity,kwargs...) end gids = generate_gids(model,spaces) trian = DistributedTriangulation(map(get_triangulation,spaces),model) - vector_type = _find_vector_type(spaces,gids) + vector_type = _find_vector_type(spaces,gids;split_own_and_ghost=split_own_and_ghost) DistributedSingleFieldFESpace(spaces,gids,trian,vector_type) end diff --git a/test/DivConformingTests.jl b/test/DivConformingTests.jl index 2a1886b3..33fc3a3f 100644 --- a/test/DivConformingTests.jl +++ b/test/DivConformingTests.jl @@ -59,12 +59,10 @@ function setup_p2_model() Gridap.Geometry.UnstructuredDiscreteModel(grid) end -function f(model,reffe) +function f(model,reffe,trian,das) V = FESpace(model,reffe,conformity=:Hdiv) U = TrialFESpace(V) - das = FullyAssembledRows() - trian = Triangulation(das,model) degree = 2 dΩ = Measure(trian,degree) a(u,v) = ∫( u⋅v )*dΩ @@ -82,6 +80,7 @@ function f(model,reffe) dc2 = dc.contribs.items[2] c1 = Gridap.CellData.get_contribution(dc1,t1) c2 = Gridap.CellData.get_contribution(dc2,t2) + tol = 1.0e-12 @test norm(c1[1]-c2[2]) < tol @test norm(c1[2]-c2[1]) < tol @@ -122,10 +121,18 @@ function main(distribute,nranks) model = GridapDistributed.DistributedDiscreteModel(models,gids) + das = FullyAssembledRows() + trian = Triangulation(das,model) + reffe=ReferenceFE(raviart_thomas,Float64,0) - f(model,reffe) + f(model,reffe,trian,das) + f(trian,reffe,trian,das) + f(Triangulation(model),reffe,trian,das) + reffe=ReferenceFE(QUAD, raviart_thomas, 0) - f(model,reffe) + f(model,reffe,trian,das) + f(trian,reffe,trian,das) + f(Triangulation(model),reffe,trian,das) end end # module From fb853157c457d948fc6cd6cb802b6418c5cd2eaf Mon Sep 17 00:00:00 2001 From: "Alberto F. Martin" Date: Wed, 12 Nov 2025 12:26:42 +1100 Subject: [PATCH 2/3] Homogeneize semantics of FESpace constructors for Hdiv spaces to the default FESpace constructors. In particular, re their behaviour when they are feed with DistributedModels versus DistributedTriangulation. --- src/DivConformingFESpaces.jl | 38 ++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/DivConformingFESpaces.jl b/src/DivConformingFESpaces.jl index 599fe24a..b29a0742 100644 --- a/src/DivConformingFESpaces.jl +++ b/src/DivConformingFESpaces.jl @@ -1,4 +1,3 @@ - function FESpaces.FESpace(model::DistributedDiscreteModel, reffe::Tuple{RaviartThomas,Any,Any}; conformity=nothing, @@ -25,16 +24,14 @@ function FESpace(model::DistributedDiscreteModel, _common_fe_space_constructor(model,cell_reffes;conformity,split_own_and_ghost,kwargs...) end -function _setup_dmodel(_trian::DistributedTriangulation) +function _setup_dmodel_and_dtrian(_trian::DistributedTriangulation) trian = add_ghost_cells(_trian) models = map(local_views(trian)) do t get_active_model(t) end - GenericDistributedDiscreteModel(models, generate_cell_gids(trian)) + GenericDistributedDiscreteModel(models, generate_cell_gids(trian)), trian end - - function FESpace( _trian::DistributedTriangulation, reffe::Tuple{RaviartThomas,Any,Any}; @@ -42,10 +39,12 @@ function FESpace( split_own_and_ghost=false, constraint=nothing,kwargs... ) - dmodel = _setup_dmodel(_trian) - FESpace(dmodel, reffe; conformity=conformity, - split_own_and_ghost=split_own_and_ghost, - constraint=constraint, kwargs...) + dmodel, dtrian = _setup_dmodel_and_dtrian(_trian) + cell_reffes = map(local_views(dmodel)) do m + basis,reffe_args,reffe_kwargs = reffe + cell_reffe = ReferenceFE(m,basis,reffe_args...;reffe_kwargs...) + end + _common_fe_space_constructor(dmodel,cell_reffes,dtrian;conformity,split_own_and_ghost,kwargs...) end function FESpace(_trian::DistributedTriangulation, @@ -54,10 +53,23 @@ function FESpace(_trian::DistributedTriangulation, split_own_and_ghost=false, constraint=nothing, kwargs...) - dmodel = _setup_dmodel(_trian) - FESpace(dmodel, reffe; conformity=conformity, - split_own_and_ghost=split_own_and_ghost, - constraint=constraint, kwargs...) + dmodel, dtrian = _setup_dmodel_and_dtrian(_trian) + cell_reffes = map(local_views(dmodel)) do m + Fill(reffe,num_cells(m)) + end + _common_fe_space_constructor(dmodel,cell_reffes,dtrian;conformity,split_own_and_ghost,kwargs...) +end + +function _common_fe_space_constructor(model,cell_reffes,trian;conformity,split_own_and_ghost,kwargs...) + sign_flips=_generate_sign_flips(model,cell_reffes) + spaces = map(local_views(model),sign_flips,cell_reffes,local_views(trian)) do m,sign_flip,cell_reffe,trian + conf = Conformity(testitem(cell_reffe),conformity) + cell_fe = CellFE(m,cell_reffe,conf,sign_flip) + FESpace(m, cell_fe; trian=trian, kwargs...) + end + gids = generate_gids(model,spaces) + vector_type = _find_vector_type(spaces,gids;split_own_and_ghost=split_own_and_ghost) + DistributedSingleFieldFESpace(spaces,gids,trian,vector_type) end function _common_fe_space_constructor(model,cell_reffes;conformity,split_own_and_ghost,kwargs...) From e12d74f26d961482e7edd19d90cff5e08a8a85a0 Mon Sep 17 00:00:00 2001 From: "Alberto F. Martin" <38347633+amartinhuertas@users.noreply.github.com> Date: Fri, 19 Dec 2025 12:42:10 +1100 Subject: [PATCH 3/3] Update NEWS.md --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 86a11fff..c79e5524 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 - New overloads for the `TrialFESpace` constructor where the data to be imposed is passed as a `DistributedCellField`. Since PR[#183](https://github.com/gridap/GridapDistributed.jl/pull/183). +- Added missing `FESpace` constructors for distributed triangulations specialized for the RT FEs case. Since PR[#188](https://github.com/gridap/GridapDistributed.jl/pull/188) ## [0.4.10] - 2025-09-29