Skip to content

Commit

Permalink
bfacemask! for 3D, introduce allow_new flag
Browse files Browse the repository at this point in the history
  • Loading branch information
j-fu committed Oct 21, 2021
1 parent aac25d3 commit 5ce2a2f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 49 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 <[email protected]>, Christian Merdon <[email protected]>"]
version = "0.8.5"
version = "0.8.6"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
8 changes: 8 additions & 0 deletions src/extendablegrid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,14 @@ Set new grid component
"""
Base.setindex!(grid::ExtendableGrid,v,T::Type{<:AbstractGridComponent})= grid.components[T]=veryform(grid,v,T)

"""
$(TYPEDSIGNATURES)
Remove grid component
"""
Base.delete!(grid::ExtendableGrid,T::Type{<:AbstractGridComponent})= delete!(grid.components,T)



"""
$(TYPEDSIGNATURES)
Expand Down
88 changes: 40 additions & 48 deletions src/regionedit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,85 +40,77 @@ end
$(TYPEDSIGNATURES)
Edit region numbers of grid boundary facets via rectangular mask.
For 1D grids, inner boundaries can be added by this method.
If `allow_new` is true (default), new facets are added
"""
function bfacemask!(grid::ExtendableGrid,
maskmin::AbstractArray,
maskmax::AbstractArray,
ireg::Int;
allow_new=true,
tol=1.0e-10)

xmaskmin=maskmin.-tol
xmaskmax=maskmax.+tol


nbfaces=num_bfaces(grid)
bfacenodes=grid[BFaceNodes]
nbfaces=size(bfacenodes,2)




Ti=eltype(bfacenodes)
dim=dim_space(grid)
bfaceregions=grid[BFaceRegions]
new_bfacenodes=ElasticArray{Ti,2}(bfacenodes)
coord=grid[Coordinates]

function isbface(ix)
for ibface=1:num_bfaces(grid)
if bfacenodes[1,ibface]==ix
return ibface
end
end
return 0
end

function isbface(ix,iy)
for ibface=1:num_bfaces(grid)
if (bfacenodes[1,ibface] == ix && bfacenodes[2,ibface] == iy) ||
(bfacenodes[1,ibface] == iy && bfacenodes[2,ibface] == ix)
return ibface
end
xfacenodes=bfacenodes
if allow_new
new_bfacenodes=ElasticArray{Ti,2}(bfacenodes)
facenodes=grid[FaceNodes]
bfacefaces=grid[BFaceFaces]
nfaces=size(facenodes,2)
bmark=zeros(Int,nfaces)
for ibface=1:nbfaces
bmark[bfacefaces[ibface]]=ibface
end
return 0
xfacenodes=facenodes
end

if dim_space(grid)==1
for inode=1:num_nodes(grid)
x=coord[1,inode]
if x>xmaskmin[1] && x<xmaskmax[1]
ibface=isbface(inode)
if ibface>0
bfaceregions[ibface]=ireg
else
push!(bfaceregions,ireg)
append!(new_bfacenodes,[inode])

for ixface=1:size(xfacenodes,2)
in_region=true
for inode=1:num_targets(xfacenodes,ixface)
ignode=xfacenodes[inode,ixface]
for idim=1:dim_space(grid)
if coord[idim,ignode]<xmaskmin[idim]
in_region=false
elseif coord[idim,ignode]>xmaskmax[idim]
in_region=false
end
end
end
else
facenodes=grid[FaceNodes]
for iface=1:size(facenodes,2)
in_region=true
for inode=1:num_targets(facenodes,iface)
ignode=facenodes[inode,iface]
for idim=1:dim_space(grid)
if coord[idim,ignode]<xmaskmin[idim]
in_region=false
elseif coord[idim,ignode]>xmaskmax[idim]
in_region=false
end
end
end
if in_region
ibface=isbface(facenodes[1,iface],facenodes[2,iface])

if in_region
if allow_new
ibface=bmark[ixface]
if ibface>0
bfaceregions[ibface]=ireg
else
push!(bfaceregions,ireg)
append!(new_bfacenodes,[facenodes[1,iface],facenodes[2,iface]])
@views append!(new_bfacenodes,xfacenodes[:,ixface])
end
else
bfaceregions[ixface]=ireg
end
end
end


delete!(grid,BFaceFaces)
btype=grid[BFaceGeometries][1]
grid[BFaceNodes]=Array{Ti,2}(new_bfacenodes)
if allow_new
grid[BFaceNodes]=Array{Ti,2}(new_bfacenodes)
end
grid[BFaceGeometries]=VectorOfConstants(btype,length(bfaceregions))
grid[NumBFaceRegions]=max(num_bfaceregions(grid),ireg)
return grid
Expand Down

4 comments on commit 5ce2a2f

@j-fu
Copy link
Member Author

@j-fu j-fu commented on 5ce2a2f Oct 21, 2021

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.

An unexpected error occurred during registration.

@j-fu
Copy link
Member Author

@j-fu j-fu commented on 5ce2a2f Oct 21, 2021

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 updated: JuliaRegistries/General/47191

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.8.6 -m "<description of version>" 5ce2a2f3f7402ea8dc4f702a09645d9f4a477af5
git push origin v0.8.6

Please sign in to comment.