Skip to content

Commit

Permalink
Merge pull request #233 from lkeegan/fix_232_UnitFormulaFormatter_Pow…
Browse files Browse the repository at this point in the history
…erUnitsCheck

improve thread safety of UnitFormulaFormatter, PowerUnitsCheck
  • Loading branch information
fbergmann committed May 30, 2022
2 parents 7d740d4 + 7394a36 commit 52183c6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
17 changes: 9 additions & 8 deletions src/sbml/units/UnitFormulaFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,9 @@ UnitFormulaFormatter::getUnitDefinitionFromPower(const ASTNode * node,
exponentNode->isReal() == true ||
exponentUD->isVariantOfDimensionless())
{
SBMLTransforms::mapComponentValues(model);
exponentValue = SBMLTransforms::evaluateASTNode(node->getRightChild(), model);
SBMLTransforms::clearComponentValues();
SBMLTransforms::IdValueMap values;
SBMLTransforms::getComponentValuesForModel(model, values);
exponentValue = SBMLTransforms::evaluateASTNode(node->getRightChild(), values, model);

for (unsigned int n = 0; n < variableUD->getNumUnits(); n++)
{
Expand Down Expand Up @@ -749,9 +749,9 @@ UnitFormulaFormatter::getUnitDefinitionFromRoot(const ASTNode * node,

if (tempUD2->isVariantOfDimensionless())
{
SBMLTransforms::mapComponentValues(model);
double value = SBMLTransforms::evaluateASTNode(child);
SBMLTransforms::clearComponentValues();
SBMLTransforms::IdValueMap values;
SBMLTransforms::getComponentValuesForModel(model, values);
double value = SBMLTransforms::evaluateASTNode(child, values);
if (!util_isNaN(value))
{
double doubleExponent =
Expand Down Expand Up @@ -2716,8 +2716,9 @@ UnitFormulaFormatter::inverseFunctionOnUnits(UnitDefinition* expectedUD,
if (mathUD == NULL || mathUD->getNumUnits() == 0
|| mathUD->isVariantOfDimensionless() == true)
{
SBMLTransforms::mapComponentValues(this->model);
double exp = 1.0/(SBMLTransforms::evaluateASTNode(math, this->model));
SBMLTransforms::IdValueMap values;
SBMLTransforms::getComponentValuesForModel(this->model, values);
double exp = 1.0/(SBMLTransforms::evaluateASTNode(math, values, this->model));
resolvedUD = new UnitDefinition(*expectedUD);
for (unsigned int i = 0; i < resolvedUD->getNumUnits(); i++)
{
Expand Down
12 changes: 6 additions & 6 deletions src/sbml/validator/constraints/PowerUnitsCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ PowerUnitsCheck::checkUnitsFromPower (const Model& m,

if (tempUD->isVariantOfDimensionless())
{
SBMLTransforms::mapComponentValues(&m);
double value1 = SBMLTransforms::evaluateASTNode(child);
SBMLTransforms::clearComponentValues();
SBMLTransforms::IdValueMap values;
SBMLTransforms::getComponentValuesForModel(&m, values);
double value1 = SBMLTransforms::evaluateASTNode(child, values);
if (!util_isNaN(value1))
{
if (floor(value1) != value1)
Expand Down Expand Up @@ -319,9 +319,9 @@ PowerUnitsCheck::checkUnitsFromPower (const Model& m,
{
// technically here there is an issue
// stoichiometry is dimensionless
SBMLTransforms::mapComponentValues(&m);
double value1 = SBMLTransforms::evaluateASTNode(child, &m);
SBMLTransforms::clearComponentValues();
SBMLTransforms::IdValueMap values;
SBMLTransforms::getComponentValuesForModel(&m, values);
double value1 = SBMLTransforms::evaluateASTNode(child, values, &m);
// but it may not be an integer
if (util_isNaN(value1))
// we cant check
Expand Down

0 comments on commit 52183c6

Please sign in to comment.