Skip to content

Commit 5063859

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 7822295 commit 5063859

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
@@ -596,12 +596,20 @@ def _process_override_data(
596596
override_file: OMPathABC,
597597
override_var: dict[str, str],
598598
override_sim: dict[str, str],
599+
variable_filter: Optional[str] = None,
599600
) -> None:
600601
"""
601602
Define the override parameters. As the definition of simulation specific override parameter changes with OM
602603
1.26.0, version specific code is needed. Please keep in mind, that this will fail if OMC is not used to run the
603604
model executable.
605+
606+
Including also override of variable filter settings.
604607
"""
608+
609+
# define variable filter if defined (override any original setting)
610+
if variable_filter is not None:
611+
om_cmd.arg_set(key="variableFilter", val=variable_filter)
612+
605613
if len(override_var) == 0 and len(override_sim) == 0:
606614
return
607615

@@ -937,6 +945,29 @@ def setOptimizationOptions(
937945
datatype="optimization-option",
938946
overridedata=None)
939947

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

0 commit comments

Comments
 (0)