Skip to content

Commit

Permalink
Fixed to_mcnp
Browse files Browse the repository at this point in the history
  • Loading branch information
BitterB0NG0 committed Oct 16, 2024
1 parent 93aab59 commit 281e0c0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
20 changes: 12 additions & 8 deletions src/pymcnp/files/inp/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def to_mcnp(self) -> str:
INP string for ``CellKeyword`` object.
"""

return self.value
return str(self.value.value) if hasattr(self.value, "value") else str(self.value)

def __init__(
self, keyword: CellKeyword, value: any, suffix: types.McnpInteger = None, designator: types.Designator = None
Expand Down Expand Up @@ -484,18 +484,20 @@ def to_mcnp(self) -> str:
"""

# Processing Suffix
suffix_str = self.suffix if hasattr(self, "suffix") and self.suffix is not None else ""
suffix_str = str(self.suffix.to_mcnp()) if hasattr(self, "suffix") else ""

# Processing Designator
designator_str = (
f":{','.join(self.designator)}" if hasattr(self, "designator") and self.designator is not None else ""
f":{','.join(self.designator.particles)}"
if hasattr(self, "designator") and self.designator is not None
else ""
)

value_str = ""
if isinstance(self.value, tuple):
value_str = " ".join([str(param) for param in self.value])
value_str = " ".join([str(param.value) if hasattr(param, "value") else str(param) for param in self.value])
else:
value_str = self.value
value_str = self.value.value if hasattr(self.value, "value") else str(self.value)

return f"{self.keyword}{suffix_str}{designator_str}={value_str}"

Expand Down Expand Up @@ -1470,12 +1472,14 @@ def to_mcnp(self) -> str:
INP string for ``Cell`` object.
"""

density_str = self.density if self.material else " "
number_str = self.number.to_mcnp()
material_str = self.material.to_mcnp()
density_str = self.density.to_mcnp() if self.density is not None else " "
geometry_str = self.geometry.to_mcnp()
options_str = " ".join(option.to_mcnp() for option in self.options)
options_str = " ".join([option.to_mcnp() for option in self.options])

return _parser.Postprocessor.add_continuation_lines(
f"{self.number} {self.material} {density_str} {geometry_str} {options_str}"
f"{number_str} {material_str} {density_str} {geometry_str} {options_str}"
)

def to_arguments(self) -> dict:
Expand Down
2 changes: 1 addition & 1 deletion src/pymcnp/files/inp/datum.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ def to_mcnp(self) -> str:
INP string for ``Datum`` object.
"""

suffix_str = f"{self.suffix}" if hasattr(self, "suffix") else ""
suffix_str = self.suffix.to_mcnp() if hasattr(self, "suffix") else ""
designator_str = f":{self.designator}" if hasattr(self, "designator") else ""

parameters_str = ""
Expand Down
10 changes: 6 additions & 4 deletions src/pymcnp/files/inp/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,14 @@ def to_mcnp(self) -> str:
INP string for ``Surface`` object.
"""

# parameters_str = " ".join([str(param) for _ in,
source = (
f"{self.number}{' ' + {self.transform} + ' ' if self.transform is not None else ' '}"
f"{self.mnemonic} {' '.join(str(parameter) if parameter is not None else '' for parameter in self.parameters)}"
number_str = self.number.to_mcnp()
transform_str = self.transform.to_mcnp() if self.transform is not None else " "
parameter_str = " ".join(
str(parameter.value) if hasattr(parameter, "to_mcnp") else str(parameter) for parameter in self.parameters
)

source = f"{number_str} {transform_str} {self.mnemonic} {parameter_str}"

return _parser.Postprocessor.add_continuation_lines(source)

def to_arguments(self) -> dict:
Expand Down

0 comments on commit 281e0c0

Please sign in to comment.