2009-05-06 12:10:27 +02:00
/*
2017-05-18 18:36:38 +02:00
* Copyright ( C ) 2008 - 2017 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
* along with Dynare . If not , see < http : //www.gnu.org/licenses/>.
*/
2009-05-06 12:10:27 +02:00
# ifndef K_ORD_DYNARE3_H
# define K_ORD_DYNARE3_H
# include <vector>
2018-11-08 16:25:50 +01:00
# include <memory>
2019-01-08 16:09:25 +01:00
# include "t_container.hh"
# include "sparse_tensor.hh"
2019-01-04 16:29:57 +01:00
# include "decision_rule.hh"
# include "dynamic_model.hh"
2009-05-06 12:10:27 +02:00
2019-01-08 17:12:05 +01:00
# include "exception.hh"
# include "dynare_exception.hh"
2019-01-08 16:09:25 +01:00
# include "fs_tensor.hh"
2019-01-08 17:12:05 +01:00
# include "SylvException.hh"
2019-01-08 16:09:25 +01:00
# include "tl_exception.hh"
2019-01-04 16:29:57 +01:00
# include "kord_exception.hh"
2019-01-08 17:12:05 +01:00
# include "nlsolve.hh"
2019-01-04 16:29:57 +01:00
# include "approximation.hh"
2009-05-06 12:10:27 +02:00
class KordpDynare ;
/*////////////////////////////////////////////*/
// instantiations 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 ;
2009-05-06 12:10:27 +02:00
public :
2019-03-06 18:40:19 +01:00
DynareNameList ( const KordpDynare & dynare , std : : vector < std : : string > names_arg ) ;
2009-05-27 16:28:23 +02:00
int
getNum ( ) const
{
2019-03-06 18:40:19 +01:00
return static_cast < int > ( names . size ( ) ) ;
2009-05-27 16:28:23 +02:00
}
2019-03-06 18:40:19 +01:00
const std : : string &
2009-05-27 16:28:23 +02:00
getName ( int i ) const
{
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 ;
2009-05-06 12:10:27 +02:00
public :
2009-05-27 16:28:23 +02:00
DynareStateNameList ( const KordpDynare & dynare , const DynareNameList & dnl ,
2010-03-09 18:22:33 +01:00
const DynareNameList & denl ) ;
2009-05-27 16:28:23 +02:00
int
getNum ( ) const
{
2019-03-06 18:40:19 +01:00
return static_cast < int > ( names . size ( ) ) ;
2009-05-27 16:28:23 +02:00
}
2019-03-06 18:40:19 +01:00
const std : : string &
2009-05-27 16:28:23 +02:00
getName ( int i ) const
{
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
} ;
/*********************************************/
// The following only implements DynamicModel with help of ogdyn::DynareModel
// instantiation of pure abstract DynamicModel decl. in dynamic_model.h
2010-12-17 18:34:23 +01:00
class DynamicModelAC ;
2009-09-23 15:14:05 +02:00
class DynamicModelDLL ;
2010-12-17 18:34:23 +01:00
class DynamicModelMFile ;
2009-11-30 17:31:27 +01:00
2009-05-27 16:28:23 +02:00
class KordpDynare : public DynamicModel
{
2009-05-06 12:10:27 +02:00
friend class DynareNameList ;
friend class DynareStateNameList ;
friend class DynamicModelDLL ;
2010-12-17 18:34:23 +01:00
friend class DynamicModelMFile ;
2009-11-30 17:31:27 +01:00
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 ;
const int nYs ; // ={npred + nboth ; }
const int nYss ; // nyss ={ nboth + nforw ; }
const int nY ; // = num_endo={ nstat + npred + nboth + nforw ; }
2009-08-24 18:01:25 +02:00
const int nJcols ; // no of jacobian columns= nExog+nEndo+nsPred+nsForw
2010-03-09 17:09:18 +01:00
const Vector & NNZD ; /* the total number of non-zero derivative elements
2009-11-30 17:31:27 +01:00
where hessian is 2 nd : NZZD ( order = 2 ) */
2009-05-06 12:10:27 +02:00
const int nSteps ;
const int nOrder ;
2009-05-27 16:28:23 +02:00
Journal & journal ;
2010-03-09 17:09:18 +01:00
Vector & ySteady ;
Vector & params ;
TwoDMatrix & vCov ;
2009-05-06 12:10:27 +02:00
TensorContainer < FSSparseTensor > md ; // ModelDerivatives
2010-03-09 18:22:33 +01:00
DynareNameList dnl , denl ;
2010-03-09 17:09:18 +01:00
DynareStateNameList dsnl ;
2009-05-06 12:10:27 +02:00
const double ss_tol ;
2019-02-06 15:50:01 +01:00
const std : : vector < int > & varOrder ;
2010-03-09 17:09:18 +01:00
const TwoDMatrix & ll_Incidence ;
2009-05-06 12:10:27 +02:00
double qz_criterium ;
2019-02-06 15:50:01 +01:00
std : : vector < int > JacobianIndices ;
2012-06-24 11:23:12 +02:00
TwoDMatrix * g1p ;
TwoDMatrix * g2p ;
TwoDMatrix * g3p ;
2009-05-06 12:10:27 +02:00
public :
2019-02-06 15:50:01 +01:00
KordpDynare ( const std : : vector < std : : string > & endo , int num_endo ,
const std : : vector < std : : string > & exo , int num_exo , int num_par ,
2010-03-09 17:09:18 +01:00
Vector & ySteady , TwoDMatrix & vCov , Vector & params , int nstat , int nPred ,
int nforw , int nboth , const int nJcols , const Vector & NNZD ,
2009-11-30 17:31:27 +01:00
const int nSteps , const int ord ,
2019-02-06 15:50:01 +01:00
Journal & jr , std : : unique_ptr < DynamicModelAC > dynamicModelFile_arg , double sstol ,
const std : : vector < int > & varOrder , const TwoDMatrix & ll_Incidence ,
2018-11-08 16:25:50 +01:00
double qz_criterium ) noexcept ( false ) ;
2019-02-06 15:50:01 +01:00
KordpDynare ( const std : : vector < std : : string > & endo , int num_endo ,
const std : : vector < std : : string > & exo , int num_exo , int num_par ,
2012-07-07 21:21:28 +02:00
Vector & ySteady , TwoDMatrix & vCov , Vector & params , int nstat , int nPred ,
int nforw , int nboth , const int nJcols , const Vector & NNZD ,
const int nSteps , const int ord ,
2019-02-06 15:50:01 +01:00
Journal & jr , std : : unique_ptr < DynamicModelAC > dynamicModelFile_arg , double sstol ,
const std : : vector < int > & varOrder , const TwoDMatrix & ll_Incidence ,
2018-11-08 16:25:50 +01:00
double qz_criterium , TwoDMatrix * g1_arg , TwoDMatrix * g2_arg , TwoDMatrix * g3_arg ) noexcept ( false ) ;
2009-05-27 16:28:23 +02:00
2018-11-08 16:25:50 +01:00
virtual ~ KordpDynare ( ) ;
2009-05-27 16:28:23 +02:00
int
nstat ( ) const
{
return nStat ;
}
int
nboth ( ) const
{
return nBoth ;
}
int
npred ( ) const
{
return nPred ;
}
int
nforw ( ) const
{
return nForw ;
}
int
nexog ( ) const
{
return nExog ;
}
int
nys ( ) const
{
return nYs ;
}
int
nyss ( ) const
{
return nYss ;
}
int
ny ( ) const
{
return nY ;
}
int
steps ( ) const
{
return nSteps ;
}
int
order ( ) const
{
return nOrder ;
}
const NameList &
getAllEndoNames ( ) const
{
2010-03-09 17:09:18 +01:00
return dnl ;
2009-05-27 16:28:23 +02:00
}
const NameList &
getStateNames ( ) const
{
2010-03-09 17:09:18 +01:00
return dsnl ;
2009-05-27 16:28:23 +02:00
}
const NameList &
getExogNames ( ) const
{
2010-03-09 17:09:18 +01:00
return denl ;
2009-05-27 16:28:23 +02:00
}
const TwoDMatrix &
getVcov ( ) const
{
2010-03-09 17:09:18 +01:00
return vCov ;
2009-05-27 16:28:23 +02:00
}
Vector &
getParams ( )
{
2010-03-09 17:09:18 +01:00
return params ;
2009-05-27 16:28:23 +02:00
}
const TensorContainer < FSSparseTensor > &
getModelDerivatives ( ) const
{
return md ;
}
const Vector &
getSteady ( ) const
{
2010-03-09 17:09:18 +01:00
return ySteady ;
2009-05-27 16:28:23 +02:00
}
Vector &
getSteady ( )
{
2010-03-09 17:09:18 +01:00
return ySteady ;
2009-05-27 16:28:23 +02:00
}
2009-11-30 17:31:27 +01:00
void solveDeterministicSteady ( ) ;
Dynare++ / sylvester equation solver: refactor Vector and ConstVector classes
- these classes now encapsulate a std::shared_ptr<{const, }double>, so that
they do not perform memory management, and several {Const,}Vector instances
can transparently share the same underlying data
- make converting constructor from ConstVector to Vector explicit, since that
entails memory allocation (but the reverse conversion is almost costless, so
keep it implicit); do the same for GeneralMatrix/ConstGeneralMatrix,
TwoDMatrix/ConstTwoDMatrix
- remove the constructors that were extracting a row/column from a matrix, and
replace them by getRow() and getCol() methods on {Const,}GeneralMatrix
- rename and change the API of the complex version Vector::add(), so that it is
explicit that it deals with complex numbers
- add constructors that take a MATLAB mxArray
2019-01-22 16:07:44 +01:00
void evaluateSystem ( Vector & out , const ConstVector & yy , const Vector & xx ) noexcept ( false ) ;
void evaluateSystem ( Vector & out , const ConstVector & yym , const ConstVector & yy ,
const ConstVector & yyp , const Vector & xx ) noexcept ( false ) ;
2016-07-16 00:13:47 +02:00
void calcDerivativesAtSteady ( ) ;
2019-02-06 15:50:01 +01:00
std : : unique_ptr < DynamicModelAC > dynamicModelFile ;
2019-03-06 18:40:19 +01:00
std : : unique_ptr < DynamicModel >
2009-05-27 16:28:23 +02:00
clone ( ) const
{
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
}
2018-11-08 16:25:50 +01:00
void LLxSteady ( const Vector & yS , Vector & llxSteady ) noexcept ( false ) ; // Given the steady state in yS, returns in llxSteady the steady state extended with leads and lags
2009-05-27 16:28:23 +02:00
2009-05-06 12:10:27 +02:00
private :
2018-11-08 16:25:50 +01:00
void ReorderDynareJacobianIndices ( ) noexcept ( false ) ;
2019-02-06 15:50:01 +01:00
void populateDerivativesContainer ( const TwoDMatrix & g , int ord , const std : : vector < int > & vOrder ) ;
2009-05-06 12:10:27 +02:00
} ;
# endif