2009-05-06 12:10:27 +02:00
|
|
|
/*
|
2023-12-05 15:44:23 +01:00
|
|
|
* Copyright © 2008-2023 Dynare Team
|
2009-05-19 10:57:07 +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/>.
|
2009-05-19 10:57:07 +02:00
|
|
|
*/
|
2009-05-06 12:10:27 +02:00
|
|
|
|
|
|
|
#ifndef K_ORD_DYNARE3_H
|
|
|
|
#define K_ORD_DYNARE3_H
|
2019-03-07 18:17:43 +01:00
|
|
|
|
2018-11-08 16:25:50 +01:00
|
|
|
#include <memory>
|
2023-11-29 19:00:21 +01:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2019-03-07 18:17:43 +01:00
|
|
|
|
2019-04-02 16:33:15 +02:00
|
|
|
#include "Vector.hh"
|
2019-01-04 16:29:57 +01:00
|
|
|
#include "decision_rule.hh"
|
2019-04-02 16:33:15 +02:00
|
|
|
#include "dynamic_abstract_class.hh"
|
2023-11-29 19:00:21 +01:00
|
|
|
#include "dynamic_model.hh"
|
|
|
|
#include "journal.hh"
|
|
|
|
#include "sparse_tensor.hh"
|
|
|
|
#include "t_container.hh"
|
|
|
|
#include "twod_matrix.hh"
|
2009-05-06 12:10:27 +02:00
|
|
|
|
|
|
|
class KordpDynare;
|
|
|
|
|
2019-07-09 17:26:27 +02:00
|
|
|
// Trivial implementation of pure abstract class NameList in dynamic_model.h
|
2009-05-27 16:28:23 +02:00
|
|
|
class DynareNameList : public NameList
|
|
|
|
{
|
2019-02-06 15:50:01 +01:00
|
|
|
std::vector<std::string> names;
|
2023-11-29 19:00:21 +01:00
|
|
|
|
2009-05-06 12:10:27 +02:00
|
|
|
public:
|
2019-07-09 17:26:27 +02:00
|
|
|
DynareNameList(std::vector<std::string> names_arg);
|
2023-12-05 15:44:23 +01:00
|
|
|
[[nodiscard]] int
|
2019-04-02 16:33:15 +02:00
|
|
|
getNum() const override
|
2009-05-27 16:28:23 +02:00
|
|
|
{
|
2019-03-06 18:40:19 +01:00
|
|
|
return static_cast<int>(names.size());
|
2009-05-27 16:28:23 +02:00
|
|
|
}
|
2023-12-05 15:44:23 +01:00
|
|
|
[[nodiscard]] const std::string&
|
2019-04-02 16:33:15 +02:00
|
|
|
getName(int i) const override
|
2009-05-27 16:28:23 +02:00
|
|
|
{
|
2019-03-06 18:40:19 +01:00
|
|
|
return names[i];
|
2009-05-27 16:28:23 +02:00
|
|
|
}
|
2009-05-06 12:10:27 +02:00
|
|
|
};
|
|
|
|
|
2009-05-27 16:28:23 +02:00
|
|
|
class DynareStateNameList : public NameList
|
|
|
|
{
|
2019-02-06 15:50:01 +01:00
|
|
|
std::vector<std::string> names;
|
2023-11-29 19:00:21 +01:00
|
|
|
|
2009-05-06 12:10:27 +02:00
|
|
|
public:
|
2023-11-29 19:00:21 +01:00
|
|
|
DynareStateNameList(const KordpDynare& dynare, const DynareNameList& dnl,
|
|
|
|
const DynareNameList& denl);
|
2023-12-05 15:44:23 +01:00
|
|
|
[[nodiscard]] int
|
2019-04-02 16:33:15 +02:00
|
|
|
getNum() const override
|
2009-05-27 16:28:23 +02:00
|
|
|
{
|
2019-03-06 18:40:19 +01:00
|
|
|
return static_cast<int>(names.size());
|
2009-05-27 16:28:23 +02:00
|
|
|
}
|
2023-12-05 15:44:23 +01:00
|
|
|
[[nodiscard]] const std::string&
|
2019-04-02 16:33:15 +02:00
|
|
|
getName(int i) const override
|
2009-05-27 16:28:23 +02:00
|
|
|
{
|
2019-03-06 18:40:19 +01:00
|
|
|
return names[i];
|
2009-05-27 16:28:23 +02:00
|
|
|
}
|
2009-05-06 12:10:27 +02:00
|
|
|
};
|
2019-04-02 16:33:15 +02:00
|
|
|
|
2009-05-06 12:10:27 +02:00
|
|
|
// The following only implements DynamicModel with help of ogdyn::DynareModel
|
|
|
|
// instantiation of pure abstract DynamicModel decl. in dynamic_model.h
|
2009-05-27 16:28:23 +02:00
|
|
|
class KordpDynare : public DynamicModel
|
|
|
|
{
|
2019-04-02 16:33:15 +02:00
|
|
|
public:
|
2009-05-06 12:10:27 +02:00
|
|
|
const int nStat;
|
|
|
|
const int nBoth;
|
|
|
|
const int nPred;
|
|
|
|
const int nForw;
|
|
|
|
const int nExog;
|
|
|
|
const int nPar;
|
2023-11-29 19:00:21 +01:00
|
|
|
const int nYs; // = npred + nboth
|
|
|
|
const int nYss; // = nboth + nforw
|
|
|
|
const int nY; // = nstat + npred + nboth + nforw
|
|
|
|
const int nJcols; // nb of jacobian columns = nExog+nY+nYs+nYss
|
|
|
|
const ConstVector& NNZD; /* the total number of non-zero derivative elements
|
2019-07-09 17:12:23 +02:00
|
|
|
where hessian is 2nd : NNZD(order=2) */
|
2009-05-06 12:10:27 +02:00
|
|
|
const int nSteps;
|
|
|
|
const int nOrder;
|
2023-11-29 19:00:21 +01:00
|
|
|
|
2019-04-02 16:33:15 +02:00
|
|
|
private:
|
2023-11-29 19:00:21 +01:00
|
|
|
Journal& journal;
|
|
|
|
Vector& ySteady;
|
|
|
|
Vector& params;
|
|
|
|
TwoDMatrix& vCov;
|
2019-04-10 18:56:14 +02:00
|
|
|
TensorContainer<FSSparseTensor> md; // Model derivatives, in Dynare++ form
|
2010-03-09 18:22:33 +01:00
|
|
|
DynareNameList dnl, denl;
|
2010-03-09 17:09:18 +01:00
|
|
|
DynareStateNameList dsnl;
|
2023-11-29 19:00:21 +01:00
|
|
|
const ConstTwoDMatrix& ll_Incidence;
|
2019-04-02 16:33:15 +02:00
|
|
|
std::vector<int> dynppToDyn; // Maps Dynare++ jacobian variable indices to Dynare ones
|
|
|
|
std::vector<int> dynToDynpp; // Maps Dynare jacobian variable indices to Dynare++ ones
|
2012-06-24 11:23:12 +02:00
|
|
|
|
2019-04-02 16:33:15 +02:00
|
|
|
std::unique_ptr<DynamicModelAC> dynamicModelFile;
|
2023-11-29 19:00:21 +01:00
|
|
|
|
2009-05-06 12:10:27 +02:00
|
|
|
public:
|
2023-11-29 19:00:21 +01:00
|
|
|
KordpDynare(const std::vector<std::string>& endo, const std::vector<std::string>& exo,
|
|
|
|
int num_exo, int num_par, Vector& ySteady, TwoDMatrix& vCov, Vector& params,
|
|
|
|
int nstat, int nPred, int nforw, int nboth, const ConstVector& NNZD, int nSteps,
|
|
|
|
int ord, Journal& jr, std::unique_ptr<DynamicModelAC> dynamicModelFile_arg,
|
|
|
|
const std::vector<int>& varOrder, const ConstTwoDMatrix& ll_Incidence);
|
2009-05-27 16:28:23 +02:00
|
|
|
|
2023-12-05 15:44:23 +01:00
|
|
|
[[nodiscard]] int
|
2019-04-02 16:33:15 +02:00
|
|
|
nstat() const override
|
2009-05-27 16:28:23 +02:00
|
|
|
{
|
|
|
|
return nStat;
|
|
|
|
}
|
2023-12-05 15:44:23 +01:00
|
|
|
[[nodiscard]] int
|
2019-04-02 16:33:15 +02:00
|
|
|
nboth() const override
|
2009-05-27 16:28:23 +02:00
|
|
|
{
|
|
|
|
return nBoth;
|
|
|
|
}
|
2023-12-05 15:44:23 +01:00
|
|
|
[[nodiscard]] int
|
2019-04-02 16:33:15 +02:00
|
|
|
npred() const override
|
2009-05-27 16:28:23 +02:00
|
|
|
{
|
|
|
|
return nPred;
|
|
|
|
}
|
2023-12-05 15:44:23 +01:00
|
|
|
[[nodiscard]] int
|
2019-04-02 16:33:15 +02:00
|
|
|
nforw() const override
|
2009-05-27 16:28:23 +02:00
|
|
|
{
|
|
|
|
return nForw;
|
|
|
|
}
|
2023-12-05 15:44:23 +01:00
|
|
|
[[nodiscard]] int
|
2019-04-02 16:33:15 +02:00
|
|
|
nexog() const override
|
2009-05-27 16:28:23 +02:00
|
|
|
{
|
|
|
|
return nExog;
|
|
|
|
}
|
2023-12-05 15:44:23 +01:00
|
|
|
[[nodiscard]] int
|
2021-06-15 14:30:32 +02:00
|
|
|
ny() const
|
|
|
|
{
|
2023-11-29 19:00:21 +01:00
|
|
|
return nStat + nBoth + nPred + nForw;
|
2021-06-15 14:30:32 +02:00
|
|
|
}
|
2023-12-05 15:44:23 +01:00
|
|
|
[[nodiscard]] int
|
2021-06-15 14:30:32 +02:00
|
|
|
nys() const
|
|
|
|
{
|
2023-11-29 19:00:21 +01:00
|
|
|
return nBoth + nPred;
|
2021-06-15 14:30:32 +02:00
|
|
|
}
|
2023-12-05 15:44:23 +01:00
|
|
|
[[nodiscard]] int
|
2019-04-02 16:33:15 +02:00
|
|
|
order() const override
|
2009-05-27 16:28:23 +02:00
|
|
|
{
|
|
|
|
return nOrder;
|
|
|
|
}
|
2023-12-05 15:44:23 +01:00
|
|
|
[[nodiscard]] const std::vector<int>&
|
2021-06-15 14:30:32 +02:00
|
|
|
getDynppToDyn() const
|
|
|
|
{
|
|
|
|
return dynppToDyn;
|
|
|
|
}
|
2023-12-05 15:44:23 +01:00
|
|
|
[[nodiscard]] const std::vector<int>&
|
2021-06-15 14:30:32 +02:00
|
|
|
getDynToDynpp() const
|
|
|
|
{
|
|
|
|
return dynToDynpp;
|
|
|
|
}
|
2023-12-05 15:44:23 +01:00
|
|
|
[[nodiscard]] const NameList&
|
2019-04-02 16:33:15 +02:00
|
|
|
getAllEndoNames() const override
|
2009-05-27 16:28:23 +02:00
|
|
|
{
|
2010-03-09 17:09:18 +01:00
|
|
|
return dnl;
|
2009-05-27 16:28:23 +02:00
|
|
|
}
|
2023-12-05 15:44:23 +01:00
|
|
|
[[nodiscard]] const NameList&
|
2019-04-02 16:33:15 +02:00
|
|
|
getStateNames() const override
|
2009-05-27 16:28:23 +02:00
|
|
|
{
|
2010-03-09 17:09:18 +01:00
|
|
|
return dsnl;
|
2009-05-27 16:28:23 +02:00
|
|
|
}
|
2023-12-05 15:44:23 +01:00
|
|
|
[[nodiscard]] const NameList&
|
2019-04-02 16:33:15 +02:00
|
|
|
getExogNames() const override
|
2009-05-27 16:28:23 +02:00
|
|
|
{
|
2010-03-09 17:09:18 +01:00
|
|
|
return denl;
|
2009-05-27 16:28:23 +02:00
|
|
|
}
|
2023-12-05 15:44:23 +01:00
|
|
|
[[nodiscard]] const TwoDMatrix&
|
2019-04-02 16:33:15 +02:00
|
|
|
getVcov() const override
|
2009-05-27 16:28:23 +02:00
|
|
|
{
|
2010-03-09 17:09:18 +01:00
|
|
|
return vCov;
|
2009-05-27 16:28:23 +02:00
|
|
|
}
|
|
|
|
|
2023-12-05 15:44:23 +01:00
|
|
|
[[nodiscard]] const TensorContainer<FSSparseTensor>&
|
2019-04-02 16:33:15 +02:00
|
|
|
getModelDerivatives() const override
|
2009-05-27 16:28:23 +02:00
|
|
|
{
|
|
|
|
return md;
|
|
|
|
}
|
2023-12-05 15:44:23 +01:00
|
|
|
[[nodiscard]] const Vector&
|
2019-04-02 16:33:15 +02:00
|
|
|
getSteady() const override
|
2009-05-27 16:28:23 +02:00
|
|
|
{
|
2010-03-09 17:09:18 +01:00
|
|
|
return ySteady;
|
2009-05-27 16:28:23 +02:00
|
|
|
}
|
2023-11-29 19:00:21 +01:00
|
|
|
Vector&
|
2019-04-02 16:33:15 +02:00
|
|
|
getSteady() override
|
2009-05-27 16:28:23 +02:00
|
|
|
{
|
2010-03-09 17:09:18 +01:00
|
|
|
return ySteady;
|
2009-05-27 16:28:23 +02:00
|
|
|
}
|
|
|
|
|
2019-04-02 16:33:15 +02:00
|
|
|
void solveDeterministicSteady() override;
|
2023-11-29 19:00:21 +01:00
|
|
|
void evaluateSystem(Vector& out, const ConstVector& yy, const Vector& xx) override;
|
|
|
|
void evaluateSystem(Vector& out, const ConstVector& yym, const ConstVector& yy,
|
|
|
|
const ConstVector& yyp, const Vector& xx) override;
|
2019-04-02 16:33:15 +02:00
|
|
|
void calcDerivativesAtSteady() override;
|
2023-12-05 15:44:23 +01:00
|
|
|
[[nodiscard]] std::unique_ptr<DynamicModel>
|
2019-04-02 16:33:15 +02:00
|
|
|
clone() const override
|
2009-05-27 16:28:23 +02:00
|
|
|
{
|
2010-03-09 17:09:18 +01:00
|
|
|
std::cerr << "KordpDynare::clone() not implemented" << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
2009-05-27 16:28:23 +02:00
|
|
|
}
|
2023-11-29 19:00:21 +01:00
|
|
|
|
2009-05-06 12:10:27 +02:00
|
|
|
private:
|
2023-11-29 19:00:21 +01:00
|
|
|
// Given the steady state in yS, returns in llxSteady the steady state extended with leads and
|
|
|
|
// lags
|
|
|
|
void LLxSteady(const Vector& yS, Vector& llxSteady);
|
2019-04-02 16:33:15 +02:00
|
|
|
/* Computes the permutations mapping back and forth between Dynare and
|
|
|
|
Dynare++ orderings of variables */
|
2023-11-29 19:00:21 +01:00
|
|
|
void computeJacobianPermutation(const std::vector<int>& var_order);
|
2019-04-10 18:56:14 +02:00
|
|
|
// Fills model derivatives in Dynare++ form (at a given order) given the Dynare form
|
2023-11-29 19:00:21 +01:00
|
|
|
void populateDerivativesContainer(const std::vector<TwoDMatrix>& dyn_md, int ord);
|
2009-05-06 12:10:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|