comparison src/Grids/tensor_grid.jl @ 1480:4550beef9694 feature/boundary_conditions

Merge with default
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Sat, 23 Dec 2023 23:03:13 +0100
parents de4e15924d26
children d9d9ab18cdfc 611ae2308aa1
comparison
equal deleted inserted replaced
1479:b96858a50e35 1480:4550beef9694
41 Base.iterate(g::TensorGrid, state) = iterate(Iterators.product(g.grids...), state) |> _iterate_combine_coords 41 Base.iterate(g::TensorGrid, state) = iterate(Iterators.product(g.grids...), state) |> _iterate_combine_coords
42 _iterate_combine_coords(::Nothing) = nothing 42 _iterate_combine_coords(::Nothing) = nothing
43 _iterate_combine_coords((next,state)) = combine_coordinates(next...), state 43 _iterate_combine_coords((next,state)) = combine_coordinates(next...), state
44 44
45 Base.IteratorSize(::Type{<:TensorGrid{<:Any, D}}) where D = Base.HasShape{D}() 45 Base.IteratorSize(::Type{<:TensorGrid{<:Any, D}}) where D = Base.HasShape{D}()
46 Base.eltype(::Type{<:TensorGrid{T}}) where T = T 46 Base.length(g::TensorGrid) = prod(length, g.grids)
47 Base.length(g::TensorGrid) = sum(length, g.grids)
48 Base.size(g::TensorGrid) = LazyTensors.concatenate_tuples(size.(g.grids)...) 47 Base.size(g::TensorGrid) = LazyTensors.concatenate_tuples(size.(g.grids)...)
48 Base.size(g::TensorGrid, d) = size(g)[d]
49 49
50 50
51 refine(g::TensorGrid, r::Int) = mapreduce(g->refine(g,r), TensorGrid, g.grids) 51 refine(g::TensorGrid, r::Int) = mapreduce(g->refine(g,r), TensorGrid, g.grids)
52 coarsen(g::TensorGrid, r::Int) = mapreduce(g->coarsen(g,r), TensorGrid, g.grids) 52 coarsen(g::TensorGrid, r::Int) = mapreduce(g->coarsen(g,r), TensorGrid, g.grids)
53 53
71 return map(bid -> TensorGridBoundary{i, typeof(bid)}(), boundary_identifiers(g.grids[i])) 71 return map(bid -> TensorGridBoundary{i, typeof(bid)}(), boundary_identifiers(g.grids[i]))
72 end 72 end
73 return LazyTensors.concatenate_tuples(per_grid...) 73 return LazyTensors.concatenate_tuples(per_grid...)
74 end 74 end
75 75
76
77 """ 76 """
78 boundary_grid(g::TensorGrid, id::TensorGridBoundary) 77 boundary_grid(g::TensorGrid, id::TensorGridBoundary)
79 78
80 The grid for the boundary of `g` specified by `id`. 79 The grid for the boundary of `g` specified by `id`.
81 """ 80 """
83 local_boundary_grid = boundary_grid(g.grids[grid_id(id)], boundary_id(id)) 82 local_boundary_grid = boundary_grid(g.grids[grid_id(id)], boundary_id(id))
84 new_grids = Base.setindex(g.grids, local_boundary_grid, grid_id(id)) 83 new_grids = Base.setindex(g.grids, local_boundary_grid, grid_id(id))
85 return TensorGrid(new_grids...) 84 return TensorGrid(new_grids...)
86 end 85 end
87 86
87 function boundary_indices(g::TensorGrid, id::TensorGridBoundary)
88 per_grid_ind = map(g.grids) do g
89 ntuple(i->:, ndims(g))
90 end
91
92 local_b_ind = boundary_indices(g.grids[grid_id(id)], boundary_id(id))
93 b_ind = Base.setindex(per_grid_ind, local_b_ind, grid_id(id))
94
95 return LazyTensors.concatenate_tuples(b_ind...)
96 end
88 97
89 function combined_coordinate_vector_type(coordinate_types...) 98 function combined_coordinate_vector_type(coordinate_types...)
90 combined_coord_length = mapreduce(_ncomponents, +, coordinate_types) 99 combined_coord_length = mapreduce(_ncomponents, +, coordinate_types)
91 combined_coord_type = mapreduce(eltype, promote_type, coordinate_types) 100 combined_coord_type = mapreduce(eltype, promote_type, coordinate_types)
92 101