From 0d9857e73702bc68bb5d7a3d1fefac21ace9bc46 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Wed, 7 Feb 2024 15:03:23 +0100
Subject: [PATCH] k_order_welfare MEX: drop ObjectiveAC abstract class, it has
 a single subclass

---
 .../k_order_welfare/k_ord_objective.cc        |  5 +--
 .../k_order_welfare/k_ord_objective.hh        |  8 ++--
 .../k_order_welfare/k_order_welfare.cc        |  8 ++--
 .../objective_abstract_class.hh               | 38 -------------------
 mex/sources/k_order_welfare/objective_m.cc    |  4 +-
 mex/sources/k_order_welfare/objective_m.hh    | 17 ++++-----
 6 files changed, 20 insertions(+), 60 deletions(-)
 delete mode 100644 mex/sources/k_order_welfare/objective_abstract_class.hh

diff --git a/mex/sources/k_order_welfare/k_ord_objective.cc b/mex/sources/k_order_welfare/k_ord_objective.cc
index cb2a357ea2..943ce8dd51 100644
--- a/mex/sources/k_order_welfare/k_ord_objective.cc
+++ b/mex/sources/k_order_welfare/k_ord_objective.cc
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2021-2023 Dynare Team
+ * Copyright © 2021-2024 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -18,13 +18,12 @@
  */
 
 #include "k_ord_objective.hh"
-#include "objective_abstract_class.hh"
 
 #include <cassert>
 #include <utility>
 
 KordwDynare::KordwDynare(KordpDynare& m, ConstVector& NNZD_arg, Journal& jr, Vector& inParams,
-                         std::unique_ptr<ObjectiveAC> objectiveFile_arg,
+                         std::unique_ptr<ObjectiveMFile> objectiveFile_arg,
                          const std::vector<int>& dr_order) :
     model {m},
     NNZD {NNZD_arg},
diff --git a/mex/sources/k_order_welfare/k_ord_objective.hh b/mex/sources/k_order_welfare/k_ord_objective.hh
index 71b0a38f56..0acc4932e6 100644
--- a/mex/sources/k_order_welfare/k_ord_objective.hh
+++ b/mex/sources/k_order_welfare/k_ord_objective.hh
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2021-2023 Dynare Team
+ * Copyright © 2021-2024 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -21,7 +21,7 @@
 #define K_ORD_OBJECTIVE_HH
 
 #include "k_ord_dynare.hh"
-#include "objective_abstract_class.hh"
+#include "objective_m.hh"
 
 class KordwDynare;
 
@@ -38,11 +38,11 @@ private:
   TensorContainer<FSSparseTensor> ud; // planner's objective derivatives, in Dynare++ form
   std::vector<int> dynppToDyn;        // Maps Dynare++ jacobian variable indices to Dynare ones
   std::vector<int> dynToDynpp;        // Maps Dynare jacobian variable indices to Dynare++ ones
-  std::unique_ptr<ObjectiveAC> objectiveFile;
+  std::unique_ptr<ObjectiveMFile> objectiveFile;
 
 public:
   KordwDynare(KordpDynare& m, ConstVector& NNZD_arg, Journal& jr, Vector& inParams,
-              std::unique_ptr<ObjectiveAC> objectiveFile_arg, const std::vector<int>& varOrder);
+              std::unique_ptr<ObjectiveMFile> objectiveFile_arg, const std::vector<int>& varOrder);
   void calcDerivativesAtSteady();
   void populateDerivativesContainer(const std::vector<TwoDMatrix>& dyn_ud, int ord);
   [[nodiscard]] const TensorContainer<FSSparseTensor>&
diff --git a/mex/sources/k_order_welfare/k_order_welfare.cc b/mex/sources/k_order_welfare/k_order_welfare.cc
index 3178d91f7c..04c2cbe7c3 100644
--- a/mex/sources/k_order_welfare/k_order_welfare.cc
+++ b/mex/sources/k_order_welfare/k_order_welfare.cc
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2021-2022 Dynare Team
+ * Copyright © 2021-2024 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -87,8 +87,8 @@ The routine proceeds in several steps:
    to the approxAtSteady method in the ApproximationWelfare class carries out the necessary
    operation
    - Importing the derivatives of the felicity function with the calcDerivativesAtSteady() method of
