From d0ec5eb15520fd207bb556ae05095033888b629f Mon Sep 17 00:00:00 2001
From: NormannR <normann@dynare.org>
Date: Fri, 11 Jun 2021 12:37:31 +0200
Subject: [PATCH] Allows to write M_.objective_tmp_nbr in the driver.m file
 Writes the number of temporary terms of the planner objective function
 derivatives objective_tmp_nbr in the driver.m file. Useful for the k-order
 approximations of welfare.

---
 src/ComputingTasks.cc | 6 +++++-
 src/ModelTree.hh      | 7 +++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/ComputingTasks.cc b/src/ComputingTasks.cc
index 48bdd023..bd12f523 100644
--- a/src/ComputingTasks.cc
+++ b/src/ComputingTasks.cc
@@ -2214,7 +2214,11 @@ PlannerObjectiveStatement::writeOutput(ostream &output, const string &basename,
   output << "M_.NNZDerivatives_objective = [";
   for (int i=1; i < static_cast<int>(model_tree.getNNZDerivatives().size()); i++)
     output << (i > model_tree.getComputedDerivsOrder() ? -1 : model_tree.getNNZDerivatives()[i]) << ";";
-  output << "];";
+  output << "];" << endl;
+  output << "M_.objective_tmp_nbr = [";
+  for (const auto &temporary_terms_derivative : model_tree.getTemporaryTermsDerivatives())
+    output << temporary_terms_derivative.size() << "; ";
+  output << "];" << endl;
   model_tree.writeStaticFile(basename + ".objective", false, false, false, "", {}, {}, false);
 }
 
diff --git a/src/ModelTree.hh b/src/ModelTree.hh
index 0014c34a..467c0c94 100644
--- a/src/ModelTree.hh
+++ b/src/ModelTree.hh
@@ -462,6 +462,13 @@ public:
     return NNZDerivatives;
   }
 
+  //! Returns the vector of temporary terms derivatives
+  inline const vector<temporary_terms_t> &
+  getTemporaryTermsDerivatives() const
+  {
+    return temporary_terms_derivatives;
+  }
+
   //!Returns the maximum order of computed derivatives
   inline int
   getComputedDerivsOrder() const
-- 
GitLab