Skip to content
Snippets Groups Projects
Verified Commit 2c6807a6 authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Block decomposition: no longer use global variables for temporary terms in the static M-file

Rather use a single vector as in non-block mode.
parent caea047c
No related branches found
No related tags found
No related merge requests found
function [r, g1] = block_mfs_steadystate(y, b, y_all, exo, params, M) function [r, g1] = block_mfs_steadystate(y, b, y_all, exo, params, T, M)
% Wrapper around the *_static.m file, for use with dynare_solve, % Wrapper around the *_static.m file, for use with dynare_solve,
% when block_mfs option is given to steady. % when block_mfs option is given to steady.
% Copyright (C) 2009-2012 Dynare Team % Copyright (C) 2009-2020 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -21,5 +21,5 @@ function [r, g1] = block_mfs_steadystate(y, b, y_all, exo, params, M) ...@@ -21,5 +21,5 @@ function [r, g1] = block_mfs_steadystate(y, b, y_all, exo, params, M)
y_all(M.block_structure_stat.block(b).variable) = y; y_all(M.block_structure_stat.block(b).variable) = y;
eval(['[r,g1] = ' M.fname '.static(b, y_all, exo, params);']); eval(['[r,g1] = ' M.fname '.static(b, y_all, exo, params, T);']);
g1 = full(g1); g1 = full(g1);
...@@ -19,6 +19,7 @@ function [x,info] = dynare_solve_block_or_bytecode(y, exo, params, options, M) ...@@ -19,6 +19,7 @@ function [x,info] = dynare_solve_block_or_bytecode(y, exo, params, options, M)
info = 0; info = 0;
x = y; x = y;
if options.block && ~options.bytecode if options.block && ~options.bytecode
T = NaN(M.block_structure_stat.tmp_nbr, 1);
for b = 1:length(M.block_structure_stat.block) for b = 1:length(M.block_structure_stat.block)
ss = x; ss = x;
if M.block_structure_stat.block(b).Simulation_Type ~= 1 && ... if M.block_structure_stat.block(b).Simulation_Type ~= 1 && ...
...@@ -26,7 +27,7 @@ if options.block && ~options.bytecode ...@@ -26,7 +27,7 @@ if options.block && ~options.bytecode
if options.solve_algo <= 4 || options.solve_algo >= 9 if options.solve_algo <= 4 || options.solve_algo >= 9
[y, check] = dynare_solve('block_mfs_steadystate', ... [y, check] = dynare_solve('block_mfs_steadystate', ...
ss(M.block_structure_stat.block(b).variable), ... ss(M.block_structure_stat.block(b).variable), ...
options, b, ss, exo, params, M); options, b, ss, exo, params, T, M);
if check ~= 0 if check ~= 0
% error(['STEADY: convergence % error(['STEADY: convergence
% problems in block ' int2str(b)]) % problems in block ' int2str(b)])
...@@ -37,7 +38,7 @@ if options.block && ~options.bytecode ...@@ -37,7 +38,7 @@ if options.block && ~options.bytecode
else else
n = length(M.block_structure_stat.block(b).variable); n = length(M.block_structure_stat.block(b).variable);
[ss, check] = solve_one_boundary([M.fname '.block.static_' int2str(b)], ss, exo, ... [ss, check] = solve_one_boundary([M.fname '.block.static_' int2str(b)], ss, exo, ...
params, [], M.block_structure_stat.block(b).variable, n, 1, false, b, 0, options.simul.maxit, ... params, [], T, M.block_structure_stat.block(b).variable, n, 1, false, b, 0, options.simul.maxit, ...
options.solve_tolf, ... options.solve_tolf, ...
options.slowc, 0, options.solve_algo, true, false, false, M, options); options.slowc, 0, options.solve_algo, true, false, false, M, options);
if check if check
...@@ -46,8 +47,8 @@ if options.block && ~options.bytecode ...@@ -46,8 +47,8 @@ if options.block && ~options.bytecode
end end
end end
end end
[r, g1, x] = feval([M.fname '.static'], b, ss, ... % The following updates the temporary terms vector
exo, params); [r, g1, x, ~, T] = feval([M.fname '.static'], b, ss, exo, params, T);
end end
elseif options.bytecode elseif options.bytecode
if options.solve_algo > 4 if options.solve_algo > 4
......
...@@ -69,12 +69,13 @@ end ...@@ -69,12 +69,13 @@ end
% Compute the residuals % Compute the residuals
if options_.block && ~options_.bytecode if options_.block && ~options_.bytecode
z = zeros(M_.endo_nbr,1); z = zeros(M_.endo_nbr,1);
T = NaN(M_.block_structure_stat.tmp_nbr, 1);
for i = 1:length(M_.block_structure_stat.block) for i = 1:length(M_.block_structure_stat.block)
[r, g, yy, var_indx] = feval([M_.fname '.static'],... [r, g, yy, var_indx, T] = feval([M_.fname '.static'],...
i,... i,...
oo_.steady_state,... oo_.steady_state,...
[oo_.exo_steady_state; ... [oo_.exo_steady_state; ...
oo_.exo_det_steady_state], M_.params); oo_.exo_det_steady_state], M_.params, T);
idx = M_.block_structure_stat.block(i).equation; idx = M_.block_structure_stat.block(i).equation;
z(idx) = r; z(idx) = r;
end end
......
function [y, info] = solve_one_boundary(fname, y, x, params, steady_state, ... function [y, info] = solve_one_boundary(fname, y, x, params, steady_state, T, ...
y_index_eq, nze, periods, is_linear, Block_Num, y_kmin, maxit_, solve_tolf, lambda, cutoff, stack_solve_algo, is_forward, is_dynamic, verbose, M, options, oo) y_index_eq, nze, periods, is_linear, Block_Num, y_kmin, maxit_, solve_tolf, lambda, cutoff, stack_solve_algo, is_forward, is_dynamic, verbose, M, options, oo)
% 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
...@@ -10,6 +10,7 @@ function [y, info] = solve_one_boundary(fname, y, x, params, steady_state, ... ...@@ -10,6 +10,7 @@ function [y, info] = solve_one_boundary(fname, y, x, params, steady_state, ...
% 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 % params [vector] All the parameters of the model
% steady_state [vector] steady state of the model % steady_state [vector] steady state of the model
% T [matrix] Temporary terms
% 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
...@@ -94,7 +95,7 @@ for it_=start:incr:finish ...@@ -94,7 +95,7 @@ for it_=start:incr:finish
if is_dynamic if is_dynamic
[r, y, g1, g2, g3] = feval(fname, y, x, params, steady_state, it_, 0); [r, y, g1, g2, g3] = feval(fname, y, x, params, steady_state, it_, 0);
else else
[r, y, g1] = feval(fname, y, x, params); [r, y, g1] = feval(fname, y, x, params, T);
end 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;
...@@ -263,7 +264,7 @@ for it_=start:incr:finish ...@@ -263,7 +264,7 @@ for it_=start:incr:finish
[r, y, g1, g2, g3] = feval(fname, y, x, params, ... [r, y, g1, g2, g3] = feval(fname, y, x, params, ...
steady_state, it_, 0); steady_state, it_, 0);
else else
[r, y, g1] = feval(fname, y, x, params); [r, y, g1] = feval(fname, y, x, params, T);
end end
if max(abs(r))>=options.solve_tolf if max(abs(r))>=options.solve_tolf
[dx,flag1] = bicgstab(g1,-r,1e-7,Blck_size,L1,U1); [dx,flag1] = bicgstab(g1,-r,1e-7,Blck_size,L1,U1);
......
Subproject commit a6d9ba6e558c9f149ee81cc0e00837623563cb50 Subproject commit 04b7d4386dd8a6dbd74c032e92d09e6ca0758fd6
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment