Skip to content

Commit

Permalink
Add tol and strict kwargs to glue()
Browse files Browse the repository at this point in the history
  • Loading branch information
j-fu committed Mar 22, 2024
1 parent 75f3f44 commit def5e29
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ExtendableGrids"
uuid = "cfc395e8-590f-11e8-1f13-43a2532b2fa8"
authors = ["Juergen Fuhrmann <juergen.fuhrmann@wias-berlin.de>", "Christian Merdon <christian.merdon@wias-berlin.de>", "Johannes Taraz <johannes.taraz@gmail.com>"]
version = "1.4.0"
version = "1.4.1"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
44 changes: 32 additions & 12 deletions src/simplexgrid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ end
g1regions=1:num_bfaceregions(g1),
g2regions=1:num_bfaceregions(g2),
interface=0,
warnonly = false,
tol=1.0e-10,
naive=false)
Expand All @@ -661,6 +662,7 @@ Merge two grids along their common boundary facets.
- g1regions: boundary regions to be used from grid1. Default: all.
- g2regions: boundary regions to be used from grid2. Default: all.
- interface: if nonzero, create interface region in new grid, otherwise, ignore
- strict: Assume all bfaces form specfied regions shall be matched, throw error on failure
- tol: Distance below which two points are seen as identical. Default: 1.0e-10
- naive: use naive quadratic complexity matching (for checking backward compatibility). Default: false
Expand All @@ -673,6 +675,7 @@ function glue(g1::ExtendableGrid,g2::ExtendableGrid;
breg=nothing,
interface=0,
tol=1.0e-10,
strict = false,
naive = false)
Ti=eltype(g1[CellNodes])
dim=dim_space(g1)
Expand Down Expand Up @@ -755,8 +758,9 @@ function glue(g1::ExtendableGrid,g2::ExtendableGrid;
for idim=1:dim
bc[idim]=0.0
for jdim=1:dim
bc[idim]+=coord[idim,bfnodes[jdim,iface]]/dim
bc[idim]+=coord[idim,bfnodes[jdim,iface]]
end
bc[idim]/=3.0
end
bc
end
Expand All @@ -772,6 +776,25 @@ function glue(g1::ExtendableGrid,g2::ExtendableGrid;
breg2used[reg]=true
end

nbf1used=0
for ibf1=1:nbf1
if breg1used[bfreg1[ibf1]]
nbf1used+=1
end
end

nbf2used=0
for ibf2=1:nbf2
if breg2used[bfreg2[ibf2]]
nbf2used+=1
end
end

if nbf1used!=nbf2used && strict
error("glue: trying to match $nbf1used grid1 bfaces with $nbf2used grid2 bfaces.")
end


if naive
# Run over all pairs of boundary faces and try to match them
# This can scale catastrophically...
Expand All @@ -788,14 +811,7 @@ function glue(g1::ExtendableGrid,g2::ExtendableGrid;
# Use a binned point list for speed up.
# Facets are found through their barycenters.
bcenter=zeros(dim)
bpl=BinnedPointList(eltype(coord1),dim)
nbf1used=0

for ibf1=1:nbf1
if breg1used[bfreg1[ibf1]]
nbf1used+=1
end
end
bpl=BinnedPointList(eltype(coord1),dim;tol)

# marker for facet numbers
bf1used=zeros(Int,nbf1used)
Expand All @@ -822,9 +838,13 @@ function glue(g1::ExtendableGrid,g2::ExtendableGrid;
end
end
end

@info "glue: $(n_matching_faces) matching bfaces found"


if (n_matching_faces != nbf1used || n_matching_faces != nbf2used) && strict
error("glue: bfaces to be matched: $nbf1used vs. $nbf2used, bfaces matched: $n_matching_faces.")
else
@info "glue: $(n_matching_faces) matching bfaces found"
end

creg1=g1[CellRegions]
creg2=g2[CellRegions]

Expand Down
2 changes: 1 addition & 1 deletion test/test_gridstuff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function check_cellfinder(xgrid)
EG = xgrid[UniqueCellGeometries]
@info "Testing CellFinder for geometries=$EG..."
xCoordinates = xgrid[Coordinates]
@show xCoordinates
# @show xCoordinates
xCellNodes = xgrid[CellNodes]
edim = dim_element(EG[1])
CF::CellFinder{Float64,Int32} = CellFinder(xgrid)
Expand Down

2 comments on commit def5e29

@j-fu
Copy link
Owner Author

@j-fu j-fu commented on def5e29 Mar 22, 2024

Choose a reason for hiding this comment

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

@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/103432

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 v1.4.1 -m "<description of version>" def5e2905433d981a3429d741e9185da8dd07bb5
git push origin v1.4.1

Please sign in to comment.