Commit 74232e9e authored by sebastien's avatar sebastien
Browse files

* Added new option stack_solve_algo to simul

* Added solve_algo=5 for steady
* Remove obsolete method option of simul
* Added various checks to avoid unimplemented combinations of bytecode/block/solve_algo/stack_solve_algo


git-svn-id: https://www.dynare.org/svn/dynare/trunk@2882 ac1d8469-bf42-47a9-8791-bf33cf982152
parent 9f452009
......@@ -106,6 +106,9 @@ function global_initialization()
% Model
options_.linear = 0;
% Deterministic simulation
options_.stack_solve_algo = 0;
% Solution
options_.order = 2;
options_.solve_algo = 2;
......@@ -173,7 +176,6 @@ function global_initialization()
options_.prefilter = 0;
options_.presample = 0;
options_.prior_trunc = 1e-10;
options_.simulation_method = 0;
options_.smoother = 0;
options_.student_degrees_of_freedom = 3;
options_.subdraws = [];
......
......@@ -71,6 +71,16 @@ if options_.simul_algo == 0
options_.scalv= 1 ;
if ~options_.block && ~options_.bytecode && options_.stack_solve_algo ~= 0
error('SIMUL: for the moment, you must use stack_solve_algo=0 when not using block nor bytecode option')
end
if options_.block && ~options_.bytecode && (options_.stack_solve_algo == 0 || options_.stack_solve_algo == 5)
error('SIMUL: for the moment, you must use stack_solve_algo={1,2,3,4} when using block without bytecode option')
end
if options_.block && options_.bytecode && options_.stack_solve_algo ~= 5
error('SIMUL: for the moment, you must use stack_solve_algo=5 with block and bytecode option')
end
if(options_.block)
if(options_.bytecode)
oo_.endo_simul=bytecode('dynamic');
......
function [y, info] = solve_one_boundary(fname, y, x, params, y_index_eq, nze, periods, is_linear, Block_Num, y_kmin, maxit_, solve_tolf, lambda, cutoff, simulation_method, forward_backward, is_dynamic, verbose)
function [y, info] = solve_one_boundary(fname, y, x, params, y_index_eq, nze, periods, is_linear, Block_Num, y_kmin, maxit_, solve_tolf, lambda, cutoff, stack_solve_algo, forward_backward, is_dynamic, verbose)
% Computes the deterministic simulation of a block of equation containing
% lead or lag variables
%
......@@ -23,11 +23,12 @@ function [y, info] = solve_one_boundary(fname, y, x, params, y_index_eq, nze, pe
% Newton
% cutoff [double] cutoff to correct the direction in Newton in case
% of singular jacobian matrix
% simulation_method [integer] linear solver method used in the
% stack_solve_algo [integer] linear solver method used in the
% Newton algorithm :
% - 0 sprse LU
% - 1 sparse LU
% - 2 GMRES
% - 3 BicGStab
% - 4 Optimal path length
% forward_backward [integer] The block has to be solve forward
% (1) or backward (0)
% is_dynamic [integer] (1) The block belong to the dynamic
......@@ -35,7 +36,7 @@ function [y, info] = solve_one_boundary(fname, y, x, params, y_index_eq, nze, pe
% (0) The block belong to the static
% file and th oo_.deteerminstic
% field remains unchanged
% verobse [integer] (0) iterations are not printed
% verbose [integer] (0) iterations are not printed
% (1) iterations are printed
%
% OUTPUTS
......@@ -48,7 +49,7 @@ function [y, info] = solve_one_boundary(fname, y, x, params, y_index_eq, nze, pe
% none.
%
% Copyright (C) 1996-2008 Dynare Team
% Copyright (C) 1996-2009 Dynare Team
%
% This file is part of Dynare.
%
......@@ -232,7 +233,7 @@ function [y, info] = solve_one_boundary(fname, y, x, params, y_index_eq, nze, pe
else
info = -Block_Num*10;
end
elseif((~is_dynamic & options_.solve_algo==2) || (is_dynamic & simulation_method==4))
elseif((~is_dynamic & options_.solve_algo==2) || (is_dynamic & stack_solve_algo==4))
lambda=1;
stpmx = 100 ;
if (is_dynamic)
......@@ -254,7 +255,7 @@ function [y, info] = solve_one_boundary(fname, y, x, params, y_index_eq, nze, pe
[yn,info] = csolve(@local_fname, y(y_index_eq),@local_fname,1e-6,500, x, params, y, y_index_eq, fname, 1);
dx = ya - yn;
y(y_index_eq) = yn;
elseif((simulation_method==0 & is_dynamic) | (~is_dynamic & options_.solve_algo==1)),
elseif((stack_solve_algo==1 & is_dynamic) | (~is_dynamic & options_.solve_algo==1)),
dx = g1\r;
ya = ya - lambda*dx;
if(is_dynamic)
......@@ -262,7 +263,7 @@ function [y, info] = solve_one_boundary(fname, y, x, params, y_index_eq, nze, pe
else
y(y_index_eq) = ya;
end;
elseif(simulation_method==2 & is_dynamic),
elseif(stack_solve_algo==2 & is_dynamic),
flag1=1;
while(flag1>0)
[L1, U1]=luinc(g1,luinc_tol);
......@@ -288,7 +289,7 @@ function [y, info] = solve_one_boundary(fname, y, x, params, y_index_eq, nze, pe
end;
end;
end;
elseif(simulation_method==3 & is_dynamic),
elseif(stack_solve_algo==3 & is_dynamic),
flag1=1;
while(flag1>0)
[L1, U1]=luinc(g1,luinc_tol);
......@@ -317,7 +318,7 @@ function [y, info] = solve_one_boundary(fname, y, x, params, y_index_eq, nze, pe
else
disp('unknown option : ');
if(is_dynamic)
disp(['options_.simulation_method = ' num2str(simulation_method) ' not implemented']);
disp(['options_.stack_solve_algo = ' num2str(stack_solve_algo) ' not implemented']);
else
disp(['options_.solve_algo = ' num2str(options_.solve_algo) ' not implemented']);
end;
......
function y = solve_two_boundaries(fname, y, x, params, y_index, nze, periods, y_kmin_l, y_kmax_l, is_linear, Block_Num, y_kmin, maxit_, solve_tolf, lambda, cutoff, simulation_method)
function y = solve_two_boundaries(fname, y, x, params, y_index, nze, periods, y_kmin_l, y_kmax_l, is_linear, Block_Num, y_kmin, maxit_, solve_tolf, lambda, cutoff, stack_solve_algo)
% Computes the deterministic simulation of a block of equation containing
% both lead and lag variables using relaxation methods
%
......@@ -25,11 +25,12 @@ function y = solve_two_boundaries(fname, y, x, params, y_index, nze, periods, y_
% Newton
% cutoff [double] cutoff to correct the direction in Newton in case
% of singular jacobian matrix
% simulation_method [integer] linear solver method used in the
% stack_solve_algo [integer] linear solver method used in the
% Newton algorithm :
% - 0 sprse LU
% - 1 sprse LU
% - 2 GMRES
% - 3 BicGStab
% - 4 Optimal path length
%
% OUTPUTS
% y [matrix] All endogenous variables of the model
......@@ -41,7 +42,7 @@ function y = solve_two_boundaries(fname, y, x, params, y_index, nze, periods, y_
% none.
%
% Copyright (C) 1996-2008 Dynare Team
% Copyright (C) 1996-2009 Dynare Team
%
% This file is part of Dynare.
%
......@@ -58,7 +59,7 @@ function y = solve_two_boundaries(fname, y, x, params, y_index, nze, periods, y_
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
global options_ oo_ M_ T9025 T1149 T11905;
global oo_ M_;
cvg=0;
iter=0;
Per_u_=0;
......@@ -208,7 +209,7 @@ function y = solve_two_boundaries(fname, y, x, params, y_index, nze, periods, y_
g1aa=g1a;
ba=b;
max_resa=max_res;
if(simulation_method==0),
if(stack_solve_algo==1),
dx = g1a\b- ya;
ya = ya + lambda*dx;
y(1+y_kmin:periods+y_kmin,y_index)=reshape(ya',length(y_index),periods)';
......@@ -220,7 +221,7 @@ function y = solve_two_boundaries(fname, y, x, params, y_index, nze, periods, y_
% v
% sprintf(v,y(:,y_index)')
% return;
elseif(simulation_method==2),
elseif(stack_solve_algo==2),
flag1=1;
while(flag1>0)
[L1, U1]=luinc(g1a,luinc_tol);
......@@ -241,7 +242,7 @@ function y = solve_two_boundaries(fname, y, x, params, y_index, nze, periods, y_
y(1+y_kmin:periods+y_kmin,y_index)=reshape(ya',length(y_index),periods)';
end;
end;
elseif(simulation_method==3),
elseif(stack_solve_algo==3),
flag1=1;
while(flag1>0)
[L1, U1]=luinc(g1a,luinc_tol);
......@@ -262,6 +263,8 @@ function y = solve_two_boundaries(fname, y, x, params, y_index, nze, periods, y_
y(1+y_kmin:periods+y_kmin,y_index)=reshape(ya',length(y_index),periods)';
end;
end;
elseif(stack_solve_algo==4),
error('SOLVE_TWO_BOUNDARIES: stack_solve_algo=4 not implemented')
end;
end
iter=iter+1;
......
......@@ -28,6 +28,13 @@ function steady_()
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
global M_ oo_ it_ options_
if options_.bytecode && options_.solve_algo ~= 5
error('STEADY: for the moment, you must use solve_algo=5 with bytecode option')
end
if ~options_.bytecode && options_.solve_algo == 5
error('STEADY: you can''t yet use solve_algo=5 without bytecode option')
end
if options_.steadystate_flag
[oo_.steady_state,check] = feval([M_.fname '_steadystate'],...
......
......@@ -1483,12 +1483,14 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
mDynamicModelFile << " return;\n";
mDynamicModelFile << " end;\n";
mDynamicModelFile << " %it is the deterministic simulation of the block decomposed dynamic model\n";
mDynamicModelFile << " if(options_.simulation_method==0)\n";
mDynamicModelFile << " if(options_.stack_solve_algo==1)\n";
mDynamicModelFile << " mthd='Sparse LU';\n";
mDynamicModelFile << " elseif(options_.simulation_method==2)\n";
mDynamicModelFile << " elseif(options_.stack_solve_algo==2)\n";
mDynamicModelFile << " mthd='GMRES';\n";
mDynamicModelFile << " elseif(options_.simulation_method==3)\n";
mDynamicModelFile << " elseif(options_.stack_solve_algo==3)\n";
mDynamicModelFile << " mthd='BICGSTAB';\n";
mDynamicModelFile << " elseif(options_.stack_solve_algo==4)\n";
mDynamicModelFile << " mthd='OPTIMPATH';\n";
mDynamicModelFile << " else\n";
mDynamicModelFile << " mthd='UNKNOWN';\n";
mDynamicModelFile << " end;\n";
......@@ -1594,7 +1596,7 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
mDynamicModelFile << " y = solve_one_boundary('" << dynamic_basename << "_" << i + 1 << "'" <<
", y, x, params, y_index, " << nze <<
", options_.periods, " << block_triangular.ModelBlock->Block_List[i].is_linear <<
", blck_num, y_kmin, options_.maxit_, options_.solve_tolf, options_.slowc, options_.cutoff, options_.simulation_method, 1, 1, 0);\n";
", blck_num, y_kmin, options_.maxit_, options_.solve_tolf, options_.slowc, options_.cutoff, options_.stack_solve_algo, 1, 1, 0);\n";
mDynamicModelFile << " tmp = y(:,M_.block_structure.block(" << i + 1 << ").variable);\n";
mDynamicModelFile << " if(isnan(tmp) | isinf(tmp))\n";
mDynamicModelFile << " disp(['Inf or Nan value during the resolution of block " << i <<"']);\n";
......@@ -1625,7 +1627,7 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
mDynamicModelFile << " y = solve_one_boundary('" << dynamic_basename << "_" << i + 1 << "'" <<
", y, x, params, y_index, " << nze <<
", options_.periods, " << block_triangular.ModelBlock->Block_List[i].is_linear <<
", blck_num, y_kmin, options_.maxit_, options_.solve_tolf, options_.slowc, options_.cutoff, options_.simulation_method, 1, 1, 0);\n";
", blck_num, y_kmin, options_.maxit_, options_.solve_tolf, options_.slowc, options_.cutoff, options_.stack_solve_algo, 1, 1, 0);\n";
mDynamicModelFile << " tmp = y(:,M_.block_structure.block(" << i + 1 << ").variable);\n";
mDynamicModelFile << " if(isnan(tmp) | isinf(tmp))\n";
mDynamicModelFile << " disp(['Inf or Nan value during the resolution of block " << i <<"']);\n";
......@@ -1657,7 +1659,7 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
", options_.periods, " << block_triangular.ModelBlock->Block_List[i].Max_Lag <<
", " << block_triangular.ModelBlock->Block_List[i].Max_Lead <<
", " << block_triangular.ModelBlock->Block_List[i].is_linear <<
", blck_num, y_kmin, options_.maxit_, options_.solve_tolf, options_.slowc, options_.cutoff, options_.simulation_method);\n";
", blck_num, y_kmin, options_.maxit_, options_.solve_tolf, options_.slowc, options_.cutoff, options_.stack_solve_algo);\n";
mDynamicModelFile << " tmp = y(:,M_.block_structure.block(" << i + 1 << ").variable);\n";
mDynamicModelFile << " if(isnan(tmp) | isinf(tmp))\n";
mDynamicModelFile << " disp(['Inf or Nan value during the resolution of block " << i <<"']);\n";
......
......@@ -87,7 +87,7 @@ class ParsingDriver;
%}
%token AR AUTOCORR
%token BAYESIAN_IRF BETA_PDF BICGSTAB BLOCK
%token BAYESIAN_IRF BETA_PDF BLOCK
%token BVAR_DENSITY BVAR_FORECAST
%token BVAR_PRIOR_DECAY BVAR_PRIOR_FLAT BVAR_PRIOR_LAMBDA
%token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN
......@@ -98,15 +98,15 @@ class ParsingDriver;
%token FILENAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS
%token <string_val> FLOAT_NUMBER
%token FORECAST
%token GAMMA_PDF GAUSSIAN_ELIMINATION GMRES GRAPH
%token GAMMA_PDF GRAPH
%token HISTVAL HOMOTOPY_SETUP HOMOTOPY_MODE HOMOTOPY_STEPS HP_FILTER HP_NGRID
%token IDENTIFICATION INF_CONSTANT INITVAL INITVAL_FILE
%token <string_val> INT_NUMBER
%token INV_GAMMA_PDF INV_GAMMA1_PDF INV_GAMMA2_PDF IRF
%token KALMAN_ALGO KALMAN_TOL
%token LAPLACE LIK_ALGO LIK_INIT LINEAR LOAD_MH_FILE LOAD_PARAMS_AND_STEADY_STATE LOGLINEAR LU
%token LAPLACE LIK_ALGO LIK_INIT LINEAR LOAD_MH_FILE LOAD_PARAMS_AND_STEADY_STATE LOGLINEAR
%token MARKOWITZ MARGINAL_DENSITY MAX
%token METHOD MFS MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER MIN
%token MFS MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER MIN
%token MODE_CHECK MODE_COMPUTE MODE_FILE MODEL MODEL_COMPARISON MODEL_INFO MSHOCKS
%token MODIFIEDHARMONICMEAN MOMENTS_VARENDO DIFFUSE_FILTER
%token <string_val> NAME
......@@ -118,7 +118,7 @@ class ParsingDriver;
%token <string_val> QUOTED_STRING
%token QZ_CRITERIUM
%token RELATIVE_IRF REPLIC RPLOT SAVE_PARAMS_AND_STEADY_STATE
%token SHOCKS SIGMA_E SIMUL SIMUL_ALGO SIMUL_SEED SMOOTHER SOLVE_ALGO
%token SHOCKS SIGMA_E SIMUL SIMUL_ALGO SIMUL_SEED SMOOTHER STACK_SOLVE_ALGO SOLVE_ALGO
%token STDERR STEADY STOCH_SIMUL
%token TEX RAMSEY_POLICY PLANNER_DISCOUNT
%token <string_val> TEX_NAME
......@@ -678,7 +678,7 @@ simul_options_list : simul_options_list COMMA simul_options
simul_options : o_periods
| o_datafile
| o_method
| o_stack_solve_algo
| o_markowitz
;
......@@ -1497,6 +1497,7 @@ o_dr_algo : DR_ALGO EQUAL INT_NUMBER {
}
o_solve_algo : SOLVE_ALGO EQUAL INT_NUMBER { driver.option_num("solve_algo", $3); };
o_simul_algo : SIMUL_ALGO EQUAL INT_NUMBER { driver.option_num("simul_algo", $3); };
o_stack_solve_algo : STACK_SOLVE_ALGO EQUAL INT_NUMBER { driver.option_num("stack_solve_algo", $3); };
o_linear : LINEAR { driver.linear(); };
o_order : ORDER EQUAL INT_NUMBER { driver.option_num("order", $3); };
o_replic : REPLIC EQUAL INT_NUMBER { driver.option_num("replic", $3); };
......@@ -1511,11 +1512,6 @@ o_hp_ngrid : HP_NGRID EQUAL INT_NUMBER { driver.option_num("hp_ngrid", $3); };
o_periods : PERIODS EQUAL INT_NUMBER
{ driver.option_num("periods", $3); driver.option_num("simul", "1"); };
o_cutoff : CUTOFF EQUAL number { driver.option_num("cutoff", $3); }
o_method : METHOD EQUAL INT_NUMBER { driver.option_num("simulation_method",$3);}
| METHOD EQUAL LU { driver.option_num("simulation_method", "0"); }
| METHOD EQUAL GAUSSIAN_ELIMINATION { driver.option_num("simulation_method", "1"); }
| METHOD EQUAL GMRES { driver.option_num("simulation_method", "2"); }
| METHOD EQUAL BICGSTAB { driver.option_num("simulation_method", "3"); };
o_markowitz : MARKOWITZ EQUAL number { driver.option_num("markowitz", $3); };
o_mfs : MFS EQUAL number { driver.option_num("mfs", $3); };
o_simul : SIMUL { driver.option_num("simul", "1"); };
......
......@@ -168,7 +168,6 @@ int sigma_e = 0;
/* Inside of a Dynare statement */
<DYNARE_STATEMENT>datafile {return token::DATAFILE;}
<DYNARE_STATEMENT>method {return token::METHOD;}
<DYNARE_STATEMENT>nobs {return token::NOBS;}
<DYNARE_STATEMENT>first_obs {return token::FIRST_OBS;}
<DYNARE_STATEMENT>prefilter {return token::PREFILTER;}
......@@ -332,6 +331,7 @@ int sigma_e = 0;
<DYNARE_STATEMENT>solve_algo {return token::SOLVE_ALGO;}
<DYNARE_STATEMENT>dr_algo {return token::DR_ALGO;}
<DYNARE_STATEMENT>simul_algo {return token::SIMUL_ALGO;}
<DYNARE_STATEMENT>stack_solve_algo {return token::STACK_SOLVE_ALGO;}
<DYNARE_STATEMENT>drop {return token::DROP;}
<DYNARE_STATEMENT>order {return token::ORDER;}
<DYNARE_STATEMENT>replic {return token::REPLIC;}
......@@ -353,14 +353,12 @@ int sigma_e = 0;
<DYNARE_STATEMENT>[\\] {return Dynare::parser::token_type (yytext[0]);}
<DYNARE_STATEMENT>[\'] {return Dynare::parser::token_type (yytext[0]);}
<DYNARE_STATEMENT,DYNARE_BLOCK>use_dll {return token::USE_DLL;}
<DYNARE_STATEMENT,DYNARE_BLOCK>lu {return token::LU;}
<DYNARE_STATEMENT,DYNARE_BLOCK>gaussian_elimination {return token::GAUSSIAN_ELIMINATION;}
<DYNARE_STATEMENT,DYNARE_BLOCK>gmres {return token::GMRES;}
<DYNARE_STATEMENT,DYNARE_BLOCK>bicgstab {return token::BICGSTAB;}
<DYNARE_STATEMENT,DYNARE_BLOCK>block {return token::BLOCK;}
<DYNARE_STATEMENT,DYNARE_BLOCK>bytecode {return token::BYTECODE;}
<DYNARE_BLOCK>use_dll {return token::USE_DLL;}
<DYNARE_BLOCK>block {return token::BLOCK;}
<DYNARE_BLOCK>bytecode {return token::BYTECODE;}
<DYNARE_STATEMENT,DYNARE_BLOCK>linear {return token::LINEAR;}
<DYNARE_STATEMENT,DYNARE_BLOCK>[,] {return token::COMMA;}
<DYNARE_STATEMENT,DYNARE_BLOCK>[:] {return Dynare::parser::token_type (yytext[0]);}
<DYNARE_STATEMENT,DYNARE_BLOCK>[\(\)] {return Dynare::parser::token_type (yytext[0]);}
......
......@@ -645,181 +645,6 @@ StaticDllModel::Write_Inf_To_Bin_File(const string &static_basename, const strin
SaveCode.close();
}
void
StaticDllModel::writeSparseStaticMFile(const string &static_basename, const string &basename, const int mode) const
{
string sp;
ofstream mStaticModelFile;
ostringstream tmp, tmp1, tmp_eq;
int prev_Simulation_Type;
//SymbolicGaussElimination SGE;
bool OK;
chdir(basename.c_str());
string filename = static_basename + ".m";
mStaticModelFile.open(filename.c_str(), ios::out | ios::binary);
if (!mStaticModelFile.is_open())
{
cerr << "Error: Can't open file " << filename << " for writing" << endl;
exit(EXIT_FAILURE);
}
mStaticModelFile << "%\n";
mStaticModelFile << "% " << filename << " : Computes static model for Dynare\n";
mStaticModelFile << "%\n";
mStaticModelFile << "% Warning : this file is generated automatically by Dynare\n";
mStaticModelFile << "% from model file (.mod)\n\n";
mStaticModelFile << "%/\n";
int i, k;
mStaticModelFile << "function [varargout] = " << static_basename << "(varargin)\n";
mStaticModelFile << " global oo_ options_ M_ ;\n";
//Temporary variables declaration
OK=true;
ostringstream tmp_output;
for (temporary_terms_type::const_iterator it = temporary_terms.begin();
it != temporary_terms.end(); it++)
{
if (OK)
OK=false;
else
tmp_output << " ";
(*it)->writeOutput(tmp_output, oMatlabStaticModelSparse, temporary_terms);
}
if (tmp_output.str().length()>0)
mStaticModelFile << " global " << tmp_output.str() << " M_ ;\n";
mStaticModelFile << " T_init=0;\n";
tmp_output.str("");
for (temporary_terms_type::const_iterator it = temporary_terms.begin();
it != temporary_terms.end(); it++)
{
tmp_output << " ";
(*it)->writeOutput(tmp_output, oMatlabStaticModel, temporary_terms);
tmp_output << "=T_init;\n";
}
if (tmp_output.str().length()>0)
mStaticModelFile << tmp_output.str();
mStaticModelFile << " y_size=M_.endo_nbr;\n";
mStaticModelFile << " %it is the deterministic simulation of the block decomposed static model\n";
mStaticModelFile << " maxit_=options_.maxit_;\n";
mStaticModelFile << " solve_tolf=options_.solve_tolf;\n";
mStaticModelFile << " y=oo_.steady_state';\n";
mStaticModelFile << " x=[oo_.exo_steady_state oo_.exo_det_steady_state];\n";
prev_Simulation_Type=-1;
mStaticModelFile << " params=M_.params;\n";
mStaticModelFile << " oo_.deterministic_simulation.status = 0;\n";
for (i = 0;i < block_triangular.ModelBlock->Size;i++)
{
k = block_triangular.ModelBlock->Block_List[i].Simulation_Type;
if ((k == EVALUATE_FORWARD) && (block_triangular.ModelBlock->Block_List[i].Size))
{
mStaticModelFile << " oo_.deterministic_simulation.status = 1;\n";
mStaticModelFile << " oo_.deterministic_simulation.error = 0;\n";
mStaticModelFile << " oo_.deterministic_simulation.iterations = 0;\n";
mStaticModelFile << " if(isfield(oo_.deterministic_simulation,'block'))\n";
mStaticModelFile << " blck_num = length(oo_.deterministic_simulation.block)+1;\n";
mStaticModelFile << " else\n";
mStaticModelFile << " blck_num = 1;\n";
mStaticModelFile << " end;\n";
mStaticModelFile << " oo_.deterministic_simulation.block(blck_num).status = 1;\n";
mStaticModelFile << " oo_.deterministic_simulation.block(blck_num).error = 0;\n";
mStaticModelFile << " oo_.deterministic_simulation.block(blck_num).iterations = 0;\n";
//mStaticModelFile << " for it_ = y_kmin+1:(periods+y_kmin)\n";
mStaticModelFile << " y=" << static_basename << "_" << i + 1 << "(y, x, params);\n";
mStaticModelFile << " tmp = y(:,M_.block_structure.block(" << i + 1 << ").variable);\n";
mStaticModelFile << " if(isnan(tmp) | isinf(tmp))\n";
mStaticModelFile << " disp(['Inf or Nan value during the evaluation of block " << i <<"']);\n";
mStaticModelFile << " return;\n";
mStaticModelFile << " end;\n";
}
else if ((k == EVALUATE_BACKWARD) && (block_triangular.ModelBlock->Block_List[i].Size))
{
mStaticModelFile << " oo_.deterministic_simulation.status = 1;\n";
mStaticModelFile << " oo_.deterministic_simulation.error = 0;\n";
mStaticModelFile << " oo_.deterministic_simulation.iterations = 0;\n";
mStaticModelFile << " if(isfield(oo_.deterministic_simulation,'block'))\n";
mStaticModelFile << " blck_num = length(oo_.deterministic_simulation.block)+1;\n";
mStaticModelFile << " else\n";
mStaticModelFile << " blck_num = 1;\n";
mStaticModelFile << " end;\n";
mStaticModelFile << " oo_.deterministic_simulation.block(blck_num).status = 1;\n";
mStaticModelFile << " oo_.deterministic_simulation.block(blck_num).error = 0;\n";
mStaticModelFile << " oo_.deterministic_simulation.block(blck_num).iterations = 0;\n";
mStaticModelFile << " " << static_basename << "_" << i + 1 << "(y, x, params);\n";
mStaticModelFile << " tmp = y(:,M_.block_structure.block(" << i + 1 << ").variable);\n";
mStaticModelFile << " if(isnan(tmp) | isinf(tmp))\n";
mStaticModelFile << " disp(['Inf or Nan value during the evaluation of block " << i <<"']);\n";
mStaticModelFile << " return;\n";
mStaticModelFile << " end;\n";
}
else if ((k == SOLVE_FORWARD_COMPLETE || k == SOLVE_FORWARD_SIMPLE) && (block_triangular.ModelBlock->Block_List[i].Size))
{
/*mStaticModelFile << " g1=0;\n";
mStaticModelFile << " r=0;\n";*/
tmp.str("");
for (int ik=block_triangular.ModelBlock->Block_List[i].Nb_Recursives ;ik<block_triangular.ModelBlock->Block_List[i].Size;ik++)
{
tmp << " " << block_triangular.ModelBlock->Block_List[i].Variable[ik]+1;
}
mStaticModelFile << " y_index = [" << tmp.str() << "];\n";
/*int nze, m;
for (nze=0,m=0;m<=block_triangular.ModelBlock->Block_List[i].Max_Lead+block_triangular.ModelBlock->Block_List[i].Max_Lag;m++)*/
int nze=block_triangular.ModelBlock->Block_List[i].IM_lead_lag[0].size;
mStaticModelFile << " if(isfield(oo_.deterministic_simulation,'block'))\n";
mStaticModelFile << " blck_num = length(oo_.deterministic_simulation.block)+1;\n";
mStaticModelFile << " else\n";
mStaticModelFile << " blck_num = 1;\n";
mStaticModelFile << " end;\n";
mStaticModelFile << " y = solve_one_boundary('" << static_basename << "_" << i + 1 << "'" <<
", y, x, params, y_index, " << nze <<
", 1, " << block_triangular.ModelBlock->Block_List[i].is_linear <<
", blck_num, 0, options_.maxit_, options_.solve_tolf, options_.slowc, options_.cutoff, options_.simulation_method, 1, 0, 0);\n";
mStaticModelFile << " tmp = y(:,M_.block_structure.block(" << i + 1 << ").variable);\n";
mStaticModelFile << " if(isnan(tmp) | isinf(tmp))\n";
mStaticModelFile << " disp(['Inf or Nan value during the resolution of block " << i <<"']);\n";
mStaticModelFile << " return;\n";
mStaticModelFile << " end;\n";
}
else if ((k == SOLVE_BACKWARD_COMPLETE || k == SOLVE_BACKWARD_SIMPLE) && (block_triangular.ModelBlock->Block_List[i].Size))
{
/*mStaticModelFile << " g1=0;\n";
mStaticModelFile << " r=0;\n";*/
tmp.str("");
for (int ik=block_triangular.ModelBlock->Block_List[i].Nb_Recursives ;ik<block_triangular.ModelBlock->Block_List[i].Size;ik++)
{
tmp << " " << block_triangular.ModelBlock->Block_List[i].Variable[ik]+1;
}
mStaticModelFile << " y_index = [" << tmp.str() << "];\n";
/*int nze, m;
for (nze=0,m=0;m<=block_triangular.ModelBlock->Block_List[i].Max_Lead+block_triangular.ModelBlock->Block_List[i].Max_Lag;m++)*/
int nze=block_triangular.ModelBlock->Block_List[i].IM_lead_lag[0].size;
mStaticModelFile << " if(isfield(oo_.deterministic_simulation,'block'))\n";
mStaticModelFile << " blck_num = length(oo_.deterministic_simulation.block)+1;\n";
mStaticModelFile << " else\n";
mStaticModelFile << " blck_num = 1;\n";
mStaticModelFile << " end;\n";
mStaticModelFile << " y = solve_one_boundary('" << static_basename << "_" << i + 1 << "'" <<
", y, x, params, y_index, " << nze <<
", 0, " << block_triangular.ModelBlock->Block_List[i].is_linear <<
", blck_num, y_kmin, options_.maxit_, options_.solve_tolf, options_.slowc, options_.cutoff, options_.simulation_method, 1, 0, 0);\n";
mStaticModelFile << " tmp = y(:,M_.block_structure.block(" << i + 1 << ").variable);\n";
mStaticModelFile << " if(isnan(tmp) | isinf(tmp))\n";
mStaticModelFile << " disp(['Inf or Nan value during the resolution of block " << i <<"']);\n";
mStaticModelFile << " return;\n";
mStaticModelFile << " end;\n";
}
}
mStaticModelFile << " oo_.steady_state = y';\n";
mStaticModelFile << "return;\n";
mStaticModelFile.close();
writeModelEquationsOrdered_M( block_triangular.ModelBlock, static_basename);
chdir("..");
}
void
StaticDllModel::evaluateJacobian(const eval_context_type &eval_context, jacob_map *j_m, bool dynamic)
......
......@@ -77,8 +77,6 @@ private:
//! Writes static model file (C version)
/*! \todo add third derivatives handling */
void writeStaticCFile(const string &static_basename) const;
//! Writes static model file when SparseDLL option is on
void writeSparseStaticMFile(const string &static_basename, const string &basename, const int mode) const;
//! Writes the Block reordred structure of the model in M output
void writeModelEquationsOrdered_M(Model_Block *ModelBlock, const string &static_basename) const;
//! Writes the code of the Block reordred structure of the model in virtual machine bytecode
......
Supports Markdown
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