Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b1835a2
Changes required to handle FESpaces built on triangulation portions
amartinhuertas Oct 15, 2025
15b11bf
Debugged the code base resulting from b1835a29eeeb9cde6baf62823921d6d…
amartinhuertas Oct 16, 2025
16fefdb
Replaced tabs by 4x spaces
amartinhuertas Oct 16, 2025
036041c
Fixed remaining call to _add_constraints()
amartinhuertas Oct 16, 2025
8881ea7
Bug-fixes for fespaces built out of triangulations
amartinhuertas Oct 16, 2025
4e9fe2d
* Adding more debug messages
amartinhuertas Oct 17, 2025
e65bcd1
snapshot of bug
amartinhuertas Oct 17, 2025
fcdf883
Adding a missing case for the interior boundary
amartinhuertas Oct 18, 2025
bcdb680
Additional functionality related to the identification of the interior
amartinhuertas Oct 18, 2025
638a42c
Snapshot of a very particular triangulation on top of non-conforming
amartinhuertas Oct 18, 2025
4f63e19
- Debugged the code resulting from bcdb6806408ace84229b8ac07e1e69f3e5…
amartinhuertas Oct 19, 2025
2188f76
Temporarily point to Gridap's dev master branch
amartinhuertas Oct 19, 2025
605d393
Some refactoring of functions in charge of generating constraints
amartinhuertas Oct 19, 2025
fe14ca3
Refactoring FESpaces.jl in order to provide the hanging dof constraints
amartinhuertas Oct 19, 2025
cb83f8b
Minor fix
amartinhuertas Oct 19, 2025
6e02b71
Fix
amartinhuertas Oct 20, 2025
c37f624
Fixed call to the ReferenceFE constructor in MaxwellNonConformingOctr…
amartinhuertas Oct 22, 2025
c4039e8
Testing with Gridap's branch #constraints
amartinhuertas Nov 24, 2025
e6d8720
Implemented missing functionality required to be able to implement
amartinhuertas Dec 8, 2025
25060bf
Alternative algorithm for computing the facet integration data
amartinhuertas Dec 10, 2025
86b550a
Bug-fixes to new algorithms developed in 25060bf8e6841d17043f51427edb…
amartinhuertas Dec 10, 2025
14e764f
Removing old commented code
amartinhuertas Dec 10, 2025
d72dbd7
Type annotation fix in _generate_face_subface_ldof_to_cell_ldof
amartinhuertas Dec 11, 2025
46494de
Capturing nasty BUG
amartinhuertas Dec 12, 2025
2d726e3
BUG in generate_dg_operator work-arounded
amartinhuertas Dec 12, 2025
9482f1b
Bump required Gridap version to 0.19.6
amartinhuertas Dec 12, 2025
60a3b5c
Changes required to have a RT spact defined on a portion of a
amartinhuertas Dec 16, 2025
63aa249
Adding missing file
amartinhuertas Dec 16, 2025
f89fd1d
Removed hdiv error norm check
amartinhuertas Dec 16, 2025
9068e63
Added kw-arg constraint kw-arg to FESpace constructors within P4est
amartinhuertas Dec 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
[compat]
ArgParse = "1"
FillArrays = "0.8.4, 0.9, 0.10, 0.11, 0.12, 1"
Gridap = "0.19.2"
Gridap = "0.19.6"
GridapDistributed = "0.4"
Logging = "1"
MPI = "0.20"
Expand Down
328 changes: 267 additions & 61 deletions src/FESpaces.jl

Large diffs are not rendered by default.

368 changes: 247 additions & 121 deletions src/Geometry.jl

Large diffs are not rendered by default.

484 changes: 469 additions & 15 deletions src/OctreeDistributedDiscreteModels.jl

Large diffs are not rendered by default.

