Fix segfault of notmpterms option with block decomposition

By the way, ensure that temporary terms associated to external functions are
not removed, since they are not optional.
master
Sébastien Villemot 2022-11-04 12:00:11 +01:00
parent 2a8e26310d
commit 836351565d
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
2 changed files with 11 additions and 4 deletions

View File

@ -986,7 +986,7 @@ ModelTree::computeTemporaryTerms(bool is_matlab, bool no_tmp_terms)
}
void
ModelTree::computeBlockTemporaryTerms()
ModelTree::computeBlockTemporaryTerms(bool no_tmp_terms)
{
int nb_blocks = blocks.size();
blocks_temporary_terms.resize(nb_blocks);
@ -1017,6 +1017,14 @@ ModelTree::computeBlockTemporaryTerms()
additionalBlockTemporaryTerms(blk, blocks_temporary_terms, reference_count);
}
/* If the user has specified the notmpterms option, clear all temporary
terms, except those that correspond to external functions (since they are
not optional) */
if (no_tmp_terms)
for (auto &it : blocks_temporary_terms)
for (auto &it2 : it)
erase_if(it2, [](expr_t e) { return !dynamic_cast<AbstractExternalFunctionNode *>(e); });
// Compute indices in the temporary terms vector
blocks_temporary_terms_idxs.clear();
for (int idx{0};
@ -1977,8 +1985,7 @@ ModelTree::computingPassBlock(const eval_context_t &eval_context, bool no_tmp_te
printBlockDecomposition();
computeChainRuleJacobian();
determineLinearBlocks();
if (!no_tmp_terms)
computeBlockTemporaryTerms();
computeBlockTemporaryTerms(no_tmp_terms);
block_decomposed = true;
}

View File

@ -247,7 +247,7 @@ protected:
//! Computes temporary terms (for all equations and derivatives)
void computeTemporaryTerms(bool is_matlab, bool no_tmp_terms);
//! Computes temporary terms per block
void computeBlockTemporaryTerms();
void computeBlockTemporaryTerms(bool no_tmp_terms);
private:
/* Add additional temporary terms for a given block. This method is called by