Mercurial > repos > public > sbplib_julia
annotate src/Grids/curvilinear_grid.jl @ 1430:9fc3c1af33e5 feature/grids/curvilinear
Add testsets and a few tests
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 26 Jul 2023 21:00:44 +0200 |
parents | 9c689a627244 |
children | 6adf31ba6cfd |
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 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
4 Jacobian::JT |
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 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
7 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
8 # Indexing interface |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
9 Base.getindex(g::CurvilinearGrid, I...) = g.physicalcoordinates[I...] |
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 # function Base.getindex(g::TensorGrid, I...) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
12 # szs = ndims.(g.grids) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
13 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
14 # Is = LazyTensors.split_tuple(I, szs) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
15 # 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
|
16 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
17 # return vcat(ps...) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
18 # end |
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 # function Base.eachindex(g::TensorGrid) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
21 # szs = LazyTensors.concatenate_tuples(size.(g.grids)...) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
22 # return CartesianIndices(szs) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
23 # end |
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 # # Iteration interface |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
26 # 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
|
27 # 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
|
28 # _iterate_combine_coords(::Nothing) = nothing |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
29 # _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
|
30 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
31 # 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
|
32 # Base.eltype(::Type{<:TensorGrid{T}}) where T = T |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
33 # Base.length(g::TensorGrid) = sum(length, g.grids) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
34 # 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
|
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 # 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
|
38 # 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
|
39 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
40 # """ |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
41 # TensorGridBoundary{N, BID} <: BoundaryIdentifier |
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 # 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
|
44 # 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
|
45 # """ |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
46 # struct TensorGridBoundary{N, BID} <: BoundaryIdentifier end |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
47 # 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
|
48 # 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
|
49 |
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 # boundary_identifiers(g::TensorGrid) |
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 # 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
|
54 # """ |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
55 # function boundary_identifiers(g::TensorGrid) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
56 # per_grid = map(eachindex(g.grids)) do i |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
57 # 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
|
58 # end |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
59 # return LazyTensors.concatenate_tuples(per_grid...) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
60 # end |
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 |
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 # boundary_grid(g::TensorGrid, id::TensorGridBoundary) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
65 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
66 # 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
|
67 # """ |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
68 # function boundary_grid(g::TensorGrid, id::TensorGridBoundary) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
69 # 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
|
70 # 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
|
71 # return TensorGrid(new_grids...) |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
72 # end |
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 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
78 |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
79 |
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 # 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
|
82 # 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
|
83 # entries in the jacobian. |
9fc3c1af33e5
Add testsets and a few tests
Jonatan Werpers <jonatan@werpers.com>
parents:
1426
diff
changeset
|
84 |