From bbb20b438736a338c70d3465eaef887839146d65 Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Tue, 30 Jan 2024 14:33:51 -0700 Subject: [PATCH] add totalinvtracker as known type so archetypes can init buypol with one --- cli/cycpp.py | 10 +++++++++- cyclus/gentypesystem.py | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/cli/cycpp.py b/cli/cycpp.py index 5e72815a7d..9eb8ab576d 100755 --- a/cli/cycpp.py +++ b/cli/cycpp.py @@ -102,11 +102,14 @@ ('{0}::toolkit::ResBuf'.format(CYCNS), CYCNS + '::Product'), ('{0}::toolkit::ResBuf'.format(CYCNS), CYCNS + '::Material'), '{0}::toolkit::ResMap'.format(CYCNS), + '{0}::toolkit::TotalInvTracker'.format(CYCNS), + ('{0}::toolkit::TotalInvTracker'.format(CYCNS), '{0}::toolkit::ResBuf'.format(CYCNS), CYCNS + '::Material'), } TEMPLATES = {'std::vector', 'std::set', 'std::list', 'std::pair', 'std::map', '{0}::toolkit::ResBuf'.format(CYCNS), - CYCNS + '::toolkit::ResMap',} + CYCNS + '::toolkit::ResMap', + CYCNS + '::toolkit::TotalInvTracker',} WRANGLERS = { '{0}::Agent'.format(CYCNS), @@ -1079,6 +1082,7 @@ def impl(self, ind=" "): "m->{var}.capacity());\n"), CYCNS + '::toolkit::ResBuf': "{var}.capacity(m->{var}.capacity());\n", CYCNS + '::toolkit::ResMap': '{var}.obj_ids(m->obj_ids());\n', + CYCNS + '::toolkit::TotalInvTracker': "{var}.capacity();\n", } class InitFromDbFilter(CodeGeneratorFilter): @@ -1145,6 +1149,7 @@ def impl(self, ind=" "): CYCNS + '::toolkit::ResBuf': '{var}.capacity({capacity});\n', CYCNS + '::toolkit::ResMap': ( '{var}.obj_ids(qr.GetVal<{tstr}>("{var}"))\n;'), + CYCNS + '::toolkit::TotalInvTracker': '{var}.capacity();\n', } @@ -1893,6 +1898,7 @@ def impl(self, ind=" "): CYCNS + '::toolkit::ResourceBuff': None, CYCNS + '::toolkit::ResBuf': None, CYCNS + '::toolkit::ResMap': '{var}.obj_ids()', + CYCNS + '::Toolkit::TotalInvTracker': None, } @@ -1947,6 +1953,7 @@ def impl(self, ind=" "): 'invs[\"{var}\"] = {var}.PopNRes({var}.count());\n' '{var}.Push(invs["{var}"]);\n'), CYCNS + '::toolkit::ResMap': "invs[\"{var}\"] = {var}.ResValues();\n", + CYCNS + '::toolkit::TotalInvTracker': ';\n', } @@ -1995,6 +2002,7 @@ def impl(self, ind=" "): CYCNS + '::toolkit::ResourceBuff': "{var}.PushAll(inv[\"{var}\"]);\n", CYCNS + '::toolkit::ResBuf': "{var}.Push(inv[\"{var}\"]);\n", CYCNS + '::toolkit::ResMap': "{var}.ResValues(inv[\"{var}\"]);\n", + CYCNS + '::toolkit::TotalInvTracker': ";\n", } diff --git a/cyclus/gentypesystem.py b/cyclus/gentypesystem.py index 5bc60fcd21..366a465987 100644 --- a/cyclus/gentypesystem.py +++ b/cyclus/gentypesystem.py @@ -377,6 +377,7 @@ def convert_to_cpp(self, x, t): 'std::list': 'std_list', 'std::vector': 'std_vector', 'cyclus::toolkit::ResBuf': 'cpp_cyclus.ResBuf', + 'cyclus::toolkit::TotalInvTracker': 'cpp_cyclus.TotalInvTracker', 'cyclus::toolkit::ResMap': 'cpp_cyclus.ResMap', } @@ -384,7 +385,7 @@ def convert_to_cpp(self, x, t): RESOURCES = ['MATERIAL', 'PRODUCT'] INVENTORIES = ['cyclus::toolkit::ResourceBuff', 'cyclus::toolkit::ResBuf', - 'cyclus::toolkit::ResMap'] + 'cyclus::toolkit::TotalInvTracker', 'cyclus::toolkit::ResMap'] USE_SHARED_PTR = ('MATERIAL', 'PRODUCT', 'cyclus::Material', 'cyclus::Product') @@ -419,6 +420,7 @@ def convert_to_cpp(self, x, t): 'std::list': 'std_list', 'std::vector': 'std_vector', 'cyclus::toolkit::ResBuf': 'res_buf', + 'cyclus::toolkit::TotalInvTracker': 'total_inv_tracker', 'cyclus::toolkit::ResMap': 'res_map', } @@ -453,6 +455,7 @@ def convert_to_cpp(self, x, t): 'std::list': 'List', 'std::vector': 'Vector', 'cyclus::toolkit::ResBuf': 'ResBuf', + 'cyclus::toolkit::TotalInvTracker': 'total_inv_tracker', 'cyclus::toolkit::ResMap': 'ResMap', } @@ -489,6 +492,7 @@ def convert_to_cpp(self, x, t): 'std::list': ('val',), 'std::vector': ('val',), 'cyclus::toolkit::ResBuf': ('val',), + 'cyclus::toolkit::TotalInvTracker': ('val',), 'cyclus::toolkit::ResMap': ('key', 'val'), } @@ -509,6 +513,7 @@ def convert_to_cpp(self, x, t): 'std::list': 'np.NPY_OBJECT', 'std::vector': 'np.NPY_OBJECT', 'cyclus::toolkit::ResBuf': 'np.NPY_OBJECT', + 'cyclus::toolkit::TotalInvTracker': 'np.NPY_OBJECT', 'cyclus::toolkit::ResMap': 'np.NPY_OBJECT', } @@ -529,6 +534,7 @@ def convert_to_cpp(self, x, t): 'std::list': '[]', 'std::vector': '[]', 'cyclus::toolkit::ResBuf': 'None', + 'cyclus::toolkit::TotalInvTracker': 'None', 'cyclus::toolkit::ResMap': 'None', } @@ -646,6 +652,7 @@ def convert_to_cpp(self, x, t): ' py{var}[i] = {var}_i\n', 'py{var}'), 'cyclus::toolkit::ResBuf': ('', '', 'None'), + 'cyclus::toolkit::TotalInvTracker': ('', '', 'None'), 'cyclus::toolkit::ResMap': ('', '', 'None'), } @@ -758,6 +765,12 @@ def convert_to_cpp(self, x, t): 'py{var} = <_{classname}> {var}\n' 'cpp{var} = deref(py{var}.ptx)\n', 'cpp{var}'), + 'cyclus::toolkit::TotalInvTracker': ( + 'cdef _{classname} py{var}\n' + 'cdef cpp_cyclus.TotalInvTracker[{valtype}] cpp{var}\n', + 'py{var} = <_{classname}> {var}\n' + 'cpp{var} = deref(py{var}.ptx)\n', + 'cpp{var}'), 'cyclus::toolkit::ResMap': ( 'cdef _{classname} py{var}\n' 'cdef cpp_cyclus.ResMap[{keytype}, {valtype}] cpp{var}\n',