Mercurial > repos > public > sbplib_julia
annotate src/Grids/curvilinear_grid.jl @ 1449:a0b1449dba4e feature/grids/curvilinear
Remove commented code
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 23 Nov 2023 10:14:48 +0100 |
parents | 1656228095b5 |
children | 647c8b18b84f |
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 |
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 # # Iteration interface |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
22 # 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
|
23 # 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
|
24 # _iterate_combine_coords(::Nothing) = nothing |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
25 # _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
|
26 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
27 # 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
|
28 # Base.eltype(::Type{<:TensorGrid{T}}) where T = T |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
29 # Base.length(g::TensorGrid) = sum(length, g.grids) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
30 # 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
|
31 |
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 # 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
|
34 # 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
|
35 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
36 # """ |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
37 # TensorGridBoundary{N, BID} <: BoundaryIdentifier |
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 # 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
|
40 # 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
|
41 # """ |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
42 # struct TensorGridBoundary{N, BID} <: BoundaryIdentifier end |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
43 # 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
|
44 # 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
|
45 |
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 # boundary_identifiers(g::TensorGrid) |
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 # 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
|
50 # """ |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
51 # function boundary_identifiers(g::TensorGrid) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
52 # per_grid = map(eachindex(g.grids)) do i |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
53 # 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
|
54 # end |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
55 # return LazyTensors.concatenate_tuples(per_grid...) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
56 # end |
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 # """ |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
60 # boundary_grid(g::TensorGrid, id::TensorGridBoundary) |
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 # 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
|
63 # """ |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
64 # function boundary_grid(g::TensorGrid, id::TensorGridBoundary) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
65 # 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
|
66 # 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
|
67 # return TensorGrid(new_grids...) |
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 |
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 |
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 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
77 # 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
|
78 # 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
|
79 # entries in the jacobian. |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
80 |