Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Dóra Kocsis
dynare
Commits
69ddfadd
Commit
69ddfadd
authored
Jun 22, 2011
by
Sébastien Villemot
Browse files
Preprocessor: factorize code common between StaticModel and DynamicModel, and put it in ModelTree
parent
ae76a8f8
Changes
6
Hide whitespace changes
Inline
Side-by-side
preprocessor/DynamicModel.cc
View file @
69ddfadd
...
...
@@ -45,9 +45,7 @@ DynamicModel::DynamicModel(SymbolTable &symbol_table_arg,
max_exo_lag
(
0
),
max_exo_lead
(
0
),
max_exo_det_lag
(
0
),
max_exo_det_lead
(
0
),
dynJacobianColsNbr
(
0
),
global_temporary_terms
(
true
),
cutoff
(
1e-15
),
mfs
(
0
)
global_temporary_terms
(
true
)
{
}
...
...
@@ -83,16 +81,6 @@ DynamicModel::compileChainRuleDerivative(ofstream &code_file, unsigned int &inst
}
}
void
DynamicModel
::
initializeVariablesAndEquations
()
{
for
(
int
j
=
0
;
j
<
equation_number
();
j
++
)
{
equation_reordered
.
push_back
(
j
);
variable_reordered
.
push_back
(
j
);
}
}
void
DynamicModel
::
computeTemporaryTermsOrdered
()
{
...
...
@@ -3978,9 +3966,3 @@ DynamicModel::fillEvalContext(eval_context_t &eval_context) const
it
!=
trendVars
.
end
();
it
++
)
eval_context
[
*
it
]
=
2
;
//not <= 0 bc of log, not 1 bc of powers
}
void
DynamicModel
::
set_cutoff_to_zero
()
{
cutoff
=
0
;
}
preprocessor/DynamicModel.hh
View file @
69ddfadd
...
...
@@ -194,9 +194,6 @@ private:
//! Indicate if the temporary terms are computed for the overall model (true) or not (false). Default value true
bool
global_temporary_terms
;
//! vector of block reordered variables and equations
vector
<
int
>
equation_reordered
,
variable_reordered
,
inv_equation_reordered
,
inv_variable_reordered
;
//! Vector describing equations: BlockSimulationType, if BlockSimulationType == EVALUATE_s then a expr_t on the new normalized equation
equation_type_and_normalized_equation_t
equation_type_and_normalized_equation
;
...
...
@@ -244,17 +241,7 @@ public:
//! Adds a variable node
/*! This implementation allows for non-zero lag */
virtual
VariableNode
*
AddVariable
(
int
symb_id
,
int
lag
=
0
);
//! Absolute value under which a number is considered to be zero
double
cutoff
;
//! Compute the minimum feedback set in the dynamic model:
/*! 0 : all endogenous variables are considered as feedback variables
1 : the variables belonging to non normalized equation are considered as feedback variables
2 : the variables belonging to a non linear equation are considered as feedback variables
3 : the variables belonging to a non normalizable non linear equation are considered as feedback variables
default value = 0 */
int
mfs
;
//! the file containing the model and the derivatives code
ofstream
code_file
;
//! Execute computations (variable sorting + derivation)
/*!
\param jacobianExo whether derivatives w.r. to exo and exo_det should be in the Jacobian (derivatives w.r. to endo are always computed)
...
...
@@ -292,9 +279,6 @@ public:
//! Writes LaTeX file with the equations of the dynamic model
void
writeLatexFile
(
const
string
&
basename
)
const
;
//! Initialize equation_reordered & variable_reordered
void
initializeVariablesAndEquations
();
virtual
int
getDerivID
(
int
symb_id
,
int
lag
)
const
throw
(
UnknownDerivIDException
);
virtual
int
getDynJacobianCol
(
int
deriv_id
)
const
throw
(
UnknownDerivIDException
);
virtual
void
addAllParamDerivId
(
set
<
int
>
&
deriv_id_set
);
...
...
@@ -338,8 +322,6 @@ public:
//! Fills eval context with values of model local variables and auxiliary variables
void
fillEvalContext
(
eval_context_t
&
eval_context
)
const
;
void
set_cutoff_to_zero
();
//! Return the number of blocks
virtual
unsigned
int
getNbBlocks
()
const
...
...
preprocessor/ModelTree.cc
View file @
69ddfadd
...
...
@@ -957,7 +957,10 @@ ModelTree::BlockLinear(const blocks_derivatives_t &blocks_derivatives, const vec
ModelTree
::
ModelTree
(
SymbolTable
&
symbol_table_arg
,
NumericalConstants
&
num_constants_arg
,
ExternalFunctionsTable
&
external_functions_table_arg
)
:
DataTree
(
symbol_table_arg
,
num_constants_arg
,
external_functions_table_arg
)
DataTree
(
symbol_table_arg
,
num_constants_arg
,
external_functions_table_arg
),
cutoff
(
1e-15
),
mfs
(
0
)
{
for
(
int
i
=
0
;
i
<
3
;
i
++
)
NNZDerivatives
[
i
]
=
0
;
...
...
@@ -1405,3 +1408,19 @@ ModelTree::addNonstationaryVariables(vector<int> nonstationary_vars, expr_t defl
nonstationary_vars
.
pop_back
();
}
}
void
ModelTree
::
initializeVariablesAndEquations
()
{
for
(
int
j
=
0
;
j
<
equation_number
();
j
++
)
{
equation_reordered
.
push_back
(
j
);
variable_reordered
.
push_back
(
j
);
}
}
void
ModelTree
::
set_cutoff_to_zero
()
{
cutoff
=
0
;
}
preprocessor/ModelTree.hh
View file @
69ddfadd
...
...
@@ -99,6 +99,12 @@ protected:
//! Nonstationary variables and their deflators
trend_symbols_map_t
nonstationary_symbols_map
;
//! vector of block reordered variables and equations
vector
<
int
>
equation_reordered
,
variable_reordered
,
inv_equation_reordered
,
inv_variable_reordered
;
//! the file containing the model and the derivatives code
ofstream
code_file
;
//! Computes 1st derivatives
/*! \param vars the derivation IDs w.r. to which compute the derivatives */
void
computeJacobian
(
const
set
<
int
>
&
vars
);
...
...
@@ -230,8 +236,19 @@ protected:
virtual
int
getBlockInitialDetExogenousID
(
int
block_number
,
int
variable_number
)
const
=
0
;
//! Return the position of the other endogenous variable_number in the block number belonging to the block block_number
virtual
int
getBlockInitialOtherEndogenousID
(
int
block_number
,
int
variable_number
)
const
=
0
;
//! Initialize equation_reordered & variable_reordered
void
initializeVariablesAndEquations
();
public:
ModelTree
(
SymbolTable
&
symbol_table_arg
,
NumericalConstants
&
num_constants_arg
,
ExternalFunctionsTable
&
external_functions_table_arg
);
//! Absolute value under which a number is considered to be zero
double
cutoff
;
//! Compute the minimum feedback set
/*! 0 : all endogenous variables are considered as feedback variables
1 : the variables belonging to non normalized equation are considered as feedback variables
2 : the variables belonging to a non linear equation are considered as feedback variables
3 : the variables belonging to a non normalizable non linear equation are considered as feedback variables
default value = 0 */
int
mfs
;
//! Declare a node as an equation of the model
void
addEquation
(
expr_t
eq
);
//! Adds tags to equation number i
...
...
@@ -244,7 +261,8 @@ public:
void
addTrendVariables
(
vector
<
int
>
trend_vars
,
expr_t
growth_factor
)
throw
(
TrendException
);
//! Adds a nonstationary variable with its deflator
void
addNonstationaryVariables
(
vector
<
int
>
nonstationary_vars
,
expr_t
deflator
)
throw
(
TrendException
);
void
set_cutoff_to_zero
();
inline
static
std
::
string
c_Equation_Type
(
int
type
)
{
...
...
preprocessor/StaticModel.cc
View file @
69ddfadd
...
...
@@ -39,9 +39,7 @@ StaticModel::StaticModel(SymbolTable &symbol_table_arg,
NumericalConstants
&
num_constants_arg
,
ExternalFunctionsTable
&
external_functions_table_arg
)
:
ModelTree
(
symbol_table_arg
,
num_constants_arg
,
external_functions_table_arg
),
global_temporary_terms
(
true
),
cutoff
(
1e-15
),
mfs
(
0
)
global_temporary_terms
(
true
)
{
}
...
...
@@ -71,16 +69,6 @@ StaticModel::compileChainRuleDerivative(ofstream &code_file, unsigned int &instr
}
}
void
StaticModel
::
initializeVariablesAndEquations
()
{
for
(
int
j
=
0
;
j
<
equation_number
();
j
++
)
{
equation_reordered
.
push_back
(
j
);
variable_reordered
.
push_back
(
j
);
}
}
void
StaticModel
::
computeTemporaryTermsOrdered
()
{
...
...
@@ -1611,9 +1599,3 @@ StaticModel::writeAuxVarInitval(ostream &output, ExprNodeOutputType output_type)
output
<<
";"
<<
endl
;
}
}
void
StaticModel
::
set_cutoff_to_zero
()
{
cutoff
=
0
;
}
preprocessor/StaticModel.hh
View file @
69ddfadd
...
...
@@ -123,9 +123,6 @@ protected:
//! Indicate if the temporary terms are computed for the overall model (true) or not (false). Default value true
bool
global_temporary_terms
;
//! vector of block reordered variables and equations
vector
<
int
>
equation_reordered
,
variable_reordered
,
inv_equation_reordered
,
inv_variable_reordered
;
//! Vector describing equations: BlockSimulationType, if BlockSimulationType == EVALUATE_s then a expr_t on the new normalized equation
equation_type_and_normalized_equation_t
equation_type_and_normalized_equation
;
...
...
@@ -169,16 +166,6 @@ public:
//! Writes information on block decomposition when relevant
void
writeOutput
(
ostream
&
output
,
bool
block
)
const
;
//! Absolute value under which a number is considered to be zero
double
cutoff
;
//! Compute the minimum feedback set in the static model:
/*! 0 : all endogenous variables are considered as feedback variables
1 : the variables belonging to a non linear equation are considered as feedback variables
2 : the variables belonging to a non normalizable non linear equation are considered as feedback variables
default value = 0 */
int
mfs
;
//! the file containing the model and the derivatives code
ofstream
code_file
;
//! Execute computations (variable sorting + derivation)
/*!
\param jacobianExo whether derivatives w.r. to exo and exo_det should be in the Jacobian (derivatives w.r. to endo are always computed)
...
...
@@ -203,13 +190,8 @@ public:
//! Writes initializations in oo_.steady_state or steady state file for the auxiliary variables
void
writeAuxVarInitval
(
ostream
&
output
,
ExprNodeOutputType
output_type
)
const
;
//! Initialize equation_reordered & variable_reordered
void
initializeVariablesAndEquations
();
virtual
int
getDerivID
(
int
symb_id
,
int
lag
)
const
throw
(
UnknownDerivIDException
);
void
set_cutoff_to_zero
();
//! Return the number of blocks
virtual
unsigned
int
getNbBlocks
()
const
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment