From 2da9d5adda9d578da9787732487476d0ada28475 Mon Sep 17 00:00:00 2001
From: Ferhat Mihoubi <ferhat.mihoubi@univ-evry.fr>
Date: Wed, 18 Aug 2010 13:45:07 +0200
Subject: [PATCH] Bug correction in the deterministic simulation: to solve a
 purely backward or forward looking block requires contemporaneous derivatives
 only.

---
 DynamicModel.cc | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/DynamicModel.cc b/DynamicModel.cc
index 1850f115..cee51df6 100644
--- a/DynamicModel.cc
+++ b/DynamicModel.cc
@@ -646,12 +646,16 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
               unsigned int varr = getBlockVariableID(block, var);
               expr_t id = it->second.second;
               int lag = it->second.first;
-              output << "    g1(" << eq+1 << ", " << var+1-block_recursive << ") = ";
-              id->writeOutput(output, local_output_type, local_temporary_terms);
-              output << "; % variable=" << symbol_table.getName(symbol_table.getID(eEndogenous, varr))
-                     << "(" << lag
-                     << ") " << varr+1
-                     << ", equation=" << eqr+1 << endl;
+              if (lag == 0)
+                {
+                  output << "    g1(" << eq+1 << ", " << var+1-block_recursive << ") = ";
+                  id->writeOutput(output, local_output_type, local_temporary_terms);
+                  output << "; % variable=" << symbol_table.getName(symbol_table.getID(eEndogenous, varr))
+                         << "(" << lag
+                         << ") " << varr+1
+                         << ", equation=" << eqr+1 << endl;
+                }
+
             }
           output << "  end;\n";
           break;
@@ -1195,6 +1199,8 @@ DynamicModel::writeModelEquationsCode_Block(string &file_name, const string &bin
                   unsigned int varr = getBlockVariableID(block, var);
                   if (eq >= block_recursive and var >= block_recursive)
                     {
+                      if (lag != 0 && (simulation_type == SOLVE_FORWARD_COMPLETE || simulation_type == SOLVE_BACKWARD_COMPLETE))
+                        continue;
                       if (!Uf[eqr].Ufl)
                         {
                           Uf[eqr].Ufl = (Uff_l *) malloc(sizeof(Uff_l));
@@ -1547,6 +1553,8 @@ DynamicModel::Write_Inf_To_Bin_File_Block(const string &dynamic_basename, const
       unsigned int eq = it->first.first;
       unsigned int var = it->first.second;
       int lag = it->second.first;
+      if (lag != 0 && !is_two_boundaries)
+        continue;
       if (eq >= block_recursive && var >= block_recursive)
         {
           int v = eq - block_recursive;
-- 
GitLab