From 6ec7f580d577848509d07e05f2120d4bab8c32e6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Mon, 16 Oct 2023 11:47:28 -0400
Subject: [PATCH] =?UTF-8?q?New=20option=20=E2=80=9Cstatic=5Fmfs=E2=80=9D?=
 =?UTF-8?q?=20to=20=E2=80=9Cmodel=E2=80=9D=20block=20(and=20=E2=80=9Cmodel?=
 =?UTF-8?q?=5Foptions=E2=80=9D=20command)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Currently defaults to 0.
---
 src/DynamicModel.cc  |  4 +++-
 src/DynamicModel.hh  | 12 ++++++++++++
 src/DynareBison.yy   |  2 ++
 src/DynareFlex.ll    |  1 +
 src/ParsingDriver.cc |  7 +++++++
 src/ParsingDriver.hh |  2 ++
 src/StaticModel.cc   |  7 ++++++-
 src/StaticModel.hh   |  9 ++++++++-
 8 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc
index 7721cdff..5274ae0f 100644
--- a/src/DynamicModel.cc
+++ b/src/DynamicModel.cc
@@ -87,7 +87,8 @@ DynamicModel::DynamicModel(const DynamicModel &m) :
   variableMapping{m.variableMapping},
   blocks_jacob_cols_endo{m.blocks_jacob_cols_endo},
   var_expectation_functions_to_write{m.var_expectation_functions_to_write},
-  mfs{m.mfs}
+  mfs{m.mfs},
+  static_mfs{m.static_mfs}
 {
   copyHelper(m);
 }
@@ -135,6 +136,7 @@ DynamicModel::operator=(const DynamicModel &m)
 
   var_expectation_functions_to_write = m.var_expectation_functions_to_write;
   mfs = m.mfs;
+  static_mfs = m.static_mfs;
 
   copyHelper(m);
 
diff --git a/src/DynamicModel.hh b/src/DynamicModel.hh
index 0d2187b1..c3571821 100644
--- a/src/DynamicModel.hh
+++ b/src/DynamicModel.hh
@@ -31,6 +31,7 @@ using namespace std;
 //! Stores a dynamic model
 class DynamicModel : public ModelTree
 {
+  friend class StaticModel; // For reading static_mfs from converting constructor
 public:
   //! A reference to the trend component model table
   TrendComponentModelTable &trend_component_model_table;
@@ -112,6 +113,11 @@ private:
   // Value of the “mfs” option of “model” block (or ”model_options” command)
   int mfs{1};
 
+  /* Value of the “static_mfs” option of “model” block (or the “model_options”
+     command).
+     Only used when converting to StaticModel class. */
+  int static_mfs{0};
+
   // Writes dynamic model file (MATLAB/Octave version, legacy representation)
   void writeDynamicMFile(const string &basename) const;
   //! Writes the code of the block-decomposed model in virtual machine bytecode
@@ -670,6 +676,12 @@ public:
   {
     mfs = mfs_arg;
   }
+
+  void
+  setStaticMFS(int static_mfs_arg)
+  {
+    static_mfs = static_mfs_arg;
+  }
 };
 
 template<bool julia>
diff --git a/src/DynareBison.yy b/src/DynareBison.yy
index 7b4b5f68..8c29deb7 100644
--- a/src/DynareBison.yy
+++ b/src/DynareBison.yy
@@ -196,6 +196,7 @@ class ParsingDriver;
 %token ENDVAL_STEADY STEADY_SOLVE_ALGO STEADY_MAXIT STEADY_TOLF STEADY_TOLX STEADY_MARKOWITZ
 %token HOMOTOPY_MAX_COMPLETION_SHARE HOMOTOPY_MIN_STEP_SIZE HOMOTOPY_INITIAL_STEP_SIZE HOMOTOPY_STEP_SIZE_INCREASE_SUCCESS_COUNT
 %token HOMOTOPY_LINEARIZATION_FALLBACK HOMOTOPY_MARGINAL_LINEARIZATION_FALLBACK FROM_INITVAL_TO_ENDVAL
+%token STATIC_MFS
 
 %token <vector<string>> SYMBOL_VEC
 
@@ -944,6 +945,7 @@ resid : RESID ';'
 model_option : BLOCK { driver.block(); }
              | CUTOFF EQUAL non_negative_number { driver.cutoff($3); };
              | MFS EQUAL INT_NUMBER { driver.mfs($3); };
+             | STATIC_MFS EQUAL INT_NUMBER { driver.static_mfs($3); };
              | BYTECODE { driver.bytecode(); }
              | USE_DLL { driver.use_dll(); }
              | NO_STATIC { driver.no_static();}
