diff --git a/src/DynamicModel.hh b/src/DynamicModel.hh index 491cbeef..7efae9c9 100644 --- a/src/DynamicModel.hh +++ b/src/DynamicModel.hh @@ -740,7 +740,11 @@ DynamicModel::writeDynamicPerBlockHelper(int blk, ostream &output, temporary_ter // The Jacobian if we have to solve the block - // Write temporary terms for derivatives + /* Write temporary terms for derivatives. + Also note that in the case of “evaluate” blocks, derivatives are not + computed in deterministic mode; still their temporary terms must be + computed even in that mode, because they may be needed in subsequent + blocks. */ write_eq_tt(blocks[blk].size); if constexpr(isCOutput(output_type)) diff --git a/src/StaticModel.hh b/src/StaticModel.hh index facb4e09..a67637d7 100644 --- a/src/StaticModel.hh +++ b/src/StaticModel.hh @@ -243,13 +243,20 @@ StaticModel::writeStaticPerBlockHelper(int blk, ostream &output, temporary_terms exit(EXIT_FAILURE); } } + + /* Write temporary terms for derivatives. + This is done even for “evaluate” blocks, whose derivatives are not + computed at runtime; still those temporary terms may be needed by + subsequent blocks (not calling write_eq_tt() would not be a bug though, + because those terms would not be added to temporary_terms_union and would + therefore not be used; still, it’s probably better performance-wise to + use those temporary terms). */ + write_eq_tt(blocks[blk].size); + // The Jacobian if we have to solve the block if (simulation_type != BlockSimulationType::evaluateBackward && simulation_type != BlockSimulationType::evaluateForward) { - // Write temporary terms for derivatives - write_eq_tt(blocks[blk].size); - ostringstream i_output, j_output, v_output; for (int line_counter { ARRAY_SUBSCRIPT_OFFSET(output_type) }; const auto &[indices, d] : blocks_derivatives[blk])