Skip to content

Commit

Permalink
Merge pull request #71 from kaelyndunnell/surface-area-subbins
Browse files Browse the repository at this point in the history
  • Loading branch information
RemDelaporteMathurin authored Dec 21, 2024
2 parents 790ff61 + 0457d1a commit 3c4b1d9
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 6 deletions.
56 changes: 51 additions & 5 deletions src/hisp/bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,38 @@ class SubBin:
mode: str
dfw: bool
parent_bin_index: int
low_wetted_area: float # m^2
high_wetted_area: float # m^2
total_area: float # m^2
f: float # fraction of heat values in low_wetted_area from SMITER
# (f = H_low * low_wetted_area /(H_low * low_wetted_area + H_high * high_wetted_area))
low_wetted_area: float
high_wetted_area: float
total_area: float
f: float

def __init__(
self,
mode: str,
thickness: float = None,
material: str = None,
):
"""
A SubBin object represents a sub-bin of a FW bin in a reactor.
Args:
thickness: The thickness of the subbin (in m).
material: The material of the subbin.
mode: The mode of the subbin (shadowed, wetted, low_wetted, high_wetted).
Attributes:
thickness: The thickness of the subbin (in m).
material: The material of the subbin.
mode: The mode of the subbin (shadowed, wetted, low_wetted, high_wetted).
dfw: A boolean indicating if the subbin is a Divertor First Wall (DFW) subbin.
parent_bin_index: The index of the parent bin.
low_wetted_area: The low wetted area of the parent bin (in m^2).
high_wetted_area: The high wetted area of the parent bin (in m^2).
total_area: The total area of the parent bin (in m^2).
f: The fraction of heat values in the low wetted area. Calculated from SMITER as:
f = H_low * low_wetted_area / (H_low * low_wetted_area + H_high * high_wetted_area)
"""
self.thickness = thickness
self.material = material
self.mode = mode
Expand Down Expand Up @@ -48,6 +68,32 @@ def wetted_frac(self):
elif self.mode == "high_wetted":
return (1 - self.f) * self.total_area / self.high_wetted_area

@property
def surface_area(self) -> float:
"""Calculates the surface area of the subbin (in m^2).
Returns:
The surface area of the subbin (in m^2).
"""
if self.shadowed:
low_wetted_area = self.low_wetted_area
high_wetted_area = self.high_wetted_area
if (
isinstance(self.low_wetted_area, type(np.nan))
or self.low_wetted_area is None
):
low_wetted_area = 0
if (
isinstance(self.high_wetted_area, type(np.nan))
or self.high_wetted_area is None
):
high_wetted_area = 0
return self.total_area - low_wetted_area - high_wetted_area
elif self.mode in ["wetted", "low_wetted"]:
return self.low_wetted_area
elif self.mode == "high_wetted":
return self.high_wetted_area


class FWBin:
index: int
Expand Down
63 changes: 62 additions & 1 deletion test/test_bin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import numpy as np
import pytest
import pandas as pd
from hisp.bin import FWBin3Subs, FWBin2Subs, DivBin, FWBin, BinCollection, Reactor
from hisp.bin import (
FWBin3Subs,
FWBin2Subs,
DivBin,
FWBin,
BinCollection,
Reactor,
SubBin,
)

# create Reactor
fw_bins = [FWBin3Subs() for _ in range(18)]
Expand Down Expand Up @@ -143,3 +151,56 @@ def test_arc_length():
bins = BinCollection([bin_1, bin_2, bin_3])
assert np.allclose(bins.arc_length(), [1, 3, 4])
assert np.allclose(bins.arc_length(middle=True), [0.5, 2, 3.5])


def test_sub_bin_surface_area_3_subbins():

# BUILD
my_bin = FWBin()

subbin_shadowed = SubBin(mode="shadowed")
subbin_low_wetted = SubBin(mode="low_wetted")
subbin_high_wetted = SubBin(mode="high_wetted")
my_bin.sub_bins = [subbin_shadowed, subbin_low_wetted, subbin_high_wetted]

bin_low_wetted_area = 5
bin_high_wetted_area = 3
bin_shadowed_area = 2

bin_total_area = bin_low_wetted_area + bin_high_wetted_area + bin_shadowed_area

for subbin in my_bin.sub_bins:
subbin.low_wetted_area = bin_low_wetted_area
subbin.high_wetted_area = bin_high_wetted_area
subbin.total_area = bin_total_area

# TEST
assert (
subbin_shadowed.surface_area
== bin_total_area - bin_low_wetted_area - bin_high_wetted_area
)
assert subbin_low_wetted.surface_area == bin_low_wetted_area
assert subbin_high_wetted.surface_area == bin_high_wetted_area


def test_sub_bin_surface_area_2_subbins():

# BUILD
my_bin = FWBin()

subbin_shadowed = SubBin(mode="shadowed")
subbin_wetted = SubBin(mode="wetted")
my_bin.sub_bins = [subbin_shadowed, subbin_wetted]

bin_wetted_area = 5
bin_shadowed_area = 2

bin_total_area = bin_wetted_area + bin_shadowed_area

for subbin in my_bin.sub_bins:
subbin.low_wetted_area = bin_wetted_area
subbin.total_area = bin_total_area

# TEST
assert subbin_shadowed.surface_area == bin_total_area - bin_wetted_area
assert subbin_wetted.surface_area == bin_wetted_area

0 comments on commit 3c4b1d9

Please sign in to comment.