diff --git a/src/pymcnp/files/inp/datum.py b/src/pymcnp/files/inp/datum.py index d19b36d..d7de0cb 100644 --- a/src/pymcnp/files/inp/datum.py +++ b/src/pymcnp/files/inp/datum.py @@ -7866,6 +7866,1122 @@ def __init__(self, mnemonic: Datum.DatumMnemonic, parameters: tuple[any]): self.parameters = parameters +class SourceDefinition(Datum): + """ + ``SourceDefinition`` represents INP nps data cards. + + ``SourceDefinition`` inherits attributes from ``Datum``. It represents the + INP model physics source definition data card syntax element. + + Attributes: + pairs: Tuple of key-value pairs. + """ + + class SourceDefinitionOption: + """ + ``SourceDefinitionOption`` represents INP source definition data card + options. + + ``SourceDefinitionOption`` implements INP source definition data card + options. Its attributes store keywords and values, and its methods + provide entry and endpoints for working with INP source definition + data card options. It represents the generic INP source definition + data card option syntax element, so ``SourceDefinition`` depends on + ``SourceDefinitionOption`` as a generic data structure and superclass. + + Attributes: + keyword: Activation control data card option keyword. + value: Activation control data card option value. + """ + + class SourceDefinitionKeyword(StrEnum): + """ + ``SourceDefinitionKeyword`` represents INP source definition data + card keywords. + + ``SourceDefinitionKeyword`` implements INP source definition data + card keywords as a Python inner class. It enumerates MCNP keywords + and provides methods for casting strings to + ``SourceDefinitionKeyword`` instances. It represents the INP + source definition data card keyword syntax element, so + ``SourceDefinition`` and ``SourceDefinitionOption`` depend on + ``SourceDefinitionKeyword`` as an enum. + """ + + CEL = "cel" + SUR = "sur" + ERG = "erg" + TME = "tme" + DIR = "dir" + VEC = "vec" + NRM = "nrm" + POS = "pos" + RAD = "rad" + EXT = "ext" + AXS = "axs" + X = "x" + Y = "y" + Z = "z" + CCC = "ccc" + ARA = "ara" + WGT = "wgt" + TR = "tr" + EFF = "eff" + PAR = "par" + DAT = "dat" + LOC = "loc" + BEM = "bem" + BAP = "bap" + + @staticmethod + def from_mcnp(source: str): + """ + ``from_mcnp`` generates ``SourceDefinitionKeyword`` objects + from INP. + + ``from_mcnp`` constructs instances of + ``SourceDefinitionKeyword`` from INP source strings, so it + operates as a class constructor method and INP parser helper + function. + + Parameters: + source: INP for source definition option keyword. + + Returns: + ``SourceDefinitionKeyword`` object. + + Raises: + MCNPSemanticError: INVALID_DATUM_SOURCE_KEYWORD. + """ + + source = _parser.Preprocessor.process_inp(source) + + # Processing Keyword + if source not in [enum.value for enum in SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword]: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_KEYWORD) + + return SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword(source) + + def __init__(self, keyword: SourceDefinitionKeyword, value: any): + """ + ``__init__`` initializes ``SourceDefinitionOption``. + + Parameters: + keyword: Source definition data card option keyword. + value: Source definition data card option value. + + Raises: + MCNPSemanticError: INVALID_DATUM_SOURCE_KEYWORD. + """ + + if keyword is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_KEYWORD) + + match keyword: + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.CEL: + obj = SourceDefinition.Cel(value) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.SUR: + obj = SourceDefinition.Sur(value) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.ERG: + obj = SourceDefinition.Erg(value) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.TME: + obj = SourceDefinition.Tme(value) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.DIR: + obj = SourceDefinition.Dir(value) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.VEC: + obj = SourceDefinition.Vec(value) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.NRM: + obj = SourceDefinition.Nrm(value) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.POS: + obj = SourceDefinition.Pos(value) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.RAD: + obj = SourceDefinition.Rad(value) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.EXT: + obj = SourceDefinition.Ext(value) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.AXS: + obj = SourceDefinition.Axs(value) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.X: + obj = SourceDefinition.X(value) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.Y: + obj = SourceDefinition.Y(value) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.Z: + obj = SourceDefinition.Z(value) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.CCC: + obj = SourceDefinition.Ccc(value) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.ARA: + obj = SourceDefinition.Ara(value) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.WGT: + obj = SourceDefinition.Wgt(value) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.TR: + obj = SourceDefinition.Tr(value) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.EFF: + obj = SourceDefinition.Eff(value) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.PAR: + obj = SourceDefinition.Par(value) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.DAT: + obj = SourceDefinition.Dat(value) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.LOC: + obj = SourceDefinition.Loc(value) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.BEM: + obj = SourceDefinition.Bem(value) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.BAP: + obj = SourceDefinition.Bap(value) + + self.__dict__ = obj.__dict__ + self.__class__ = obj.__class__ + + @staticmethod + def from_mcnp(source: str): + """ + ``from_mcnp`` generates ``SourceDefinitionOption`` objects from + INP. + + ``from_mcnp`` constructs instances of ``SourceDefinitionOption`` + from INP source strings, so it operates as a class constructor + method and INP parser helper function. Although defined on the + superclass, it returns ``SourceDefinitionOption`` subclasses. + + Parameters: + source: INP for activation option. + + Returns: + ``SourceDefinitionOption`` object. + + Raises: + MCNPSyntaxError: TOOFEW_DATUM_SOURCE. + MCNPSyntaxError: TOOLONG_DATUM_SOURCE. + """ + + source = _parser.Preprocessor.process_inp(source) + tokens = _parser.Parser( + re.split(r"=| ", source), errors.MCNPSyntaxError(errors.MCNPSyntaxCodes.TOOFEW_DATUM_SOURCE) + ) + + # Processing Keyword + keyword = SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.from_mcnp(tokens.popl()) + + # Processing Values + match keyword: + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.CEL: + value = types.McnpInteger.from_mcnp(tokens.popl()) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.SUR: + value = types.McnpInteger.from_mcnp(tokens.popl()) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.ERG: + if tokens.peekl()[0] == "d": + value = types.DistributionNumber.from_mcnp(tokens.popl()) + else: + value = types.McnpReal.from_mcnp(tokens.popl()) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.TME: + value = types.McnpReal.from_mcnp(tokens.popl()) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.DIR: + if tokens.peekl()[0] == "d": + value = types.DistributionNumber.from_mcnp(tokens.popl()) + else: + value = types.McnpReal.from_mcnp(tokens.popl()) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.VEC: + value = ( + types.McnpReal.from_mcnp(tokens.popl()), + types.McnpReal.from_mcnp(tokens.popl()), + types.McnpReal.from_mcnp(tokens.popl()), + ) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.NRM: + value = types.McnpInteger.from_mcnp(tokens.popl()) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.POS: + value = ( + types.McnpReal.from_mcnp(tokens.popl()), + types.McnpReal.from_mcnp(tokens.popl()), + types.McnpReal.from_mcnp(tokens.popl()), + ) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.RAD: + if tokens.peekl()[0] == "d": + value = types.DistributionNumber.from_mcnp(tokens.popl()) + else: + value = types.McnpReal.from_mcnp(tokens.popl()) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.EXT: + value = types.McnpReal.from_mcnp(tokens.popl()) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.AXS: + value = ( + types.McnpReal.from_mcnp(tokens.popl()), + types.McnpReal.from_mcnp(tokens.popl()), + types.McnpReal.from_mcnp(tokens.popl()), + ) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.X: + value = types.McnpReal.from_mcnp(tokens.popl()) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.Y: + value = types.McnpReal.from_mcnp(tokens.popl()) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.Z: + value = types.McnpReal.from_mcnp(tokens.popl()) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.CCC: + value = types.McnpInteger.from_mcnp(tokens.popl()) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.ARA: + value = types.McnpReal.from_mcnp(tokens.popl()) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.WGT: + value = types.McnpReal.from_mcnp(tokens.popl()) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.TR: + value = types.McnpInteger.from_mcnp(tokens.popl()) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.EFF: + value = types.McnpReal.from_mcnp(tokens.popl()) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.PAR: + value = tokens.popl() + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.DAT: + value = ( + types.McnpInteger.from_mcnp(tokens.popl()), + types.McnpInteger.from_mcnp(tokens.popl()), + types.McnpInteger.from_mcnp(tokens.popl()), + ) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.LOC: + value = ( + types.McnpReal.from_mcnp(tokens.popl()), + types.McnpReal.from_mcnp(tokens.popl()), + types.McnpReal.from_mcnp(tokens.popl()), + ) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.BEM: + value = ( + types.McnpReal.from_mcnp(tokens.popl()), + types.McnpReal.from_mcnp(tokens.popl()), + types.McnpReal.from_mcnp(tokens.popl()), + ) + case SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.BAP: + value = ( + types.McnpReal.from_mcnp(tokens.popl()), + types.McnpReal.from_mcnp(tokens.popl()), + types.McnpReal.from_mcnp(tokens.popl()), + ) + + if tokens: + raise errors.MCNPSyntaxError(errors.MCNPSyntaxCodes.TOOLONG_DATUM_SOURCE) + + return SourceDefinition.SourceDefinitionOption(keyword, value) + + def to_mcnp(self): + """ + ``to_mcnp`` generates INP from ``SourceDefinitionOption`` objects. + + ``to_mcnp`` creates INP source string from ``SourceDefinitionOption`` + objects, so it provides an MCNP endpoint. + + Returns: + INP string for ``SourceDefinitionOption`` object. + """ + + return f"{SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword(self.keyword)}={self.value}" + + class Cel(SourceDefinitionOption): + """ + ``Cel`` represents INP Cel source definition data card + options. + + ``Cel`` inherits attributes from ``SourceDefinitionOption``. It + represents the INP Cel source definition data card option syntax element. + + Attributes: + number: Cell number. + """ + + def __init__(self, number: types.McnpInteger): + """ + ``__init__`` initializes ``Cel``. + + Parameters: + number: Cell number. + + Raises: + MCNPSemanticError: INVALID_DATUM_SOURCE_VALUE. + """ + + if number is None or not (1 <= number <= 99_999_999): + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + self.keyword = SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.CEL + self.value = number + self.number = number + + class Sur(SourceDefinitionOption): + """ + ``Sur`` represents INP Sur source definition data card + options. + + ``Sur`` inherits attributes from ``SourceDefinitionOption``. It + represents the INP Sur source definition data card option syntax element. + + Attributes: + number: Surface number. + """ + + def __init__(self, number: types.McnpInteger): + """ + ``__init__`` initializes ``Sur``. + + Parameters: + number: Surface number. + + Raises: + MCNPSemanticError: INVALID_DATUM_SOURCE_VALUE. + """ + + if number is None or not (1 <= number <= 99_999_999): + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + self.keyword = SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.SUR + self.value = number + self.number = number + + class Erg(SourceDefinitionOption): + """ + ``Erg`` represents INP Erg source definition data card + options. + + ``Erg`` inherits attributes from ``SourceDefinitionOption``. It + represents the INP Erg source definition data card option syntax element. + + Attributes: + energy: Kinetic energy. + """ + + def __init__(self, energy: Union[types.McnpReal, types.DistributionNumber]): + """ + ``__init__`` initializes ``Erg``. + + Parameters: + energy: Kinetic energy. + + Raises: + MCNPSemanticError: INVALID_DATUM_SOURCE_VALUE. + """ + + if isinstance(energy, types.McnpReal): + if energy is None or not (energy >= 0): + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + else: + if energy is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + self.keyword = SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.ERG + self.value = energy + self.energy = energy + + class Tme(SourceDefinitionOption): + """ + ``Tme`` represents INP Tme source definition data card + options. + + ``Tme`` inherits attributes from ``SourceDefinitionOption``. It + represents the INP Tme source definition data card option syntax element. + + Attributes: + time: Time. + """ + + def __init__(self, time: types.McnpReal): + """ + ``__init__`` initializes ``Tme``. + + Parameters: + _ + + Raises: + MCNPSemanticError: INVALID_DATUM_SOURCE_VALUE. + """ + + if time is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + self.keyword = SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.TME + self.value = time + self.time = time + + class Dir(SourceDefinitionOption): + """ + ``Dir`` represents INP Dir source definition data card + options. + + ``Dir`` inherits attributes from ``SourceDefinitionOption``. It + represents the INP Dir source definition data card option syntax element. + + Attributes: + cosine: Cosine of the angle between VEC and particle's direction. + """ + + def __init__(self, cosine: Union[types.McnpReal, types.DistributionNumber]): + """ + ``__init__`` initializes ``Dir``. + + Parameters: + cosine: Cosine of the angle between VEC and particle's direction. + + Raises: + MCNPSemanticError: INVALID_DATUM_SOURCE_VALUE. + """ + + if isinstance(cosine, types.McnpReal): + if cosine is None or not (-1 <= cosine <= 1): + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + else: + if cosine is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + self.keyword = SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.DIR + self.value = cosine + self.cosine = cosine + + class Vec(SourceDefinitionOption): + """ + ``Vec`` represents INP Vec source definition data card + options. + + ``Vec`` inherits attributes from ``SourceDefinitionOption``. It + represents the INP Vec source definition data card option syntax element. + + Attributes: + vector: Reference vector for DIR in vector notation. + """ + + def __init__(self, vector: tuple[types.McnpReal]): + """ + ``__init__`` initializes ``Vec``. + + Parameters: + vector: Reference vector for DIR in vector notation. + + Raises: + MCNPSemanticError: INVALID_DATUM_SOURCE_VALUE. + """ + + if vector is None or not (len(vector) == 3): + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + x, y, z = vector + + if x is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + if y is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + if z is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + self.keyword = SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.VEC + self.value = vector + self.vector = vector + + class Nrm(SourceDefinitionOption): + """ + ``Nrm`` represents INP Nrm source definition data card + options. + + ``Nrm`` inherits attributes from ``SourceDefinitionOption``. It + represents the INP Nrm source definition data card option syntax element. + + Attributes: + sign: Sign of the surface normal. + """ + + def __init__(self, sign: types.McnpInteger): + """ + ``__init__`` initializes ``Nrm``. + + Parameters: + sign: Sign of the surface normal. + + Raises: + MCNPSemanticError: INVALID_DATUM_SOURCE_VALUE. + """ + + if sign is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + self.keyword = SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.NRM + self.value = sign + self.sign = sign + + class Pos(SourceDefinitionOption): + """ + ``Pos`` represents INP Pos source definition data card + options. + + ``Pos`` inherits attributes from ``SourceDefinitionOption``. It + represents the INP Pos source definition data card option syntax element. + + Attributes: + position: Reference point for sampling in vector notation. + """ + + def __init__(self, position: tuple[types.McnpInteger]): + """ + ``__init__`` initializes ``Pos``. + + Parameters: + position: Reference point for sampling in vector notation. + + Raises: + MCNPSemanticError: INVALID_DATUM_SOURCE_VALUE. + """ + + if position is None or not (len(position) == 3): + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + x, y, z = position + + if x is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + if y is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + if z is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + self.keyword = SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.POS + self.value = position + self.position = position + + class Rad(SourceDefinitionOption): + """ + ``Rad`` represents INP Rad source definition data card + options. + + ``Rad`` inherits attributes from ``SourceDefinitionOption``. It + represents the INP Rad source definition data card option syntax element. + + Attributes: + distance: Radial distance of the position. + """ + + def __init__(self, distance: Union[types.McnpReal, types.DistributionNumber]): + """ + ``__init__`` initializes ``Rad``. + + Parameters: + distance: Radial distance of the position. + + Raises: + MCNPSemanticError: INVALID_DATUM_SOURCE_VALUE. + """ + + if distance is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + self.keyword = SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.RAD + self.value = distance + self.distance = distance + + class Ext(SourceDefinitionOption): + """ + ``Ext`` represents INP Ext source definition data card + options. + + ``Ext`` inherits attributes from ``SourceDefinitionOption``. It + represents the INP Ext source definition data card option syntax element. + + Attributes: + ext: Distance from POS along AXS or cosine of angle from AXS. + """ + + def __init__(self, ext: types.McnpReal): + """ + ``__init__`` initializes ``Ext``. + + Parameters: + ext: Distance from POS along AXS or cosine of angle from AXS. + + Raises: + MCNPSemanticError: INVALID_DATUM_SOURCE_VALUE. + """ + + if ext is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + self.keyword = SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.EXT + self.value = ext + self.ext = ext + + class Axs(SourceDefinitionOption): + """ + ``Axs`` represents INP Axs source definition data card + options. + + ``Axs`` inherits attributes from ``SourceDefinitionOption``. It + represents the INP Axs source definition data card option syntax element. + + Attributes: + vector: Reference vector for EXT and READ. + """ + + def __init__(self, vector: tuple[types.McnpReal]): + """ + ``__init__`` initializes ``Axs``. + + Parameters: + vector: Reference vector for EXT and READ. + + Raises: + MCNPSemanticError: INVALID_DATUM_SOURCE_VALUE. + """ + + if vector is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + self.keyword = SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.AXS + self.value = vector + self.vector = vector + + class X(SourceDefinitionOption): + """ + ``X`` represents INP X source definition data card + options. + + ``X`` inherits attributes from ``SourceDefinitionOption``. It + represents the INP X source definition data card option syntax element. + + Attributes: + x: X-coordinate of position. + """ + + def __init__(self, x: types.McnpReal): + """ + ``__init__`` initializes ``X``. + + Parameters: + x: X-coordinate of position. + + Raises: + MCNPSemanticError: INVALID_DATUM_SOURCE_VALUE. + """ + + if x is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + self.keyword = SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.X + self.value = x + self.x = x + + class Y(SourceDefinitionOption): + """ + ``Y`` represents INP Y source definition data card + options. + + ``Y`` inherits attributes from ``SourceDefinitionOption``. It + represents the INP Y source definition data card option syntax element. + + Attributes: + y: Y-coordinate of position. + """ + + def __init__(self, y: types.McnpReal): + """ + ``__init__`` initializes ``Y``. + + Parameters: + y: Y-coordinate of position. + + Raises: + MCNPSemanticError: INVALID_DATUM_SOURCE_VALUE. + """ + + if y is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + self.keyword = SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.Y + self.value = y + self.y = y + + class Z(SourceDefinitionOption): + """ + ``Z`` represents INP Z source definition data card + options. + + ``Z`` inherits attributes from ``SourceDefinitionOption``. It + represents the INP Z source definition data card option syntax element. + + Attributes: + z: Z-coordinate of position. + """ + + def __init__(self, z: types.McnpReal): + """ + ``__init__`` initializes ``Z``. + + Parameters: + y: Y-coordinate of position. + + Raises: + MCNPSemanticError: INVALID_DATUM_SOURCE_VALUE. + """ + + if z is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + self.keyword = SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.Z + self.value = z + self.z = z + + class Ccc(SourceDefinitionOption): + """ + ``Ccc`` represents INP Ccc source definition data card + options. + + ``Ccc`` inherits attributes from ``SourceDefinitionOption``. It + represents the INP Ccc source definition data card option syntax element. + + Attributes: + number: Cookie-cutter cell number. + """ + + def __init__(self, number: types.McnpInteger): + """ + ``__init__`` initializes ``Ccc``. + + Parameters: + number Cookie-cutter cell number. + + Raises: + MCNPSemanticError: INVALID_DATUM_SOURCE_VALUE. + """ + + if number is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + self.keyword = SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.CCC + self.value = number + self.number = number + + class Ara(SourceDefinitionOption): + """ + ``Ara`` represents INP Ara source definition data card + options. + + ``Ara`` inherits attributes from ``SourceDefinitionOption``. It + represents the INP Ara source definition data card option syntax element. + + Attributes: + area: Area of surface. + """ + + def __init__(self, area: types.McnpReal): + """ + ``__init__`` initializes ``Ara``. + + Parameters: + area: Area of surface. + + Raises: + MCNPSemanticError: INVALID_DATUM_SOURCE_VALUE. + """ + + if area is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + self.keyword = SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.ARA + self.value = area + self.area = area + + class Wgt(SourceDefinitionOption): + """ + ``Wgt`` represents INP Wgt source definition data card + options. + + ``Wgt`` inherits attributes from ``SourceDefinitionOption``. It + represents the INP Wgt source definition data card option syntax element. + + Attributes: + weight: Particle weight. + """ + + def __init__(self, weight: types.McnpReal): + """ + ``__init__`` initializes ``Wgt``. + + Parameters: + weight: Particle weight. + + Raises: + MCNPSemanticError: INVALID_DATUM_SOURCE_VALUE. + """ + + if weight is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + self.keyword = SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.WGT + self.value = weight + self.weight = weight + + class Tr(SourceDefinitionOption): + """ + ``Tr`` represents INP Tr source definition data card + options. + + ``Tr`` inherits attributes from ``SourceDefinitionOption``. It + represents the INP Tr source definition data card option syntax element. + + Attributes: + transformation: Source particle transformation number. + """ + + def __init__(self, transformation: types.McnpInteger): + """ + ``__init__`` initializes ``Tr``. + + Parameters: + transformation: Source particle transformation number. + + Raises: + MCNPSemanticError: INVALID_DATUM_SOURCE_VALUE. + """ + + if transformation is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + self.keyword = SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.TR + self.value = transformatino + self.transformation = transformation + + class Eff(SourceDefinitionOption): + """ + ``Eff`` represents INP Eff source definition data card + options. + + ``Eff`` inherits attributes from ``SourceDefinitionOption``. It + represents the INP Eff source definition data card option syntax element. + + Attributes: + criterion: Rejection efficiency criterion for poition sampling. + """ + + def __init__(self, criterion: types.McnpReal): + """ + ``__init__`` initializes ``Eff``. + + Parameters: + criterion: Rejection efficiency criterion for poition sampling. + + Raises: + MCNPSemanticError: INVALID_DATUM_SOURCE_VALUE. + """ + + if criterion is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + self.keyword = SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.EFF + self.value = criterion + self.criterion = criterion + + class Par(SourceDefinitionOption): + """ + ``Par`` represents INP Par source definition data card + options. + + ``Par`` inherits attributes from ``SourceDefinitionOption``. It + represents the INP Par source definition data card option syntax element. + + Attributes: + symbol: Source particle type by symbol or number. + """ + + def __init__(self, symbol: str): + """ + ``__init__`` initializes ``Par``. + + Parameters: + symbol: Source particle type by symbol or number. + + Raises: + MCNPSemanticError: INVALID_DATUM_SOURCE_VALUE. + """ + + if symbol is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + self.keyword = SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.PAR + self.value = symbol + self.symbol = symbol + + class Dat(SourceDefinitionOption): + """ + ``Dat`` represents INP Dat source definition data card + options. + + ``Dat`` inherits attributes from ``SourceDefinitionOption``. It + represents the INP Dat source definition data card option syntax element. + + Attributes: + date: Date to use for cosmic-ray and background sources. + """ + + def __init__(self, date: tuple[types.McnpInteger]): + """ + ``__init__`` initializes ``Dat``. + + Parameters: + date: Date to use for cosmic-ray and background sources. + + Raises: + MCNPSemanticError: INVALID_DATUM_SOURCE_VALUE. + """ + + if date is None or not (len(date) == 3): + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + m, d, y = date + + if m is None or not (1 <= m <= 12): + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + if d is None or not (1 <= d <= 31): + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + if y is None or not (0 <= y <= 9999): + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + self.keyword = SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.DAT + self.value = date + self.date = date + + class Loc(SourceDefinitionOption): + """ + ``Loc`` represents INP Loc source definition data card + options. + + ``Loc`` inherits attributes from ``SourceDefinitionOption``. It + represents the INP Loc source definition data card option syntax element. + + Attributes: + location: Location of cosmic particle source. + """ + + def __init__(self, location: tuple[types.McnpReal]): + """ + ``__init__`` initializes ``Loc``. + + Parameters: + location: Location of cosmic particle source. + + Raises: + MCNPSemanticError: INVALID_DATUM_SOURCE_VALUE. + """ + + if location is None or not (len(location) == 3): + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + lat, lng, alt = location + + if lat is None or not (-90 <= lat <= 90): + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + if lng is None or not (-180 <= lng <= 180): + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + if alt is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + self.keyword = SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.LOC + self.value = location + self.location = location + + class Bem(SourceDefinitionOption): + """ + ``Bem`` represents INP Bem source definition data card + options. + + ``Bem`` inherits attributes from ``SourceDefinitionOption``. It + represents the INP Bem source definition data card option syntax element. + + Attributes: + parameters: Beam emittance parameters. + """ + + def __init__(self, parameters: tuple[types.McnpReal]): + """ + ``__init__`` initializes ``Bem``. + + Parameters: + parameters: Beam emittance parameters. + + Raises: + MCNPSemanticError: INVALID_DATUM_SOURCE_VALUE. + """ + + if parameters is None or not (len(parameters) == 3): + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + exn, eyn, bm1 = parameters + + if exn is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + if eyn is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + if bm1 is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + self.keyword = SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.BEM + self.value = parameters + self.parameters = parameters + + class Bap(SourceDefinitionOption): + """ + ``Bap`` represents INP Bap source definition data card + options. + + ``Bap`` inherits attributes from ``SourceDefinitionOption``. It + represents the INP Bap source definition data card option syntax element. + + Attributes: + parameters: Beam aperture parameters. + """ + + def __init__(self, parameters: tuple[types.McnpReal]): + """ + ``__init__`` initializes ``Bap``. + + Parameters: + parameters: Beam aperture parameters. + + Raises: + MCNPSemanticError: INVALID_DATUM_SOURCE_VALUE. + """ + + if parameters is None or not (len(parameters) == 3): + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + ba1, ba2, u = parameters + + if ba1 is None or not (ba1 > 0): + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + if ba2 is None or not (ba2 > 0): + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + if u is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_SOURCE_VALUE) + + self.keyword = SourceDefinition.SourceDefinitionOption.SourceDefinitionKeyword.BAP + self.value = parameters + self.parameters = parameters + + def __init__(self, pairs: tuple[SourceDefinitionOption]): + """ + ``__init__`` initializes ``SourceDefinition``. + + Parameters: + pairs: Tuple of key-value pairs. + """ + + if pairs is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_PARAMETERS) + + for pair in pairs: + if pair is None: + raise errors.MCNPSemanticError(errors.MCNPSemanticCodes.INVALID_DATUM_PARAMETERS) + + self.id: final[str] = "sdef" + self.mnemonic: final[Datum.DatumMnemonic] = Datum.DatumMnemonic.GENERAL_SOURCE_DEFINITION + self.parameters: final[tuple] = pairs + + self.pairs: final[SourceDefinitionOption] = pairs + + class HistroyCutoff(Datum): """ ``HistroyCutoff`` represents INP nps data cards.