write steady state model
parent
b5be9b7437
commit
d70ae4d103
|
@ -108,6 +108,7 @@ type Model
|
|||
static_params_derivs::Function
|
||||
dynamic::Function
|
||||
dynamic_params_derivs::Function
|
||||
steady_state::Function
|
||||
end
|
||||
|
||||
function model()
|
||||
|
@ -154,6 +155,7 @@ function model()
|
|||
function()end, # static_params_derivs
|
||||
function()end, # dynamic
|
||||
function()end, # dynamic_params_derivs
|
||||
function()end # steady_state
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -687,8 +687,9 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
|||
case oCDynamicSteadyStateOperator:
|
||||
output << "steady_state[" << tsid << "]";
|
||||
break;
|
||||
case oJuliaSteadyStateFile:
|
||||
case oSteadyStateFile:
|
||||
output << "ys_(" << tsid + 1 << ")";
|
||||
output << "ys_" << LEFT_ARRAY_SUBSCRIPT(output_type) << tsid + 1 << RIGHT_ARRAY_SUBSCRIPT(output_type);
|
||||
break;
|
||||
case oCSteadyStateFile:
|
||||
output << "ys_[" << tsid << "]";
|
||||
|
@ -737,8 +738,9 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
|||
case oMatlabDynamicSteadyStateOperator:
|
||||
output << "oo_.exo_steady_state(" << i << ")";
|
||||
break;
|
||||
case oJuliaSteadyStateFile:
|
||||
case oSteadyStateFile:
|
||||
output << "exo_(" << i << ")";
|
||||
output << "exo_" << LEFT_ARRAY_SUBSCRIPT(output_type) << i << RIGHT_ARRAY_SUBSCRIPT(output_type);
|
||||
break;
|
||||
case oCSteadyStateFile:
|
||||
output << "exo_[" << i - 1 << "]";
|
||||
|
@ -787,8 +789,9 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
|||
case oMatlabDynamicSteadyStateOperator:
|
||||
output << "oo_.exo_det_steady_state(" << tsid + 1 << ")";
|
||||
break;
|
||||
case oJuliaSteadyStateFile:
|
||||
case oSteadyStateFile:
|
||||
output << "exo_(" << i << ")";
|
||||
output << "exo_" << LEFT_ARRAY_SUBSCRIPT(output_type) << i << RIGHT_ARRAY_SUBSCRIPT(output_type);
|
||||
break;
|
||||
case oCSteadyStateFile:
|
||||
output << "exo_[" << i - 1 << "]";
|
||||
|
@ -4819,7 +4822,8 @@ ExternalFunctionNode::writeOutput(ostream &output, ExprNodeOutputType output_typ
|
|||
deriv_node_temp_terms_t &tef_terms) const
|
||||
{
|
||||
if (output_type == oMatlabOutsideModel || output_type == oSteadyStateFile
|
||||
|| output_type == oCSteadyStateFile || IS_LATEX(output_type))
|
||||
|| output_type == oCSteadyStateFile || output_type == oJuliaSteadyStateFile
|
||||
|| IS_LATEX(output_type))
|
||||
{
|
||||
string name = IS_LATEX(output_type) ? datatree.symbol_table.getTeXName(symb_id)
|
||||
: datatree.symbol_table.getName(symb_id);
|
||||
|
|
|
@ -76,8 +76,9 @@ enum ExprNodeOutputType
|
|||
oMatlabDynamicSparseSteadyStateOperator, //!< Matlab code, dynamic block decomposed model, inside a steady state operator
|
||||
oCDynamicSteadyStateOperator, //!< C code, dynamic model, inside a steady state operator
|
||||
oJuliaDynamicSteadyStateOperator, //!< Julia code, dynamic model, inside a steady state operator
|
||||
oSteadyStateFile, //!< Matlab code, in the generated steady state file
|
||||
oCSteadyStateFile //!< C code, in the generated steady state file
|
||||
oSteadyStateFile, //!< Matlab code, in the generated steady state file
|
||||
oCSteadyStateFile, //!< C code, in the generated steady state file
|
||||
oJuliaSteadyStateFile //!< Julia code, in the generated steady state file
|
||||
};
|
||||
|
||||
#define IS_MATLAB(output_type) ((output_type) == oMatlabStaticModel \
|
||||
|
|
|
@ -819,7 +819,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo
|
|||
}
|
||||
|
||||
// Create steady state file
|
||||
steady_state_model.writeSteadyStateFile(basename, mod_file_struct.ramsey_model_present);
|
||||
steady_state_model.writeSteadyStateFile(basename, mod_file_struct.ramsey_model_present, false);
|
||||
}
|
||||
|
||||
cout << "done" << endl;
|
||||
|
@ -1092,7 +1092,7 @@ ModFile::writeExternalFilesJulia(const string &basename, FileOutputType output)
|
|||
<< "try" << endl
|
||||
<< " using " << basename << "DynamicParamsDerivs" << endl
|
||||
<< "catch" << endl
|
||||
<< "end" << endl << endl
|
||||
<< "end" << endl
|
||||
<< "export model__" << endl << endl
|
||||
<< "model__ = model()" << endl
|
||||
<< "model__.fname = \"" << basename << "\"" << endl
|
||||
|
@ -1133,6 +1133,7 @@ ModFile::writeExternalFilesJulia(const string &basename, FileOutputType output)
|
|||
mod_file_struct.order_option, true);
|
||||
dynamic_model.writeParamsDerivativesFile(basename, true);
|
||||
}
|
||||
steady_state_model.writeSteadyStateFile(basename, mod_file_struct.ramsey_model_present, true);
|
||||
|
||||
jlOutputFile << "model__.static = " << basename << "Static.getStaticFunction()" << endl
|
||||
<< "model__.dynamic = " << basename << "Dynamic.getDynamicFunction()" << endl
|
||||
|
@ -1147,7 +1148,13 @@ ModFile::writeExternalFilesJulia(const string &basename, FileOutputType output)
|
|||
<< " " << basename << "DynamicParamsDerivs.getParamsDerivsFunction()" << endl
|
||||
<< " catch" << endl
|
||||
<< " function()end" << endl
|
||||
<< " end" << endl << endl
|
||||
<< " end" << endl
|
||||
<< "try" << endl
|
||||
<< " using " << basename << "SteadyState2" << endl
|
||||
<< " model__.steady_state = " << basename
|
||||
<< "SteadyState2.getSteadyStateFunction()" << endl
|
||||
<< "catch" << endl
|
||||
<< "end" << endl
|
||||
<< "end" << endl;
|
||||
jlOutputFile.close();
|
||||
cout << "done" << endl;
|
||||
|
|
|
@ -105,13 +105,12 @@ SteadyStateModel::checkPass(bool ramsey_model, WarningConsolidation &warnings) c
|
|||
}
|
||||
|
||||
void
|
||||
SteadyStateModel::writeSteadyStateFile(const string &basename, bool ramsey_model) const
|
||||
SteadyStateModel::writeSteadyStateFile(const string &basename, bool ramsey_model, bool julia) const
|
||||
{
|
||||
if (def_table.size() == 0)
|
||||
return;
|
||||
|
||||
string filename = basename + "_steadystate2.m";
|
||||
|
||||
string filename = julia ? basename + "SteadyState2.jl" : basename + "_steadystate2.m";
|
||||
ofstream output;
|
||||
output.open(filename.c_str(), ios::out | ios::binary);
|
||||
if (!output.is_open())
|
||||
|
@ -120,10 +119,21 @@ SteadyStateModel::writeSteadyStateFile(const string &basename, bool ramsey_model
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
output << "function [ys_, params, info] = " << basename << "_steadystate2("
|
||||
<< "ys_, exo_, params)" << endl
|
||||
<< "% Steady state generated by Dynare preprocessor" << endl
|
||||
<< " info = 0;" << endl;
|
||||
ExprNodeOutputType output_type = (julia ? oJuliaSteadyStateFile : oSteadyStateFile);
|
||||
|
||||
if (!julia)
|
||||
output << "function [ys_, params, info] = " << basename << "_steadystate2("
|
||||
<< "ys_, exo_, params)" << endl
|
||||
<< "% Steady state generated by Dynare preprocessor" << endl
|
||||
<< " info = 0;" << endl;
|
||||
else
|
||||
output << "module " << basename << "SteadyState2" << endl << endl
|
||||
<< "export getSteadyStateFunction" << endl << endl
|
||||
<< "function getSteadyStateFunction()" << endl
|
||||
<< " steady_state" << endl
|
||||
<< "end" << endl << endl
|
||||
<< "function steady_state(ys_, exo_, params)" << endl
|
||||
<< " info = 0" << endl;
|
||||
|
||||
for (size_t i = 0; i < def_table.size(); i++)
|
||||
{
|
||||
|
@ -135,7 +145,7 @@ SteadyStateModel::writeSteadyStateFile(const string &basename, bool ramsey_model
|
|||
{
|
||||
variable_node_map_t::const_iterator it = variable_node_map.find(make_pair(symb_ids[j], 0));
|
||||
assert(it != variable_node_map.end());
|
||||
dynamic_cast<ExprNode *>(it->second)->writeOutput(output, oSteadyStateFile);
|
||||
dynamic_cast<ExprNode *>(it->second)->writeOutput(output, output_type);
|
||||
if (j < symb_ids.size()-1)
|
||||
output << ",";
|
||||
}
|
||||
|
@ -143,13 +153,21 @@ SteadyStateModel::writeSteadyStateFile(const string &basename, bool ramsey_model
|
|||
output << "]";
|
||||
|
||||
output << "=";
|
||||
def_table[i].second->writeOutput(output, oSteadyStateFile);
|
||||
def_table[i].second->writeOutput(output, output_type);
|
||||
output << ";" << endl;
|
||||
}
|
||||
output << " % Auxiliary equations" << endl;
|
||||
static_model.writeAuxVarInitval(output, oSteadyStateFile);
|
||||
output << " check_=0;" << endl
|
||||
<< "end" << endl;
|
||||
if (!julia)
|
||||
output << " % Auxiliary equations" << endl;
|
||||
else
|
||||
output << " # Auxiliary equations" << endl;
|
||||
static_model.writeAuxVarInitval(output, output_type);
|
||||
output << " check_=0;" << endl;
|
||||
|
||||
if (julia)
|
||||
output << " (ys_, params, info)" << endl;
|
||||
output << "end" << endl;
|
||||
if (julia)
|
||||
output << "end" << endl;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -48,7 +48,7 @@ public:
|
|||
/*!
|
||||
\param[in] ramsey_model Is there a Ramsey model in the MOD file? If yes, then use the "ys" in argument of the steady state file as initial values
|
||||
*/
|
||||
void writeSteadyStateFile(const string &basename, bool ramsey_model) const;
|
||||
void writeSteadyStateFile(const string &basename, bool ramsey_model, bool julia) const;
|
||||
void writeSteadyStateFileC(const string &basename, bool ramsey_model) const;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue