Commit 648c3cd1 authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Preprocessor: implement STEADY_STATE operator with "use_dll" and "block"

options (closes #98)
parent 6c66e3d2
......@@ -299,7 +299,7 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const
<< " % // Simulation type "
<< BlockSim(simulation_type) << " //" << endl
<< " % ////////////////////////////////////////////////////////////////////////" << endl;
output << " global options_;" << endl;
output << " global options_ oo_;" << endl;
//The Temporary terms
if (simulation_type == EVALUATE_BACKWARD || simulation_type == EVALUATE_FORWARD)
{
......@@ -1447,7 +1447,7 @@ DynamicModel::writeDynamicCFile(const string &dynamic_basename, const int order)
mDynamicModelFile << "/* The gateway routine */" << endl
<< "void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])" << endl
<< "{" << endl
<< " double *y, *x, *params;" << endl
<< " double *y, *x, *params, *steady_state;" << endl
<< " double *residual, *g1, *v2, *v3;" << endl
<< " int nb_row_x, it_;" << endl
<< endl
......@@ -1505,8 +1505,9 @@ DynamicModel::writeDynamicCFile(const string &dynamic_basename, const int order)
<< " v3 = mxGetPr(plhs[3]);" << endl
<< " }" << endl
<< endl
<< " steady_state = mxGetPr(mxGetField(mexGetVariable(\"global\", \"oo_\"), 0, \"steady_state\"));" << endl
<< " /* Call the C subroutines. */" << endl
<< " Dynamic(y, x, nb_row_x, params, it_, residual, g1, v2, v3);" << endl
<< " Dynamic(y, x, nb_row_x, params, steady_state, it_, residual, g1, v2, v3);" << endl
<< "}" << endl;
mDynamicModelFile.close();
}
......@@ -2108,7 +2109,7 @@ DynamicModel::writeDynamicModel(ostream &DynamicOutput, bool use_dll) const
}
else
{
DynamicOutput << "void Dynamic(double *y, double *x, int nb_row_x, double *params, int it_, double *residual, double *g1, double *v2, double *v3)" << endl
DynamicOutput << "void Dynamic(double *y, double *x, int nb_row_x, double *params, double *steady_state, int it_, double *residual, double *g1, double *v2, double *v3)" << endl
<< "{" << endl
<< " double lhs, rhs;" << endl
<< endl
......
......@@ -582,8 +582,12 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
output << "oo_.steady_state(" << tsid + 1 << ")";
break;
case oMatlabDynamicSteadyStateOperator:
case oMatlabDynamicSparseSteadyStateOperator:
output << "oo_.steady_state(" << tsid + 1 << ")";
break;
case oCDynamicSteadyStateOperator:
output << "steady_state[" << tsid << "]";
break;
case oSteadyStateFile:
output << "ys_(" << tsid + 1 << ")";
break;
......@@ -1457,11 +1461,11 @@ UnaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
new_output_type = oLatexDynamicSteadyStateOperator;
break;
case oCDynamicModel:
cerr << "Steady State Operator not implemented for oCDynamicModel." << endl;
exit(EXIT_FAILURE);
new_output_type = oCDynamicSteadyStateOperator;
break;
case oMatlabDynamicModelSparse:
cerr << "Steady State Operator not implemented for oMatlabDynamicModelSparse." << endl;
exit(EXIT_FAILURE);
new_output_type = oMatlabDynamicSparseSteadyStateOperator;
break;
default:
new_output_type = output_type;
break;
......
......@@ -60,17 +60,18 @@ typedef map<pair<int, vector<expr_t> >, int> deriv_node_temp_terms_t;
//! Possible types of output when writing ExprNode(s)
enum ExprNodeOutputType
{
oMatlabStaticModel, //!< Matlab code, static model declarations
oMatlabDynamicModel, //!< Matlab code, dynamic model declarations
oMatlabStaticModelSparse, //!< Matlab code, static block decomposed mode declaration
oMatlabDynamicModelSparse, //!< Matlab code, dynamic block decomposed mode declaration
oCDynamicModel, //!< C code, dynamic model declarations
oMatlabStaticModel, //!< Matlab code, static model
oMatlabDynamicModel, //!< Matlab code, dynamic model
oMatlabStaticModelSparse, //!< Matlab code, static block decomposed model
oMatlabDynamicModelSparse, //!< Matlab code, dynamic block decomposed model
oCDynamicModel, //!< C code, dynamic model
oMatlabOutsideModel, //!< Matlab code, outside model block (for example in initval)
oLatexStaticModel, //!< LaTeX code, static model declarations
oLatexDynamicModel, //!< LaTeX code, dynamic model declarations
oLatexDynamicSteadyStateOperator, //!< LaTeX code, dynamic model steady state declarations
oMatlabDynamicSteadyStateOperator, //!< Matlab code, dynamic model steady state declarations
oMatlabDynamicModelSparseSteadyStateOperator, //!< Matlab code, dynamic block decomposed model steady state declarations
oLatexStaticModel, //!< LaTeX code, static model
oLatexDynamicModel, //!< LaTeX code, dynamic model
oLatexDynamicSteadyStateOperator, //!< LaTeX code, dynamic model, inside a steady state operator
oMatlabDynamicSteadyStateOperator, //!< Matlab code, dynamic model, inside a steady state operator
oMatlabDynamicSparseSteadyStateOperator, //!< Matlab code, dynamic block decomposed model, inside a steady state operator
oCDynamicSteadyStateOperator, //!< C code, dynamic model, inside a steady state operator
oSteadyStateFile //!< Matlab code, in the generated steady state file
};
......@@ -80,10 +81,10 @@ enum ExprNodeOutputType
|| (output_type) == oMatlabStaticModelSparse \
|| (output_type) == oMatlabDynamicModelSparse \
|| (output_type) == oMatlabDynamicSteadyStateOperator \
|| (output_type) == oMatlabDynamicModelSparseSteadyStateOperator \
|| (output_type) == oMatlabDynamicSparseSteadyStateOperator \
|| (output_type) == oSteadyStateFile)
#define IS_C(output_type) ((output_type) == oCDynamicModel)
#define IS_C(output_type) ((output_type) == oCDynamicModel || (output_type) == oCDynamicSteadyStateOperator)
#define IS_LATEX(output_type) ((output_type) == oLatexStaticModel \
|| (output_type) == oLatexDynamicModel \
......
......@@ -13,11 +13,14 @@ OCTAVE_MODS = \
optimal_policy/mult_elimination_test.mod \
ramst_initval_file.mod \
ramst_normcdf_and_friends.mod \
ramst_steady_state.mod \
example1_varexo_det.mod \
predetermined_variables.mod \
fs2000_ssfile.mod \
comments.mod \
steady_state_operator/standard.mod \
steady_state_operator/use_dll.mod \
steady_state_operator/block.mod \
steady_state_operator/bytecode_test.mod \
block_bytecode/fs2000_simk.mod \
block_bytecode/fs2000_lu.mod \
block_bytecode/fs2000_bicgstab.mod \
......
// Tests the steady_state operator, in static and dynamic M-files with block decomposition
var c k w;
varexo x;
parameters alph gam delt bet aa c_steady_state;
alph=0.5;
gam=0.5;
delt=0.02;
bet=0.05;
aa=0.5;
model(block);
c + k - aa*x*k(-1)^alph - (1-delt)*k(-1);
c^(-gam) - (1+bet)^(-1)*(aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam);
w = steady_state(k);
end;
initval;
x = 1;
k = ((delt+bet)/(1.0*aa*alph))^(1/(alph-1));
c = aa*k^alph-delt*k;
w = 0;
end;
steady;
//check;
shocks;
var x;
periods 1;
values 1.2;
end;
simul(periods=20);
if(abs(oo_.steady_state(2) - oo_.steady_state(3)) > 1e-10)
error('Test failed in static M-file for steady_state')
end
if(abs(oo_.steady_state(2) - oo_.endo_simul(3,2)) > 1e-10)
error('Test failed in dynamic M-file for steady_state')
end
// Tests the steady_state operator, with the bytecode
var c k w;
varexo x;
parameters alph gam delt bet aa c_steady_state;
alph=0.5;
gam=0.5;
delt=0.02;
bet=0.05;
aa=0.5;
model(bytecode);
c + k - aa*x*k(-1)^alph - (1-delt)*k(-1);
c^(-gam) - (1+bet)^(-1)*(aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam);
w = steady_state(k);
end;
initval;
x = 1;
k = ((delt+bet)/(1.0*aa*alph))^(1/(alph-1));
c = aa*k^alph-delt*k;
w = 0;
end;
steady(solve_algo=5);
//check;
shocks;
var x;
periods 1;
values 1.2;
end;
simul(periods=20, stack_solve_algo=5);
if(abs(oo_.steady_state(2) - oo_.steady_state(3)) > 1e-10)
error('Test failed in static M-file for steady_state')
end
if(abs(oo_.steady_state(2) - oo_.endo_simul(3,2)) > 1e-10)
error('Test failed in dynamic M-file for steady_state')
end
// Tests the steady_state, in static and dynamic M-files
// Tests the steady_state operator, in static and dynamic M-files
var c k w;
varexo x;
......
// Tests the steady_state operator, in static M-file and dynamic C-file
var c k w;
varexo x;
parameters alph gam delt bet aa c_steady_state;
alph=0.5;
gam=0.5;
delt=0.02;
bet=0.05;
aa=0.5;
model(use_dll);
c + k - aa*x*k(-1)^alph - (1-delt)*k(-1);
c^(-gam) - (1+bet)^(-1)*(aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam);
w = steady_state(k);
end;
initval;
x = 1;
k = ((delt+bet)/(1.0*aa*alph))^(1/(alph-1));
c = aa*k^alph-delt*k;
w = 0;
end;
steady;
check;
shocks;
var x;
periods 1;
values 1.2;
end;
simul(periods=20);
if(abs(oo_.steady_state(2) - oo_.steady_state(3)) > 1e-10)
error('Test failed in static M-file for steady_state')
end
if(abs(oo_.steady_state(2) - oo_.endo_simul(3,2)) > 1e-10)
error('Test failed in dynamic M-file for steady_state')
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment