diff --git a/src/hisp/bin.py b/src/hisp/bin.py index 478cefe..c09f9d0 100644 --- a/src/hisp/bin.py +++ b/src/hisp/bin.py @@ -9,11 +9,10 @@ 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, @@ -21,6 +20,27 @@ def __init__( 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 @@ -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 diff --git a/test/test_bin.py b/test/test_bin.py index f1d32a4..0d92077 100644 --- a/test/test_bin.py +++ b/test/test_bin.py @@ -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)] @@ -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