diff --git a/src/DynareBison.yy b/src/DynareBison.yy index ba6c3d73e686934e802191df54b61e16bc02077f..959866629a30c2fe0dac4c27738520963fa9ef58 100644 --- a/src/DynareBison.yy +++ b/src/DynareBison.yy @@ -195,7 +195,7 @@ class ParsingDriver; %token FSOLVE_OPTIONS %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 +%token HOMOTOPY_LINEARIZATION_FALLBACK HOMOTOPY_MARGINAL_LINEARIZATION_FALLBACK FROM_INITVAL_TO_ENDVAL %token <vector<string>> SYMBOL_VEC @@ -3204,8 +3204,13 @@ initial_condition_decomposition_option : o_icd_type | o_icd_with_epilogue ; -homotopy_setup: HOMOTOPY_SETUP ';' homotopy_list END ';' - { driver.end_homotopy();}; +homotopy_setup : HOMOTOPY_SETUP ';' homotopy_list END ';' + { driver.end_homotopy(false); } + | HOMOTOPY_SETUP '(' FROM_INITVAL_TO_ENDVAL ')' ';' END ';' + { driver.end_homotopy(true); } + | HOMOTOPY_SETUP '(' FROM_INITVAL_TO_ENDVAL ')' ';' homotopy_list END ';' + { driver.end_homotopy(true); } + ; homotopy_list : homotopy_item | homotopy_list homotopy_item diff --git a/src/DynareFlex.ll b/src/DynareFlex.ll index 921d716f28ff0980c341e940f8de9f5f6a8b2c1c..fe6d8dbcde7cad4c8f12f8441fc09337a1f0e812 100644 --- a/src/DynareFlex.ll +++ b/src/DynareFlex.ll @@ -362,6 +362,7 @@ DATE -?[0-9]+([ya]|m([1-9]|1[0-2])|q[1-4]) <DYNARE_STATEMENT>nocorr {return token::NOCORR;} <DYNARE_STATEMENT>optim {return token::OPTIM;} <DYNARE_STATEMENT>periods {return token::PERIODS;} +<DYNARE_BLOCK>from_initval_to_endval {return token::FROM_INITVAL_TO_ENDVAL;} <DYNARE_STATEMENT>endval_steady {return token::ENDVAL_STEADY;} <DYNARE_STATEMENT,DYNARE_BLOCK>model_name {return token::MODEL_NAME;} <DYNARE_STATEMENT>auxiliary_model_name {return token::AUXILIARY_MODEL_NAME;} diff --git a/src/NumericalInitialization.cc b/src/NumericalInitialization.cc index 8c2e32e3912da91b0868445fd91f53c4e80ac0df..cc5253bb9f938e5033aefe52702a6c6d5b9b59c7 100644 --- a/src/NumericalInitialization.cc +++ b/src/NumericalInitialization.cc @@ -534,8 +534,10 @@ HistvalFileStatement::writeJsonOutput(ostream &output) const output << "}"; } -HomotopySetupStatement::HomotopySetupStatement(homotopy_values_t homotopy_values_arg, +HomotopySetupStatement::HomotopySetupStatement(bool from_initval_to_endval_arg, + homotopy_values_t homotopy_values_arg, const SymbolTable &symbol_table_arg) : + from_initval_to_endval{from_initval_to_endval_arg}, homotopy_values{move(homotopy_values_arg)}, symbol_table{symbol_table_arg} { @@ -548,7 +550,8 @@ HomotopySetupStatement::writeOutput(ostream &output, [[maybe_unused]] const stri output << "%" << endl << "% HOMOTOPY_SETUP instructions" << endl << "%" << endl - << "options_.homotopy_values = [];" << endl; + << "options_.homotopy_from_initval_to_endval = " << boolalpha << from_initval_to_endval << ';' << endl + << "options_.homotopy_values = zeros(0, 4);" << endl; for (auto [symb_id, expression1, expression2] : homotopy_values) { diff --git a/src/NumericalInitialization.hh b/src/NumericalInitialization.hh index 3e7d910fa25087a91dd4c80752f380e930d9e7fc..f368696e0bd0aed6ce54c4879ef98d12a056816a 100644 --- a/src/NumericalInitialization.hh +++ b/src/NumericalInitialization.hh @@ -172,10 +172,11 @@ public: /*! Order matter so we use a vector. First expr_t can be NULL if no initial value given. */ using homotopy_values_t = vector<tuple<int, expr_t, expr_t>>; private: + const bool from_initval_to_endval; // Whether the from_initval_to_endval option was passed const homotopy_values_t homotopy_values; const SymbolTable &symbol_table; public: - HomotopySetupStatement(homotopy_values_t homotopy_values_arg, + HomotopySetupStatement(bool from_initval_to_endval_arg, homotopy_values_t homotopy_values_arg, const SymbolTable &symbol_table_arg); void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const override; void writeJsonOutput(ostream &output) const override; diff --git a/src/ParsingDriver.cc b/src/ParsingDriver.cc index c01162e555686186d0dd22ee76b17787a0e2d489..8868f3cf1701e3a1ac0f4fe8715233354dcb99c4 100644 --- a/src/ParsingDriver.cc +++ b/src/ParsingDriver.cc @@ -793,9 +793,9 @@ ParsingDriver::end_histval(bool all_values_required) } void -ParsingDriver::end_homotopy() +ParsingDriver::end_homotopy(bool from_initval_to_endval) { - mod_file->addStatement(make_unique<HomotopySetupStatement>(move(homotopy_values), mod_file->symbol_table)); + mod_file->addStatement(make_unique<HomotopySetupStatement>(from_initval_to_endval, move(homotopy_values), mod_file->symbol_table)); homotopy_values.clear(); } diff --git a/src/ParsingDriver.hh b/src/ParsingDriver.hh index 5edf4fca616e3c1b66eb7fd39e1e602a5016920e..90a10d3b0c9c011da35423d46679f623b6c5e72a 100644 --- a/src/ParsingDriver.hh +++ b/src/ParsingDriver.hh @@ -427,7 +427,7 @@ public: //! Writes end of an histval block void end_histval(bool all_values_required); //! Writes end of an homotopy_setup block - void end_homotopy(); + void end_homotopy(bool from_initval_to_endval); //! Begin epilogue block void begin_epilogue(); //! End epilogue block