-     the KordwDynare class. It relies on the Matlab-generated files, which are handled by the
-     ObjectiveAC and ObjectiveMFile classes
+     the KordwDynare class. It relies on the MATLAB-generated files, which are handled by the
+     ObjectiveMFile class
    - Pinpointing the derivatives of the felicity and welfare functions. The performStep method of
      the KOrderWelfare class carries out the calculations,resorting to the FaaDiBruno class and its
      methods to get the needed intermediary results.
@@ -301,7 +301,7 @@ extern "C"
                                         mxGetPr(objective_tmp_nbr_mx) + kOrder + 1, 0);
 
     // Getting derivatives of the planner's objective function
-    std::unique_ptr<ObjectiveAC> objectiveFile;
+    std::unique_ptr<ObjectiveMFile> objectiveFile;
     objectiveFile = std::make_unique<ObjectiveMFile>(fname, ntt_objective);
 
     // make KordwDynare object
diff --git a/mex/sources/k_order_welfare/objective_abstract_class.hh b/mex/sources/k_order_welfare/objective_abstract_class.hh
deleted file mode 100644
index 6dd7a3dfe8..0000000000
--- a/mex/sources/k_order_welfare/objective_abstract_class.hh
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright © 2021-2023 Dynare Team
- *
- * 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
- * along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
- */
-
-#ifndef OBJECTIVE_ABSTRACT_CLASS_HH
-#define OBJECTIVE_ABSTRACT_CLASS_HH
-
-#include <vector>
-
-#include "twod_matrix.hh"
-
-class ObjectiveAC
-{
-protected:
-  int ntt; // Size of vector of temporary terms
-public:
-  ObjectiveAC(int ntt_arg) : ntt {ntt_arg} {};
-  virtual ~ObjectiveAC() = default;
-  virtual void eval(const Vector& y, const Vector& x, const Vector& params, Vector& residual,
-                    std::vector<TwoDMatrix>& md)
-      = 0;
-};
-#endif
diff --git a/mex/sources/k_order_welfare/objective_m.cc b/mex/sources/k_order_welfare/objective_m.cc
index 461f9f6d3c..1996cbb39f 100644
--- a/mex/sources/k_order_welfare/objective_m.cc
+++ b/mex/sources/k_order_welfare/objective_m.cc
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2021-2023 Dynare Team
+ * Copyright © 2021-2024 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -27,7 +27,7 @@
 #include "objective_m.hh"
 
 ObjectiveMFile::ObjectiveMFile(const std::string& modName, int ntt_arg) :
-    ObjectiveAC(ntt_arg), ObjectiveMFilename {modName + ".objective.static"}
+    ntt {ntt_arg}, ObjectiveMFilename {modName + ".objective.static"}
 {
 }
 
diff --git a/mex/sources/k_order_welfare/objective_m.hh b/mex/sources/k_order_welfare/objective_m.hh
index 4de2aec51c..f6c5f1ee80 100644
--- a/mex/sources/k_order_welfare/objective_m.hh
+++ b/mex/sources/k_order_welfare/objective_m.hh
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2021-2023 Dynare Team
+ * Copyright © 2021-2024 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -20,24 +20,23 @@
 #ifndef OBJECTIVE_M_HH
 #define OBJECTIVE_M_HH
 
-#include "objective_abstract_class.hh"
+#include <vector>
 
-#include "mex.h"
 #include <dynmex.h>
 
-/**
- * handles calls to <model>/+objective/static.m
- *
- **/
-class ObjectiveMFile : public ObjectiveAC
+#include "twod_matrix.hh"
+
+// Handles calls to <model>/+objective/static.m
+class ObjectiveMFile
 {
 private:
+  int ntt; // Size of vector of temporary terms
   const std::string ObjectiveMFilename;
   static void unpackSparseMatrixAndCopyIntoTwoDMatData(mxArray* sparseMat, TwoDMatrix& tdm);
 
 public:
   explicit ObjectiveMFile(const std::string& modName, int ntt_arg);
   void eval(const Vector& y, const Vector& x, const Vector& params, Vector& residual,
-            std::vector<TwoDMatrix>& md) override;
+            std::vector<TwoDMatrix>& md);
 };
 #endif
-- 
GitLab