Block decomposition: fix crash when a variable appears in an equation but has zero symbolic derivative

master
Sébastien Villemot 2022-06-13 16:24:33 +02:00
parent 5d1264e2b9
commit 9b04c5436e
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
2 changed files with 6 additions and 2 deletions

View File

@ -4441,7 +4441,11 @@ DynamicModel::computeChainRuleJacobian()
switch (derivType)
{
case BlockDerivativeType::standard:
d = derivatives[1][{ eq_orig, deriv_id }];
if (auto it = derivatives[1].find({ eq_orig, deriv_id });
it != derivatives[1].end())
d = it->second;
else
d = Zero;
break;
case BlockDerivativeType::chainRule:
d = equations[eq_orig]->getChainRuleDerivative(deriv_id, recursive_vars);

View File

@ -106,7 +106,7 @@ protected:
For each derivation order, stores a map whose key is a vector of integer: the
first integer is the equation index, the remaining ones are the derivation
IDs of variables (in non-decreasing order, to avoid storing symmetric
elements several times) */
elements several times). Only non-zero derivatives are stored. */
vector<map<vector<int>, expr_t>> derivatives;
//! Number of non-zero derivatives