Skip to content

misc

Geometry functions for PROCESS summary plots.

plot_fw_90_deg_pipe_bend(ax, m_file, scan)

Plot the first wall pipe 90 degree bend on the given axis, with axes in mm.

Parameters:

Name Type Description Default
ax
required
m_file
required
scan int
required
Source code in process/core/io/plot/summary/geometry/misc.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def plot_fw_90_deg_pipe_bend(ax, m_file, scan: int):
    """Plot the first wall pipe 90 degree bend on the given axis, with axes in mm.

    Parameters
    ----------
    ax :

    m_file :

    scan: int :

    """
    # Get pipe radius from m_file, fallback to 0.1 m
    r = m_file.get("radius_fw_channel", scan=scan)
    elbow_radius = m_file.get("radius_fw_channel_90_bend", scan=scan)

    draw_bend(
        ax,
        elbow_radius,
        np.pi / 2,
        r,
        title="First Wall Pipe 90° Bend",
        alpha=1.0,
    )

plot_blkt_pipe_bends(fig, m_file, scan)

Plot the blanket pipe bends on the given axis, with axes in mm.

Parameters:

Name Type Description Default
fig
required
m_file
required
scan int
required
Source code in process/core/io/plot/summary/geometry/misc.py
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
def plot_blkt_pipe_bends(fig, m_file, scan: int):
    """Plot the blanket pipe bends on the given axis, with axes in mm.

    Parameters
    ----------
    fig :

    m_file :

    scan: int :

    """
    ax_90 = fig.add_subplot(341)
    ax_180 = fig.add_subplot(342)

    r = m_file.get("radius_blkt_channel", scan=scan)
    fallback_radius = 0.1  # meters

    elbow_radius_90 = (
        m_file.get("radius_blkt_channel_90_bend", scan=scan) or fallback_radius
    )
    elbow_radius_180 = (
        m_file.get("radius_blkt_channel_180_bend", scan=scan) or fallback_radius
    )

    draw_bend(ax_90, elbow_radius_90, np.pi / 2, r, title="Blanket Pipe 90° Bend")
    draw_bend(ax_180, elbow_radius_180, np.pi, r, title="Blanket Pipe 180° Bend")

plot_blkt_structure(ax, fig, m_file, scan, radial_build, colour_scheme)

Plot the blkt structure and relevant angles

Source code in process/core/io/plot/summary/geometry/misc.py
 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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
