Mercurial > repos > public > sbplib_julia
annotate src/Grids/curvilinear_grid.jl @ 1450:647c8b18b84f feature/grids/curvilinear
Implement iterator interface
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 23 Nov 2023 10:16:19 +0100 |
parents | a0b1449dba4e |
children | 2e08f3444354 |
rev | line source |
---|---|
1433 | 1 # TBD: Rename to MappedGrid? |
1430
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
2 struct CurvilinearGrid{T,D, GT<:Grid{<:Any,D}, CT<:AbstractArray{T,D}, JT<:AbstractArray{<:AbstractArray{<:Any, 2}, D}} <: Grid{T,D} |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
3 logicalgrid::GT |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
4 physicalcoordinates::CT |
1431
6adf31ba6cfd
Add `jacobian` and `logicalgrid`
Jonatan Werpers <jonatan@werpers.com>
parents:
1430
diff
changeset
|
5 jacobian::JT |
1430
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
6 end |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
7 |
1431
6adf31ba6cfd
Add `jacobian` and `logicalgrid`
Jonatan Werpers <jonatan@werpers.com>
parents:
1430
diff
changeset
|
8 jacobian(g::CurvilinearGrid) = g.jacobian |
6adf31ba6cfd
Add `jacobian` and `logicalgrid`
Jonatan Werpers <jonatan@werpers.com>
parents:
1430
diff
changeset
|
9 logicalgrid(g::CurvilinearGrid) = g.logicalgrid |
6adf31ba6cfd
Add `jacobian` and `logicalgrid`
Jonatan Werpers <jonatan@werpers.com>
parents:
1430
diff
changeset
|
10 |
1430
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
11 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
12 # Indexing interface |
1432
64b60b42d367
Implement indexing interface
Jonatan Werpers <jonatan@werpers.com>
parents:
1431
diff
changeset
|
13 Base.getindex(g::CurvilinearGrid, I::Vararg{Int}) = g.physicalcoordinates[I...] |
64b60b42d367
Implement indexing interface
Jonatan Werpers <jonatan@werpers.com>
parents:
1431
diff
changeset
|
14 Base.eachindex(g::CurvilinearGrid) = eachindex(g.logicalgrid) |
64b60b42d367
Implement indexing interface
Jonatan Werpers <jonatan@werpers.com>
parents:
1431
diff
changeset
|
15 |
64b60b42d367
Implement indexing interface
Jonatan Werpers <jonatan@werpers.com>
parents:
1431
diff
changeset
|
16 Base.firstindex(g::CurvilinearGrid, d) = firstindex(g.logicalgrid, d) |
64b60b42d367
Implement indexing interface
Jonatan Werpers <jonatan@werpers.com>
parents:
1431
diff
changeset
|
17 Base.lastindex(g::CurvilinearGrid, d) = lastindex(g.logicalgrid, d) |
1430
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
18 |
1450
647c8b18b84f
Implement iterator interface
Jonatan Werpers <jonatan@werpers.com>
parents:
1449
diff
changeset
|
19 # Iteration interface |
1430
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
20 |
1450
647c8b18b84f
Implement iterator interface
Jonatan Werpers <jonatan@werpers.com>
parents:
1449
diff
changeset
|
21 Base.iterate(g::CurvilinearGrid) = iterate(g.physicalcoordinates) |
647c8b18b84f
Implement iterator interface
Jonatan Werpers <jonatan@werpers.com>
parents:
1449
diff
changeset
|
22 Base.iterate(g::CurvilinearGrid, state) = iterate(g.physicalcoordinates, state) |
1430
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
23 |
1450
647c8b18b84f
Implement iterator interface
Jonatan Werpers <jonatan@werpers.com>
parents:
1449
diff
changeset
|
24 Base.IteratorSize(::Type{<:CurvilinearGrid{<:Any, D}}) where D = Base.HasShape{D}() |
647c8b18b84f
Implement iterator interface
Jonatan Werpers <jonatan@werpers.com>
parents:
1449
diff
changeset
|
25 Base.length(g::CurvilinearGrid) = length(g.logicalgrid) |
647c8b18b84f
Implement iterator interface
Jonatan Werpers <jonatan@werpers.com>
parents:
1449
diff
changeset
|
26 Base.size(g::CurvilinearGrid) = size(g.logicalgrid) |
647c8b18b84f
Implement iterator interface
Jonatan Werpers <jonatan@werpers.com>
parents:
1449
diff
changeset
|
27 Base.size(g::CurvilinearGrid, d) = size(g.logicalgrid, d) |
1430
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
28 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
29 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
30 # refine(g::TensorGrid, r::Int) = mapreduce(g->refine(g,r), TensorGrid, g.grids) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
31 # coarsen(g::TensorGrid, r::Int) = mapreduce(g->coarsen(g,r), TensorGrid, g.grids) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
32 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
33 # """ |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
34 # TensorGridBoundary{N, BID} <: BoundaryIdentifier |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
35 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
36 # A boundary identifier for a tensor grid. `N` Specifies which grid in the |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
37 # tensor product and `BID` which boundary on that grid. |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
38 # """ |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
39 # struct TensorGridBoundary{N, BID} <: BoundaryIdentifier end |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
40 # grid_id(::TensorGridBoundary{N, BID}) where {N, BID} = N |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
41 # boundary_id(::TensorGridBoundary{N, BID}) where {N, BID} = BID() |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
42 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
43 # """ |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
44 # boundary_identifiers(g::TensorGrid) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
45 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
46 # Returns a tuple containing the boundary identifiers of `g`. |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
47 # """ |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
48 # function boundary_identifiers(g::TensorGrid) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
49 # per_grid = map(eachindex(g.grids)) do i |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
50 # return map(bid -> TensorGridBoundary{i, typeof(bid)}(), boundary_identifiers(g.grids[i])) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
51 # end |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
52 # return LazyTensors.concatenate_tuples(per_grid...) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
53 # end |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
54 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
55 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
56 # """ |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
57 # boundary_grid(g::TensorGrid, id::TensorGridBoundary) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
58 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
59 # The grid for the boundary of `g` specified by `id`. |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
60 # """ |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
61 # function boundary_grid(g::TensorGrid, id::TensorGridBoundary) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
62 # local_boundary_grid = boundary_grid(g.grids[grid_id(id)], boundary_id(id)) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
63 # new_grids = Base.setindex(g.grids, local_boundary_grid, grid_id(id)) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
64 # return TensorGrid(new_grids...) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
65 # end |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
66 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
67 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
68 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
69 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
70 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
71 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
72 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
73 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
74 # Do we add a convenience function `curvilinear_grid`? It could help with |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
75 # creating the logical grid, evaluating functions and possibly calculating the |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
76 # entries in the jacobian. |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
77 |