Mercurial > repos > public > sbplib_julia
annotate src/Grids/curvilinear_grid.jl @ 1433:1656228095b5 feature/grids/curvilinear
Add TBD
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 28 Aug 2023 09:38:15 +0200 |
parents | 64b60b42d367 |
children | a0b1449dba4e |
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 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
19 # function Base.getindex(g::TensorGrid, I...) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
20 # szs = ndims.(g.grids) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
21 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
22 # Is = LazyTensors.split_tuple(I, szs) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
23 # 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
|
24 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
25 # return vcat(ps...) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
26 # end |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
27 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
28 # function Base.eachindex(g::TensorGrid) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
29 # szs = LazyTensors.concatenate_tuples(size.(g.grids)...) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
30 # return CartesianIndices(szs) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
31 # end |
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 # # Iteration interface |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
34 # 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
|
35 # 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
|
36 # _iterate_combine_coords(::Nothing) = nothing |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
37 # _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
|
38 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
39 # 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
|
40 # Base.eltype(::Type{<:TensorGrid{T}}) where T = T |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
41 # Base.length(g::TensorGrid) = sum(length, g.grids) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
42 # 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
|
43 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
44 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
45 # 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
|
46 # 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
|
47 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
48 # """ |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
49 # TensorGridBoundary{N, BID} <: BoundaryIdentifier |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
50 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
51 # 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
|
52 # 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
|
53 # """ |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
54 # struct TensorGridBoundary{N, BID} <: BoundaryIdentifier end |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
55 # 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
|
56 # 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
|
57 |
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 # boundary_identifiers(g::TensorGrid) |
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 # 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
|
62 # """ |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
63 # function boundary_identifiers(g::TensorGrid) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
64 # per_grid = map(eachindex(g.grids)) do i |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
65 # 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
|
66 # end |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
67 # return LazyTensors.concatenate_tuples(per_grid...) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
68 # end |
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 # boundary_grid(g::TensorGrid, id::TensorGridBoundary) |
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 # 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
|
75 # """ |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
76 # function boundary_grid(g::TensorGrid, id::TensorGridBoundary) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
77 # 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
|
78 # 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
|
79 # return TensorGrid(new_grids...) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
80 # end |
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 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
89 # 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
|
90 # 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
|
91 # entries in the jacobian. |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
92 |