comparison src/Grids/geometry.jl @ 2074:8fe7233067fb feature/sbp_operators/laplace_curvilinear

Merge feature/grids/geometry_functions
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 17 Feb 2026 21:01:50 +0100
parents bc09d0bfac65
children 6797a6cb1da7
comparison
equal deleted inserted replaced
2055:274f4c1ce4b5 2074:8fe7233067fb
3 tangent::PT 3 tangent::PT
4 4
5 Line{PT}(p::PT, tangent::PT) where PT = new{PT}(p,tangent) 5 Line{PT}(p::PT, tangent::PT) where PT = new{PT}(p,tangent)
6 end 6 end
7 7
8
8 """ 9 """
9 Line(p,t) 10 Line(p,t)
10 11
11 A line, as a callable object, starting at `p` with tangent `t`. 12 A line, as a callable object, starting at `p` with tangent `t`.
13 The parametrization is ``l(s) = p + st``.
12 14
13 # Example 15 # Example
14 ```julia-repl 16 ```julia-repl
15 julia> l = Grids.Line([1,1],[2,1]) 17 julia> l = Grids.Line([1,1],[2,1])
16 Diffinitive.Grids.Line{StaticArraysCore.SVector{2, Int64}}([1, 1], [2, 1]) 18 Diffinitive.Grids.Line{StaticArraysCore.SVector{2, Int64}}([1, 1], [2, 1])
45 b::PT 47 b::PT
46 48
47 LineSegment{PT}(p::PT, tangent::PT) where PT = new{PT}(p,tangent) 49 LineSegment{PT}(p::PT, tangent::PT) where PT = new{PT}(p,tangent)
48 end 50 end
49 51
52
50 """ 53 """
51 LineSegment(a,b) 54 LineSegment(a,b)
52 55
53 A line segment, as a callable object, from `a` to `b`. 56 A line segment, as a callable object, from `a` to `b`.
57 The parametrization is ``l(s) = (1-s)a + s*b`` where ``s∈(0,1)``.
54 58
55 # Example 59 # Example
56 ```julia-repl 60 ```julia-repl
57 julia> l = Grids.LineSegment([1,1],[2,1]) 61 julia> l = Grids.LineSegment([1,1],[2,1])
58 Diffinitive.Grids.LineSegment{StaticArraysCore.SVector{2, Int64}}([1, 1], [2, 1]) 62 Diffinitive.Grids.LineSegment{StaticArraysCore.SVector{2, Int64}}([1, 1], [2, 1])
85 89
86 (c::LineSegment)(s) = (1-s)*c.a + s*c.b 90 (c::LineSegment)(s) = (1-s)*c.a + s*c.b
87 91
88 Grids.jacobian(c::LineSegment, s) = c.b - c.a 92 Grids.jacobian(c::LineSegment, s) = c.b - c.a
89 93
94
90 """ 95 """
91 linesegments(ps...) 96 linesegments(ps...)
92 97
93 An array of line segments between the points `ps[1]`, `ps[2]`, and so on. 98 An array of line segments between the points `ps[1]`, `ps[2]`, and so on.
94 99
109 """ 114 """
110 function polygon_edges(ps...) 115 function polygon_edges(ps...)
111 n = length(ps) 116 n = length(ps)
112 return [LineSegment(ps[i], ps[mod1(i+1,n)]) for i ∈ eachindex(ps)] 117 return [LineSegment(ps[i], ps[mod1(i+1,n)]) for i ∈ eachindex(ps)]
113 end 118 end
119
114 120
115 struct Circle{PT,T} 121 struct Circle{PT,T}
116 c::PT 122 c::PT
117 r::T 123 r::T
118 124
153 function Grids.jacobian(C::Circle, θ) 159 function Grids.jacobian(C::Circle, θ)
154 (;r) = C 160 (;r) = C
155 r*@SVector[-sin(θ), cos(θ)] 161 r*@SVector[-sin(θ), cos(θ)]
156 end 162 end
157 163
164
158 struct Arc{PT,T} 165 struct Arc{PT,T}
159 c::Circle{PT,T} 166 c::Circle{PT,T}
160 θ₀::T 167 θ₀::T
161 θ₁::T 168 θ₁::T
162 end 169 end
226 233
227 """ 234 """
228 TransfiniteInterpolationSurface(c₁, c₂, c₃, c₄) 235 TransfiniteInterpolationSurface(c₁, c₂, c₃, c₄)
229 236
230 A surface defined by the transfinite interpolation of the curves `c₁`, `c₂`, `c₃`, and `c₄`. 237 A surface defined by the transfinite interpolation of the curves `c₁`, `c₂`, `c₃`, and `c₄`.
238 The transfinite interpolation maps the unit square ([0,1]⊗[0,1]) to the patch delimited by the given curves.
239 The curves should encircle the patch counterclockwise.
240
241 See https://en.wikipedia.org/wiki/Transfinite_interpolation for more information on transfinite interpolation.
231 """ 242 """
232 struct TransfiniteInterpolationSurface{T1,T2,T3,T4} 243 struct TransfiniteInterpolationSurface{T1,T2,T3,T4}
233 c₁::T1 244 c₁::T1
234 c₂::T2 245 c₂::T2
235 c₃::T3 246 c₃::T3
236 c₄::T4 247 c₄::T4
237 end 248 end
238 249
239 function (s::TransfiniteInterpolationSurface)(u,v) 250 function (s::TransfiniteInterpolationSurface)(u,v)
251 if (u,v) ∉ unitsquare()
252 throw(DomainError((u,v), "Transfinite interpolation was called with parameters outside the unit square."))
253 end
240 c₁, c₂, c₃, c₄ = s.c₁, s.c₂, s.c₃, s.c₄ 254 c₁, c₂, c₃, c₄ = s.c₁, s.c₂, s.c₃, s.c₄
241 P₀₀ = c₁(0) 255 P₀₀ = c₁(0)
242 P₁₀ = c₂(0) 256 P₁₀ = c₂(0)
243 P₁₁ = c₃(0) 257 P₁₁ = c₃(0)
244 P₀₁ = c₄(0) 258 P₀₁ = c₄(0)
288 302
289 return true 303 return true
290 end 304 end
291 305
292 function Grids.jacobian(s::TransfiniteInterpolationSurface, ξ̄) 306 function Grids.jacobian(s::TransfiniteInterpolationSurface, ξ̄)
307 if ξ̄ ∉ unitsquare()
308 throw(DomainError(ξ̄, "Transfinite interpolation was called with parameters outside the unit square."))
309 end
293 u, v = ξ̄ 310 u, v = ξ̄
294 311
295 c₁, c₂, c₃, c₄ = s.c₁, s.c₂, s.c₃, s.c₄ 312 c₁, c₂, c₃, c₄ = s.c₁, s.c₂, s.c₃, s.c₄
296 P₀₀ = c₁(0) 313 P₀₀ = c₁(0)
297 P₁₀ = c₂(0) 314 P₁₀ = c₂(0)