Skip to content

Commit bd71787

Browse files
committed
update handling of variable_filter
* use public function `ModelicaSystemABC.set_variable_filter()` to define * process it in `ModelicaSystemABC._process_override_data()` as command line argument
1 parent 03a50ab commit bd71787

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

OMPython/modelica_system_abc.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,12 +595,20 @@ def _process_override_data(
595595
override_file: OMPathABC,
596596
override_var: dict[str, str],
597597
override_sim: dict[str, str],
598+
variable_filter: Optional[str] = None,
598599
) -> None:
599600
"""
600601
Define the override parameters. As the definition of simulation specific override parameter changes with OM
601602
1.26.0, version specific code is needed. Please keep in mind, that this will fail if OMC is not used to run the
602603
model executable.
604+
605+
Including also override of variable filter settings.
603606
"""
607+
608+
# define variable filter if defined (override any original setting)
609+
if variable_filter is not None:
610+
om_cmd.arg_set(key="variableFilter", val=variable_filter)
611+
604612
if len(override_var) == 0 and len(override_sim) == 0:
605613
return
606614

@@ -931,6 +939,29 @@ def setOptimizationOptions(
931939
datatype="optimization-option",
932940
overridedata=None)
933941

942+
def set_variable_filter(
943+
self,
944+
variable_filter: Optional[str] = None,
945+
escape: bool = False,
946+
) -> None:
947+
"""
948+
This method is used to set variable filters. If escape is True, all regex special characters are escaped.
949+
"""
950+
if variable_filter is None:
951+
self._variable_filter = None
952+
return
953+
954+
if escape:
955+
variable_filter = re.escape(variable_filter)
956+
957+
# Validate filter_val as a regular expression
958+
try:
959+
re.compile(variable_filter)
960+
except re.error as exc:
961+
raise ModelicaSystemError(f"Invalid variable_filter regular expression: {variable_filter!r} ({exc})")
962+
963+
self._variable_filter = variable_filter
964+
934965
@staticmethod
935966
def toInputs(data: dict[str, list[float]]) -> dict[str, list[tuple[float, float]]]:
936967
"""

0 commit comments

Comments
 (0)