comparison src/Grids/mapped_grid.jl @ 1954:b0915f43b122 feature/sbp_operators/laplace_curvilinear

Merge feature/grids/geometry_functions
author Jonatan Werpers <jonatan@werpers.com>
date Sat, 08 Feb 2025 09:38:58 +0100
parents e97f4352b8d0
children
comparison
equal deleted inserted replaced
1953:835b1dcee38e 1954:b0915f43b122
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 """
96 """ 96 mapped_grid(x, J, size...)
97 mapped_grid(x, J, size::Vararg{Int})
98 97
99 A `MappedGrid` with a default logical grid on the D-dimensional unit hyper 98 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 99 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. 100 and `size` determines the size of the logical grid.
102 """ 101 """
103 function mapped_grid(x, J, size::Vararg{Int}) 102 function mapped_grid(x, J, size::Vararg{Int})
104 D = length(size) 103 D = length(size)
105 lg = equidistant_grid(ntuple(i->0., D), ntuple(i->1., D), size...) 104 return mapped_grid(x, J, unithyperbox(D), size...)
106 return mapped_grid(lg, x, J) 105 end
107 end 106
108 107 """
109 """ 108 mapped_grid(x, J, lg::Grid)
110 mapped_grid(lg::Grid, x, J)
111 109
112 A `MappedGrid` with logical grid `lg`. Physical coordinates and Jacobian are 110 A `MappedGrid` with logical grid `lg`. Physical coordinates and Jacobian are
113 determined by the functions `x` and `J`. 111 determined by the functions `x` and `J`.
114 """ 112 """
115 function mapped_grid(lg::Grid, x, J) 113 function mapped_grid(x, J, lg::Grid)
116 return MappedGrid( 114 return MappedGrid(
117 lg, 115 lg,
118 map(x,lg), 116 map(x,lg),
119 map(J,lg), 117 map(J,lg),
120 ) 118 )
121 end 119 end
122 120
123 """ 121 """
122 mapped_grid(x, J, ps::ParameterSpace, size...)
123
124 A `MappedGrid` with logical grid `lg`. Physical coordinates and Jacobian are
125 determined by the functions `x` and `J`.
126 """
127 function mapped_grid(x, J, ps::ParameterSpace, size::Vararg{Int})
128 lg = equidistant_grid(ps, size...)
129 return mapped_grid(x, J, lg)
130 end
131
132 """
124 metric_tensor(g::MappedGrid) 133 metric_tensor(g::MappedGrid)
125 134
126 The metric tensor of `g` as a grid function. 135 The metric tensor of `g` as a grid function.
127 """ 136 """
128 function metric_tensor(g::MappedGrid) 137 function metric_tensor(g::MappedGrid)
169 normal(g::MappedGrid, boundary) 178 normal(g::MappedGrid, boundary)
170 179
171 The outward pointing normal as a grid function on the corresponding boundary grid. 180 The outward pointing normal as a grid function on the corresponding boundary grid.
172 """ 181 """
173 function normal(g::MappedGrid, boundary) 182 function normal(g::MappedGrid, boundary)
174 b_indices = boundary_indices(g, boundary) 183 return map(boundary_indices(g, boundary)) do I
175 σ = _boundary_sign(component_type(g), boundary) 184 normal(g, boundary, Tuple(I)...)
176 return map(jacobian(g)[b_indices...]) do ∂x∂ξ 185 end
177 ∂ξ∂x = inv(∂x∂ξ) 186 end
178 k = grid_id(boundary) 187
179 σ*∂ξ∂x[k,:]/norm(∂ξ∂x[k,:]) 188 """
180 end 189 normal(g::MappedGrid, boundary, i...)
181 end 190
182 191 The outward pointing normal to the specified boundary in grid point `i`.
192 """
183 function normal(g::MappedGrid, boundary, i...) 193 function normal(g::MappedGrid, boundary, i...)
184 σ = _boundary_sign(component_type(g), boundary) 194 σ = _boundary_sign(component_type(g), boundary)
185 ∂ξ∂x = inv(jacobian(g)[i...]) 195 ∂ξ∂x = inv(jacobian(g)[i...])
186 196
187 k = grid_id(boundary) 197 k = grid_id(boundary)