39 changes: 9 additions & 30 deletions src/PXestTypeMethods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1914,36 +1914,15 @@ function generate_cell_faces_and_non_conforming_glue(pXest_type::PXestType,
owner_faces_pindex = Vector{Vector{Int}}(undef, Dc - 1)
owner_faces_lids = Vector{Dict{Int,Tuple{Int,Int,Int}}}(undef, Dc - 1)

lface_to_cvertices = Gridap.ReferenceFEs.get_faces(Dc == 2 ? QUAD : HEX, Dc - 1, 0)
pindex_to_cfvertex_to_fvertex = Gridap.ReferenceFEs.get_vertex_permutations(Dc == 2 ? SEGMENT : QUAD)

owner_faces_pindex[Dc-1], owner_faces_lids[Dc-1] = _compute_owner_faces_pindex_and_lids(Dc,
pXest_refinement_rule,
n_cell_vertices,
n_cell_edges,
n_cell_faces,
num_hanging_faces[Dc],
hanging_faces_glue[Dc],
hanging_faces_to_cell[Dc],
hanging_faces_to_lface[Dc],
gridap_cell_faces[1],
gridap_cell_faces[Dc],
lface_to_cvertices,
pindex_to_cfvertex_to_fvertex)

if (Dc == 3)
owner_faces_pindex[1], owner_faces_lids[1]=
_compute_owner_edges_pindex_and_lids(
n_cell_vertices,
n_cell_edges,
n_cell_faces,
num_hanging_faces[2],
hanging_faces_glue[2],
hanging_faces_to_cell[2],
hanging_faces_to_lface[2],
gridap_cell_faces[1],
gridap_cell_faces[2])
end
_fill_owner_faces_pindex_and_lids!(Dc,
pXest_refinement_rule,
owner_faces_pindex,
owner_faces_lids,
num_hanging_faces,
hanging_faces_glue,
hanging_faces_to_cell,
hanging_faces_to_lface,
gridap_cell_faces)

return num_regular_faces,
num_hanging_faces,
Expand Down
93 changes: 89 additions & 4 deletions test/DarcyNonConformingOctreeModelsTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ module DarcyNonConformingOctreeModelsTests
using Logging
using Test

include("CoarseDiscreteModelsTools.jl")
include("GenerateTriangulationPortionTools.jl")


function test_transfer_ops_and_redistribute(ranks,
dmodel::GridapDistributed.DistributedDiscreteModel{Dc},
order) where Dc
Expand Down Expand Up @@ -166,6 +170,87 @@ module DarcyNonConformingOctreeModelsTests
end
end

function test_2d_fe_space_on_triangulation(ranks,order;num_amr_steps=5,num_ghost_layers=1)
coarse_model=CartesianDiscreteModel((0,1,0,1),(1,1))
dmodel=OctreeDistributedDiscreteModel(ranks,coarse_model,2;num_ghost_layers=num_ghost_layers)
dtrian=generate_triangulation_portion(ranks,dmodel)
for i=1:num_amr_steps
dmodel,dtrian=test_fe_space_on_triangulation(ranks,dmodel,dtrian,order,i)
end
end

function test_fe_space_on_triangulation(ranks,cmodel,ctrian,order,amr_step)
ref_coarse_flags=map(ranks,partition(get_cell_gids(cmodel.dmodel))) do rank,indices
flags=zeros(Cint,length(indices))
flags.=nothing_flag

flags[1]=refine_flag
flags[own_length(indices)]=refine_flag

# To create some unbalance
if (rank%2==0 && own_length(indices)>1)
flags[div(own_length(indices),2)]=refine_flag
end
flags
end
fmodel,glue=Gridap.Adaptivity.adapt(cmodel,ref_coarse_flags)
ftrian = generate_triangulation_portion(ranks,fmodel,ctrian=ctrian,glue=glue)

u_ex, p_ex, f_ex=get_analytical_functions(2)

V = FESpace(ftrian,
ReferenceFE(raviart_thomas,Float64,order),
conformity=:Hdiv,
dirichlet_tags="boundary")

Q = FESpace(ftrian,
ReferenceFE(lagrangian,Float64,order);
conformity=:L2)

U = TrialFESpace(V,u_ex)
P = TrialFESpace(Q)

Y = MultiFieldFESpace([V, Q])
X = MultiFieldFESpace([U, P])

degree = 2*(order+1)
dΩ = Measure(ftrian,degree)

btrian = Boundary(ftrian,tags="interior_boundary")
degree = 2*(order+1)
dΓ = Measure(btrian,degree)
nb = get_normal_vector(btrian)

a((u, p),(v, q)) = ∫(u⋅v)dΩ +∫(q*(∇⋅u))dΩ-∫((∇⋅v)*p)dΩ
b(( v, q)) = ∫( v⋅f_ex + q*(∇⋅u_ex))dΩ - ∫((v⋅nb)*p_ex )dΓ

op = AffineFEOperator(a,b,X,Y)
xh = solve(op)

uh, ph = xh
eu = u_ex - uh
ep = p_ex - ph

l2(v) = sqrt(sum(∫(v⋅v)*dΩ))

eu_l2 = l2(eu)
ep_l2 = l2(ep)

# writevtk(fmodel, "fmodel_amr_level_$(amr_step)")
# writevtk(ftrian, "ftrian_amr_level_$(amr_step)")

tol=1e-5
println("[SOLVE FINE] eu_l2 < tol: $(eu_l2) < $(tol)")
println("[SOLVE FINE] ep_l2 < tol: $(ep_l2) < $(tol)")

tol = 1.0e-6
@assert eu_l2 < tol
@assert ep_l2 < tol

fmodel, ftrian
end


u_ex_2D(x) = VectorValue(2*x[1],x[1]+x[2])
p_ex_2D(x) = x[1]-x[2]
f_ex_2D(x) = u_ex_2D(x) + ∇(p_ex_2D)(x)
Expand All @@ -182,7 +267,6 @@ module DarcyNonConformingOctreeModelsTests
end
end

include("CoarseDiscreteModelsTools.jl")

function solve_darcy(model::GridapDistributed.DistributedDiscreteModel{Dc},order) where {Dc}
if (Dc==2)
Expand Down Expand Up @@ -241,16 +325,13 @@ module DarcyNonConformingOctreeModelsTests
ep = p_ex - ph

l2(v) = sqrt(sum(∫(v⋅v)*dΩ))
h1(v) = sqrt(sum(∫(v*v + ∇(v)⋅∇(v))*dΩ))

eu_l2 = l2(eu)
ep_l2 = l2(ep)
ep_h1 = h1(ep)

tol = 1.0e-6
@test eu_l2 < tol
@test ep_l2 < tol
@test ep_h1 < tol
end

function run(distribute)
Expand All @@ -264,5 +345,9 @@ module DarcyNonConformingOctreeModelsTests

order=2
test_3d(ranks,order)

order=1
test_2d_fe_space_on_triangulation(ranks,order;num_amr_steps=5)

end
end
71 changes: 71 additions & 0 deletions test/GenerateTriangulationPortionTools.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
function _generate_triangulation_portion(ranks, fmodel)
trians = map(ranks,
local_views(fmodel.dmodel),
partition(get_cell_gids(fmodel))) do rank, lmodel, indices
mask = Vector{Bool}(undef,num_cells(lmodel))
mask .= false
cell_to_part = local_to_owner(indices)
graph = GridapDistributed.compute_cell_graph(lmodel)
ncells = num_cells(lmodel)
icell_to_jcells_ptrs = graph.colptr
icell_to_jcells_data = graph.rowval
for icell in 1:ncells
if cell_to_part[icell] == rank
pini = icell_to_jcells_ptrs[icell]
pend = icell_to_jcells_ptrs[icell+1]-1
for p in pini:pend
jcell = icell_to_jcells_data[p]
if cell_to_part[jcell] != rank
mask[icell] = true
end
end
end
end
Triangulation(lmodel, mask)
end
GridapDistributed.DistributedTriangulation(trians,fmodel)
end

function _generate_triangulation_portion(ranks, fmodel, ctrian, glue)
trians = map(ranks,
local_views(fmodel.dmodel),
local_views(ctrian),
glue) do rank, fmodel, ctrian, glue
mask = Vector{Bool}(undef,num_cells(fmodel))
mask .= false

cglue = get_glue(ctrian, Val{num_cell_dims(ctrian)}())
for ccell in cglue.tface_to_mface
fcells = glue.o2n_faces_map[ccell]
for fcell in fcells
mask[fcell] = true
end
end
Triangulation(fmodel, mask)
end
GridapDistributed.DistributedTriangulation(trians,fmodel)
end

function generate_triangulation_portion(ranks,fmodel; ctrian=nothing, glue=nothing)
if (length(ranks)==1 && ctrian==nothing)
trians = map(ranks, local_views(fmodel.dmodel)) do rank, fmodel
mask = Vector{Bool}(undef,num_cells(fmodel))
mask .= false
for cell=1:Int(round(num_cells(fmodel)*0.25))
mask[cell] = true
end
for cell=Int(round(num_cells(fmodel)*0.75)):num_cells(fmodel)
mask[cell] = true
end
Triangulation(fmodel, mask)
end
return GridapDistributed.DistributedTriangulation(trians,fmodel)
else
if ctrian==nothing
@assert glue==nothing
return _generate_triangulation_portion(ranks, fmodel)
else
return _generate_triangulation_portion(ranks, fmodel, ctrian, glue)
end
end
end
2 changes: 1 addition & 1 deletion test/MaxwellNonConformingOctreeModelsTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ module MaxwellNonConformingOctreeModelsTests
u_ex, f_ex=get_analytical_functions(Dc)

V = FESpace(model,
ReferenceFE(nedelec,order),
ReferenceFE(nedelec,Float64, order),
conformity=:Hcurl,
dirichlet_tags="boundary")

Expand Down
Loading
Loading