From 9b04c5436ef01aca68140e504e3d6381402d7a1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Mon, 13 Jun 2022 16:24:33 +0200 Subject: [PATCH] Block decomposition: fix crash when a variable appears in an equation but has zero symbolic derivative --- src/DynamicModel.cc | 6 +++++- src/ModelTree.hh | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc index 4503f2c4..8b424eb3 100644 --- a/src/DynamicModel.cc +++ b/src/DynamicModel.cc @@ -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); diff --git a/src/ModelTree.hh b/src/ModelTree.hh index d3e2a5c3..32c11974 100644 --- a/src/ModelTree.hh +++ b/src/ModelTree.hh @@ -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, expr_t>> derivatives; //! Number of non-zero derivatives