def plot_blkt_structure(
    ax: plt.Axes,
    fig: plt.Figure,
    m_file: MFile,
    scan: int,
    radial_build: dict[str, float],
    colour_scheme: Literal[1, 2],
):
    """Plot the blkt structure and relevant angles"""
    # MFILE variables needed to plot the blkt structure and angles
    rmajor = m_file.get("rmajor", scan=scan)
    rminor = m_file.get("rminor", scan=scan)
    dr_fw_plasma_gap_outboard = m_file.get("dr_fw_plasma_gap_outboard", scan=scan)
    dr_fw_plasma_gap_inboard = m_file.get("dr_fw_plasma_gap_inboard", scan=scan)
    dr_fw_inboard = m_file.get("dr_fw_inboard", scan=scan)
    dr_fw_outboard = m_file.get("dr_fw_outboard", scan=scan)
    dr_blkt_outboard = m_file.get("dr_blkt_outboard", scan=scan)
    dr_blkt_inboard = m_file.get("dr_blkt_inboard", scan=scan)
    dz_blkt_half = m_file.get("dz_blkt_half", scan=scan)
    deg_blkt_outboard_poloidal_plasma = m_file.get(
        "deg_blkt_outboard_poloidal_plasma", scan=scan
    )
    deg_blkt_inboard_poloidal_plasma = m_file.get(
        "deg_blkt_inboard_poloidal_plasma", scan=scan
    )
    f_deg_blkt_outboard_poloidal_plasma = m_file.get(
        "f_deg_blkt_outboard_poloidal_plasma", scan=scan
    )
    f_deg_blkt_inboard_poloidal_plasma = m_file.get(
        "f_deg_blkt_inboard_poloidal_plasma", scan=scan
    )
    deg_div_poloidal_plasma = m_file.get("deg_div_poloidal_plasma", scan=scan)
    f_ster_div_single = m_file.get("f_ster_div_single", scan=scan)
    i_single_null = m_file.get("i_single_null", scan=scan)

    # ======================

    plot_blanket(ax, m_file, scan, radial_build, colour_scheme)
    plot_plasma(ax, m_file, scan, colour_scheme)
    plot_firstwall(ax, m_file, scan, radial_build, colour_scheme)

    ax.set_xlabel("Radial position [m]")
    ax.set_ylabel("Vertical position [m]")
    ax.set_title("Blanket and First Wall Poloidal Cross-Section")
    ax.minorticks_on()
    ax.grid(which="minor", linestyle=":", linewidth=0.5, alpha=0.5)

    r_blkt_outboard_out = (
        rmajor + rminor + dr_fw_outboard + dr_fw_plasma_gap_outboard + dr_blkt_outboard
    )
    r_blkt_inboard_in = (
        rmajor - rminor - dr_fw_plasma_gap_inboard - dr_fw_inboard - dr_blkt_inboard
    )
    r_fw_outboard_in = r_blkt_outboard_out - dr_blkt_outboard - dr_fw_outboard
    r_fw_inboard_out = r_blkt_inboard_in + dr_blkt_inboard + dr_fw_inboard

    # Plot a horizontal line at dz_blkt_half (blanket half height)
    for dz_blkt in (dz_blkt_half, -dz_blkt_half):
        ax.axhline(
            dz_blkt,
            color="purple",
            linestyle="--",
            linewidth=1.5,
            label="Blanket Half Height",
        )

    if DivertorNumberModels(i_single_null) == DivertorNumberModels.DOUBLE_NULL:
        # Plot arrows for the outboard blanket angles
        ax.annotate(
            "",
            xy=(rmajor, 0),
            xytext=(rmajor, dz_blkt_half),
            arrowprops={"arrowstyle": "<-", "color": "purple"},
            zorder=5,
        )
    # If single null then only plot the lower arrow for the outboard blanket angle
    ax.annotate(
        "",
        xy=(rmajor, 0),
        xytext=(rmajor, -dz_blkt_half),
        arrowprops={"arrowstyle": "<-", "color": "purple"},
        zorder=5,
    )

    # Plot arc showing the angle between the two outboard blanket arrows
    arc_radius = 1.0

    # 3 to 6 o'clock position is -90 degrees,
    angle_start = -90.0
    match DivertorNumberModels(i_single_null):
        case DivertorNumberModels.SINGLE_NULL:
            angle_end = 90.0 + deg_div_poloidal_plasma
        case DivertorNumberModels.DOUBLE_NULL:
            # 3 to 12 o'clock position is +90 degrees
            angle_end = 90.0

    theta = np.linspace(np.deg2rad(angle_start), np.deg2rad(angle_end), 50)
    arc_x = rmajor + arc_radius * np.cos(theta)
    arc_y = arc_radius * np.sin(theta)

    ax.plot(arc_x, arc_y, color="purple", linewidth=2)

    # Add angle label at the arc
    mid_angle = np.deg2rad((angle_start + angle_end) / 2)
    label_radius = arc_radius * 1.8
    label_x = rmajor + label_radius * np.cos(mid_angle)
    label_y = label_radius * np.sin(mid_angle)

    # Plot the info box for the outboard blanket
    ax.text(
        label_x,
        label_y,
        f"{deg_blkt_outboard_poloidal_plasma:.1f}°\n({f_deg_blkt_outboard_poloidal_plasma * 100:.1f}%)",  # noqa: E501
        fontsize=7,
        color="purple",
        ha="center",
        va="center",
        weight="bold",
        bbox={
            "boxstyle": "round",
            "facecolor": "white",
            "alpha": 0.8,
            "edgecolor": "purple",
            "linewidth": 1.5,
        },
    )

    # Plot arrows for the inboard blanket angles
    for dz_blkt in (dz_blkt_half, -dz_blkt_half):
        ax.annotate(
            "",
            xy=(rmajor, 0),
            xytext=(r_fw_inboard_out, dz_blkt),
            arrowprops={"arrowstyle": "<-", "color": "green"},
            zorder=5,
        )

    # Plot arc showing the angle between the two inboard blanket arrows
    arc_radius = 1.0
    angle_start = -deg_blkt_inboard_poloidal_plasma / 2
    angle_end = deg_blkt_inboard_poloidal_plasma / 2

    theta = np.linspace(np.deg2rad(angle_start), np.deg2rad(angle_end), 50)
    arc_x = rmajor - arc_radius * np.cos(theta)
    arc_y = arc_radius * np.sin(theta)

    ax.plot(arc_x, arc_y, color="green", linewidth=2)

    # Add angle label at the arc
    mid_angle = np.deg2rad((angle_start + angle_end) / 2)
    label_radius = arc_radius * 1.8
    label_x = rmajor - label_radius * np.cos(mid_angle)
    label_y = label_radius * np.sin(mid_angle)

    # Plot the info box for the inboard blanket
    ax.text(
        label_x,
        label_y,
        f"{deg_blkt_inboard_poloidal_plasma:.1f}°\n({f_deg_blkt_inboard_poloidal_plasma * 100:.1f}%)",  # noqa: E501
        fontsize=7,
        color="green",
        ha="center",
        va="center",
        weight="bold",
        bbox={
            "boxstyle": "round",
            "facecolor": "white",
            "alpha": 0.8,
            "edgecolor": "green",
            "linewidth": 1.5,
        },
        zorder=5,
    )

    # Plot arrows for the divertor angles
    # If double null then plot the upper also
    if DivertorNumberModels(i_single_null) == DivertorNumberModels.DOUBLE_NULL:
        # Plot arc showing the angle between the two arrows (divertor angle)
        arc_radius = 1.5
        # 3 to 12 o'clock position is +90 degrees,
        angle_start = 90.0
        angle_end = 90.0 + deg_div_poloidal_plasma

        theta = np.linspace(np.deg2rad(angle_start), np.deg2rad(angle_end), 50)
        arc_x = rmajor + arc_radius * np.cos(theta)
        arc_y = arc_radius * np.sin(theta)

        ax.plot(arc_x, arc_y, color="black", linewidth=2)

        # Add angle label at the arc
        mid_angle = np.deg2rad((angle_start + angle_end) / 2)
        label_radius = arc_radius * 1.8
        label_x = rmajor + label_radius * np.cos(mid_angle)
        label_y = label_radius * np.sin(mid_angle)

        ax.text(
            label_x,
            label_y,
            f"{deg_div_poloidal_plasma:.1f}°\n({f_ster_div_single * 100:.1f}%)",
            fontsize=7,
            color="black",
            ha="center",
            va="center",
            weight="bold",
            bbox=box_style("white", alpha=0.8, linewidth=1.5, edgecolor="black"),
            zorder=5,
        )

    # Plot arc showing the angle between the two arrows for the lower divertor (divertor
    # angle)
    arc_radius = 1.5
    # 3 to 6 o'clock is -90 degrees
    angle_start = -90.0
    angle_end = angle_start - deg_div_poloidal_plasma

    theta = np.linspace(np.deg2rad(angle_start), np.deg2rad(angle_end), 50)
    arc_x = rmajor + arc_radius * np.cos(theta)
    arc_y = arc_radius * np.sin(theta)

    ax.plot(arc_x, arc_y, color="black", linewidth=2)

    # Add angle label at the arc
    mid_angle = np.deg2rad((angle_start + angle_end) / 2)
    label_radius = arc_radius * 1.8
    label_x = rmajor + label_radius * np.cos(mid_angle)
    label_y = label_radius * np.sin(mid_angle)

    # Plot the info box for the lower divertor angle
    ax.text(
        label_x,
        label_y,
        f"{deg_div_poloidal_plasma:.1f}°\n({f_ster_div_single * 100:.1f}%)",
        fontsize=7,
        color="black",
        ha="center",
        va="center",
        weight="bold",
        bbox=box_style("white", alpha=0.8, linewidth=1.5, edgecolor="black"),
        zorder=5,
    )

    # Plot vertical lines at the inner and outer radial boundaries of the blanket
    linestyle = {
        "color": "black",
        "linestyle": "--",
        "linewidth": 1.5,
        "zorder": 10,
    }
    ax.axvline(r_blkt_inboard_in, **linestyle)
    ax.axvline(r_blkt_outboard_out, **linestyle)
    ax.axvline(r_fw_inboard_out, **linestyle)
    ax.axvline(r_fw_outboard_in, **linestyle)

    ax.axvline(
        rmajor,
        color="black",
        linestyle="--",
        linewidth=1.5,
        label="Major Radius $R_0$",
    )

    # Plot midplane line (horizontal dashed line at Z=0)
    ax.axhline(0.0, color="black", linestyle="--", linewidth=1.5, label="Midplane")

    textstr_blkt_areas = (
        "$\\mathbf{Blanket \\ Areas:}$\n\nInboard blanket, with holes and"
        f" gaps: {m_file.get('a_blkt_inboard_surface', scan=scan):,.3f}"
        " $\\text{m}^2$\nOutboard blanket, with holes and gaps:"
        f" {m_file.get('a_blkt_outboard_surface', scan=scan):,.3f}"
        " $\\text{m}^2$\nTotal blanket, with holes and gaps:"
        f" {m_file.get('a_blkt_total_surface', scan=scan):,.3f}"
        " $\\text{m}^2$\n\nInboard blanket, full coverage:"
        f" {m_file.get('a_blkt_inboard_surface_full_coverage', scan=scan):,.3f}"
        " $\\text{m}^2$\nOutboard blanket, full coverage:"
        f" {m_file.get('a_blkt_outboard_surface_full_coverage', scan=scan):,.3f}"
        " $\\text{m}^2$\nTotal blanket, full coverage:"
        f" {m_file.get('a_blkt_total_surface_full_coverage', scan=scan):,.3f}"
        " $\\text{m}^2$ "
    )

    ax.text(
        0.05,
        0.3,
        textstr_blkt_areas,
        **text_layout(fig),
        bbox=box_style("wheat"),
    )

    textstr_blkt_volumes = (
        "$\\mathbf{Blanket \\ Volumes:}$\n\nInboard blanket, with holes and"
        f" gaps: {m_file.get('vol_blkt_inboard', scan=scan):,.3f}"
        " $\\text{m}^3$\nOutboard blanket, with holes and gaps:"
        f" {m_file.get('vol_blkt_outboard', scan=scan):,.3f}"
        " $\\text{m}^3$\nTotal blanket, with holes and gaps:"
        f" {m_file.get('vol_blkt_total', scan=scan):,.3f}"
        " $\\text{m}^3$\n\nInboard blanket, full coverage:"
        f" {m_file.get('vol_blkt_inboard_full_coverage', scan=scan):,.3f}"
        " $\\text{m}^3$\nOutboard blanket, full coverage:"
        f" {m_file.get('vol_blkt_outboard_full_coverage', scan=scan):,.3f}"
        " $\\text{m}^3$\nTotal blanket, full coverage:"
        f" {m_file.get('vol_blkt_total_full_coverage', scan=scan):,.3f}"
        " $\\text{m}^3$ "
    )

    ax.text(
        0.05,
        0.05,
        textstr_blkt_volumes,
        **text_layout(fig),
        bbox=box_style("wheat"),
    )