Mercurial > repos > public > sbplib_julia
comparison src/Grids/mapped_grid.jl @ 1877:21e5fe1545c0 refactor/lazy_tensors/elementwise_ops
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 27 Jan 2025 16:56:04 +0100 |
parents | 516eaabf1169 |
children | edee7d677efb f93ba5832146 |
comparison
equal
deleted
inserted
replaced
1840:cb3a8450ed44 | 1877:21e5fe1545c0 |
---|---|
80 all_indices = SVector{D}(1:D) | 80 all_indices = SVector{D}(1:D) |
81 free_variable_indices = deleteat(all_indices, grid_id(id)) | 81 free_variable_indices = deleteat(all_indices, grid_id(id)) |
82 jacobian_components = (:, free_variable_indices) | 82 jacobian_components = (:, free_variable_indices) |
83 | 83 |
84 # Create grid function for boundary grid jacobian | 84 # Create grid function for boundary grid jacobian |
85 boundary_jacobian = componentview((@view g.jacobian[b_indices...]) , jacobian_components...) | 85 boundary_jacobian = componentview((@view g.jacobian[b_indices]) , jacobian_components...) |
86 boundary_physicalcoordinates = @view g.physicalcoordinates[b_indices...] | 86 boundary_physicalcoordinates = @view g.physicalcoordinates[b_indices] |
87 | 87 |
88 return MappedGrid( | 88 return MappedGrid( |
89 boundary_grid(g.logical_grid, id), | 89 boundary_grid(g.logical_grid, id), |
90 boundary_physicalcoordinates, | 90 boundary_physicalcoordinates, |
91 boundary_jacobian, | 91 boundary_jacobian, |
92 ) | 92 ) |
93 end | 93 end |
94 | 94 |
95 | 95 # TODO: Make sure all methods of `mapped_grid` are implemented correctly and tested. |
96 """ | 96 """ |
97 mapped_grid(x, J, size::Vararg{Int}) | 97 mapped_grid(x, J, size::Vararg{Int}) |
98 | 98 |
99 A `MappedGrid` with a default logical grid on the D-dimensional unit hyper | 99 A `MappedGrid` with a default logical grid on the D-dimensional unit hyper |
100 box [0,1]ᴰ. `x` and `J`are functions to be evaluated on the logical grid | 100 box [0,1]ᴰ. `x` and `J` are functions to be evaluated on the logical grid |
101 and `size` determines the size of the logical grid. | 101 and `size` determines the size of the logical grid. |
102 """ | 102 """ |
103 function mapped_grid(x, J, size::Vararg{Int}) | 103 function mapped_grid(x, J, size::Vararg{Int}) |
104 D = length(size) | 104 D = length(size) |
105 lg = equidistant_grid(ntuple(i->0., D), ntuple(i->1., D), size...) | 105 lg = equidistant_grid(ntuple(i->0., D), ntuple(i->1., D), size...) # TODO: Clean this up with ParamaterSpace once feature/grids/manifolds is merged |
106 return mapped_grid(lg, x, J) | 106 return mapped_grid(x, J, lg) |
107 end | 107 end |
108 | 108 |
109 """ | 109 """ |
110 mapped_grid(lg::Grid, x, J) | 110 mapped_grid(x, J, lg::Grid) |
111 | 111 |
112 A `MappedGrid` with logical grid `lg`. Physical coordinates and Jacobian are | 112 A `MappedGrid` with logical grid `lg`. Physical coordinates and Jacobian are |
113 determined by the functions `x` and `J`. | 113 determined by the functions `x` and `J`. |
114 """ | 114 """ |
115 function mapped_grid(lg::Grid, x, J) | 115 function mapped_grid(x, J, lg::Grid) |
116 return MappedGrid( | 116 return MappedGrid( |
117 lg, | 117 lg, |
118 map(x,lg), | 118 map(x,lg), |
119 map(J,lg), | 119 map(J,lg), |
120 ) | 120 ) |
121 end | 121 end |
122 | 122 |
123 """ | 123 """ |
124 mapped_grid(x, J, parameterspace, size) | |
125 | |
126 A `MappedGrid` with logical grid `lg`. Physical coordinates and Jacobian are | |
127 determined by the functions `x` and `J`. | |
128 """ | |
129 function mapped_grid(x, J, parameterspace, size::Vararg{Int}) | |
130 lg = equidistant_grid(parameterspace, size...) | |
131 return mapped_grid(x, J, lg) | |
132 end | |
133 | |
134 """ | |
124 metric_tensor(g::MappedGrid) | 135 metric_tensor(g::MappedGrid) |
125 | 136 |
126 The metric tensor of `g` as a grid function. | 137 The metric tensor of `g` as a grid function. |
127 """ | 138 """ |
128 function metric_tensor(g::MappedGrid) | 139 function metric_tensor(g::MappedGrid) |
169 normal(g::MappedGrid, boundary) | 180 normal(g::MappedGrid, boundary) |
170 | 181 |
171 The outward pointing normal as a grid function on the corresponding boundary grid. | 182 The outward pointing normal as a grid function on the corresponding boundary grid. |
172 """ | 183 """ |
173 function normal(g::MappedGrid, boundary) | 184 function normal(g::MappedGrid, boundary) |
174 b_indices = boundary_indices(g, boundary) | 185 return map(boundary_indices(g, boundary)) do I |
175 σ = _boundary_sign(component_type(g), boundary) | 186 normal(g, boundary, Tuple(I)...) |
176 | |
177 # TODO: Refactor this when `boundary_indices(g, ...)` has been made iterable. | |
178 return map(jacobian(g)[b_indices...]) do ∂x∂ξ | |
179 ∂ξ∂x = inv(∂x∂ξ) | |
180 k = grid_id(boundary) | |
181 σ*∂ξ∂x[k,:]/norm(∂ξ∂x[k,:]) | |
182 end | 187 end |
183 end | 188 end |
184 | 189 |
185 """ | 190 """ |
186 normal(g::MappedGrid, boundary, i...) | 191 normal(g::MappedGrid, boundary, i...) |