cellml / libcellml

Repository for libCellML development.
https://libcellml.org
Apache License 2.0
16 stars 21 forks source link

Importing Units from a common resource #1160

Closed hsorby closed 1 year ago

hsorby commented 1 year ago

When using a model as a database for units, the units do not get resolved as expected. For example, given a model:

<?xml version="1.0" encoding="UTF-8"?>
<model xmlns="http://www.cellml.org/cellml/2.0#" name="triangle_point_I">
  <import xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="triangle_units_base.cellml">
    <units units_ref="mm" name="mm"/>
  </import>
  <import xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="triangle_units_opposite_I.cellml">
    <component component_ref="opposite" name="opposite"/>
  </import>
  <component name="point">
    <variable name="var2" units="mm" />
  </component>
</model>

and the imported units model:

<?xml version="1.0" encoding="UTF-8"?>
<model xmlns="http://www.cellml.org/cellml/2.0#" name="diamond_units_base">
  <units name="mm">
    <unit prefix="milli" units="metre"/>
  </units>
</model>

and the imported component model:

<?xml version="1.0" encoding="UTF-8"?>
<model xmlns="http://www.cellml.org/cellml/2.0#" name="triangle_opposite">
  <import xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="triangle_units_base.cellml">
    <units units_ref="mm" name="mm"/>
  </import>
  <component name="opposite">
    <variable name="var1" units="mm" />
  </component>
</model>

Will result in the following model:

<?xml version="1.0" encoding="UTF-8"?>
<model xmlns="http://www.cellml.org/cellml/2.0#" name="triangle_point_I">
  <units name="mm">
    <unit prefix="milli" units="metre"/>
  </units>
  <units name="mm_1">
    <unit prefix="milli" units="metre"/>
  </units>
  <component name="opposite">
    <variable name="var1" units="mm_1"/>
  </component>
  <component name="point">
    <variable name="var2" units="mm"/>
  </component>
</model>

Which is not the desired outcome. The desired output would be:

<?xml version="1.0" encoding="UTF-8"?>
<model xmlns="http://www.cellml.org/cellml/2.0#" name="triangle_point_I">
  <units name="mm">
    <unit prefix="milli" units="metre"/>
  </units>
  <component name="opposite">
    <variable name="var1" units="mm"/>
  </component>
  <component name="point">
    <variable name="var2" units="mm"/>
  </component>
</model>