Mercurial > repos > public > sbplib_julia
comparison src/Grids/manifolds.jl @ 2008:df2cbcb7a2b1 default
Merge feature/grids/manifolds
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 01 May 2025 15:05:11 +0200 |
parents | a1b2453c02c9 |
children |
comparison
equal
deleted
inserted
replaced
2005:52e5ab4a96d5 | 2008:df2cbcb7a2b1 |
---|---|
1 """ | |
2 Chart{D} | |
3 | |
4 A parametrized description of a manifold or part of a manifold. | |
5 """ | |
6 struct Chart{D, PST<:ParameterSpace{D}, MT} | |
7 mapping::MT | |
8 parameterspace::PST | |
9 end | |
10 | |
11 Base.ndims(::Chart{D}) where D = D | |
12 parameterspace(c::Chart) = c.parameterspace | |
13 | |
14 function (c::Chart)(ξ) | |
15 if ξ ∉ parameterspace(c) | |
16 throw(DomainError(ξ, "chart was called logical coordinates outside the parameterspace. If this was inteded, use the `mapping` field from the Chart struct instead.")) | |
17 end | |
18 return c.mapping(ξ) | |
19 end | |
20 | |
21 """ | |
22 jacobian(c::Chart, ξ) | |
23 | |
24 The jacobian of the mapping evaluated at `ξ`. This defers to the | |
25 implementation of `jacobian` for the mapping itself. If no implementation is | |
26 available one can easily be specified for either the mapping function or the | |
27 chart itself. | |
28 ```julia | |
29 c = Chart(f, ps) | |
30 jacobian(f::typeof(f), ξ) = f′(ξ) | |
31 ``` | |
32 or | |
33 ```julia | |
34 c = Chart(f, ps) | |
35 jacobian(c::typeof(c),ξ) = f′(ξ) | |
36 ``` | |
37 which will both allow calling `jacobian(c,ξ)`. | |
38 """ | |
39 function jacobian(c::Chart, ξ) | |
40 if ξ ∉ parameterspace(c) | |
41 throw(DomainError(ξ, "jacobian was called with logical coordinates outside the parameterspace of the chart. If this was inteded, use the `mapping` field from the Chart struct instead.")) | |
42 end | |
43 return jacobian(c.mapping, ξ) | |
44 end | |
45 | |
46 boundary_identifiers(c::Chart) = boundary_identifiers(parameterspace(c)) | |
47 | |
48 | |
49 """ | |
50 Atlas | |
51 | |
52 A collection of charts and their connections. | |
53 Should implement methods for `charts` and `connections`. | |
54 """ | |
55 abstract type Atlas end | |
56 | |
57 """ | |
58 charts(::Atlas) | |
59 | |
60 The colloction of charts in the atlas. | |
61 """ | |
62 function charts end | |
63 | |
64 """ | |
65 connections(::Atlas) | |
66 | |
67 Collection of 2-tuples of multiblock boundary identifiers. | |
68 """ | |
69 function connections end | |
70 | |
71 | |
72 """ | |
73 CartesianAtlas{D,C<:Chart,AT<:AbstractArray{C,D}} <: Atlas | |
74 | |
75 An atlas where the charts are arranged and connected like an array. | |
76 """ | |
77 struct CartesianAtlas{D,C<:Chart,AT<:AbstractArray{C,D}} <: Atlas | |
78 charts::AT | |
79 end | |
80 | |
81 charts(a::CartesianAtlas) = a.charts | |
82 | |
83 function connections(a::CartesianAtlas) | |
84 c = Tuple{MultiBlockBoundary, MultiBlockBoundary}[] | |
85 | |
86 for d ∈ 1:ndims(charts(a)) | |
87 Is = eachslice(CartesianIndices(charts(a)); dims=d) | |
88 for i ∈ 1:length(Is)-1 # For each interface between slices | |
89 for jk ∈ eachindex(Is[i]) # For each block in slice | |
90 Iᵢⱼₖ = Tuple(Is[i][jk]) | |
91 Iᵢ₊₁ⱼₖ = Tuple(Is[i+1][jk]) | |
92 push!(c, | |
93 ( | |
94 MultiBlockBoundary{Iᵢⱼₖ, CartesianBoundary{d,UpperBoundary}}(), | |
95 MultiBlockBoundary{Iᵢ₊₁ⱼₖ, CartesianBoundary{d,LowerBoundary}}(), | |
96 ) | |
97 ) | |
98 end | |
99 end | |
100 end | |
101 | |
102 return c | |
103 end | |
104 | |
105 """ | |
106 boundary_identifiers(a::CartesianAtlas) | |
107 | |
108 All non-connected boundaries of the charts of `a`. | |
109 """ | |
110 function boundary_identifiers(a::CartesianAtlas) | |
111 bs = MultiBlockBoundary[] | |
112 | |
113 for d ∈ 1:ndims(charts(a)) | |
114 Is = eachslice(CartesianIndices(charts(a)); dims=d) | |
115 | |
116 for (i,b) ∈ ((1,LowerBoundary),(length(Is),UpperBoundary)) # For first and last slice | |
117 for jk ∈ eachindex(Is[i]) # For each block in slice | |
118 Iᵢⱼₖ = Tuple(Is[i][jk]) | |
119 push!(bs, | |
120 MultiBlockBoundary{Iᵢⱼₖ, CartesianBoundary{d,b}}(), | |
121 ) | |
122 end | |
123 end | |
124 end | |
125 | |
126 return bs | |
127 end | |
128 | |
129 | |
130 """ | |
131 UnstructuredAtlas{C<:Chart, CN<:Tuple{MultiBlockBoundary,MultiBlockBoundary}, ...} <: Atlas | |
132 | |
133 An atlas with connections determined by a vector `MultiBlockBoundary` pairs. | |
134 """ | |
135 struct UnstructuredAtlas{C<:Chart, CN<:Tuple{MultiBlockBoundary,MultiBlockBoundary}, CV<:AbstractVector{C}, CNV<:AbstractVector{CN}} <: Atlas | |
136 charts::CV | |
137 connections::CNV | |
138 end | |
139 | |
140 charts(a::UnstructuredAtlas) = a.charts | |
141 connections(a::UnstructuredAtlas) = a.connections | |
142 | |
143 """ | |
144 boundary_identifiers(a::UnstructuredAtlas) | |
145 | |
146 All non-connected boundaries of the charts of `a`. | |
147 """ | |
148 function boundary_identifiers(a::UnstructuredAtlas) | |
149 bs = MultiBlockBoundary[] | |
150 | |
151 for (i,c) ∈ enumerate(charts(a)) | |
152 for b ∈ boundary_identifiers(c) | |
153 mbb = MultiBlockBoundary{i,typeof(b)}() | |
154 | |
155 if !any(cn->mbb∈cn, connections(a)) | |
156 push!(bs, mbb) | |
157 end | |
158 end | |
159 end | |
160 | |
161 return bs | |
162 end |