From 86b2b4c2dadcbb07fd425f2178db27cd52c6113e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Fri, 4 Jun 2021 16:20:29 +0200
Subject: [PATCH] When order option > 3, compute planner objective derivatives
 at that order

Ref. dynare!1866
---
 src/ComputingTasks.cc | 4 ++--
 src/ComputingTasks.hh | 2 +-
 src/ModFile.cc        | 2 +-
 src/Statement.cc      | 2 +-
 src/Statement.hh      | 2 +-
 5 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/ComputingTasks.cc b/src/ComputingTasks.cc
index 8f65bc0a..9d87b446 100644
--- a/src/ComputingTasks.cc
+++ b/src/ComputingTasks.cc
@@ -2202,9 +2202,9 @@ PlannerObjectiveStatement::getPlannerObjective() const
 }
 
 void
-PlannerObjectiveStatement::computingPass()
+PlannerObjectiveStatement::computingPass(const ModFileStructure &mod_file_struct)
 {
-  model_tree.computingPass(3, 0, {}, false, false, false);
+  model_tree.computingPass(max(3, mod_file_struct.order_option), 0, {}, false, false, false);
   computing_pass_called = true;
 }
 
diff --git a/src/ComputingTasks.hh b/src/ComputingTasks.hh
index d86cb4bc..96ae1627 100644
--- a/src/ComputingTasks.hh
+++ b/src/ComputingTasks.hh
@@ -517,7 +517,7 @@ public:
     (no exogenous, no lead/lag) */
   void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) override;
   /*! \todo allow for the possibility of disabling temporary terms */
-  void computingPass() override;
+  void computingPass(const ModFileStructure &mod_file_struct) override;
   void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const override;
   void writeJsonOutput(ostream &output) const override;
   //! Return a reference the Planner Objective model tree
diff --git a/src/ModFile.cc b/src/ModFile.cc
index 0a13ace9..55f59f66 100644
--- a/src/ModFile.cc
+++ b/src/ModFile.cc
@@ -840,7 +840,7 @@ ModFile::computingPass(bool no_tmp_terms, OutputType output, int params_derivs_o
     }
 
   for (auto &statement : statements)
-    statement->computingPass();
+    statement->computingPass(mod_file_struct);
 
   // Compute epilogue derivatives (but silence standard output)
   streambuf *oldcout = cout.rdbuf();
diff --git a/src/Statement.cc b/src/Statement.cc
index 85c6d235..c18b404b 100644
--- a/src/Statement.cc
+++ b/src/Statement.cc
@@ -30,7 +30,7 @@ Statement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &wa
 }
 
 void
-Statement::computingPass()
+Statement::computingPass(const ModFileStructure &mod_file_struct)
 {
 }
 
diff --git a/src/Statement.hh b/src/Statement.hh
index dc4cf190..8988441d 100644
--- a/src/Statement.hh
+++ b/src/Statement.hh
@@ -164,7 +164,7 @@ public:
     method. Otherwise the default implementation (i.e. a no-op) will apply and
     some checks won't be run. */
   virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
-  virtual void computingPass();
+  virtual void computingPass(const ModFileStructure &mod_file_struct);
   //! Write Matlab output code
   /*!
     \param output is the output stream of the main matlab file
-- 
GitLab