diff --git a/src/DynareFlex.ll b/src/DynareFlex.ll
index be0389f9..60544e89 100644
--- a/src/DynareFlex.ll
+++ b/src/DynareFlex.ll
@@ -801,6 +801,7 @@ DATE -?[0-9]+([ya]|m([1-9]|1[0-2])|q[1-4])
 }
 <DYNARE_STATEMENT,DYNARE_BLOCK>cutoff {return token::CUTOFF;}
 <DYNARE_STATEMENT,DYNARE_BLOCK>mfs {return token::MFS;}
+<DYNARE_STATEMENT,DYNARE_BLOCK>static_mfs {return token::STATIC_MFS;}
 <DYNARE_STATEMENT,DYNARE_BLOCK>balanced_growth_test_tol {return token::BALANCED_GROWTH_TEST_TOL;}
 <DYNARE_BLOCK>gamma_pdf {return token::GAMMA_PDF;}
 <DYNARE_BLOCK>beta_pdf {return token::BETA_PDF;}
diff --git a/src/ParsingDriver.cc b/src/ParsingDriver.cc
index 161cc25e..0cbba3a3 100644
--- a/src/ParsingDriver.cc
+++ b/src/ParsingDriver.cc
@@ -700,6 +700,13 @@ ParsingDriver::mfs(const string &value)
   mod_file->dynamic_model.setMFS(val);
 }
 
+void
+ParsingDriver::static_mfs(const string &value)
+{
+  int val = stoi(value);
+  mod_file->dynamic_model.setStaticMFS(val);
+}
+
 void
 ParsingDriver::compilation_setup_substitute_flags(const string &flags)
 {
diff --git a/src/ParsingDriver.hh b/src/ParsingDriver.hh
index 90a10d3b..d1acbae2 100644
--- a/src/ParsingDriver.hh
+++ b/src/ParsingDriver.hh
@@ -337,6 +337,8 @@ public:
   void cutoff(const string &value);
   //! mfs option of model block
   void mfs(const string &value);
+  //! static_mfs option of model block
+  void static_mfs(const string &value);
   //! the flags to substitute for the default compiler flags used by `use_dll`
   void compilation_setup_substitute_flags(const string &flags);
   //! the flags to add to the default compiler flags used by `use_dll`
diff --git a/src/StaticModel.cc b/src/StaticModel.cc
index 83bdb1ee..3d076140 100644
--- a/src/StaticModel.cc
+++ b/src/StaticModel.cc
@@ -50,7 +50,8 @@ StaticModel::copyHelper(const StaticModel &m)
 StaticModel::StaticModel(const StaticModel &m) :
   ModelTree{m},
   ramsey_multipliers_derivatives{m.ramsey_multipliers_derivatives},
-  ramsey_multipliers_derivatives_sparse_colptr{m.ramsey_multipliers_derivatives_sparse_colptr}
+  ramsey_multipliers_derivatives_sparse_colptr{m.ramsey_multipliers_derivatives_sparse_colptr},
+  static_mfs{m.static_mfs}
 {
   copyHelper(m);
 }
@@ -63,6 +64,8 @@ StaticModel::operator=(const StaticModel &m)
   ramsey_multipliers_derivatives = m.ramsey_multipliers_derivatives;
   ramsey_multipliers_derivatives_sparse_colptr = m.ramsey_multipliers_derivatives_sparse_colptr;
 
+  static_mfs = m.static_mfs;
+
   copyHelper(m);
 
   return *this;
@@ -115,6 +118,8 @@ StaticModel::StaticModel(const DynamicModel &m) :
   user_set_add_libs = m.user_set_add_libs;
   user_set_subst_libs = m.user_set_subst_libs;
   user_set_compiler = m.user_set_compiler;
+
+  static_mfs = m.static_mfs;
 }
 
 void
diff --git a/src/StaticModel.hh b/src/StaticModel.hh
index 67e24815..f605c258 100644
--- a/src/StaticModel.hh
+++ b/src/StaticModel.hh
@@ -53,6 +53,13 @@ private:
   // Stores, for each temporary term, its index in the MATLAB/Octave vector
   temporary_terms_idxs_t ramsey_multipliers_derivatives_temporary_terms_idxs;
 
+  /* Value of the “static_mfs” option of “model” block (or the “model_options”
+     command).
+     NB: the default value defined here is not used when converting from
+     DynamicModel class, and in particular it does not affect the main “model”
+     block. See the DynamicModel class for the default value in that case. */
+  int static_mfs{0};
+
   // Writes static model file (MATLAB/Octave version, legacy representation)
   void writeStaticMFile(const string &basename) const;
 
@@ -199,7 +206,7 @@ public:
   int
   getMFS() const override
   {
-    return 0;
+    return static_mfs;
   }
 };
 
-- 
GitLab