2020-06-02 17:45:28 +02:00
|
|
|
function oo_ = solve_block_decomposed_problem(options_, M_, oo_)
|
|
|
|
% Computes deterministic simulation with block option without bytecode
|
|
|
|
|
2022-04-13 13:15:19 +02:00
|
|
|
% Copyright © 2020-2022 Dynare Team
|
2020-06-02 17:45:28 +02:00
|
|
|
%
|
|
|
|
% This file is part of Dynare.
|
|
|
|
%
|
|
|
|
% Dynare is free software: you can redistribute it and/or modify
|
|
|
|
% it under the terms of the GNU General Public License as published by
|
|
|
|
% the Free Software Foundation, either version 3 of the License, or
|
|
|
|
% (at your option) any later version.
|
|
|
|
%
|
|
|
|
% Dynare is distributed in the hope that it will be useful,
|
|
|
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
% GNU General Public License for more details.
|
|
|
|
%
|
|
|
|
% You should have received a copy of the GNU General Public License
|
2021-06-09 17:33:48 +02:00
|
|
|
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2020-06-02 17:45:28 +02:00
|
|
|
|
|
|
|
cutoff = 1e-15;
|
|
|
|
|
|
|
|
if options_.stack_solve_algo==0
|
|
|
|
mthd='Sparse LU';
|
|
|
|
elseif options_.stack_solve_algo==1
|
|
|
|
mthd='Relaxation';
|
|
|
|
elseif options_.stack_solve_algo==2
|
|
|
|
mthd='GMRES';
|
|
|
|
elseif options_.stack_solve_algo==3
|
|
|
|
mthd='BICGSTAB';
|
|
|
|
elseif options_.stack_solve_algo==4
|
|
|
|
mthd='OPTIMPATH';
|
|
|
|
else
|
|
|
|
mthd='UNKNOWN';
|
|
|
|
end
|
|
|
|
if options_.verbosity
|
|
|
|
printline(41)
|
|
|
|
disp(sprintf('MODEL SIMULATION (method=%s):',mthd))
|
|
|
|
skipline()
|
|
|
|
end
|
|
|
|
|
2020-06-17 17:28:59 +02:00
|
|
|
y=oo_.endo_simul;
|
2020-06-02 17:45:28 +02:00
|
|
|
T=NaN(M_.block_structure.dyn_tmp_nbr, options_.periods+M_.maximum_lag+M_.maximum_lead);
|
2022-03-23 16:49:05 +01:00
|
|
|
oo_.deterministic_simulation.status = false;
|
2020-06-02 17:45:28 +02:00
|
|
|
|
2020-06-19 18:34:48 +02:00
|
|
|
funcname = [ M_.fname '.dynamic'];
|
|
|
|
|
2020-06-04 18:15:54 +02:00
|
|
|
for blk = 1:length(M_.block_structure.block)
|
2020-06-02 17:45:28 +02:00
|
|
|
recursive_size = M_.block_structure.block(blk).endo_nbr - M_.block_structure.block(blk).mfs;
|
|
|
|
y_index = M_.block_structure.block(blk).variable((recursive_size+1):end);
|
|
|
|
|
|
|
|
if M_.block_structure.block(blk).Simulation_Type == 1 || ... % evaluateForward
|
|
|
|
M_.block_structure.block(blk).Simulation_Type == 2 % evaluateBackward
|
|
|
|
oo_.deterministic_simulation.status = true;
|
|
|
|
oo_.deterministic_simulation.error = 0;
|
|
|
|
oo_.deterministic_simulation.iterations = 0;
|
|
|
|
oo_.deterministic_simulation.block(blk).status = true;
|
|
|
|
oo_.deterministic_simulation.block(blk).error = 0;
|
|
|
|
oo_.deterministic_simulation.block(blk).iterations = 0;
|
2020-06-15 18:13:51 +02:00
|
|
|
if M_.block_structure.block(blk).Simulation_Type == 1
|
|
|
|
range = M_.maximum_lag+1:M_.maximum_lag+options_.periods;
|
|
|
|
else
|
|
|
|
range = M_.maximum_lag+options_.periods:-1:M_.maximum_lag+1;
|
|
|
|
end
|
|
|
|
for it_ = range
|
2020-06-17 17:28:59 +02:00
|
|
|
y2 = dynvars_from_endo_simul(y, it_, M_);
|
2020-06-19 18:34:48 +02:00
|
|
|
[~, y2, T(:, it_)] = feval(funcname, blk, y2, oo_.exo_simul, M_.params, oo_.steady_state, T(:, it_), it_, false);
|
2020-06-17 17:28:59 +02:00
|
|
|
y(find(M_.lead_lag_incidence(M_.maximum_endo_lag+1, :)), it_) = y2(nonzeros(M_.lead_lag_incidence(M_.maximum_endo_lag+1, :)));
|
2020-06-15 18:13:51 +02:00
|
|
|
end
|
2020-06-02 17:45:28 +02:00
|
|
|
elseif M_.block_structure.block(blk).Simulation_Type == 3 || ... % solveForwardSimple
|
|
|
|
M_.block_structure.block(blk).Simulation_Type == 4 || ... % solveBackwardSimple
|
|
|
|
M_.block_structure.block(blk).Simulation_Type == 6 || ... % solveForwardComplete
|
|
|
|
M_.block_structure.block(blk).Simulation_Type == 7 % solveBackwardComplete
|
2022-02-09 13:59:52 +01:00
|
|
|
is_forward = M_.block_structure.block(blk).Simulation_Type == 3 || M_.block_structure.block(blk).Simulation_Type == 6;
|
2022-03-31 17:39:43 +02:00
|
|
|
[y, T, oo_] = solve_one_boundary(funcname, y, oo_.exo_simul, M_.params, oo_.steady_state, T, y_index, M_.block_structure.block(blk).NNZDerivatives, options_.periods, M_.block_structure.block(blk).is_linear, blk, M_.maximum_lag, options_.simul.maxit, options_.dynatol.f, cutoff, options_.stack_solve_algo, is_forward, true, false, M_, options_, oo_);
|
2020-06-02 17:45:28 +02:00
|
|
|
elseif M_.block_structure.block(blk).Simulation_Type == 5 || ... % solveTwoBoundariesSimple
|
|
|
|
M_.block_structure.block(blk).Simulation_Type == 8 % solveTwoBoundariesComplete
|
2022-03-31 17:39:43 +02:00
|
|
|
[y, T, oo_] = solve_two_boundaries(funcname, y, oo_.exo_simul, M_.params, oo_.steady_state, T, y_index, M_.block_structure.block(blk).NNZDerivatives, options_.periods, M_.block_structure.block(blk).maximum_lag, M_.block_structure.block(blk).maximum_lead, M_.block_structure.block(blk).is_linear, blk, M_.maximum_lag, options_.simul.maxit, options_.dynatol.f, cutoff, options_.stack_solve_algo, options_, M_, oo_);
|
2020-06-02 17:45:28 +02:00
|
|
|
end
|
|
|
|
|
2020-06-17 17:28:59 +02:00
|
|
|
tmp = y(M_.block_structure.block(blk).variable, :);
|
2020-06-02 17:45:28 +02:00
|
|
|
if any(isnan(tmp) | isinf(tmp))
|
|
|
|
disp(['Inf or Nan value during the resolution of block ' num2str(blk)]);
|
|
|
|
oo_.deterministic_simulation.status = false;
|
|
|
|
oo_.deterministic_simulation.error = 100;
|
|
|
|
oo_.deterministic_simulation.block(blk).status = false;
|
|
|
|
oo_.deterministic_simulation.block(blk).error = 100;
|
|
|
|
end
|
|
|
|
if ~oo_.deterministic_simulation.status
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-17 17:28:59 +02:00
|
|
|
oo_.endo_simul = y;
|