From 5c6951a82f0254f94c6df3dddc32aa21d1953d40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Schm=C3=B6lder?= Date: Sun, 8 Dec 2024 12:34:56 +0100 Subject: [PATCH] Formatting --- cadet/cadet.py | 31 ++++++++++++++-------------- cadet/cadet_dll_parameterprovider.py | 5 +++++ cadet/cadet_dll_utils.py | 22 ++++++++++++++++---- 3 files changed, 39 insertions(+), 19 deletions(-) diff --git a/cadet/cadet.py b/cadet/cadet.py index 4de20f1..5a37840 100644 --- a/cadet/cadet.py +++ b/cadet/cadet.py @@ -474,55 +474,56 @@ def inverse_transform(self, x: str) -> str: """ return str.lower(x) - def run( + def run_load( self, timeout: Optional[int] = None, + clear: bool = True ) -> ReturnInformation: """ - Run the CADET simulation. + Run the CADET simulation and load the results. Parameters ---------- timeout : Optional[int] Maximum time allowed for the simulation to run, in seconds. + clear : bool + If True, clear previous results after loading new ones. Returns ------- ReturnInformation Information about the simulation run. """ - return_information = self.cadet_runner.run( - self, - timeout=timeout, - ) + return_information = self.run(timeout) + print(return_information) + self.load_results() + if clear: + self.clear() return return_information - def run_load( + def run( self, timeout: Optional[int] = None, - clear: bool = True ) -> ReturnInformation: """ - Run the CADET simulation and load the results. + Run the CADET simulation. Parameters ---------- timeout : Optional[int] Maximum time allowed for the simulation to run, in seconds. - clear : bool - If True, clear previous results after loading new ones. Returns ------- ReturnInformation Information about the simulation run. """ - return_information = self.run(timeout) - self.load_results() + return_information = self.cadet_runner.run( + self, + timeout=timeout, + ) - if clear: - self.clear() return return_information def load_results(self) -> None: diff --git a/cadet/cadet_dll_parameterprovider.py b/cadet/cadet_dll_parameterprovider.py index 9b95153..2615580 100644 --- a/cadet/cadet_dll_parameterprovider.py +++ b/cadet/cadet_dll_parameterprovider.py @@ -133,23 +133,28 @@ def __init__(self, simulation: "Cadet") -> None: self.popScope = self._fields_[17][1](utils.param_provider_pop_scope) _fields_ = [ + # 0 (Position must match indices in __init__ method.) ('userData', ctypes.py_object), + # 1 ('getDouble', ctypes.CFUNCTYPE(c_cadet_result, ctypes.py_object, ctypes.c_char_p, ctypes.POINTER(ctypes.c_double))), ('getInt', ctypes.CFUNCTYPE(c_cadet_result, ctypes.py_object, ctypes.c_char_p, point_int)), ('getBool', ctypes.CFUNCTYPE(c_cadet_result, ctypes.py_object, ctypes.c_char_p, ctypes.POINTER(ctypes.c_uint8))), ('getString', ctypes.CFUNCTYPE(c_cadet_result, ctypes.py_object, ctypes.c_char_p, ctypes.POINTER(ctypes.c_char_p))), + # 5 ('getDoubleArray', ctypes.CFUNCTYPE(c_cadet_result, ctypes.py_object, ctypes.c_char_p, point_int, array_double)), ('getIntArray', ctypes.CFUNCTYPE(c_cadet_result, ctypes.py_object, ctypes.c_char_p, point_int, ctypes.POINTER(point_int))), ('getBoolArray', ctypes.CFUNCTYPE(c_cadet_result, ctypes.py_object, ctypes.c_char_p, point_int, ctypes.POINTER(ctypes.POINTER(ctypes.c_uint8)))), ('getStringArray', ctypes.CFUNCTYPE(c_cadet_result, ctypes.py_object, ctypes.c_char_p, point_int, ctypes.POINTER(ctypes.POINTER(ctypes.c_char_p)))), + # 9 ('getDoubleArrayItem', ctypes.CFUNCTYPE(c_cadet_result, ctypes.py_object, ctypes.c_char_p, ctypes.c_int, ctypes.POINTER(ctypes.c_double))), ('getIntArrayItem', ctypes.CFUNCTYPE(c_cadet_result, ctypes.py_object, ctypes.c_char_p, ctypes.c_int, point_int)), ('getBoolArrayItem', ctypes.CFUNCTYPE(c_cadet_result, ctypes.py_object, ctypes.c_char_p, ctypes.c_int, ctypes.POINTER(ctypes.c_uint8))), ('getStringArrayItem', ctypes.CFUNCTYPE(c_cadet_result, ctypes.py_object, ctypes.c_char_p, ctypes.c_int, ctypes.POINTER(ctypes.c_char_p))), + # 13 ('exists', ctypes.CFUNCTYPE(ctypes.c_int, ctypes.py_object, ctypes.c_char_p)), ('isArray', ctypes.CFUNCTYPE(c_cadet_result, ctypes.py_object, ctypes.c_char_p, ctypes.POINTER(ctypes.c_uint8))), ('numElements', ctypes.CFUNCTYPE(ctypes.c_int, ctypes.py_object, ctypes.c_char_p)), diff --git a/cadet/cadet_dll_utils.py b/cadet/cadet_dll_utils.py index 204b52f..383f44d 100644 --- a/cadet/cadet_dll_utils.py +++ b/cadet/cadet_dll_utils.py @@ -1,14 +1,19 @@ import ctypes +from typing import Any + import numpy as np -from typing import Any, Optional def null(*args: Any) -> None: """Do nothing (used as a placeholder function).""" pass + log_print = print if 0 else null + +# %% Single entries + def param_provider_get_double( reader: Any, name: ctypes.c_char_p, @@ -170,6 +175,8 @@ def param_provider_get_string( return -1 +# %% Arrays + def param_provider_get_double_array( reader: Any, name: ctypes.c_char_p, @@ -256,6 +263,8 @@ def param_provider_get_int_array( return -1 +# %% Array items + def param_provider_get_double_array_item( reader: Any, name: ctypes.c_char_p, @@ -301,7 +310,8 @@ def param_provider_get_double_array_item( def param_provider_get_int_array_item( reader: Any, name: ctypes.c_char_p, - index: int, val: ctypes.POINTER(ctypes.c_int) + index: int, + val: ctypes.POINTER(ctypes.c_int) ) -> int: """ Retrieve an item from an integer array in the reader based on the provided name and index. @@ -343,7 +353,8 @@ def param_provider_get_int_array_item( def param_provider_get_bool_array_item( reader: Any, name: ctypes.c_char_p, - index: int, val: ctypes.POINTER(ctypes.c_uint8) + index: int, + val: ctypes.POINTER(ctypes.c_uint8) ) -> int: """ Retrieve an item from a boolean array in the reader based on the provided name and index. @@ -385,7 +396,8 @@ def param_provider_get_bool_array_item( def param_provider_get_string_array_item( reader: Any, name: ctypes.c_char_p, - index: int, val: ctypes.POINTER(ctypes.c_char_p) + index: int, + val: ctypes.POINTER(ctypes.c_char_p) ) -> int: """ Retrieve an item from a string array in the reader based on the provided name and index. @@ -431,6 +443,8 @@ def param_provider_get_string_array_item( return -1 +# %% Misc + def param_provider_exists( reader: Any, name: ctypes.c_char_p