2009-05-06 12:10:27 +02:00
/*
2009-05-19 10:57:07 +02:00
* Copyright ( C ) 2005 Ondra Kamenik
2010-03-09 15:20:18 +01:00
* Copyright ( C ) 2008 - 2010 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
// based on: $Id: dynare3.h 1764 2008-03-31 14:30:55Z kamenik $
// by 2005, Ondra Kamenik
# ifndef K_ORD_DYNARE3_H
# define K_ORD_DYNARE3_H
# include <vector>
# include "t_container.h"
# include "sparse_tensor.h"
# include "decision_rule.h"
# include "dynamic_model.h"
# include "exception.h"
# include "dynare_exception.h"
# include "fs_tensor.h"
# include "SylvException.h"
# include "tl_exception.h"
# include "kord_exception.h"
# include "nlsolve.h"
# include "approximation.h"
class KordpDynare ;
/*////////////////////////////////////////////*/
// instantiations of pure abstract class NameList in dynamic_model.h:
/*////////////////////////////////////////////*/
2009-05-27 16:28:23 +02:00
class DynareNameList : public NameList
{
vector < const char * > names ;
2009-05-06 12:10:27 +02:00
public :
2009-05-27 16:28:23 +02:00
DynareNameList ( const KordpDynare & dynare ) ;
DynareNameList ( const KordpDynare & dynare , const char * * names ) ;
int
getNum ( ) const
{
return ( int ) names . size ( ) ;
}
const char *
getName ( int i ) const
{
return names [ i ] ;
}
2009-05-06 12:10:27 +02:00
/** This for each string of the input vector calculates its index
2009-05-27 16:28:23 +02:00
* in the names . And returns the resulting vector of indices . If
* the name cannot be found , then an exception is raised . */
2009-11-30 17:31:27 +01:00
vector < int > selectIndices ( const vector < const char * > & ns ) const throw ( DynareException ) ;
2009-05-06 12:10:27 +02:00
} ;
2009-05-27 16:28:23 +02:00
class DynareExogNameList : public NameList
{
vector < const char * > names ;
2009-05-06 12:10:27 +02:00
public :
2009-05-27 16:28:23 +02:00
DynareExogNameList ( const KordpDynare & dynare ) ;
DynareExogNameList ( const KordpDynare & dynare , const char * * names ) ;
int
getNum ( ) const
{
return ( int ) names . size ( ) ;
}
const char *
getName ( int i ) const
{
return names [ i ] ;
}
2009-05-06 12:10:27 +02:00
} ;
2009-05-27 16:28:23 +02:00
class DynareStateNameList : public NameList
{
vector < const char * > 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 ,
const DynareExogNameList & denl ) ;
int
getNum ( ) const
{
return ( int ) names . size ( ) ;
}
const char *
getName ( int i ) const
{
return names [ i ] ;
}
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-09-23 15:14:05 +02:00
class DynamicModelDLL ;
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 DynareExogNameList ;
friend class DynareStateNameList ;
friend class DynamicModelDLL ;
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 17:09:18 +01:00
DynareNameList dnl ;
DynareExogNameList denl ;
DynareStateNameList dsnl ;
2009-05-06 12:10:27 +02:00
const double ss_tol ;
2010-03-09 17:09:18 +01:00
const vector < int > & varOrder ;
const TwoDMatrix & ll_Incidence ;
2009-05-06 12:10:27 +02:00
double qz_criterium ;
2010-03-09 17:09:18 +01:00
vector < int > JacobianIndices ;
2009-05-06 12:10:27 +02:00
public :
2009-05-27 16:28:23 +02:00
KordpDynare ( const char * * endo , int num_endo ,
2009-11-30 17:31:27 +01:00
const char * * 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 ,
2009-05-27 16:28:23 +02:00
Journal & jr , DynamicModelDLL & dynamicDLL , double sstol ,
2010-03-09 17:09:18 +01:00
const vector < int > & varOrder , const TwoDMatrix & ll_Incidence ,
2009-11-30 17:31:27 +01:00
double qz_criterium ) throw ( TLException ) ;
2009-05-27 16:28:23 +02:00
2009-05-06 12:10:27 +02: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 ( ) ;
void evaluateSystem ( Vector & out , const Vector & yy , const Vector & xx ) throw ( DynareException ) ;
2009-05-27 16:28:23 +02:00
void evaluateSystem ( Vector & out , const Vector & yym , const Vector & yy ,
2009-11-30 17:31:27 +01:00
const Vector & yyp , const Vector & xx ) throw ( DynareException ) ;
void calcDerivativesAtSteady ( ) throw ( DynareException ) ;
2009-05-27 16:28:23 +02:00
DynamicModelDLL & dynamicDLL ;
DynamicModel *
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
}
2010-03-09 17:09:18 +01:00
void LLxSteady ( const Vector & yS , Vector & llxSteady ) throw ( DynareException , TLException ) ; // 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 :
2010-03-09 17:09:18 +01:00
void ReorderDynareJacobianIndices ( ) throw ( TLException ) ;
void populateDerivativesContainer ( const TwoDMatrix & g , int ord , const vector < int > & vOrder ) ;
2009-05-06 12:10:27 +02:00
} ;
# endif