From 740ea833f6b4a93c260b32e62f4302483af54f7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Wed, 7 Oct 2020 18:52:34 +0200 Subject: [PATCH] Block decomposition: bugfix for solve one boundary blocks with mfs>0 Ref. dynare#1726 --- src/DynamicModel.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc index fdf7ae34..27f5d3cf 100644 --- a/src/DynamicModel.cc +++ b/src/DynamicModel.cc @@ -411,10 +411,11 @@ DynamicModel::writeDynamicPerBlockHelper(int blk, ostream &output, ExprNodeOutpu for (const auto &[indices, d] : blocks_derivatives[blk]) { auto [eq, var, lag] = indices; - if (lag == 0) + if (lag == 0 && eq >= block_recursive_size && var >= block_recursive_size) { i_output << " g1_i" << LEFT_ARRAY_SUBSCRIPT(output_type) << line_counter - << RIGHT_ARRAY_SUBSCRIPT(output_type) << '=' << eq+1 << ';' << endl; + << RIGHT_ARRAY_SUBSCRIPT(output_type) << '=' + << eq+1-block_recursive_size << ';' << endl; j_output << " g1_j" << LEFT_ARRAY_SUBSCRIPT(output_type) << line_counter << RIGHT_ARRAY_SUBSCRIPT(output_type) << '=' << var+1-block_recursive_size << ';' << endl; @@ -473,9 +474,9 @@ DynamicModel::nzeDeterministicJacobianForBlock(int blk) const || simulation_type == BlockSimulationType::solveBackwardComplete || simulation_type == BlockSimulationType::solveForwardComplete) nze_deterministic = count_if(blocks_derivatives[blk].begin(), blocks_derivatives[blk].end(), - [](const auto &kv) { + [=](const auto &kv) { auto [eq, var, lag] = kv.first; - return lag == 0; + return lag == 0 && eq >= block_recursive_size && var >= block_recursive_size; }); return nze_deterministic; }