- factorization of simulation methods for static m-file
- correction of bugs in resid.m git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@2280 ac1d8469-bf42-47a9-8791-bf33cf982152time-shift
parent
e0a8365ec8
commit
26ae037863
|
@ -208,8 +208,9 @@ function [dr,info,M_,options_,oo_] = dr1_sparse(dr,task,M_,options_,oo_)
|
||||||
dr.nyf = nnz(dr.kstate(:,2)>M_.maximum_lag+1);
|
dr.nyf = nnz(dr.kstate(:,2)>M_.maximum_lag+1);
|
||||||
elseif options_.model_mode==1
|
elseif options_.model_mode==1
|
||||||
if options_.order == 1
|
if options_.order == 1
|
||||||
|
|
||||||
[junk,jacobia_] = feval([M_.fname '_dynamic'],ones(M_.maximum_lag+M_.maximum_lead+1,1)*dr.ys',[oo_.exo_simul ...
|
[junk,jacobia_] = feval([M_.fname '_dynamic'],ones(M_.maximum_lag+M_.maximum_lead+1,1)*dr.ys',[oo_.exo_simul ...
|
||||||
oo_.exo_det_simul], it_);
|
oo_.exo_det_simul], M_.params, it_);
|
||||||
%full(jacobia_)
|
%full(jacobia_)
|
||||||
dr.eigval = [];
|
dr.eigval = [];
|
||||||
dr.nyf = 0;
|
dr.nyf = 0;
|
||||||
|
@ -221,7 +222,6 @@ function [dr,info,M_,options_,oo_] = dr1_sparse(dr,task,M_,options_,oo_)
|
||||||
M_.block_structure.block(i).dr=set_state_space(M_.block_structure.block(i).dr,M_.block_structure.block(i));
|
M_.block_structure.block(i).dr=set_state_space(M_.block_structure.block(i).dr,M_.block_structure.block(i));
|
||||||
col_selector=repmat(M_.block_structure.block(i).variable,1,M_.block_structure.block(i).maximum_endo_lag+M_.block_structure.block(i).maximum_endo_lead+1)+kron([M_.maximum_endo_lag-M_.block_structure.block(i).maximum_endo_lag:M_.maximum_endo_lag+M_.block_structure.block(i).maximum_endo_lead],M_.endo_nbr*ones(1,M_.block_structure.block(i).endo_nbr));
|
col_selector=repmat(M_.block_structure.block(i).variable,1,M_.block_structure.block(i).maximum_endo_lag+M_.block_structure.block(i).maximum_endo_lead+1)+kron([M_.maximum_endo_lag-M_.block_structure.block(i).maximum_endo_lag:M_.maximum_endo_lag+M_.block_structure.block(i).maximum_endo_lead],M_.endo_nbr*ones(1,M_.block_structure.block(i).endo_nbr));
|
||||||
row_selector = M_.block_structure.block(i).equation;
|
row_selector = M_.block_structure.block(i).equation;
|
||||||
%col_selector
|
|
||||||
jcb_=jacobia_(row_selector,col_selector);
|
jcb_=jacobia_(row_selector,col_selector);
|
||||||
jcb_ = jcb_(:,find(M_.block_structure.block(i).lead_lag_incidence')) ;
|
jcb_ = jcb_(:,find(M_.block_structure.block(i).lead_lag_incidence')) ;
|
||||||
if M_.block_structure.block(i).exo_nbr>0
|
if M_.block_structure.block(i).exo_nbr>0
|
||||||
|
|
Binary file not shown.
|
@ -49,11 +49,20 @@ function resid(period)
|
||||||
y =oo_.endo_simul(:);
|
y =oo_.endo_simul(:);
|
||||||
z = zeros(n,period);
|
z = zeros(n,period);
|
||||||
fh = str2func([M_.fname '_dynamic']);
|
fh = str2func([M_.fname '_dynamic']);
|
||||||
|
if(options_.model_mode)
|
||||||
|
addpath(M_.fname);
|
||||||
|
end;
|
||||||
for it_=M_.maximum_lag+1:period+M_.maximum_lag
|
for it_=M_.maximum_lag+1:period+M_.maximum_lag
|
||||||
|
if(options_.model_mode)
|
||||||
|
z(:,it_-M_.maximum_lag) = feval(fh,oo_.endo_simul',oo_.exo_simul, M_.params, it_);
|
||||||
|
else
|
||||||
z(:,it_-M_.maximum_lag) = feval(fh,y(iyr0),oo_.exo_simul, M_.params, it_);
|
z(:,it_-M_.maximum_lag) = feval(fh,y(iyr0),oo_.exo_simul, M_.params, it_);
|
||||||
iyr0 = iyr0 + n;
|
iyr0 = iyr0 + n;
|
||||||
|
end;
|
||||||
end
|
end
|
||||||
|
if(options_.model_mode)
|
||||||
|
rmpath(M_.fname);
|
||||||
|
end;
|
||||||
% disp([[1:period]' z']);
|
% disp([[1:period]' z']);
|
||||||
|
|
||||||
for i = 1:4
|
for i = 1:4
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
function y = solve_one_boundary(fname, y, x, y_index_eq, nze, periods, is_linear, Block_Num, y_kmin, maxit_, solve_tolf, lambda, cutoff, simulation_method, forward_backward)
|
function y = 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)
|
||||||
% Computes the deterministic simulation of a block of equation containing
|
% Computes the deterministic simulation of a block of equation containing
|
||||||
% lead or lag variables
|
% lead or lag variables
|
||||||
%
|
%
|
||||||
|
@ -7,6 +7,7 @@ function y = solve_one_boundary(fname, y, x, y_index_eq, nze, periods, is_linear
|
||||||
% to simulate
|
% to simulate
|
||||||
% y [matrix] All the endogenous variables of the model
|
% y [matrix] All the endogenous variables of the model
|
||||||
% x [matrix] All the exogenous variables of the model
|
% x [matrix] All the exogenous variables of the model
|
||||||
|
% params [vector] All the parameters of the model
|
||||||
% y_index_eq [vector of int] The index of the endogenous variables of
|
% y_index_eq [vector of int] The index of the endogenous variables of
|
||||||
% the block
|
% the block
|
||||||
% nze [integer] number of non-zero elements in the
|
% nze [integer] number of non-zero elements in the
|
||||||
|
@ -29,6 +30,13 @@ function y = solve_one_boundary(fname, y, x, y_index_eq, nze, periods, is_linear
|
||||||
% - 3 BicGStab
|
% - 3 BicGStab
|
||||||
% forward_backward [integer] The block has to be solve forward
|
% forward_backward [integer] The block has to be solve forward
|
||||||
% (1) or backward (0)
|
% (1) or backward (0)
|
||||||
|
% is_dynamic [integer] (1) The block belong to the dynamic
|
||||||
|
% file and the oo_.deterministic_simulation field has to be uptated
|
||||||
|
% (0) The block belong to the static
|
||||||
|
% file and th oo_.deteerminstic
|
||||||
|
% field remains unchanged
|
||||||
|
% verobse [integer] (0) iterations are not printed
|
||||||
|
% (1) iterations are printed
|
||||||
%
|
%
|
||||||
% OUTPUTS
|
% OUTPUTS
|
||||||
% y [matrix] All endogenous variables of the model
|
% y [matrix] All endogenous variables of the model
|
||||||
|
@ -58,7 +66,7 @@ function y = solve_one_boundary(fname, y, x, y_index_eq, nze, periods, is_linear
|
||||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
global oo_;
|
global oo_ M_;
|
||||||
Blck_size=size(y_index_eq,2);
|
Blck_size=size(y_index_eq,2);
|
||||||
g2 = [];
|
g2 = [];
|
||||||
g3 = [];
|
g3 = [];
|
||||||
|
@ -75,20 +83,32 @@ function y = solve_one_boundary(fname, y, x, y_index_eq, nze, periods, is_linear
|
||||||
start = periods+y_kmin;
|
start = periods+y_kmin;
|
||||||
finish = y_kmin+1;
|
finish = y_kmin+1;
|
||||||
end
|
end
|
||||||
|
lambda=1;
|
||||||
for it_=start:incr:finish
|
for it_=start:incr:finish
|
||||||
cvg=0;
|
cvg=0;
|
||||||
iter=0;
|
iter=0;
|
||||||
g1=spalloc( Blck_size, Blck_size, nze);
|
g1=spalloc( Blck_size, Blck_size, nze);
|
||||||
%Per_y_=it_*Blck_size;
|
|
||||||
while ~(cvg==1 | iter>maxit_),
|
while ~(cvg==1 | iter>maxit_),
|
||||||
[r, g1] = feval(fname, y, x, it_, 0, g1, g2, g3);
|
if(is_dynamic)
|
||||||
%r
|
[r, g1] = feval(fname, y, x, params, it_, 0, g1, g2, g3);
|
||||||
|
else
|
||||||
|
[r, g1] = feval(fname, y, x, params, 0);
|
||||||
|
end;
|
||||||
if(~isreal(r))
|
if(~isreal(r))
|
||||||
max_res=(-(max(max(abs(r))))^2)^0.5;
|
max_res=(-(max(max(abs(r))))^2)^0.5;
|
||||||
else
|
else
|
||||||
max_res=max(max(abs(r)));
|
max_res=max(max(abs(r)));
|
||||||
end;
|
end;
|
||||||
|
if(verbose==1)
|
||||||
|
disp(['iteration : ' int2str(iter) ' => ' num2str(max_res)]);
|
||||||
|
disp([M_.endo_names(y_index_eq,:) num2str([y(y_index_eq) r g1])]);
|
||||||
|
end;
|
||||||
|
if(is_linear)
|
||||||
|
cvg = 1;
|
||||||
|
else
|
||||||
|
cvg=(max_res<solve_tolf);
|
||||||
|
end;
|
||||||
|
if(~cvg)
|
||||||
if(iter>0)
|
if(iter>0)
|
||||||
if(~isreal(max_res) | isnan(max_res) | (max_resa<max_res && iter>1))
|
if(~isreal(max_res) | isnan(max_res) | (max_resa<max_res && iter>1))
|
||||||
if(isnan(max_res))
|
if(isnan(max_res))
|
||||||
|
@ -114,7 +134,11 @@ function y = solve_one_boundary(fname, y, x, y_index_eq, nze, periods, is_linear
|
||||||
lambda=lambda/2;
|
lambda=lambda/2;
|
||||||
reduced = 1;
|
reduced = 1;
|
||||||
disp(['reducing the path length: lambda=' num2str(lambda,'%f')]);
|
disp(['reducing the path length: lambda=' num2str(lambda,'%f')]);
|
||||||
|
if(is_dynamic)
|
||||||
y(it_,y_index_eq)=ya_save+lambda*dx;
|
y(it_,y_index_eq)=ya_save+lambda*dx;
|
||||||
|
else
|
||||||
|
y(y_index_eq)=ya_save+lambda*dx;
|
||||||
|
end;
|
||||||
continue;
|
continue;
|
||||||
else
|
else
|
||||||
if(cutoff == 0)
|
if(cutoff == 0)
|
||||||
|
@ -122,12 +146,14 @@ function y = solve_one_boundary(fname, y, x, y_index_eq, nze, periods, is_linear
|
||||||
else
|
else
|
||||||
fprintf('Error in simul: Convergence not achieved in block %d, at time %d, after %d iterations.\n Increase "options_.maxit_" or set "cutoff=0" in model options.\n',Block_Num, it_, iter);
|
fprintf('Error in simul: Convergence not achieved in block %d, at time %d, after %d iterations.\n Increase "options_.maxit_" or set "cutoff=0" in model options.\n',Block_Num, it_, iter);
|
||||||
end;
|
end;
|
||||||
|
if(is_dynamic)
|
||||||
oo_.deterministic_simulation.status = 0;
|
oo_.deterministic_simulation.status = 0;
|
||||||
oo_.deterministic_simulation.error = max_res;
|
oo_.deterministic_simulation.error = max_res;
|
||||||
oo_.deterministic_simulation.iterations = iter;
|
oo_.deterministic_simulation.iterations = iter;
|
||||||
oo_.deterministic_simulation.block(Block_Num).status = 0;% Convergency failed.
|
oo_.deterministic_simulation.block(Block_Num).status = 0;% Convergency failed.
|
||||||
oo_.deterministic_simulation.block(Block_Num).error = max_res;
|
oo_.deterministic_simulation.block(Block_Num).error = max_res;
|
||||||
oo_.deterministic_simulation.block(Block_Num).iterations = iter;
|
oo_.deterministic_simulation.block(Block_Num).iterations = iter;
|
||||||
|
end;
|
||||||
return;
|
return;
|
||||||
end;
|
end;
|
||||||
else
|
else
|
||||||
|
@ -136,18 +162,28 @@ function y = solve_one_boundary(fname, y, x, y_index_eq, nze, periods, is_linear
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
if(is_dynamic)
|
||||||
ya = y(it_,y_index_eq)';
|
ya = y(it_,y_index_eq)';
|
||||||
|
else
|
||||||
|
ya = y(y_index_eq);
|
||||||
|
end;
|
||||||
ya_save=ya;
|
ya_save=ya;
|
||||||
g1a=g1;
|
g1a=g1;
|
||||||
if(simulation_method==0),
|
if(simulation_method==0),
|
||||||
dx = (-r/g1)';
|
%dx = - inv(g1)*r;
|
||||||
|
num2str(eig(full(g1)),'%f')
|
||||||
|
dx = - g1\r;
|
||||||
ya = ya + lambda*dx;
|
ya = ya + lambda*dx;
|
||||||
y(it_,y_index_eq)=ya';
|
if(is_dynamic)
|
||||||
|
y(it_,y_index_eq) = ya';
|
||||||
|
else
|
||||||
|
y(y_index_eq) = ya;
|
||||||
|
end;
|
||||||
elseif(simulation_method==2),
|
elseif(simulation_method==2),
|
||||||
flag1=1;
|
flag1=1;
|
||||||
while(flag1>0)
|
while(flag1>0)
|
||||||
[L1, U1]=luinc(g1,luinc_tol);
|
[L1, U1]=luinc(g1,luinc_tol);
|
||||||
[za,flag1] = gmres(g1,-r',Blck_size,1e-6,Blck_size,L1,U1);
|
[za,flag1] = gmres(g1,-r,Blck_size,1e-6,Blck_size,L1,U1);
|
||||||
if (flag1>0 | reduced)
|
if (flag1>0 | reduced)
|
||||||
if(flag1==1)
|
if(flag1==1)
|
||||||
disp(['Error in simul: No convergence inside GMRES after ' num2str(iter,'%6d') ' iterations, in block' num2str(Block_Num,'%3d')]);
|
disp(['Error in simul: No convergence inside GMRES after ' num2str(iter,'%6d') ' iterations, in block' num2str(Block_Num,'%3d')]);
|
||||||
|
@ -161,14 +197,18 @@ function y = solve_one_boundary(fname, y, x, y_index_eq, nze, periods, is_linear
|
||||||
else
|
else
|
||||||
dx = za - ya;
|
dx = za - ya;
|
||||||
ya = ya + lambda*dx;
|
ya = ya + lambda*dx;
|
||||||
y(it_,y_index_eq)=ya';
|
if(is_dynamic)
|
||||||
|
y(it_,y_index_eq) = ya';
|
||||||
|
else
|
||||||
|
y(y_index_eq) = ya';
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
elseif(simulation_method==3),
|
elseif(simulation_method==3),
|
||||||
flag1=1;
|
flag1=1;
|
||||||
while(flag1>0)
|
while(flag1>0)
|
||||||
[L1, U1]=luinc(g1,luinc_tol);
|
[L1, U1]=luinc(g1,luinc_tol);
|
||||||
[za,flag1] = bicgstab(g1,-r',1e-7,Blck_size,L1,U1);
|
[za,flag1] = bicgstab(g1,-r,1e-7,Blck_size,L1,U1);
|
||||||
if (flag1>0 | reduced)
|
if (flag1>0 | reduced)
|
||||||
if(flag1==1)
|
if(flag1==1)
|
||||||
disp(['Error in simul: No convergence inside BICGSTAB after ' num2str(iter,'%6d') ' iterations, in block' num2str(Block_Num,'%3d')]);
|
disp(['Error in simul: No convergence inside BICGSTAB after ' num2str(iter,'%6d') ' iterations, in block' num2str(Block_Num,'%3d')]);
|
||||||
|
@ -182,36 +222,40 @@ function y = solve_one_boundary(fname, y, x, y_index_eq, nze, periods, is_linear
|
||||||
else
|
else
|
||||||
dx = za - ya;
|
dx = za - ya;
|
||||||
ya = ya + lambda*dx;
|
ya = ya + lambda*dx;
|
||||||
y(it_,y_index_eq)=ya';
|
if(is_dynamic)
|
||||||
end;
|
y(it_,y_index_eq) = ya';
|
||||||
end;
|
|
||||||
end;
|
|
||||||
if(is_linear)
|
|
||||||
cvg = 1;
|
|
||||||
else
|
else
|
||||||
cvg=(max_res<solve_tolf);
|
y(y_index_eq) = ya';
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
iter=iter+1;
|
iter=iter+1;
|
||||||
end
|
end
|
||||||
|
end
|
||||||
if cvg==0
|
if cvg==0
|
||||||
if(cutoff == 0)
|
if(cutoff == 0)
|
||||||
fprintf('Error in simul: Convergence not achieved in block %d, at time %d, after %d iterations.\n Increase "options_.maxit_\".\n',Block_Num, it_,iter);
|
fprintf('Error in simul: Convergence not achieved in block %d, at time %d, after %d iterations.\n Increase "options_.maxit_\".\n',Block_Num, it_,iter);
|
||||||
else
|
else
|
||||||
fprintf('Error in simul: Convergence not achieved in block %d, at time %d, after %d iterations.\n Increase "options_.maxit_" or set "cutoff=0" in model options.\n',Block_Num, it_,iter);
|
fprintf('Error in simul: Convergence not achieved in block %d, at time %d, after %d iterations.\n Increase "options_.maxit_" or set "cutoff=0" in model options.\n',Block_Num, it_,iter);
|
||||||
end;
|
end;
|
||||||
|
if(is_dynamic)
|
||||||
oo_.deterministic_simulation.status = 0;
|
oo_.deterministic_simulation.status = 0;
|
||||||
oo_.deterministic_simulation.error = max_res;
|
oo_.deterministic_simulation.error = max_res;
|
||||||
oo_.deterministic_simulation.iterations = iter;
|
oo_.deterministic_simulation.iterations = iter;
|
||||||
oo_.deterministic_simulation.block(Block_Num).status = 0;% Convergency failed.
|
oo_.deterministic_simulation.block(Block_Num).status = 0;% Convergency failed.
|
||||||
oo_.deterministic_simulation.block(Block_Num).error = max_res;
|
oo_.deterministic_simulation.block(Block_Num).error = max_res;
|
||||||
oo_.deterministic_simulation.block(Block_Num).iterations = iter;
|
oo_.deterministic_simulation.block(Block_Num).iterations = iter;
|
||||||
|
end;
|
||||||
return;
|
return;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if(is_dynamic)
|
||||||
oo_.deterministic_simulation.status = 1;
|
oo_.deterministic_simulation.status = 1;
|
||||||
oo_.deterministic_simulation.error = max_res;
|
oo_.deterministic_simulation.error = max_res;
|
||||||
oo_.deterministic_simulation.iterations = iter;
|
oo_.deterministic_simulation.iterations = iter;
|
||||||
oo_.deterministic_simulation.block(Block_Num).status = 1;% Convergency failed.
|
oo_.deterministic_simulation.block(Block_Num).status = 1;% Convergency failed.
|
||||||
oo_.deterministic_simulation.block(Block_Num).error = max_res;
|
oo_.deterministic_simulation.block(Block_Num).error = max_res;
|
||||||
oo_.deterministic_simulation.block(Block_Num).iterations = iter;
|
oo_.deterministic_simulation.block(Block_Num).iterations = iter;
|
||||||
|
end;
|
||||||
return;
|
return;
|
|
@ -1,4 +1,4 @@
|
||||||
function y = solve_two_boundaries(fname, y, x, 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, simulation_method)
|
||||||
% Computes the deterministic simulation of a block of equation containing
|
% Computes the deterministic simulation of a block of equation containing
|
||||||
% both lead and lag variables using relaxation methods
|
% both lead and lag variables using relaxation methods
|
||||||
%
|
%
|
||||||
|
@ -7,6 +7,7 @@ function y = solve_two_boundaries(fname, y, x, y_index, nze, periods, y_kmin_l,
|
||||||
% to simulate
|
% to simulate
|
||||||
% y [matrix] All the endogenous variables of the model
|
% y [matrix] All the endogenous variables of the model
|
||||||
% x [matrix] All the exogenous variables of the model
|
% x [matrix] All the exogenous variables of the model
|
||||||
|
% params [vector] All the parameters of the model
|
||||||
% y_index [vector of int] The index of the endogenous variables of
|
% y_index [vector of int] The index of the endogenous variables of
|
||||||
% the block
|
% the block
|
||||||
% nze [integer] number of non-zero elements in the
|
% nze [integer] number of non-zero elements in the
|
||||||
|
@ -72,7 +73,7 @@ function y = solve_two_boundaries(fname, y, x, y_index, nze, periods, y_kmin_l,
|
||||||
reduced = 0;
|
reduced = 0;
|
||||||
while ~(cvg==1 | iter>maxit_),
|
while ~(cvg==1 | iter>maxit_),
|
||||||
%fname
|
%fname
|
||||||
[r, g1, g2, g3, b]=feval(fname, y, x, periods, 0, g1, g2, g3, y_kmin, Blck_size);
|
[r, g1, g2, g3, b]=feval(fname, y, x, params, periods, 0, g1, g2, g3, y_kmin, Blck_size);
|
||||||
g1a=g1(:, y_kmin*Blck_size+1:(periods+y_kmin)*Blck_size);
|
g1a=g1(:, y_kmin*Blck_size+1:(periods+y_kmin)*Blck_size);
|
||||||
b = b' -g1(:, 1+(y_kmin-y_kmin_l)*Blck_size:y_kmin*Blck_size)*reshape(y(1+y_kmin-y_kmin_l:y_kmin,y_index)',1,y_kmin_l*Blck_size)'-g1(:, (periods+y_kmin)*Blck_size+1:(periods+y_kmin+y_kmax_l)*Blck_size)*reshape(y(periods+y_kmin+1:periods+y_kmin+y_kmax_l,y_index)',1,y_kmax_l*Blck_size)';
|
b = b' -g1(:, 1+(y_kmin-y_kmin_l)*Blck_size:y_kmin*Blck_size)*reshape(y(1+y_kmin-y_kmin_l:y_kmin,y_index)',1,y_kmin_l*Blck_size)'-g1(:, (periods+y_kmin)*Blck_size+1:(periods+y_kmin+y_kmax_l)*Blck_size)*reshape(y(periods+y_kmin+1:periods+y_kmin+y_kmax_l,y_index)',1,y_kmax_l*Blck_size)';
|
||||||
if(~isreal(r))
|
if(~isreal(r))
|
||||||
|
|
|
@ -170,7 +170,12 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const
|
||||||
mOutputFile << "logname_ = '" << basename << ".log';" << endl;
|
mOutputFile << "logname_ = '" << basename << ".log';" << endl;
|
||||||
mOutputFile << "diary " << basename << ".log" << endl;
|
mOutputFile << "diary " << basename << ".log" << endl;
|
||||||
mOutputFile << "options_.model_mode = " << model_tree.mode << ";\n";
|
mOutputFile << "options_.model_mode = " << model_tree.mode << ";\n";
|
||||||
|
if (model_tree.mode == eSparseMode)
|
||||||
|
{
|
||||||
mOutputFile << "addpath " << basename << ";\n";
|
mOutputFile << "addpath " << basename << ";\n";
|
||||||
|
mOutputFile << "delete('" << basename << "_static.m');\n";
|
||||||
|
mOutputFile << "delete('" << basename << "_dynamic.m');\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (model_tree.equation_number() > 0)
|
if (model_tree.equation_number() > 0)
|
||||||
|
|
|
@ -407,7 +407,8 @@ ModelTree::writeModelEquationsOrdered_M( Model_Block *ModelBlock, const string &
|
||||||
(*it)->writeOutput(tmp_output, oMatlabDynamicModel, temporary_terms);
|
(*it)->writeOutput(tmp_output, oMatlabDynamicModel, temporary_terms);
|
||||||
|
|
||||||
}
|
}
|
||||||
global_output << " global " << tmp_output.str() << " M_ ;\n";
|
if(tmp_output.str().length())
|
||||||
|
global_output << " global " << tmp_output.str() << /*" M_ ;\n"ù*/";\n";
|
||||||
//For each block
|
//For each block
|
||||||
int gen_blocks=0;
|
int gen_blocks=0;
|
||||||
for(j = 0;j < ModelBlock->Size;j++)
|
for(j = 0;j < ModelBlock->Size;j++)
|
||||||
|
@ -438,6 +439,9 @@ ModelTree::writeModelEquationsOrdered_M( Model_Block *ModelBlock, const string &
|
||||||
gen_blocks++;
|
gen_blocks++;
|
||||||
if (j>0)
|
if (j>0)
|
||||||
{
|
{
|
||||||
|
if(prev_Simulation_Type==EVALUATE_BACKWARD || prev_Simulation_Type==EVALUATE_BACKWARD_R ||
|
||||||
|
prev_Simulation_Type==EVALUATE_FORWARD || prev_Simulation_Type==EVALUATE_FORWARD_R)
|
||||||
|
output << " end;\n";
|
||||||
output << "return;\n";
|
output << "return;\n";
|
||||||
output.close();
|
output.close();
|
||||||
}
|
}
|
||||||
|
@ -456,15 +460,15 @@ ModelTree::writeModelEquationsOrdered_M( Model_Block *ModelBlock, const string &
|
||||||
||ModelBlock->Block_List[j].Simulation_Type==EVALUATE_FORWARD
|
||ModelBlock->Block_List[j].Simulation_Type==EVALUATE_FORWARD
|
||||||
||ModelBlock->Block_List[j].Simulation_Type==EVALUATE_BACKWARD_R
|
||ModelBlock->Block_List[j].Simulation_Type==EVALUATE_BACKWARD_R
|
||||||
||ModelBlock->Block_List[j].Simulation_Type==EVALUATE_FORWARD_R)
|
||ModelBlock->Block_List[j].Simulation_Type==EVALUATE_FORWARD_R)
|
||||||
output << "function [y, g1, g2, g3] = " << dynamic_basename << "_" << j+1 << "(y, x, it_, jacobian_eval, g1, g2, g3)\n";
|
output << "function [y, g1, g2, g3] = " << dynamic_basename << "_" << j+1 << "(y, x, params, jacobian_eval, g1, g2, g3, y_kmin, periods)\n";
|
||||||
else if (ModelBlock->Block_List[j].Simulation_Type==SOLVE_FORWARD_COMPLETE
|
else if (ModelBlock->Block_List[j].Simulation_Type==SOLVE_FORWARD_COMPLETE
|
||||||
|| ModelBlock->Block_List[j].Simulation_Type==SOLVE_BACKWARD_COMPLETE)
|
|| ModelBlock->Block_List[j].Simulation_Type==SOLVE_BACKWARD_COMPLETE)
|
||||||
output << "function [residual, g1, g2, g3, b] = " << dynamic_basename << "_" << j+1 << "(y, x, it_, jacobian_eval, g1, g2, g3)\n";
|
output << "function [residual, g1, g2, g3, b] = " << dynamic_basename << "_" << j+1 << "(y, x, params, it_, jacobian_eval, g1, g2, g3)\n";
|
||||||
else if (ModelBlock->Block_List[j].Simulation_Type==SOLVE_BACKWARD_SIMPLE
|
else if (ModelBlock->Block_List[j].Simulation_Type==SOLVE_BACKWARD_SIMPLE
|
||||||
|| ModelBlock->Block_List[j].Simulation_Type==SOLVE_FORWARD_SIMPLE)
|
|| ModelBlock->Block_List[j].Simulation_Type==SOLVE_FORWARD_SIMPLE)
|
||||||
output << "function [residual, g1, g2, g3, b] = " << dynamic_basename << "_" << j+1 << "(y, x, it_, jacobian_eval, g1, g2, g3)\n";
|
output << "function [residual, g1, g2, g3, b] = " << dynamic_basename << "_" << j+1 << "(y, x, params, it_, jacobian_eval, g1, g2, g3)\n";
|
||||||
else
|
else
|
||||||
output << "function [residual, g1, g2, g3, b] = " << dynamic_basename << "_" << j+1 << "(y, x, periods, jacobian_eval, g1, g2, g3, y_kmin, y_size)\n";
|
output << "function [residual, g1, g2, g3, b] = " << dynamic_basename << "_" << j+1 << "(y, x, params, periods, jacobian_eval, g1, g2, g3, y_kmin, y_size)\n";
|
||||||
output << " % ////////////////////////////////////////////////////////////////////////" << endl
|
output << " % ////////////////////////////////////////////////////////////////////////" << endl
|
||||||
<< " % //" << string(" Block ").substr(int(log10(j + 1))) << j + 1 << " " << BlockTriangular::BlockType0(ModelBlock->Block_List[j].Type)
|
<< " % //" << string(" Block ").substr(int(log10(j + 1))) << j + 1 << " " << BlockTriangular::BlockType0(ModelBlock->Block_List[j].Type)
|
||||||
<< " //" << endl
|
<< " //" << endl
|
||||||
|
@ -473,9 +477,15 @@ ModelTree::writeModelEquationsOrdered_M( Model_Block *ModelBlock, const string &
|
||||||
<< " % ////////////////////////////////////////////////////////////////////////" << endl;
|
<< " % ////////////////////////////////////////////////////////////////////////" << endl;
|
||||||
//The Temporary terms
|
//The Temporary terms
|
||||||
output << global_output.str();
|
output << global_output.str();
|
||||||
output << " if M_.param_nbr > 0\n";
|
output << " residual=zeros(" << ModelBlock->Block_List[j].Size << ",1);\n";
|
||||||
|
if (ModelBlock->Block_List[j].Simulation_Type==EVALUATE_BACKWARD
|
||||||
|
||ModelBlock->Block_List[j].Simulation_Type==EVALUATE_FORWARD
|
||||||
|
||ModelBlock->Block_List[j].Simulation_Type==EVALUATE_BACKWARD_R
|
||||||
|
||ModelBlock->Block_List[j].Simulation_Type==EVALUATE_FORWARD_R)
|
||||||
|
output << " for it_ = y_kmin+1:(y_kmin+periods)\n";
|
||||||
|
/*output << " if M_.param_nbr > 0\n";
|
||||||
output << " params = M_.params;\n";
|
output << " params = M_.params;\n";
|
||||||
output << " end\n";
|
output << " end\n";*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -796,16 +806,19 @@ ModelTree::writeModelEquationsOrdered_M( Model_Block *ModelBlock, const string &
|
||||||
}
|
}
|
||||||
prev_Simulation_Type=ModelBlock->Block_List[j].Simulation_Type;
|
prev_Simulation_Type=ModelBlock->Block_List[j].Simulation_Type;
|
||||||
}
|
}
|
||||||
|
if(prev_Simulation_Type==EVALUATE_BACKWARD || prev_Simulation_Type==EVALUATE_BACKWARD_R ||
|
||||||
|
prev_Simulation_Type==EVALUATE_FORWARD || prev_Simulation_Type==EVALUATE_FORWARD_R)
|
||||||
|
output << " end;\n";
|
||||||
output << "return;\n";
|
output << "return;\n";
|
||||||
output.close();
|
output.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ModelTree::writeModelStaticEquationsOrdered_M(ostream &output, Model_Block *ModelBlock, const string &static_basename) const
|
ModelTree::writeModelStaticEquationsOrdered_M(Model_Block *ModelBlock, const string &static_basename) const
|
||||||
{
|
{
|
||||||
int i,j,k,m, var, eq, g1_index = 1;
|
int i,j,k,m, var, eq, g1_index = 1;
|
||||||
string tmp_s, sps;
|
string tmp_s, sps;
|
||||||
ostringstream tmp_output, global_output;
|
ostringstream tmp_output, tmp1_output, global_output;
|
||||||
NodeID lhs=NULL, rhs=NULL;
|
NodeID lhs=NULL, rhs=NULL;
|
||||||
BinaryOpNode *eq_node;
|
BinaryOpNode *eq_node;
|
||||||
bool OK, lhs_rhs_done, skip_the_head;
|
bool OK, lhs_rhs_done, skip_the_head;
|
||||||
|
@ -814,6 +827,7 @@ ModelTree::writeModelStaticEquationsOrdered_M(ostream &output, Model_Block *Mode
|
||||||
int prev_Simulation_Type=-1;
|
int prev_Simulation_Type=-1;
|
||||||
int nze=0;
|
int nze=0;
|
||||||
bool *IM, *IMl;
|
bool *IM, *IMl;
|
||||||
|
ofstream output;
|
||||||
temporary_terms_type::const_iterator it_temp=temporary_terms.begin();
|
temporary_terms_type::const_iterator it_temp=temporary_terms.begin();
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
//Temporary variables declaration
|
//Temporary variables declaration
|
||||||
|
@ -827,7 +841,8 @@ ModelTree::writeModelStaticEquationsOrdered_M(ostream &output, Model_Block *Mode
|
||||||
tmp_output << " ";
|
tmp_output << " ";
|
||||||
(*it)->writeOutput(tmp_output, oMatlabStaticModelSparse, temporary_terms);
|
(*it)->writeOutput(tmp_output, oMatlabStaticModelSparse, temporary_terms);
|
||||||
}
|
}
|
||||||
global_output << " global " << tmp_output.str() << " M_ ;\n";
|
if(tmp_output.str().length())
|
||||||
|
global_output << " global " << tmp_output.str() << /*" M_ ;\n"*/ ";\n";
|
||||||
//For each block
|
//For each block
|
||||||
for(j = 0;j < ModelBlock->Size;j++)
|
for(j = 0;j < ModelBlock->Size;j++)
|
||||||
{
|
{
|
||||||
|
@ -859,19 +874,35 @@ ModelTree::writeModelStaticEquationsOrdered_M(ostream &output, Model_Block *Mode
|
||||||
}
|
}
|
||||||
if (!skip_the_head)
|
if (!skip_the_head)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (j>0)
|
if (j>0)
|
||||||
|
{
|
||||||
|
output << "return;\n";
|
||||||
|
output.close();
|
||||||
|
}
|
||||||
|
tmp1_output.str("");
|
||||||
|
tmp1_output << static_basename << "_" << j+1 << ".m";
|
||||||
|
output.open(tmp1_output.str().c_str(), ios::out | ios::binary);
|
||||||
|
output << "%\n";
|
||||||
|
output << "% " << tmp1_output.str() << " : Computes static model for Dynare\n";
|
||||||
|
output << "%\n";
|
||||||
|
output << "% Warning : this file is generated automatically by Dynare\n";
|
||||||
|
output << "% from model file (.mod)\n\n";
|
||||||
|
output << "%/\n";
|
||||||
|
|
||||||
|
/*if (j>0)
|
||||||
{
|
{
|
||||||
output << "return;\n\n\n";
|
output << "return;\n\n\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
output << "\n\n";
|
output << "\n\n";*/
|
||||||
if(ModelBlock->Block_List[j].Simulation_Type==EVALUATE_BACKWARD
|
if(ModelBlock->Block_List[j].Simulation_Type==EVALUATE_BACKWARD
|
||||||
||ModelBlock->Block_List[j].Simulation_Type==EVALUATE_FORWARD
|
||ModelBlock->Block_List[j].Simulation_Type==EVALUATE_FORWARD
|
||||||
||ModelBlock->Block_List[j].Simulation_Type==EVALUATE_BACKWARD_R
|
||ModelBlock->Block_List[j].Simulation_Type==EVALUATE_BACKWARD_R
|
||||||
||ModelBlock->Block_List[j].Simulation_Type==EVALUATE_FORWARD_R )
|
||ModelBlock->Block_List[j].Simulation_Type==EVALUATE_FORWARD_R )
|
||||||
output << "function [y, g1] = " << static_basename << "_" << j+1 << "(y, x, jacobian_eval)\n";
|
output << "function [y, g1] = " << static_basename << "_" << j+1 << "(y, x, params, jacobian_eval)\n";
|
||||||
else
|
else
|
||||||
output << "function [residual, g1, g2, g3, b] = " << static_basename << "_" << j+1 << "(y, x, jacobian_eval)\n";
|
output << "function [residual, g1, g2, g3, b] = " << static_basename << "_" << j+1 << "(y, x, params, jacobian_eval)\n";
|
||||||
output << " % ////////////////////////////////////////////////////////////////////////" << endl
|
output << " % ////////////////////////////////////////////////////////////////////////" << endl
|
||||||
<< " % //" << string(" Block ").substr(int(log10(j + 1))) << j + 1 << " "
|
<< " % //" << string(" Block ").substr(int(log10(j + 1))) << j + 1 << " "
|
||||||
<< BlockTriangular::BlockType0(ModelBlock->Block_List[j].Type) << " //" << endl
|
<< BlockTriangular::BlockType0(ModelBlock->Block_List[j].Type) << " //" << endl
|
||||||
|
@ -880,9 +911,9 @@ ModelTree::writeModelStaticEquationsOrdered_M(ostream &output, Model_Block *Mode
|
||||||
<< " % ////////////////////////////////////////////////////////////////////////" << endl;
|
<< " % ////////////////////////////////////////////////////////////////////////" << endl;
|
||||||
//The Temporary terms
|
//The Temporary terms
|
||||||
output << global_output.str();
|
output << global_output.str();
|
||||||
output << " if M_.param_nbr > 0\n";
|
/*output << " if M_.param_nbr > 0\n";
|
||||||
output << " params = M_.params;\n";
|
output << " params = M_.params;\n";
|
||||||
output << " end\n";
|
output << " end\n";*/
|
||||||
}
|
}
|
||||||
|
|
||||||
temporary_terms_type tt2;
|
temporary_terms_type tt2;
|
||||||
|
@ -1892,12 +1923,15 @@ ModelTree::Write_Inf_To_Bin_File(const string &dynamic_basename, const string &b
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ModelTree::writeSparseStaticMFile(const string &static_basename, const string &bin_basename, const int mode) const
|
ModelTree::writeSparseStaticMFile(const string &static_basename, const string &basename, const int mode) const
|
||||||
{
|
{
|
||||||
string filename;
|
string filename;
|
||||||
ofstream mStaticModelFile;
|
ofstream mStaticModelFile;
|
||||||
|
ostringstream tmp, tmp1, tmp_eq;
|
||||||
int i, k, prev_Simulation_Type, ga_index = 1;
|
int i, k, prev_Simulation_Type, ga_index = 1;
|
||||||
bool skip_head, open_par=false;
|
bool skip_head, open_par=false;
|
||||||
|
|
||||||
|
chdir(basename.c_str());
|
||||||
filename = static_basename + ".m";
|
filename = static_basename + ".m";
|
||||||
mStaticModelFile.open(filename.c_str(), ios::out | ios::binary);
|
mStaticModelFile.open(filename.c_str(), ios::out | ios::binary);
|
||||||
if (!mStaticModelFile.is_open())
|
if (!mStaticModelFile.is_open())
|
||||||
|
@ -1912,22 +1946,56 @@ ModelTree::writeSparseStaticMFile(const string &static_basename, const string &b
|
||||||
mStaticModelFile << "% from model file (.mod)\n\n";
|
mStaticModelFile << "% from model file (.mod)\n\n";
|
||||||
mStaticModelFile << "%/\n";
|
mStaticModelFile << "%/\n";
|
||||||
mStaticModelFile << "function [varargout] = " << static_basename << "(varargin)\n";
|
mStaticModelFile << "function [varargout] = " << static_basename << "(varargin)\n";
|
||||||
mStaticModelFile << " global oo_ options_ M_ ys0_ ;\n";
|
mStaticModelFile << " global oo_ M_ options_ ys0_ ;\n";
|
||||||
mStaticModelFile << " y_kmin=M_.maximum_lag;\n";
|
mStaticModelFile << " y_kmin=M_.maximum_lag;\n";
|
||||||
mStaticModelFile << " y_kmax=M_.maximum_lead;\n";
|
mStaticModelFile << " y_kmax=M_.maximum_lead;\n";
|
||||||
mStaticModelFile << " y_size=M_.endo_nbr;\n";
|
mStaticModelFile << " y_size=M_.endo_nbr;\n";
|
||||||
mStaticModelFile << " if(length(varargin)>0)\n";
|
mStaticModelFile << " if(length(varargin)>0)\n";
|
||||||
mStaticModelFile << " %it is a simple evaluation of the dynamic model for time _it\n";
|
mStaticModelFile << " %it is a simple evaluation of the dynamic model for time _it\n";
|
||||||
mStaticModelFile << " global it_;\n";
|
//mStaticModelFile << " global it_;\n";
|
||||||
mStaticModelFile << " y=varargin{1}(:);\n";
|
mStaticModelFile << " y=varargin{1}(:);\n";
|
||||||
mStaticModelFile << " ys=y;\n";
|
mStaticModelFile << " ys=y;\n";
|
||||||
mStaticModelFile << " g1=[];\n";
|
mStaticModelFile << " g1=[];\n";
|
||||||
mStaticModelFile << " x=varargin{2}(:);\n";
|
mStaticModelFile << " x=varargin{2}(:);\n";
|
||||||
|
mStaticModelFile << " params=varargin{3}(:);\n";
|
||||||
mStaticModelFile << " residual=zeros(1, " << symbol_table.endo_nbr << ");\n";
|
mStaticModelFile << " residual=zeros(1, " << symbol_table.endo_nbr << ");\n";
|
||||||
prev_Simulation_Type=-1;
|
prev_Simulation_Type=-1;
|
||||||
|
tmp.str("");
|
||||||
|
tmp_eq.str("");
|
||||||
for(i=0;i<block_triangular.ModelBlock->Size;i++)
|
for(i=0;i<block_triangular.ModelBlock->Size;i++)
|
||||||
{
|
{
|
||||||
mStaticModelFile << " y_index=[";
|
k=block_triangular.ModelBlock->Block_List[i].Simulation_Type;
|
||||||
|
if ((BlockTriangular::BlockSim(prev_Simulation_Type)!=BlockTriangular::BlockSim(k)) &&
|
||||||
|
((prev_Simulation_Type==EVALUATE_FORWARD || prev_Simulation_Type==EVALUATE_BACKWARD || prev_Simulation_Type==EVALUATE_FORWARD_R || prev_Simulation_Type==EVALUATE_BACKWARD_R)
|
||||||
|
|| (k==EVALUATE_FORWARD || k==EVALUATE_BACKWARD || k==EVALUATE_FORWARD_R || k==EVALUATE_BACKWARD_R)))
|
||||||
|
{
|
||||||
|
mStaticModelFile << " y_index_eq=[" << tmp_eq.str() << "];\n";
|
||||||
|
tmp_eq.str("");
|
||||||
|
mStaticModelFile << " y_index=[" << tmp.str() << "];\n";
|
||||||
|
tmp.str("");
|
||||||
|
mStaticModelFile << tmp1.str();
|
||||||
|
tmp1.str("");
|
||||||
|
}
|
||||||
|
for(int ik=0;ik<block_triangular.ModelBlock->Block_List[i].Size;ik++)
|
||||||
|
{
|
||||||
|
tmp << " " << block_triangular.ModelBlock->Block_List[i].Variable[ik]+1;
|
||||||
|
tmp_eq << " " << block_triangular.ModelBlock->Block_List[i].Equation[ik]+1;
|
||||||
|
}
|
||||||
|
if(k==EVALUATE_FORWARD || k==EVALUATE_BACKWARD || k==EVALUATE_FORWARD_R || k==EVALUATE_BACKWARD_R)
|
||||||
|
{
|
||||||
|
if(i==block_triangular.ModelBlock->Size-1)
|
||||||
|
{
|
||||||
|
mStaticModelFile << " y_index_eq=[" << tmp_eq.str() << "];\n";
|
||||||
|
tmp_eq.str("");
|
||||||
|
mStaticModelFile << " y_index=[" << tmp.str() << "];\n";
|
||||||
|
tmp.str("");
|
||||||
|
mStaticModelFile << tmp1.str();
|
||||||
|
tmp1.str("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*mStaticModelFile << " y_index=[";
|
||||||
for(int ik=0;ik<block_triangular.ModelBlock->Block_List[i].Size;ik++)
|
for(int ik=0;ik<block_triangular.ModelBlock->Block_List[i].Size;ik++)
|
||||||
{
|
{
|
||||||
mStaticModelFile << " " << block_triangular.ModelBlock->Block_List[i].Variable[ik]+1;
|
mStaticModelFile << " " << block_triangular.ModelBlock->Block_List[i].Variable[ik]+1;
|
||||||
|
@ -1939,12 +2007,14 @@ ModelTree::writeSparseStaticMFile(const string &static_basename, const string &b
|
||||||
mStaticModelFile << " " << block_triangular.ModelBlock->Block_List[i].Equation[ik]+1;
|
mStaticModelFile << " " << block_triangular.ModelBlock->Block_List[i].Equation[ik]+1;
|
||||||
}
|
}
|
||||||
mStaticModelFile << " ];\n";
|
mStaticModelFile << " ];\n";
|
||||||
k=block_triangular.ModelBlock->Block_List[i].Simulation_Type;
|
k=block_triangular.ModelBlock->Block_List[i].Simulation_Type;*/
|
||||||
|
|
||||||
if (BlockTriangular::BlockSim(prev_Simulation_Type)==BlockTriangular::BlockSim(k) &&
|
if (BlockTriangular::BlockSim(prev_Simulation_Type)==BlockTriangular::BlockSim(k) &&
|
||||||
(k==EVALUATE_FORWARD || k==EVALUATE_BACKWARD || k==EVALUATE_FORWARD_R || k==EVALUATE_BACKWARD_R))
|
(k==EVALUATE_FORWARD || k==EVALUATE_BACKWARD || k==EVALUATE_FORWARD_R || k==EVALUATE_BACKWARD_R))
|
||||||
skip_head=true;
|
skip_head=true;
|
||||||
else
|
else
|
||||||
skip_head=false;
|
skip_head=false;
|
||||||
|
|
||||||
switch(k)
|
switch(k)
|
||||||
{
|
{
|
||||||
case EVALUATE_FORWARD:
|
case EVALUATE_FORWARD:
|
||||||
|
@ -1954,19 +2024,28 @@ ModelTree::writeSparseStaticMFile(const string &static_basename, const string &b
|
||||||
if(!skip_head)
|
if(!skip_head)
|
||||||
{
|
{
|
||||||
ga_index = 1;
|
ga_index = 1;
|
||||||
mStaticModelFile << " [y, ga]=" << static_basename << "_" << i + 1 << "(y, x, 1);\n";
|
tmp1 << " [y, ga]=" << static_basename << "_" << i + 1 << "(y, x, params, 1);\n";
|
||||||
|
tmp1 << " residual(y_index)=ys(y_index)-y(y_index);\n";
|
||||||
|
tmp1 << " g1(y_index_eq, y_index) = ga;\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ga_index++;
|
ga_index++;
|
||||||
mStaticModelFile << " residual(y_index)=ys(y_index)-y(y_index);\n";
|
/*mStaticModelFile << " residual(y_index)=ys(y_index)-y(y_index);\n";
|
||||||
mStaticModelFile << " g1(y_index_eq, y_index) = ga(" << ga_index << ", " << ga_index << ");\n";
|
mStaticModelFile << " g1(y_index_eq, y_index) = ga(" << ga_index << ", " << ga_index << ");\n";*/
|
||||||
break;
|
break;
|
||||||
case SOLVE_FORWARD_COMPLETE:
|
case SOLVE_FORWARD_COMPLETE:
|
||||||
case SOLVE_BACKWARD_COMPLETE:
|
case SOLVE_BACKWARD_COMPLETE:
|
||||||
case SOLVE_FORWARD_SIMPLE:
|
case SOLVE_FORWARD_SIMPLE:
|
||||||
case SOLVE_BACKWARD_SIMPLE:
|
case SOLVE_BACKWARD_SIMPLE:
|
||||||
case SOLVE_TWO_BOUNDARIES_COMPLETE:
|
case SOLVE_TWO_BOUNDARIES_COMPLETE:
|
||||||
mStaticModelFile << " [r, g1(y_index_eq, y_index)]=" << static_basename << "_" << i + 1 << "(y, x, 1);\n";
|
mStaticModelFile << " y_index_eq = [" << tmp_eq.str() << "];\n";
|
||||||
|
mStaticModelFile << " y_index = [";
|
||||||
|
mStaticModelFile << tmp.str();
|
||||||
|
mStaticModelFile << " ];\n";
|
||||||
|
tmp.str("");
|
||||||
|
tmp_eq.str("");
|
||||||
|
mStaticModelFile << " [r, ga]=" << static_basename << "_" << i + 1 << "(y, x, params, 1);\n";
|
||||||
|
mStaticModelFile << " g1(y_index_eq, y_index) = ga;\n";
|
||||||
mStaticModelFile << " residual(y_index)=r;\n";
|
mStaticModelFile << " residual(y_index)=r;\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1982,8 +2061,10 @@ ModelTree::writeSparseStaticMFile(const string &static_basename, const string &b
|
||||||
mStaticModelFile << " solve_tolf=options_.solve_tolf;\n";
|
mStaticModelFile << " solve_tolf=options_.solve_tolf;\n";
|
||||||
mStaticModelFile << " y=oo_.steady_state;\n";
|
mStaticModelFile << " y=oo_.steady_state;\n";
|
||||||
mStaticModelFile << " x=oo_.exo_steady_state;\n";
|
mStaticModelFile << " x=oo_.exo_steady_state;\n";
|
||||||
|
mStaticModelFile << " params=M_.params;\n";
|
||||||
mStaticModelFile << " varargout{2}=1;\n";
|
mStaticModelFile << " varargout{2}=1;\n";
|
||||||
prev_Simulation_Type=-1;
|
prev_Simulation_Type=-1;
|
||||||
|
int Blck_Num = 0;
|
||||||
for(i = 0;i < block_triangular.ModelBlock->Size;i++)
|
for(i = 0;i < block_triangular.ModelBlock->Size;i++)
|
||||||
{
|
{
|
||||||
k = block_triangular.ModelBlock->Block_List[i].Simulation_Type;
|
k = block_triangular.ModelBlock->Block_List[i].Simulation_Type;
|
||||||
|
@ -1991,7 +2072,10 @@ ModelTree::writeSparseStaticMFile(const string &static_basename, const string &b
|
||||||
(k==EVALUATE_FORWARD || k==EVALUATE_BACKWARD || k==EVALUATE_FORWARD_R || k==EVALUATE_BACKWARD_R))
|
(k==EVALUATE_FORWARD || k==EVALUATE_BACKWARD || k==EVALUATE_FORWARD_R || k==EVALUATE_BACKWARD_R))
|
||||||
skip_head=true;
|
skip_head=true;
|
||||||
else
|
else
|
||||||
|
{
|
||||||
skip_head=false;
|
skip_head=false;
|
||||||
|
Blck_Num++;
|
||||||
|
}
|
||||||
if ((k == EVALUATE_FORWARD || k == EVALUATE_FORWARD_R || k == EVALUATE_BACKWARD || k == EVALUATE_BACKWARD_R) && (block_triangular.ModelBlock->Block_List[i].Size))
|
if ((k == EVALUATE_FORWARD || k == EVALUATE_FORWARD_R || k == EVALUATE_BACKWARD || k == EVALUATE_BACKWARD_R) && (block_triangular.ModelBlock->Block_List[i].Size))
|
||||||
{
|
{
|
||||||
if (!skip_head)
|
if (!skip_head)
|
||||||
|
@ -2000,11 +2084,11 @@ ModelTree::writeSparseStaticMFile(const string &static_basename, const string &b
|
||||||
{
|
{
|
||||||
mStaticModelFile << " end\n";
|
mStaticModelFile << " end\n";
|
||||||
}
|
}
|
||||||
mStaticModelFile << " y=" << static_basename << "_" << i + 1 << "(y, x, 0);\n";
|
mStaticModelFile << " y=" << static_basename << "_" << i + 1 << "(y, x, params, 0);\n";
|
||||||
}
|
}
|
||||||
open_par=false;
|
open_par=false;
|
||||||
}
|
}
|
||||||
else if ((k == SOLVE_FORWARD_SIMPLE || k == SOLVE_BACKWARD_SIMPLE) && (block_triangular.ModelBlock->Block_List[i].Size))
|
/*else if ((k == SOLVE_FORWARD_SIMPLE || k == SOLVE_BACKWARD_SIMPLE) && (block_triangular.ModelBlock->Block_List[i].Size))
|
||||||
{
|
{
|
||||||
if (open_par)
|
if (open_par)
|
||||||
{
|
{
|
||||||
|
@ -2029,8 +2113,8 @@ ModelTree::writeSparseStaticMFile(const string &static_basename, const string &b
|
||||||
mStaticModelFile << " end;\n";
|
mStaticModelFile << " end;\n";
|
||||||
mStaticModelFile << " return;\n";
|
mStaticModelFile << " return;\n";
|
||||||
mStaticModelFile << " end\n";
|
mStaticModelFile << " end\n";
|
||||||
}
|
}*/
|
||||||
else if ((k == SOLVE_FORWARD_COMPLETE || k == SOLVE_BACKWARD_COMPLETE || k == SOLVE_TWO_BOUNDARIES_COMPLETE) && (block_triangular.ModelBlock->Block_List[i].Size))
|
else if ((k == SOLVE_FORWARD_SIMPLE || k == SOLVE_BACKWARD_SIMPLE) || (k == SOLVE_FORWARD_COMPLETE || k == SOLVE_BACKWARD_COMPLETE || k == SOLVE_TWO_BOUNDARIES_COMPLETE) && (block_triangular.ModelBlock->Block_List[i].Size))
|
||||||
{
|
{
|
||||||
if (open_par)
|
if (open_par)
|
||||||
{
|
{
|
||||||
|
@ -2043,8 +2127,24 @@ ModelTree::writeSparseStaticMFile(const string &static_basename, const string &b
|
||||||
mStaticModelFile << " " << block_triangular.ModelBlock->Block_List[i].Variable[ik]+1;
|
mStaticModelFile << " " << block_triangular.ModelBlock->Block_List[i].Variable[ik]+1;
|
||||||
}
|
}
|
||||||
mStaticModelFile << " ];\n";
|
mStaticModelFile << " ];\n";
|
||||||
|
|
||||||
|
|
||||||
mStaticModelFile << " g1=0;g2=0;g3=0;\n";
|
mStaticModelFile << " g1=0;g2=0;g3=0;\n";
|
||||||
mStaticModelFile << " r=0;\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++)
|
||||||
|
nze+=block_triangular.ModelBlock->Block_List[i].IM_lead_lag[m].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 <<
|
||||||
|
", y_kmin, " << 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 << " r=0;\n";
|
||||||
mStaticModelFile << " cvg=0;\n";
|
mStaticModelFile << " cvg=0;\n";
|
||||||
mStaticModelFile << " iter=0;\n";
|
mStaticModelFile << " iter=0;\n";
|
||||||
mStaticModelFile << " lambda=1;\n";
|
mStaticModelFile << " lambda=1;\n";
|
||||||
|
@ -2073,7 +2173,7 @@ ModelTree::writeSparseStaticMFile(const string &static_basename, const string &b
|
||||||
mStaticModelFile << " return;\n";
|
mStaticModelFile << " return;\n";
|
||||||
mStaticModelFile << " else\n";
|
mStaticModelFile << " else\n";
|
||||||
mStaticModelFile << " fprintf('convergence achieved after %d iterations\\n',iter);\n";
|
mStaticModelFile << " fprintf('convergence achieved after %d iterations\\n',iter);\n";
|
||||||
mStaticModelFile << " end\n";
|
mStaticModelFile << " end\n";*/
|
||||||
}
|
}
|
||||||
prev_Simulation_Type=k;
|
prev_Simulation_Type=k;
|
||||||
}
|
}
|
||||||
|
@ -2088,8 +2188,9 @@ ModelTree::writeSparseStaticMFile(const string &static_basename, const string &b
|
||||||
mStaticModelFile << " varargout{2}=0;\n";
|
mStaticModelFile << " varargout{2}=0;\n";
|
||||||
mStaticModelFile << " varargout{1}=oo_.steady_state;\n";
|
mStaticModelFile << " varargout{1}=oo_.steady_state;\n";
|
||||||
mStaticModelFile << "return;\n";
|
mStaticModelFile << "return;\n";
|
||||||
writeModelStaticEquationsOrdered_M(mStaticModelFile, block_triangular.ModelBlock, static_basename);
|
writeModelStaticEquationsOrdered_M(block_triangular.ModelBlock, static_basename);
|
||||||
mStaticModelFile.close();
|
mStaticModelFile.close();
|
||||||
|
chdir("..");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -2155,7 +2256,8 @@ ModelTree::writeSparseDynamicMFile(const string &dynamic_basename, const string
|
||||||
mDynamicModelFile << " y_size=M_.endo_nbr;\n";
|
mDynamicModelFile << " y_size=M_.endo_nbr;\n";
|
||||||
mDynamicModelFile << " if(length(varargin)>0)\n";
|
mDynamicModelFile << " if(length(varargin)>0)\n";
|
||||||
mDynamicModelFile << " %it is a simple evaluation of the dynamic model for time _it\n";
|
mDynamicModelFile << " %it is a simple evaluation of the dynamic model for time _it\n";
|
||||||
mDynamicModelFile << " it_=varargin{3};\n";
|
mDynamicModelFile << " params=varargin{3};\n";
|
||||||
|
mDynamicModelFile << " it_=varargin{4};\n";
|
||||||
i = symbol_table.endo_nbr*(variable_table.max_endo_lag+variable_table.max_endo_lead+1)+
|
i = symbol_table.endo_nbr*(variable_table.max_endo_lag+variable_table.max_endo_lead+1)+
|
||||||
symbol_table.exo_nbr*(variable_table.max_exo_lag+variable_table.max_exo_lead+1);
|
symbol_table.exo_nbr*(variable_table.max_exo_lag+variable_table.max_exo_lead+1);
|
||||||
mDynamicModelFile << " g1=spalloc(" << symbol_table.endo_nbr << ", " << i << ", " << i*symbol_table.endo_nbr << ");\n";
|
mDynamicModelFile << " g1=spalloc(" << symbol_table.endo_nbr << ", " << i << ", " << i*symbol_table.endo_nbr << ");\n";
|
||||||
|
@ -2211,14 +2313,14 @@ ModelTree::writeSparseDynamicMFile(const string &dynamic_basename, const string
|
||||||
case EVALUATE_BACKWARD_R:
|
case EVALUATE_BACKWARD_R:
|
||||||
if(!skip_head)
|
if(!skip_head)
|
||||||
{
|
{
|
||||||
tmp1 << " [y, g1, g2, g3]=" << dynamic_basename << "_" << i + 1 << "(y, x, it_, 1, g1, g2, g3);\n";
|
tmp1 << " [y, g1, g2, g3]=" << dynamic_basename << "_" << i + 1 << "(y, x, params, 1, g1, g2, g3, it_-1, 1);\n";
|
||||||
tmp1 << " residual(y_index_eq)=ys(y_index)-y(it_, y_index);\n";
|
tmp1 << " residual(y_index_eq)=ys(y_index)-y(it_, y_index);\n";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SOLVE_FORWARD_SIMPLE:
|
case SOLVE_FORWARD_SIMPLE:
|
||||||
case SOLVE_BACKWARD_SIMPLE:
|
case SOLVE_BACKWARD_SIMPLE:
|
||||||
mDynamicModelFile << " y_index_eq = " << block_triangular.ModelBlock->Block_List[i].Equation[0]+1 << ";\n";
|
mDynamicModelFile << " y_index_eq = " << block_triangular.ModelBlock->Block_List[i].Equation[0]+1 << ";\n";
|
||||||
mDynamicModelFile << " [r, g1, g2, g3]=" << dynamic_basename << "_" << i + 1 << "(y, x, it_, 1, g1, g2, g3);\n";
|
mDynamicModelFile << " [r, g1, g2, g3]=" << dynamic_basename << "_" << i + 1 << "(y, x, params, it_, 1, g1, g2, g3);\n";
|
||||||
mDynamicModelFile << " residual(y_index_eq)=r;\n";
|
mDynamicModelFile << " residual(y_index_eq)=r;\n";
|
||||||
tmp_eq.str("");
|
tmp_eq.str("");
|
||||||
tmp.str("");
|
tmp.str("");
|
||||||
|
@ -2226,7 +2328,7 @@ ModelTree::writeSparseDynamicMFile(const string &dynamic_basename, const string
|
||||||
case SOLVE_FORWARD_COMPLETE:
|
case SOLVE_FORWARD_COMPLETE:
|
||||||
case SOLVE_BACKWARD_COMPLETE:
|
case SOLVE_BACKWARD_COMPLETE:
|
||||||
mDynamicModelFile << " y_index_eq = [" << tmp_eq.str() << "];\n";
|
mDynamicModelFile << " y_index_eq = [" << tmp_eq.str() << "];\n";
|
||||||
mDynamicModelFile << " [r, g1, g2, g3, b]=" << dynamic_basename << "_" << i + 1 << "(y, x, it_, 1, g1, g2, g3);\n";
|
mDynamicModelFile << " [r, g1, g2, g3, b]=" << dynamic_basename << "_" << i + 1 << "(y, x, params, it_, 1, g1, g2, g3);\n";
|
||||||
mDynamicModelFile << " residual(y_index_eq)=r;\n";
|
mDynamicModelFile << " residual(y_index_eq)=r;\n";
|
||||||
break;
|
break;
|
||||||
case SOLVE_TWO_BOUNDARIES_COMPLETE:
|
case SOLVE_TWO_BOUNDARIES_COMPLETE:
|
||||||
|
@ -2253,7 +2355,7 @@ ModelTree::writeSparseDynamicMFile(const string &dynamic_basename, const string
|
||||||
mDynamicModelFile << " ga=spalloc(" << block_triangular.ModelBlock->Block_List[i].Size << ", " << j << ", " <<
|
mDynamicModelFile << " ga=spalloc(" << block_triangular.ModelBlock->Block_List[i].Size << ", " << j << ", " <<
|
||||||
block_triangular.ModelBlock->Block_List[i].Size*j << ");\n";
|
block_triangular.ModelBlock->Block_List[i].Size*j << ");\n";
|
||||||
tmp_i=block_triangular.ModelBlock->Block_List[i].Max_Lag_Endo+block_triangular.ModelBlock->Block_List[i].Max_Lead_Endo+1;
|
tmp_i=block_triangular.ModelBlock->Block_List[i].Max_Lag_Endo+block_triangular.ModelBlock->Block_List[i].Max_Lead_Endo+1;
|
||||||
mDynamicModelFile << " [r, ga, g2, g3, b]=" << dynamic_basename << "_" << i + 1 << "(y, x, it_-" << variable_table.max_lag << ", 1, ga, g2, g3, " << variable_table.max_lag << ", " << block_triangular.ModelBlock->Block_List[i].Size << ");\n";
|
mDynamicModelFile << " [r, ga, g2, g3, b]=" << dynamic_basename << "_" << i + 1 << "(y, x, params, it_-" << variable_table.max_lag << ", 1, ga, g2, g3, " << variable_table.max_lag << ", " << block_triangular.ModelBlock->Block_List[i].Size << ");\n";
|
||||||
if(block_triangular.ModelBlock->Block_List[i].Max_Lag==variable_table.max_lag && block_triangular.ModelBlock->Block_List[i].Max_Lead==variable_table.max_lead)
|
if(block_triangular.ModelBlock->Block_List[i].Max_Lag==variable_table.max_lag && block_triangular.ModelBlock->Block_List[i].Max_Lead==variable_table.max_lead)
|
||||||
mDynamicModelFile << " g1(y_index_eq,y_index) = ga;\n";
|
mDynamicModelFile << " g1(y_index_eq,y_index) = ga;\n";
|
||||||
else
|
else
|
||||||
|
@ -2292,6 +2394,7 @@ ModelTree::writeSparseDynamicMFile(const string &dynamic_basename, const string
|
||||||
mDynamicModelFile << " x=oo_.exo_simul;\n";
|
mDynamicModelFile << " x=oo_.exo_simul;\n";
|
||||||
}
|
}
|
||||||
prev_Simulation_Type=-1;
|
prev_Simulation_Type=-1;
|
||||||
|
mDynamicModelFile << " params=M_.params;\n";
|
||||||
mDynamicModelFile << " oo_.deterministic_simulation.status = 0;\n";
|
mDynamicModelFile << " oo_.deterministic_simulation.status = 0;\n";
|
||||||
for(i = 0;i < block_triangular.ModelBlock->Size;i++)
|
for(i = 0;i < block_triangular.ModelBlock->Size;i++)
|
||||||
{
|
{
|
||||||
|
@ -2317,14 +2420,14 @@ ModelTree::writeSparseDynamicMFile(const string &dynamic_basename, const string
|
||||||
mDynamicModelFile << " else\n";
|
mDynamicModelFile << " else\n";
|
||||||
mDynamicModelFile << " blck_num = 1;\n";
|
mDynamicModelFile << " blck_num = 1;\n";
|
||||||
mDynamicModelFile << " end;\n";
|
mDynamicModelFile << " end;\n";
|
||||||
mDynamicModelFile << " oo_.deterministic_simulation.block(blck_num).status = 1;% Convergency failed.\n";
|
mDynamicModelFile << " oo_.deterministic_simulation.block(blck_num).status = 1;\n";
|
||||||
mDynamicModelFile << " oo_.deterministic_simulation.block(blck_num).error = 0;\n";
|
mDynamicModelFile << " oo_.deterministic_simulation.block(blck_num).error = 0;\n";
|
||||||
mDynamicModelFile << " oo_.deterministic_simulation.block(blck_num).iterations = 0;\n";
|
mDynamicModelFile << " oo_.deterministic_simulation.block(blck_num).iterations = 0;\n";
|
||||||
mDynamicModelFile << " g1=[];g2=[];g3=[];\n";
|
mDynamicModelFile << " g1=[];g2=[];g3=[];\n";
|
||||||
mDynamicModelFile << " for it_ = y_kmin+1:(periods+y_kmin)\n";
|
//mDynamicModelFile << " for it_ = y_kmin+1:(periods+y_kmin)\n";
|
||||||
mDynamicModelFile << " y=" << dynamic_basename << "_" << i + 1 << "(y, x, it_, 0, g1, g2, g3);\n";
|
mDynamicModelFile << " y=" << dynamic_basename << "_" << i + 1 << "(y, x, params, 0, g1, g2, g3, y_kmin, periods);\n";
|
||||||
}
|
}
|
||||||
open_par=true;
|
//open_par=true;
|
||||||
}
|
}
|
||||||
else if ((k == EVALUATE_BACKWARD || k == EVALUATE_BACKWARD_R) && (block_triangular.ModelBlock->Block_List[i].Size))
|
else if ((k == EVALUATE_BACKWARD || k == EVALUATE_BACKWARD_R) && (block_triangular.ModelBlock->Block_List[i].Size))
|
||||||
{
|
{
|
||||||
|
@ -2342,14 +2445,14 @@ ModelTree::writeSparseDynamicMFile(const string &dynamic_basename, const string
|
||||||
mDynamicModelFile << " else\n";
|
mDynamicModelFile << " else\n";
|
||||||
mDynamicModelFile << " blck_num = 1;\n";
|
mDynamicModelFile << " blck_num = 1;\n";
|
||||||
mDynamicModelFile << " end;\n";
|
mDynamicModelFile << " end;\n";
|
||||||
mDynamicModelFile << " oo_.deterministic_simulation.block(blck_num).status = 1;% Convergency failed.\n";
|
mDynamicModelFile << " oo_.deterministic_simulation.block(blck_num).status = 1;\n";
|
||||||
mDynamicModelFile << " oo_.deterministic_simulation.block(blck_num).error = 0;\n";
|
mDynamicModelFile << " oo_.deterministic_simulation.block(blck_num).error = 0;\n";
|
||||||
mDynamicModelFile << " oo_.deterministic_simulation.block(blck_num).iterations = 0;\n";
|
mDynamicModelFile << " oo_.deterministic_simulation.block(blck_num).iterations = 0;\n";
|
||||||
mDynamicModelFile << " g1=[];g2=[];g3=[];\n";
|
mDynamicModelFile << " g1=[];g2=[];g3=[];\n";
|
||||||
mDynamicModelFile << " for it_ = y_kmin+1:(periods+y_kmin)\n";
|
//mDynamicModelFile << " for it_ = y_kmin+1:(periods+y_kmin)\n";
|
||||||
mDynamicModelFile << " " << dynamic_basename << "_" << i + 1 << "(y, x, it_, 0, g1, g2, g3);\n";
|
mDynamicModelFile << " " << dynamic_basename << "_" << i + 1 << "(y, x, params, 0, g1, g2, g3, y_kmin, periods);\n";
|
||||||
}
|
}
|
||||||
open_par=true;
|
//open_par=true;
|
||||||
}
|
}
|
||||||
else if ((k == SOLVE_FORWARD_COMPLETE || k == SOLVE_FORWARD_SIMPLE) && (block_triangular.ModelBlock->Block_List[i].Size))
|
else if ((k == SOLVE_FORWARD_COMPLETE || k == SOLVE_FORWARD_SIMPLE) && (block_triangular.ModelBlock->Block_List[i].Size))
|
||||||
{
|
{
|
||||||
|
@ -2373,9 +2476,9 @@ ModelTree::writeSparseDynamicMFile(const string &dynamic_basename, const string
|
||||||
mDynamicModelFile << " blck_num = 1;\n";
|
mDynamicModelFile << " blck_num = 1;\n";
|
||||||
mDynamicModelFile << " end;\n";
|
mDynamicModelFile << " end;\n";
|
||||||
mDynamicModelFile << " y = solve_one_boundary('" << dynamic_basename << "_" << i + 1 << "'" <<
|
mDynamicModelFile << " y = solve_one_boundary('" << dynamic_basename << "_" << i + 1 << "'" <<
|
||||||
", y, x, y_index_eq, " << nze <<
|
", y, x, params, y_index_eq, " << nze <<
|
||||||
", options_.periods, " << block_triangular.ModelBlock->Block_List[i].is_linear <<
|
", 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);\n";
|
", blck_num, y_kmin, options_.maxit_, options_.solve_tolf, options_.slowc, options_.cutoff, options_.simulation_method, 1, 1, 0);\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
else if ((k == SOLVE_BACKWARD_COMPLETE || k == SOLVE_BACKWARD_SIMPLE) && (block_triangular.ModelBlock->Block_List[i].Size))
|
else if ((k == SOLVE_BACKWARD_COMPLETE || k == SOLVE_BACKWARD_SIMPLE) && (block_triangular.ModelBlock->Block_List[i].Size))
|
||||||
|
@ -2400,9 +2503,9 @@ ModelTree::writeSparseDynamicMFile(const string &dynamic_basename, const string
|
||||||
mDynamicModelFile << " blck_num = 1;\n";
|
mDynamicModelFile << " blck_num = 1;\n";
|
||||||
mDynamicModelFile << " end;\n";
|
mDynamicModelFile << " end;\n";
|
||||||
mDynamicModelFile << " y = solve_one_boundary('" << dynamic_basename << "_" << i + 1 << "'" <<
|
mDynamicModelFile << " y = solve_one_boundary('" << dynamic_basename << "_" << i + 1 << "'" <<
|
||||||
", y, x, y_index_eq, " << nze <<
|
", y, x, params, y_index_eq, " << nze <<
|
||||||
", options_.periods, " << block_triangular.ModelBlock->Block_List[i].is_linear <<
|
", 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, 0);\n";
|
", blck_num, y_kmin, options_.maxit_, options_.solve_tolf, options_.slowc, options_.cutoff, options_.simulation_method, 1, 1, 0);\n";
|
||||||
}
|
}
|
||||||
else if ((k == SOLVE_TWO_BOUNDARIES_COMPLETE || k == SOLVE_TWO_BOUNDARIES_SIMPLE) && (block_triangular.ModelBlock->Block_List[i].Size))
|
else if ((k == SOLVE_TWO_BOUNDARIES_COMPLETE || k == SOLVE_TWO_BOUNDARIES_SIMPLE) && (block_triangular.ModelBlock->Block_List[i].Size))
|
||||||
{
|
{
|
||||||
|
@ -2429,7 +2532,7 @@ ModelTree::writeSparseDynamicMFile(const string &dynamic_basename, const string
|
||||||
mDynamicModelFile << " blck_num = 1;\n";
|
mDynamicModelFile << " blck_num = 1;\n";
|
||||||
mDynamicModelFile << " end;\n";
|
mDynamicModelFile << " end;\n";
|
||||||
mDynamicModelFile << " y = solve_two_boundaries('" << dynamic_basename << "_" << i + 1 << "'" <<
|
mDynamicModelFile << " y = solve_two_boundaries('" << dynamic_basename << "_" << i + 1 << "'" <<
|
||||||
", y, x, y_index, " << nze <<
|
", y, x, params, y_index, " << nze <<
|
||||||
", options_.periods, " << block_triangular.ModelBlock->Block_List[i].Max_Lag <<
|
", options_.periods, " << block_triangular.ModelBlock->Block_List[i].Max_Lag <<
|
||||||
", " << block_triangular.ModelBlock->Block_List[i].Max_Lead <<
|
", " << block_triangular.ModelBlock->Block_List[i].Max_Lead <<
|
||||||
", " << block_triangular.ModelBlock->Block_List[i].is_linear <<
|
", " << block_triangular.ModelBlock->Block_List[i].is_linear <<
|
||||||
|
@ -3122,6 +3225,13 @@ ModelTree::writeStaticFile(const string &basename) const
|
||||||
writeStaticMFile(basename + "_static");
|
writeStaticMFile(basename + "_static");
|
||||||
break;
|
break;
|
||||||
case eSparseMode:
|
case eSparseMode:
|
||||||
|
// create a directory to store all files
|
||||||
|
#ifdef _WIN32
|
||||||
|
mkdir(basename.c_str());
|
||||||
|
#else
|
||||||
|
mkdir(basename.c_str(), 0777);
|
||||||
|
#endif
|
||||||
|
|
||||||
writeSparseStaticMFile(basename + "_static", basename, mode);
|
writeSparseStaticMFile(basename + "_static", basename, mode);
|
||||||
break;
|
break;
|
||||||
case eDLLMode:
|
case eDLLMode:
|
||||||
|
@ -3139,12 +3249,6 @@ ModelTree::writeDynamicFile(const string &basename) const
|
||||||
writeDynamicMFile(basename + "_dynamic");
|
writeDynamicMFile(basename + "_dynamic");
|
||||||
break;
|
break;
|
||||||
case eSparseMode:
|
case eSparseMode:
|
||||||
// create a directory to store all the files
|
|
||||||
#ifdef _WIN32
|
|
||||||
mkdir(basename.c_str());
|
|
||||||
#else
|
|
||||||
mkdir(basename.c_str(), 0777);
|
|
||||||
#endif
|
|
||||||
writeSparseDynamicMFile(basename + "_dynamic", basename, mode);
|
writeSparseDynamicMFile(basename + "_dynamic", basename, mode);
|
||||||
block_triangular.Free_Block(block_triangular.ModelBlock);
|
block_triangular.Free_Block(block_triangular.ModelBlock);
|
||||||
block_triangular.incidencematrix.Free_IM();
|
block_triangular.incidencematrix.Free_IM();
|
||||||
|
|
|
@ -107,7 +107,7 @@ private:
|
||||||
//! Writes the Block reordred structure of the model in M output
|
//! Writes the Block reordred structure of the model in M output
|
||||||
void writeModelEquationsOrdered_M(Model_Block *ModelBlock, const string &dynamic_basename) const;
|
void writeModelEquationsOrdered_M(Model_Block *ModelBlock, const string &dynamic_basename) const;
|
||||||
//! Writes the Block reordred structure of the static model in M output
|
//! Writes the Block reordred structure of the static model in M output
|
||||||
void writeModelStaticEquationsOrdered_M(ostream &output, Model_Block *ModelBlock, const string &static_basename) const;
|
void writeModelStaticEquationsOrdered_M(Model_Block *ModelBlock, const string &static_basename) const;
|
||||||
//! Writes the code of the Block reordred structure of the model in virtual machine bytecode
|
//! Writes the code of the Block reordred structure of the model in virtual machine bytecode
|
||||||
void writeModelEquationsCodeOrdered(const string file_name, const Model_Block *ModelBlock, const string bin_basename, ExprNodeOutputType output_type) const;
|
void writeModelEquationsCodeOrdered(const string file_name, const Model_Block *ModelBlock, const string bin_basename, ExprNodeOutputType output_type) const;
|
||||||
//! Writes static model file (Matlab version)
|
//! Writes static model file (Matlab version)
|
||||||
|
@ -115,7 +115,7 @@ private:
|
||||||
//! Writes static model file (C version)
|
//! Writes static model file (C version)
|
||||||
void writeStaticCFile(const string &static_basename) const;
|
void writeStaticCFile(const string &static_basename) const;
|
||||||
//! Writes static model file when Sparse option is on (Matlab version)
|
//! Writes static model file when Sparse option is on (Matlab version)
|
||||||
void writeSparseStaticMFile(const string &static_basename, const string &bin_basename, const int mode) const;
|
void writeSparseStaticMFile(const string &static_basename, const string &basename, const int mode) const;
|
||||||
//! Writes dynamic model file (Matlab version)
|
//! Writes dynamic model file (Matlab version)
|
||||||
void writeDynamicMFile(const string &dynamic_basename) const;
|
void writeDynamicMFile(const string &dynamic_basename) const;
|
||||||
//! Writes dynamic model file (C version)
|
//! Writes dynamic model file (C version)
|
||||||
|
|
Loading…
Reference in New Issue