Skip to content

Commit

Permalink
FMUContainer support only Co-Simulation FMUs
Browse files Browse the repository at this point in the history
  • Loading branch information
nl78 committed Dec 20, 2024
1 parent c5fd17f commit bec0882
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions fmu_manipulation_toolbox/fmu_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def set_port_type(self, type_name: str, attrs: Dict[str, str]):
def xml(self, vr: int, name=None, causality=None, start=None):

if self.child is None:
raise FMUException(f"FMUPort has no child. Bug?")
raise FMUContainerError(f"FMUPort has no child. Bug?")

child_str = f"<{self.type_name}"
if self.child:
Expand Down Expand Up @@ -85,6 +85,8 @@ def __init__(self, filename):
self.current_port = None # used during apply_operation()

self.fmu.apply_operation(self) # Should be the last command in constructor!
if self.model_identifier is None:
raise FMUContainerError(f"FMU '{self.name}' does not implement Co-Simulation mode.")

def fmi_attrs(self, attrs):
self.guid = attrs['guid']
Expand Down Expand Up @@ -176,7 +178,7 @@ def __init__(self):
def get_vr(self, cport: ContainerPort) -> int:
return self.add_vr(cport.port.type_name)

def add_vr(self, type_name:str) -> int:
def add_vr(self, type_name: str) -> int:
vr = self.vr_table[type_name]
self.vr_table[type_name] += 1
return vr
Expand Down Expand Up @@ -445,7 +447,8 @@ def make_fmu_xml(self, xml_file, step_size: float, profiling: bool):
for fmu in self.execution_order:
vr = vr_table.add_vr("Real")
name = f"container.{fmu.model_identifier}.rt_ratio"
print(f'<ScalarVariable valueReference="{vr}" name="{name}" causality="local"><Real /></ScalarVariable>', file=xml_file)
print(f'<ScalarVariable valueReference="{vr}" name="{name}" causality="local">'
f'<Real /></ScalarVariable>', file=xml_file)

# Local variable should be first to ensure to attribute them the lowest VR.
for local in self.locals.values():
Expand Down Expand Up @@ -562,7 +565,7 @@ def make_fmu_txt(self, txt_file, step_size: float, mt: bool, profiling: bool):
if profiling and type_name == "Real":
nb += len(self.execution_order)
print(nb, file=txt_file)
for profiling_port,_ in enumerate(self.execution_order):
for profiling_port, _ in enumerate(self.execution_order):
print(f"{profiling_port} -2 {profiling_port}", file=txt_file)
else:
print(nb, file=txt_file)
Expand Down

0 comments on commit bec0882

Please sign in to comment.