Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
schmoelder committed Dec 10, 2024
1 parent 8f4b7c2 commit 5c6951a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
31 changes: 16 additions & 15 deletions cadet/cadet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions cadet/cadet_dll_parameterprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
22 changes: 18 additions & 4 deletions cadet/cadet_dll_utils.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5c6951a

Please sign in to comment.