Skip to content

Commit

Permalink
SKA-390: Fixed crash if the model description had a unit definition w…
Browse files Browse the repository at this point in the history
…/o a base unit
  • Loading branch information
DominikHerr committed Feb 22, 2024
1 parent ad2a311 commit 01a690b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
7 changes: 2 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ The format is based on `Keep a Changelog (http://keepachangelog.com/en/1.0.0/) <

* Added a configuration file schema ``FmuImporterConfiguration.schema.json`` for FmuImporter and included it in release package and extended documentation how to use it.

---

## [1.2.0] - TBD

### Fixed

* Fixed configuration of boolean parameters via config file
* The importer did not run with an 'autonomous' lifecycle if the time synchronization mode was set to 'unsynchronized' - this is now working as intended.
* The importer did not run with an 'autonomous' lifecycle if the time synchronization mode was set to 'unsynchronized' - this is now working as intended
* Fixed a crash that occurred if an FMU's model description had a unit definition that did not use a base unit

---

Expand Down
22 changes: 15 additions & 7 deletions FmuImporter/FmiBridge/FmiModel/Internal/ModelDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,15 @@ private void InitUnitMap(Fmi3.fmiModelDescriptionUnitDefinitions input)
{
var unitDefinition = new UnitDefinition
{
Name = fmi3Unit.name,
Offset = fmi3Unit.BaseUnit.offset,
Factor = fmi3Unit.BaseUnit.factor
Name = fmi3Unit.name
};

if (fmi3Unit.BaseUnit != null)
{
unitDefinition.Offset = fmi3Unit.BaseUnit.offset;
unitDefinition.Factor = fmi3Unit.BaseUnit.factor;
}

UnitDefinitions.Add(unitDefinition.Name, unitDefinition);
}
}
Expand All @@ -239,15 +243,19 @@ private void InitUnitMap(Fmi2.fmiModelDescriptionUnitDefinitions input)
return;
}

foreach (var fmi3Unit in input.Unit)
foreach (var fmi2Unit in input.Unit)
{
var unitDefinition = new UnitDefinition
{
Name = fmi3Unit.name,
Offset = fmi3Unit.BaseUnit.offset,
Factor = fmi3Unit.BaseUnit.factor
Name = fmi2Unit.name
};

if (fmi2Unit.BaseUnit != null)
{
unitDefinition.Offset = fmi2Unit.BaseUnit.offset;
unitDefinition.Factor = fmi2Unit.BaseUnit.factor;
}

UnitDefinitions.Add(unitDefinition.Name, unitDefinition);
}
}
Expand Down

0 comments on commit 01a690b

Please sign in to comment.