Skip to content

Commit

Permalink
fix subgrid coordinate system for boundary grids (#38)
Browse files Browse the repository at this point in the history
* fix subgrid coordinate system for boundary grids

* use ExampleJuggler v2 (no Pluto dependency due to extensions)
  • Loading branch information
j-fu authored Feb 20, 2024
1 parent 06a2f11 commit c2af7ac
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 26 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]>", "Johannes Taraz <[email protected]>"]
version = "1.3.0"
version = "1.3.1"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ Triangulate = "f7e6ffb2-c36d-4f8f-a77e-16e897189344"
[compat]
Documenter = "1"
julia = "1.9"
ExampleJuggler = "2"
12 changes: 12 additions & 0 deletions src/coordinatesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,15 @@ abstract type Spherical1D <: AbstractCoordinateSystem end #r (integral over


const CoordinateSystems=Union{[Type{t} for t in leaftypes(AbstractCoordinateSystem)]...}


"""
codim1_coordinatesystem(CoordinateSystem)
Return coordinate system for codimension 1 subgrid.
"""
codim1_coordinatesystem(::Type{T}) where T<:AbstractCoordinateSystem = nothing
codim1_coordinatesystem(::Type{Cartesian3D})=Cartesian2D
codim1_coordinatesystem(::Type{Cartesian2D})=Cartesian1D


37 changes: 18 additions & 19 deletions src/subgrid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,6 @@ Grid component key type for indicating that grid is a refinement of the parentgr
"""
abstract type RefinedGrid <: ParentGridRelation end


"""
$(TYPEDSIGNATURES)
Default transform for subgrid creation
"""
function _copytransform!(a::AbstractArray,b::AbstractArray)
for i=1:length(a)
a[i]=b[i]
end
end

struct XIPair{Tv, Ti}
x::Tv
i::Ti
Expand All @@ -85,16 +73,23 @@ Base.isless(x::XIPair, y::XIPair) = (x.x < y.x)


"""
$(TYPEDSIGNATURES)
subgrid(parent,
subregions::AbstractArray;
transform::T=function(a,b) @views a.=b[1:length(a)] end,
boundary=false,
coordinatesystem=codim1_coordinatesystem(parent[CoordinateSystem]),
project=true) where T
Create subgrid from list of regions.
- `parent`: parent grid
- `subregions`: Array of subregions
- `subregions`: Array of subregions which define the subgrid
- `boundary`: if true, create codimension 1 subgrid from boundary regions.
- `transform` (kw parameter): transformation function between
grid and subgrid coordinates acting on one point.
Default: `copytransform`
- `boundary`: if true, create codimension 1 subgrid from boundary region.
- `coordinatesystem`: if `boundary==true`, specify coordinate system for the boundary.
Default: if parent coordinatesystem is cartesian, just the cooresponding codim1 coordinatesystem,
otherwise: `nothing`, requiring user specification for use of e.g. CellFinder with the subgrid.
- `project`: project coordinates onto subgrid dimension
A subgrid is of type `ExtendableGrid` and stores two additional components:
Expand All @@ -103,9 +98,10 @@ A subgrid is of type `ExtendableGrid` and stores two additional components:
"""
function subgrid(parent,
subregions::AbstractArray;
transform::Function=_copytransform!,
transform::T=function(a,b) @views a.=b[1:length(a)] end,
boundary=false,
project=true)
coordinatesystem=codim1_coordinatesystem(parent[CoordinateSystem]),
project=true) where T

Tc=coord_type(parent)
Ti=index_type(parent)
Expand Down Expand Up @@ -205,6 +201,9 @@ function subgrid(parent,
subgrid[BFaceGeometries]=ElementGeometries[]
subgrid[BFaceNodes]=Matrix{Ti}(undef,sub_gdim,0)
subgrid[NumBFaceRegions]=0
if !isnothing(coordinatesystem)
subgrid[CoordinateSystem]=coordinatesystem
end
else
bfacenodes=parent[BFaceNodes]
bfaceregions=parent[BFaceRegions]
Expand Down Expand Up @@ -258,8 +257,8 @@ function subgrid(parent,
subgrid[BFaceNodes]=zeros(Ti, 2, 0)
subgrid[NumBFaceRegions]=0
end
subgrid[CoordinateSystem]=parent[CoordinateSystem]
end
subgrid[CoordinateSystem]=parent[CoordinateSystem]

if sub_gdim == 1
# Sort nodes of grid for easy plotting
Expand Down
2 changes: 1 addition & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Triangulate = "f7e6ffb2-c36d-4f8f-a77e-16e897189344"

[compat]
ExampleJuggler = "0.4"
ExampleJuggler = "2"
10 changes: 7 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Test, ExampleJuggler
using ExtendableGrids, SHA
using Test

ExampleJuggler.verbose!(true)
using ExampleJuggler

using ExtendableGrids, SHA

@testset "Geomspace" begin
function test_geomspace()
Expand Down Expand Up @@ -263,6 +264,9 @@ end

include("gmsh.jl")


ExampleJuggler.verbose!(true)

@testset "Examples" begin
@testscripts(joinpath(@__DIR__, "..", "examples"), ["examples1d.jl", "examples2d.jl", "examples3d.jl", "gmsh.jl"])
end
Expand Down
16 changes: 14 additions & 2 deletions test/test_gridstuff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ function check_cellfinder(xgrid)
EG = xgrid[UniqueCellGeometries]
@info "Testing CellFinder for geometries=$EG..."
xCoordinates = xgrid[Coordinates]
@show xCoordinates
xCellNodes = xgrid[CellNodes]
edim = dim_element(EG[1])
CF::CellFinder{Float64,Int32} = CellFinder(xgrid)
Expand All @@ -89,11 +90,11 @@ function check_cellfinder(xgrid)
x_source[j] += xCoordinates[j,xCellNodes[k,cell_to_find]] + 1e-6
end
x_source ./= num_targets(xCellNodes,cell_to_find)

@show x_source
# find cell by local strategy
xref = zeros(Float64,edim+1)
cell = gFindLocal!(xref, CF, x_source; icellstart = 1)

# check xref
x = zeros(Float64,edim)
L2G = L2GTransformer(xgrid[CellGeometries][cell], xgrid, ON_CELLS)
Expand Down Expand Up @@ -151,6 +152,17 @@ function run_grid_tests()
@test check_cellfinder(get_testgrid(Tetrahedron3D))
@test check_cellfinder(get_testgrid(Parallelepiped3D))

X = LinRange(0, 1, 10)
grid = simplexgrid(X, X)
sub = subgrid(grid, [2], transform=function(a,b) a[1]=b[2] end, boundary=true)
@test check_cellfinder(sub)

grid = simplexgrid(X, X, X)
sub = subgrid(grid, [5], boundary=true)
@test check_cellfinder(sub)



@test check_uniform_refinement(reference_domain(Triangle2D), false)
@test check_uniform_refinement(reference_domain(Triangle2D), true)
@test check_uniform_refinement(reference_domain(Parallelogram2D), false)
Expand Down

2 comments on commit c2af7ac

@j-fu
Copy link
Member Author

@j-fu j-fu commented on c2af7ac Feb 20, 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/101313

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

Please sign in to comment.