diff --git a/src/DynamicModel.hh b/src/DynamicModel.hh index 491cbeef8011d62db3a36ace7d786fbb720d53ab..7efae9c9f3c6decfca1cd5e91a46cfbabda33761 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 facb4e09d2d53e7be5de34ee48ae53fa3308bca6..a67637d7a5f0745d2080ecbe08b2ef22347ab25f 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])