Skip to content

Commit c2af7ac

Browse files
authored
fix subgrid coordinate system for boundary grids (#38)
* fix subgrid coordinate system for boundary grids * use ExampleJuggler v2 (no Pluto dependency due to extensions)
1 parent 06a2f11 commit c2af7ac

File tree

7 files changed

+54
-26
lines changed

7 files changed

+54
-26
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ExtendableGrids"
22
uuid = "cfc395e8-590f-11e8-1f13-43a2532b2fa8"
33
authors = ["Juergen Fuhrmann <[email protected]>", "Christian Merdon <[email protected]>", "Johannes Taraz <[email protected]>"]
4-
version = "1.3.0"
4+
version = "1.3.1"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"

docs/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ Triangulate = "f7e6ffb2-c36d-4f8f-a77e-16e897189344"
1212
[compat]
1313
Documenter = "1"
1414
julia = "1.9"
15+
ExampleJuggler = "2"

src/coordinatesystem.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,15 @@ abstract type Spherical1D <: AbstractCoordinateSystem end #r (integral over
6969

7070

7171
const CoordinateSystems=Union{[Type{t} for t in leaftypes(AbstractCoordinateSystem)]...}
72+
73+
74+
"""
75+
codim1_coordinatesystem(CoordinateSystem)
76+
77+
Return coordinate system for codimension 1 subgrid.
78+
"""
79+
codim1_coordinatesystem(::Type{T}) where T<:AbstractCoordinateSystem = nothing
80+
codim1_coordinatesystem(::Type{Cartesian3D})=Cartesian2D
81+
codim1_coordinatesystem(::Type{Cartesian2D})=Cartesian1D
82+
83+

src/subgrid.jl

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,6 @@ Grid component key type for indicating that grid is a refinement of the parentgr
6262
"""
6363
abstract type RefinedGrid <: ParentGridRelation end
6464

65-
66-
"""
67-
$(TYPEDSIGNATURES)
68-
69-
Default transform for subgrid creation
70-
"""
71-
function _copytransform!(a::AbstractArray,b::AbstractArray)
72-
for i=1:length(a)
73-
a[i]=b[i]
74-
end
75-
end
76-
7765
struct XIPair{Tv, Ti}
7866
x::Tv
7967
i::Ti
@@ -85,16 +73,23 @@ Base.isless(x::XIPair, y::XIPair) = (x.x < y.x)
8573

8674

8775
"""
88-
$(TYPEDSIGNATURES)
76+
subgrid(parent,
77+
subregions::AbstractArray;
78+
transform::T=function(a,b) @views a.=b[1:length(a)] end,
79+
boundary=false,
80+
coordinatesystem=codim1_coordinatesystem(parent[CoordinateSystem]),
81+
project=true) where T
8982
9083
Create subgrid from list of regions.
9184
9285
- `parent`: parent grid
93-
- `subregions`: Array of subregions
86+
- `subregions`: Array of subregions which define the subgrid
87+
- `boundary`: if true, create codimension 1 subgrid from boundary regions.
9488
- `transform` (kw parameter): transformation function between
9589
grid and subgrid coordinates acting on one point.
96-
Default: `copytransform`
97-
- `boundary`: if true, create codimension 1 subgrid from boundary region.
90+
- `coordinatesystem`: if `boundary==true`, specify coordinate system for the boundary.
91+
Default: if parent coordinatesystem is cartesian, just the cooresponding codim1 coordinatesystem,
92+
otherwise: `nothing`, requiring user specification for use of e.g. CellFinder with the subgrid.
9893
- `project`: project coordinates onto subgrid dimension
9994
10095
A subgrid is of type `ExtendableGrid` and stores two additional components:
@@ -103,9 +98,10 @@ A subgrid is of type `ExtendableGrid` and stores two additional components:
10398
"""
10499
function subgrid(parent,
105100
subregions::AbstractArray;
106-
transform::Function=_copytransform!,
101+
transform::T=function(a,b) @views a.=b[1:length(a)] end,
107102
boundary=false,
108-
project=true)
103+
coordinatesystem=codim1_coordinatesystem(parent[CoordinateSystem]),
104+
project=true) where T
109105

110106
Tc=coord_type(parent)
111107
Ti=index_type(parent)
@@ -205,6 +201,9 @@ function subgrid(parent,
205201
subgrid[BFaceGeometries]=ElementGeometries[]
206202
subgrid[BFaceNodes]=Matrix{Ti}(undef,sub_gdim,0)
207203
subgrid[NumBFaceRegions]=0
204+
if !isnothing(coordinatesystem)
205+
subgrid[CoordinateSystem]=coordinatesystem
206+
end
208207
else
209208
bfacenodes=parent[BFaceNodes]
210209
bfaceregions=parent[BFaceRegions]
@@ -258,8 +257,8 @@ function subgrid(parent,
258257
subgrid[BFaceNodes]=zeros(Ti, 2, 0)
259258
subgrid[NumBFaceRegions]=0
260259
end
260+
subgrid[CoordinateSystem]=parent[CoordinateSystem]
261261
end
262-
subgrid[CoordinateSystem]=parent[CoordinateSystem]
263262

264263
if sub_gdim == 1
265264
# Sort nodes of grid for easy plotting

test/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
88
Triangulate = "f7e6ffb2-c36d-4f8f-a77e-16e897189344"
99

1010
[compat]
11-
ExampleJuggler = "0.4"
11+
ExampleJuggler = "2"

test/runtests.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
using Test, ExampleJuggler
2-
using ExtendableGrids, SHA
1+
using Test
32

4-
ExampleJuggler.verbose!(true)
3+
using ExampleJuggler
4+
5+
using ExtendableGrids, SHA
56

67
@testset "Geomspace" begin
78
function test_geomspace()
@@ -263,6 +264,9 @@ end
263264

264265
include("gmsh.jl")
265266

267+
268+
ExampleJuggler.verbose!(true)
269+
266270
@testset "Examples" begin
267271
@testscripts(joinpath(@__DIR__, "..", "examples"), ["examples1d.jl", "examples2d.jl", "examples3d.jl", "gmsh.jl"])
268272
end

test/test_gridstuff.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ function check_cellfinder(xgrid)
7878
EG = xgrid[UniqueCellGeometries]
7979
@info "Testing CellFinder for geometries=$EG..."
8080
xCoordinates = xgrid[Coordinates]
81+
@show xCoordinates
8182
xCellNodes = xgrid[CellNodes]
8283
edim = dim_element(EG[1])
8384
CF::CellFinder{Float64,Int32} = CellFinder(xgrid)
@@ -89,11 +90,11 @@ function check_cellfinder(xgrid)
8990
x_source[j] += xCoordinates[j,xCellNodes[k,cell_to_find]] + 1e-6
9091
end
9192
x_source ./= num_targets(xCellNodes,cell_to_find)
92-
93+
@show x_source
9394
# find cell by local strategy
9495
xref = zeros(Float64,edim+1)
9596
cell = gFindLocal!(xref, CF, x_source; icellstart = 1)
96-
97+
9798
# check xref
9899
x = zeros(Float64,edim)
99100
L2G = L2GTransformer(xgrid[CellGeometries][cell], xgrid, ON_CELLS)
@@ -151,6 +152,17 @@ function run_grid_tests()
151152
@test check_cellfinder(get_testgrid(Tetrahedron3D))
152153
@test check_cellfinder(get_testgrid(Parallelepiped3D))
153154

155+
X = LinRange(0, 1, 10)
156+
grid = simplexgrid(X, X)
157+
sub = subgrid(grid, [2], transform=function(a,b) a[1]=b[2] end, boundary=true)
158+
@test check_cellfinder(sub)
159+
160+
grid = simplexgrid(X, X, X)
161+
sub = subgrid(grid, [5], boundary=true)
162+
@test check_cellfinder(sub)
163+
164+
165+
154166
@test check_uniform_refinement(reference_domain(Triangle2D), false)
155167
@test check_uniform_refinement(reference_domain(Triangle2D), true)
156168
@test check_uniform_refinement(reference_domain(Parallelogram2D), false)

0 commit comments

Comments
 (0)