From e32c1470f63e0be09e78bec99da79f2f992c1b63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org> Date: Wed, 31 Jan 2024 16:19:35 +0100 Subject: [PATCH] Planner objective: refactor the driver output --- src/ComputingTasks.cc | 11 ++--------- src/ModelEquationBlock.cc | 14 +++++++++++++- src/ModelEquationBlock.hh | 4 +++- src/ModelTree.hh | 23 +---------------------- 4 files changed, 19 insertions(+), 33 deletions(-) diff --git a/src/ComputingTasks.cc b/src/ComputingTasks.cc index 90964908..f278bf6c 100644 --- a/src/ComputingTasks.cc +++ b/src/ComputingTasks.cc @@ -1,5 +1,5 @@ /* - * Copyright © 2003-2023 Dynare Team + * Copyright © 2003-2024 Dynare Team * * This file is part of Dynare. * @@ -2439,14 +2439,7 @@ void PlannerObjectiveStatement::writeOutput(ostream& output, const string& basename, [[maybe_unused]] bool minimal_workspace) const { - output << "M_.NNZDerivatives_objective = ["; - for (int i = 1; i < static_cast<int>(model_tree->getNNZDerivatives().size()); i++) - output << (i > model_tree->getComputedDerivsOrder() ? -1 : model_tree->getNNZDerivatives()[i]) - << ";"; - output << "];" << endl << "M_.objective_tmp_nbr = ["; - for (const auto& temporary_terms_derivative : model_tree->getTemporaryTermsDerivatives()) - output << temporary_terms_derivative.size() << "; "; - output << "];" << endl; + model_tree->writeDriverOutput(output); model_tree->writeStaticFile(basename + ".objective", false, "", {}, false); } diff --git a/src/ModelEquationBlock.cc b/src/ModelEquationBlock.cc index 212e0194..6667992b 100644 --- a/src/ModelEquationBlock.cc +++ b/src/ModelEquationBlock.cc @@ -1,5 +1,5 @@ /* - * Copyright © 2010-2023 Dynare Team + * Copyright © 2010-2024 Dynare Team * * This file is part of Dynare. * @@ -31,6 +31,18 @@ PlannerObjective::PlannerObjective(SymbolTable& symbol_table_arg, { } +void +PlannerObjective::writeDriverOutput(ostream& output) const +{ + output << "M_.NNZDerivatives_objective = ["; + for (int i = 1; i < static_cast<int>(NNZDerivatives.size()); i++) + output << (i > computed_derivs_order ? -1 : NNZDerivatives[i]) << ";"; + output << "];" << endl << "M_.objective_tmp_nbr = ["; + for (const auto& it : temporary_terms_derivatives) + output << it.size() << "; "; + output << "];" << endl; +} + void PlannerObjective::computingPassBlock([[maybe_unused]] const eval_context_t& eval_context, [[maybe_unused]] bool no_tmp_terms) diff --git a/src/ModelEquationBlock.hh b/src/ModelEquationBlock.hh index aedf9e61..cd6844b1 100644 --- a/src/ModelEquationBlock.hh +++ b/src/ModelEquationBlock.hh @@ -1,5 +1,5 @@ /* - * Copyright © 2010-2023 Dynare Team + * Copyright © 2010-2024 Dynare Team * * This file is part of Dynare. * @@ -31,6 +31,8 @@ class PlannerObjective : public StaticModel public: PlannerObjective(SymbolTable& symbol_table_arg, NumericalConstants& num_constants_arg, ExternalFunctionsTable& external_functions_table_arg); + // NB: masks the method with the same name in StaticModel (not in a virtual fashion) + void writeDriverOutput(ostream& output) const; protected: string diff --git a/src/ModelTree.hh b/src/ModelTree.hh index 8d068593..d3f87199 100644 --- a/src/ModelTree.hh +++ b/src/ModelTree.hh @@ -1,5 +1,5 @@ /* - * Copyright © 2003-2023 Dynare Team + * Copyright © 2003-2024 Dynare Team * * This file is part of Dynare. * @@ -689,27 +689,6 @@ public: // Write the definitions of the auxiliary variables (assumed to be in recursive order) void writeAuxVarRecursiveDefinitions(ostream& output, ExprNodeOutputType output_type) const; - //! Returns the vector of non-zero derivative counts - const vector<int>& - getNNZDerivatives() const - { - return NNZDerivatives; - } - - //! Returns the vector of temporary terms derivatives - const vector<temporary_terms_t>& - getTemporaryTermsDerivatives() const - { - return temporary_terms_derivatives; - } - - //! Returns the maximum order of computed derivatives - int - getComputedDerivsOrder() const - { - return computed_derivs_order; - } - static string BlockSim(BlockSimulationType type) { -- GitLab