Mercurial > repos > public > sbplib_julia
annotate src/Grids/curvilinear_grid.jl @ 1432:64b60b42d367 feature/grids/curvilinear
Implement indexing interface
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 28 Aug 2023 09:30:34 +0200 |
parents | 6adf31ba6cfd |
children | 1656228095b5 |
rev | line source |
---|---|
1430
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
1 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
|
2 logicalgrid::GT |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
3 physicalcoordinates::CT |
1431
6adf31ba6cfd
Add `jacobian` and `logicalgrid`
Jonatan Werpers <jonatan@werpers.com>
parents:
1430
diff
changeset
|
4 jacobian::JT |
1430
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
5 end |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
6 |
1431
6adf31ba6cfd
Add `jacobian` and `logicalgrid`
Jonatan Werpers <jonatan@werpers.com>
parents:
1430
diff
changeset
|
7 jacobian(g::CurvilinearGrid) = g.jacobian |
6adf31ba6cfd
Add `jacobian` and `logicalgrid`
Jonatan Werpers <jonatan@werpers.com>
parents:
1430
diff
changeset
|
8 logicalgrid(g::CurvilinearGrid) = g.logicalgrid |
6adf31ba6cfd
Add `jacobian` and `logicalgrid`
Jonatan Werpers <jonatan@werpers.com>
parents:
1430
diff
changeset
|
9 |
1430
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
10 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
11 # Indexing interface |
1432
64b60b42d367
Implement indexing interface
Jonatan Werpers <jonatan@werpers.com>
parents:
1431
diff
changeset
|
12 Base.getindex(g::CurvilinearGrid, I::Vararg{Int}) = g.physicalcoordinates[I...] |
64b60b42d367
Implement indexing interface
Jonatan Werpers <jonatan@werpers.com>
parents:
1431
diff
changeset
|
13 Base.eachindex(g::CurvilinearGrid) = eachindex(g.logicalgrid) |
64b60b42d367
Implement indexing interface
Jonatan Werpers <jonatan@werpers.com>
parents:
1431
diff
changeset
|
14 |
64b60b42d367
Implement indexing interface
Jonatan Werpers <jonatan@werpers.com>
parents:
1431
diff
changeset
|
15 Base.firstindex(g::CurvilinearGrid, d) = firstindex(g.logicalgrid, d) |
64b60b42d367
Implement indexing interface
Jonatan Werpers <jonatan@werpers.com>
parents:
1431
diff
changeset
|
16 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
|
17 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
18 # function Base.getindex(g::TensorGrid, I...) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
19 # szs = ndims.(g.grids) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
20 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
21 # Is = LazyTensors.split_tuple(I, szs) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
22 # ps = map((g,I)->SVector(g[I...]), g.grids, Is) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
23 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
24 # return vcat(ps...) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
25 # end |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
26 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
27 # function Base.eachindex(g::TensorGrid) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
28 # szs = LazyTensors.concatenate_tuples(size.(g.grids)...) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
29 # return CartesianIndices(szs) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
30 # end |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
31 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
32 # # Iteration interface |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
33 # Base.iterate(g::TensorGrid) = iterate(Iterators.product(g.grids...)) |> _iterate_combine_coords |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
34 # Base.iterate(g::TensorGrid, state) = iterate(Iterators.product(g.grids...), state) |> _iterate_combine_coords |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
35 # _iterate_combine_coords(::Nothing) = nothing |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
36 # _iterate_combine_coords((next,state)) = combine_coordinates(next...), state |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
37 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
38 # Base.IteratorSize(::Type{<:TensorGrid{<:Any, D}}) where D = Base.HasShape{D}() |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
39 # Base.eltype(::Type{<:TensorGrid{T}}) where T = T |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
40 # Base.length(g::TensorGrid) = sum(length, g.grids) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
41 # Base.size(g::TensorGrid) = LazyTensors.concatenate_tuples(size.(g.grids)...) |
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 # 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
|
45 # 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
|
46 |
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 # TensorGridBoundary{N, BID} <: BoundaryIdentifier |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
49 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
50 # 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
|
51 # 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
|
52 # """ |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
53 # struct TensorGridBoundary{N, BID} <: BoundaryIdentifier end |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
54 # 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
|
55 # 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
|
56 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
57 # """ |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
58 # boundary_identifiers(g::TensorGrid) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
59 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
60 # 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
|
61 # """ |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
62 # function boundary_identifiers(g::TensorGrid) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
63 # per_grid = map(eachindex(g.grids)) do i |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
64 # 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
|
65 # end |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
66 # return LazyTensors.concatenate_tuples(per_grid...) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
67 # end |
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 # boundary_grid(g::TensorGrid, id::TensorGridBoundary) |
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 # 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
|
74 # """ |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
75 # function boundary_grid(g::TensorGrid, id::TensorGridBoundary) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
76 # 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
|
77 # 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
|
78 # return TensorGrid(new_grids...) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
79 # end |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
80 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
81 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
82 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
83 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
84 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
85 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
86 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
87 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
88 # 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
|
89 # 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
|
90 # entries in the jacobian. |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
91 |