OMSimulator icon indicating copy to clipboard operation
OMSimulator copied to clipboard

Unit mismatch error although units are the same

Open larsviktorlarsson opened this issue 11 months ago • 2 comments

I have an .ssp with a SystemStructure.ssd file that has an .fmu with unit = "" on all outputs in its ModelDescription file. When I add unit to one of these connectors in SystemStructure.ssd: <ssd:Connector name="pLin.in.y" kind="output" description=""> <ssc:Real unit="bar"/> </ssd:Connector>

and connect this connector to another connector in the .ssd with the same unit:

<ssd:Connector name="pLin" kind="input" description="Input load pressure"> <ssc:Real unit="bar"/> </ssd:Connector>

<ssd:Connection endConnector="pLin" endElement="valve_model" startConnector="pLin.in.y" startElement="interface_model"/>

I get error:

error: [addConnection] Unit mismatch in connection: interface_model.pLin.in.y -> valve_model.pLin error: [importFromSnapshot] Failed to import ssd:Connection

If I instead have

<ssd:Connector name="pLin.in.y" kind="output" description=""> <ssc:Real unit=""/> </ssd:Connector>

I get no error.

Should not the units in the ssd override the units in the FMU?

Also, the fmu for valve_model has units on all connectors.

My ssp as zip: ParkerSimPack.zip

Running OMiImulator python api, version 'OMSimulator v2.1.3-win-notlm'

larsviktorlarsson avatar Feb 14 '25 13:02 larsviktorlarsson

an empty unit in Modelica is not treated the same as unit 1, need to check the specification to know how this is supposed to be handled

lenaRB avatar Mar 03 '25 13:03 lenaRB

@lochel - any follow up on this?

lenaRB avatar Apr 14 '25 12:04 lenaRB

@lochel ping

robha67 avatar Jan 07 '26 13:01 robha67

@lochel @arun3688 @lenaRB I tried now with latest version of OMSimulator ('OMSimulator v3.0.0.post103-g53bba5e-win') and it seems to work. Can you confirm that this is fixed, and if so how is it now handled?

larsviktorlarsson avatar Jan 09 '26 10:01 larsviktorlarsson

@larsviktorlarsson How should I test this?

When I run the attached SSP file with the latest OMSimulator [1], I get the following errors:

error:   [addConnection] Unit mismatch in connection: interface_model.pLin.in.y -> valve_model.pLin
error:   [importFromSnapshot] Failed to import ssd:Connection

I’m not sure whether this behavior is intended. I need to take a closer look at the SSP package and the FMUs to understand how the units are defined.

Do you have a Python or Lua script that can be used to test the different cases?


[1] OMSimulator v3.0.0.post120-g9acb585-linux-debug

lochel avatar Jan 12 '26 15:01 lochel

@lochel When I created the issue I ran an older version (<3.0) where the syntax was different from now. If I use a newer version [1] with the following (first change the file ending from .zip to .ssp on ParkerSimPack) python script:

from OMSimulator import SSP

model = SSP('ParkerSimPack.ssp')

I get the following error:


AttributeError Traceback (most recent call last) File c:\parker\python\omstroubleshoot\oms_error.py:10 2 """ 3 Created on Mon Jan 12 16:42:34 2026 4 5 @author: vicla25 6 """ 8 from OMSimulator import SSP ---> 10 model = SSP('ParkerSimPack.ssp')

File C:\ProgramData\anaconda3\Lib\site-packages\OMSimulator\ssp.py:33, in SSP.init(self, path, temp_dir) 30 logger.info(f"Temporary directory created: {suppress_path_to_str(self.temp_dir)}") 32 if path: ---> 33 self._extract_ssp(path) 35 # Ensure at least one variant exists 36 if self.activeVariantName is None:

File C:\ProgramData\anaconda3\Lib\site-packages\OMSimulator\ssp.py:70, in SSP._extract_ssp(self, path) 68 for ssd_file in ssd_files: 69 ssd_path = self.temp_dir / ssd_file ---> 70 ssd = SSD.importFromFile(ssd_path, self.resources) 71 self.add(ssd)

File C:\ProgramData\anaconda3\Lib\site-packages\OMSimulator\ssd.py:42, in SSD.importFromFile(filename, resources) 40 root = tree.getroot() 41 filename = Path(filename).resolve() ---> 42 return SSD.importFromNode(root, filename, resources) 43 except ET.ParseError as e: 44 logger.error(f"Error parsing SSD file '{filename}': {e}")

File C:\ProgramData\anaconda3\Lib\site-packages\OMSimulator\ssd.py:67, in SSD.importFromNode(root, filename, resources) 65 if system is None: 66 raise ValueError(f"Invalid SSD file: Missing ssd:System in {filename}") ---> 67 ssd.system = System.importFromNode(system, ssd, resources) 68 utils.parseDefaultExperiment(root, ssd) 69 Unit.importFromNode(root, ssd)

File C:\ProgramData\anaconda3\Lib\site-packages\OMSimulator\system.py:117, in System.importFromNode(node, ssd, resources) 115 system.systemgeometry = SystemGeometry.importFromNode(node) 116 utils.parseParameterBindings(node, system, resources) --> 117 system.elements = utils.parseElements(node, resources) 118 system.solvers = utils.parseAnnotations(node) 119 Connection.importFromNode(node, system)

File C:\ProgramData\anaconda3\Lib\site-packages\OMSimulator\utils.py:85, in parseElements(node, resources) 83 elements[name].connectors = Connector.importFromNode(component) 84 elements[name].elementgeometry = ElementGeometry.importFromNode(component) ---> 85 parseParameterBindings(component, elements[name], resources) 86 solvers = parseAnnotations(component) 87 if solvers:

File C:\ProgramData\anaconda3\Lib\site-packages\OMSimulator\utils.py:127, in parseParameterBindings(node, obj, resources) 124 for mapping in parameter_mapping_ssm.findall("ssm:MappingEntry", namespaces=namespace.ns): 125 obj.parameterMapping.mapParameter(mapping.get("source"), mapping.get("target")) --> 127 Unit.importFromNode(param_set, obj, tagname="ssv:Units")

File C:\ProgramData\anaconda3\Lib\site-packages\OMSimulator\unit.py:29, in Unit.importFromNode(node, root, tagname) 27 @staticmethod 28 def importFromNode(node, root, tagname = "ssd:Units"): ---> 29 units_element = node.find(tagname, namespaces=namespace.ns) 30 if units_element is None: 31 return

[1] 'OMSimulator v3.0.0.post116-g5158e1a-win'

So the error is not exactly the same, but still something is off with the units.

larsviktorlarsson avatar Jan 12 '26 16:01 larsviktorlarsson