-
Notifications
You must be signed in to change notification settings - Fork 0
/
subset_id.jl
243 lines (209 loc) · 6.88 KB
/
subset_id.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
"""
in_core(; ix, iy, topcut, bottomcut, leftcut, rightcut)::Bool
Returns true if cell indexed `ix`, `iy` lie inside the core.
"""
function in_core(; ix, iy, topcut, bottomcut, leftcut, rightcut)::Bool
return bottomcut + 1 < iy < topcut + 2 && leftcut + 1 < ix < rightcut + 2
end
"""
in_sol(; iy, topcut, kwargs...)::Bool
Returns true if cell indexed `ix`, `iy` lie inside the SOL.
"""
in_sol(; iy, topcut, kwargs...)::Bool = topcut + 1 < iy
"""
in_idr(; ix, iy, topcut, bottomcut, leftcut, kwargs...)::Bool
Returns true if cell indexed `ix`, `iy` lie inside the inner divertor region.
"""
function in_idr(; ix, iy, topcut, bottomcut, leftcut, kwargs...)::Bool
return bottomcut + 1 < iy < topcut + 2 && ix < leftcut + 2
end
"""
in_odr(; ix, iy, topcut, bottomcut, rightcut, kwargs...)::Bool
Returns true if cell indexed `ix`, `iy` lie inside the outer divertor region.
"""
function in_odr(; ix, iy, topcut, bottomcut, rightcut, kwargs...)::Bool
return bottomcut + 1 < iy < topcut + 2 && rightcut + 1 < ix
end
"""
is_x_aligned(;boundary_ind)::Bool
x\\_aligned edges will have odd `boundary_ind` based on chosen order of numbering them.
"""
is_x_aligned(; boundary_ind)::Bool = mod(boundary_ind, 2) == 1
"""
is_y_aligned(; boundary_ind)::Bool
y\\_aligned edges will have even `boundary_ind` based on chosen order of numbering them.
"""
is_y_aligned(; boundary_ind)::Bool = mod(boundary_ind, 2) == 0
"""
is_core_cut(;
ix,
iy,
cells,
nx,
boundary_ind,
topcut,
bottomcut,
leftcut,
rightcut,
)::Bool
Returns true if `boundary_ind` of a cell at `ix`, `iy` is on core\\_cut (Y-aliged edge).
"""
function is_core_cut(;
ix,
iy,
cells,
nx,
boundary_ind,
topcut,
bottomcut,
leftcut,
rightcut,
)::Bool
if bottomcut + 1 < iy < topcut + 2 && ix == leftcut + 2 && mod(boundary_ind, 2) == 0
ixr = rightcut + 1
this_cell = cells[xytoc(ix, iy; nx=nx)]
# Cell on the other side of core cut
other_side_cell_ind = xytoc(ixr, iy; nx=nx)
return other_side_cell_ind ∈ this_cell.boundary[boundary_ind].neighbours
end
return false
end
"""
is_pfr_cut(;
ix,
iy,
cells,
nx,
boundary_ind,
topcut,
bottomcut,
leftcut,
rightcut,
)::Bool
Returns true if `boundary_ind` of a cell at `ix`, `iy` is on core_cut (y-aliged edge).
"""
function is_pfr_cut(;
ix,
iy,
cells,
nx,
boundary_ind,
topcut,
bottomcut,
leftcut,
rightcut,
)::Bool
if bottomcut + 1 < iy < topcut + 2 && ix == leftcut + 1 && mod(boundary_ind, 2) == 0
ixr = rightcut + 2
this_cell = cells[xytoc(ix, iy; nx=nx)]
other_side_cell_ind = xytoc(ixr, iy; nx=nx) # Cell on the other side of pfr cut
return other_side_cell_ind ∈ this_cell.boundary[boundary_ind].neighbours
end
return false
end
"""
is_outer_throat(; ix, iy, boundary_ind, topcut, rightcut, kwargs...)::Bool
Returns true if `boundary_ind` of a cell at `ix`, `iy` is on outer throat.
"""
function is_outer_throat(; ix, iy, boundary_ind, topcut, rightcut, kwargs...)::Bool
return topcut + 1 < iy && ix == rightcut + 1 && boundary_ind == 2
end
"""
is_inner_throat(; ix, iy, boundary_ind, topcut, leftcut, kwargs...)::Bool
Returns true if `boundary_ind` of a cell at `ix`, `iy` is on outer throat.
"""
function is_inner_throat(; ix, iy, boundary_ind, topcut, leftcut, kwargs...)::Bool
return topcut + 1 < iy && ix == leftcut + 2 && boundary_ind == 4
end
"""
is_outer_midplane(; ix, jxa, boundary_ind)
Returns true if `boundary_ind` of a cell at `ix`, `iy` is on outer midplane.
"""
function is_outer_midplane(; ix, iy, jxa, boundary_ind, topcut, kwargs...)::Bool
# Note: USING CONVENTION to mark bottom edge of the midplane cell as midplane
return ix == jxa && boundary_ind == 2
end
"""
is_inner_midplane(; ix, jxa, boundary_ind)
Returns true if `boundary_ind` of a cell at `ix`, `iy` is on outer midplane.
"""
function is_inner_midplane(; ix, iy, jxi, boundary_ind, topcut, kwargs...)::Bool
# Note: USING CONVENTION to mark bottom edge of the midplane cell as midplane
return ix == jxi && boundary_ind == 4
end
"""
is_outer_target(; ix, nx, boundary_ind)
Returns true if `boundary_ind` of a cell at `ix`, `iy` is on outer target.
"""
is_outer_target(; ix, nx, boundary_ind) = ix == nx && boundary_ind == 2
"""
is_inner_target(; ix, boundary_ind, kwargs...)::Bool
Returns true if `boundary_ind` of a cell at `ix`, `iy` is on inner target.
"""
is_inner_target(; ix, boundary_ind) = ix == 1 && boundary_ind == 4
"""
is_core_boundary(;
ix,
iy,
boundary_ind,
bottomcut,
leftcut,
rightcut,
kwargs...,
)
Returns true if `boundary_ind` of a cell at `ix`, `iy` is on core boundary (central
blank spot boundary).
"""
function is_core_boundary(;
ix,
iy,
boundary_ind,
bottomcut,
leftcut,
rightcut,
kwargs...,
)
return bottomcut + 2 == iy && leftcut + 1 < ix < rightcut + 2 && boundary_ind == 1
end
"""
is_separatrix(; iy, boundary_ind, topcut, kwargs...)::Bool
Returns true if `boundary_ind` of a cell at `ix`, `iy` is on separatrix.
"""
function is_separatrix(; iy, boundary_ind, topcut, kwargs...)::Bool
return topcut + 2 == iy && boundary_ind == 1
end
"""
get_xpoint_nodes(
gmtry::Dict{String, Dict{String, Any}},
)::Vector{Vector{Vector{Float64}}}
Limited to finding first x-point for now. Returns x-point (r, z) for each time index of
grid\\_ggd for the first x-point only. Thus second index correspond to the rank of x-point
which is always 1 from output of this function for now.
"""
function get_xpoint_nodes(
gmtry::Dict{String, Dict{String, Any}},
)::Vector{Vector{Vector{Float64}}}
crx = gmtry["data"]["crx"]
cry = gmtry["data"]["cry"]
nt = gmtry["dim"]["time"]
# Find cells around x-point
xpcells = [(gmtry["data"]["topcut"][1] + 1, gmtry["data"]["leftcut"][1] + 1),
(gmtry["data"]["topcut"][1] + 1, gmtry["data"]["leftcut"][1] + 2),
(gmtry["data"]["topcut"][1] + 2, gmtry["data"]["leftcut"][1] + 1),
(gmtry["data"]["topcut"][1] + 2, gmtry["data"]["leftcut"][1] + 2),
(gmtry["data"]["topcut"][1] + 1, gmtry["data"]["rightcut"][1] + 1),
(gmtry["data"]["topcut"][1] + 1, gmtry["data"]["rightcut"][1] + 2),
(gmtry["data"]["topcut"][1] + 2, gmtry["data"]["rightcut"][1] + 1),
(gmtry["data"]["topcut"][1] + 2, gmtry["data"]["rightcut"][1] + 2)]
# Get list of all nodes in these cells
candidate_nodes = [
[
[
[crx[it, icorner, iy, ix], cry[it, icorner, iy, ix]] for icorner ∈ 1:4
] for (iy, ix) ∈ xpcells
] for it ∈ 1:nt
]
# Find the node that is common among all the cells
xpoint_nodes = [intersect(candidate_nodes[it]...) for it ∈ 1:nt]
return xpoint_nodes
end