Skip to content

Commit

Permalink
Merge pull request #1026 from gridap/facet_integration_non_conforming…
Browse files Browse the repository at this point in the history
…_meshes

Improve performance of PR 967
  • Loading branch information
amartinhuertas authored Aug 29, 2024
2 parents 0e8941a + 053153e commit 9675711
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 24 deletions.
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ 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).

## [0.18.6] - 2024-08-29

### Fixed

- Improved performance of PR[#967](https://github.com/gridap/Gridap.jl/pull/967). Along the way, opened the door to Triangulations of different type in SkeletonTriangulation. Since PR[#1026](https://github.com/gridap/Gridap.jl/pull/1026).

## [0.18.5] - 2024-08-28

### Changed
Expand Down
16 changes: 10 additions & 6 deletions src/Geometry/SkeletonTriangulations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@ end
minus::B
end
"""
struct SkeletonTriangulation{Dc,Dp,B} <: Triangulation{Dc,Dp}
struct SkeletonTriangulation{Dc,Dp,B,C} <: Triangulation{Dc,Dp}
plus::B
minus::B
function SkeletonTriangulation(plus::B,minus::B) where B<:Triangulation
Dc = num_cell_dims(plus)
Dp = num_point_dims(plus)
minus::C
function SkeletonTriangulation(plus::B,minus::C) where {B<:Triangulation,C<:Triangulation}
DcP = num_cell_dims(plus)
DpP = num_point_dims(plus)
DcM = num_cell_dims(minus)
DpP = num_point_dims(minus)
@assert DcP == DcM
@assert DpP == DpP
#@assert Dc + 1 == Dp
new{Dc,Dp,B}(plus,minus)
new{DcP,DpP,B,C}(plus,minus)
end
end

Expand Down
53 changes: 35 additions & 18 deletions src/Geometry/Triangulations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,13 @@ function _restrict_model(model,tface_to_mface::IdentityVector)
model
end

abstract type TrianFaceModelFaceMapInjectivity end;
struct Injective <: TrianFaceModelFaceMapInjectivity end;
struct NonInjective <: TrianFaceModelFaceMapInjectivity end;

# This is the most basic Triangulation
# It represents a physical domain built using the faces of a DiscreteModel
struct BodyFittedTriangulation{Dt,Dp,A,B,C} <: Triangulation{Dt,Dp}
struct BodyFittedTriangulation{Dt,Dp,A,B,C,D<:TrianFaceModelFaceMapInjectivity} <: Triangulation{Dt,Dp}
model::A
grid::B
tface_to_mface::C
Expand All @@ -150,33 +154,46 @@ struct BodyFittedTriangulation{Dt,Dp,A,B,C} <: Triangulation{Dt,Dp}
A = typeof(model)
B = typeof(grid)
C = typeof(tface_to_mface)
new{Dt,Dp,A,B,C}(model,grid,tface_to_mface)

# While we do not have a more definitive solution, we need to distinguish
# between injective and non-injective tface_to_mface maps.
# The inverse map, mface_to_tface, relies on PosNegPartition, which fails
# whenever the same mface is the image of more than one tface.
# In turn, I have required non-injective mappings for the computation of facet
# integrals on non-conforming cell interfaces.
if !(allunique(tface_to_mface))
tface_to_mface_injectivity = NonInjective()
D = typeof(tface_to_mface_injectivity)
new{Dt,Dp,A,B,C,D}(model,grid,tface_to_mface)
else
tface_to_mface_injectivity = Injective()
D = typeof(tface_to_mface_injectivity)
new{Dt,Dp,A,B,C,D}(model,grid,tface_to_mface)
end
end
end

get_background_model(trian::BodyFittedTriangulation) = trian.model
get_grid(trian::BodyFittedTriangulation) = trian.grid

function get_glue(trian::BodyFittedTriangulation{Dt},::Val{Dt}) where Dt
# unique(...) here is required for those cases in which an mface in
# trian.tface_to_mface is listed more than once. Otherwise, the
# constructor of PosNegPartition fails because it does not admit
# the same mface to be the image of more than one tface.
# In turn, I have required this for the computation of facet integrals
# on non-conforming cell interfaces.
if !(allunique(trian.tface_to_mface))
tface_to_mface = unique(trian.tface_to_mface)
else
tface_to_mface = trian.tface_to_mface
end
function get_glue(trian::BodyFittedTriangulation{Dt,Dp,A,B,C,Injective},::Val{Dt}) where {Dt,Dp,A,B,C}
tface_to_mface_map = Fill(GenericField(identity),num_cells(trian))
if isa(tface_to_mface,IdentityVector) && num_faces(trian.model,Dt) == num_cells(trian)
mface_to_tface = tface_to_mface
if isa(trian.tface_to_mface,IdentityVector) && num_faces(trian.model,Dt) == num_cells(trian)
mface_to_tface = trian.tface_to_mface
else
nmfaces = num_faces(trian.model,Dt)
mface_to_tface = PosNegPartition(tface_to_mface,Int32(nmfaces))
mface_to_tface = PosNegPartition(trian.tface_to_mface,Int32(nmfaces))
end
FaceToFaceGlue(tface_to_mface,tface_to_mface_map,mface_to_tface)
FaceToFaceGlue(trian.tface_to_mface,tface_to_mface_map,mface_to_tface)
end

function get_glue(trian::BodyFittedTriangulation{Dt,Dp,A,B,C,NonInjective},::Val{Dt}) where {Dt,Dp,A,B,C}
tface_to_mface_map = Fill(GenericField(identity),num_cells(trian))
mface_to_tface = nothing
# Whenever tface_to_mface is non-injective, we currently avoid the computation of
# mface_to_tface, which relies on PosNegPartition. This is a limitation that we should
# face in the future on those scenarios on which we need mface_to_tface.
FaceToFaceGlue(trian.tface_to_mface,tface_to_mface_map,mface_to_tface)
end

#function get_glue(trian::BodyFittedTriangulation{Dt},::Val{Dm}) where {Dt,Dm}
Expand Down
6 changes: 6 additions & 0 deletions test/GeometryTests/TriangulationsTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,10 @@ glue = get_glue(Ω2,Val(2))
@test isa(glue.tface_to_mface,IdentityVector)
@test isa(glue.mface_to_tface,IdentityVector)

# Using a non-injective tface_to_mface map
Ω3 = Triangulation(model, [1,2,1,2,3,3])
glue = get_glue(Ω3,Val(2))
@test isa(glue.tface_to_mface_map,Fill)
@test isa(glue.mface_to_tface,Nothing)

end # module

2 comments on commit 9675711

@amartinhuertas
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/114129

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.18.6 -m "<description of version>" 967571175f5a9c3b4a3d9ee320e3f2da817bf4cd
git push origin v0.18.6

Please sign in to comment.