From 0f60c70cf4a0e297b6d4efbebe11bf91930d03c6 Mon Sep 17 00:00:00 2001 From: Nicolas Stauff Date: Thu, 17 Feb 2022 19:42:43 -0600 Subject: [PATCH] updated pyarc plugin and example1c to enable and demonstrate unit conversion capability. --- examples/example1c_PyARC/example1c.py | 11 +++++++++-- examples/example1c_PyARC/pyarc_template | 4 ++-- src/watts/plugin_pyarc.py | 8 +++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/examples/example1c_PyARC/example1c.py b/examples/example1c_PyARC/example1c.py index abb573b2..131fe0aa 100644 --- a/examples/example1c_PyARC/example1c.py +++ b/examples/example1c_PyARC/example1c.py @@ -3,13 +3,20 @@ import os import watts +from astropy import units as u +# Uses Astropy for unit conversion +u.imperial.enable() # Enable imperial units +Quantity = u.Quantity params = watts.Parameters() # TH params -params['assembly_pitch'] = 20e-2 # m -params['assembly_length'] = 0.13 # m +params['assembly_pitch'] = Quantity(20, "cm") # 20e-2 m +params['assembly_length'] = Quantity(13, "cm") # 0.13 m +params['temp'] = Quantity(26.85, "Celsius") # 300 K + + params.show_summary(show_metadata=False, sort_by='key') diff --git a/examples/example1c_PyARC/pyarc_template b/examples/example1c_PyARC/pyarc_template index 54a33c6e..0db3bc8d 100644 --- a/examples/example1c_PyARC/pyarc_template +++ b/examples/example1c_PyARC/pyarc_template @@ -3,7 +3,7 @@ geometry{ materials{ material ( LEU ) { - temp = 300 + temp = {{ temp }} adens{ aden ( u235 ) = 2.0e-2 % atom density in at/barn-cm aden ( u238 ) = 2.0e-2 % atom density in at/barn-cm @@ -12,7 +12,7 @@ geometry{ lumped_element_aden( lu35 ) = 1e-3 } material ( LEU2 ) { - temp = 300 + temp = {{ temp }} adens{ aden ( u236 ) = 2.0e-2 % atom density in at/barn-cm aden ( u237 ) = 2.0e-2 % atom density in at/barn-cm diff --git a/src/watts/plugin_pyarc.py b/src/watts/plugin_pyarc.py index 7d6a0e3b..fed091fb 100644 --- a/src/watts/plugin_pyarc.py +++ b/src/watts/plugin_pyarc.py @@ -138,9 +138,15 @@ def prerun(self, params: Parameters) -> None: params Parameters used by the PyARC template """ + # Render the template + # Make a copy of params and convert units if necessary + # The original params remains unchanged + + params_copy = super().convert_unit(params, unit_system='si', unit_temperature='K') + print("Pre-run for PyARC Plugin") self._run_time = time.time_ns() - super().prerun(params, filename=self.pyarc_inp_name) + super().prerun(params_copy, filename=self.pyarc_inp_name) def run(self, **kwargs: Mapping): """Run PyARC