detrend epilogue equations

issue#70
Houtan Bastani 2019-12-04 15:48:33 +01:00
parent 8dc70602c8
commit 3694fc40b3
No known key found for this signature in database
GPG Key ID: 000094FB955BE169
4 changed files with 43 additions and 1 deletions

View File

@ -486,6 +486,16 @@ public:
//! Transforms the model by removing trends specified by the user
void detrendEquations();
inline const nonstationary_symbols_map_t & getNonstationarySymbolsMap() const
{
return nonstationary_symbols_map;
}
inline const map<int, expr_t> & getTrendSymbolsMap() const
{
return trend_symbols_map;
}
//! Substitutes adl operator
void substituteAdl();

View File

@ -514,6 +514,9 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, const
dynamic_model.detrendEquations();
trend_dynamic_model = dynamic_model;
dynamic_model.removeTrendVariableFromEquations();
const auto & trend_symbols = dynamic_model.getTrendSymbolsMap();
const auto & nonstationary_symbols = dynamic_model.getNonstationarySymbolsMap();
epilogue.detrend(trend_symbols, nonstationary_symbols);
}
mod_file_struct.orig_eq_nbr = dynamic_model.equation_number();

View File

@ -335,6 +335,31 @@ Epilogue::checkPass(WarningConsolidation &warnings) const
so_far_defined.push_back(it.first);
}
void
Epilogue::detrend(const map<int, expr_t> & trend_symbols_map,
const nonstationary_symbols_map_t & nonstationary_symbols_map)
{
for (auto it = nonstationary_symbols_map.crbegin();
it != nonstationary_symbols_map.crend(); it++)
for (auto & [symb_id, expr] : def_table)
{
expr = expr->detrend(it->first, it->second.first, it->second.second);
assert(expr != nullptr);
}
for (auto & [symb_id, expr] : def_table)
{
expr = expr->removeTrendLeadLag(trend_symbols_map);
assert(expr != nullptr);
}
for (auto & [symb_id, expr] : def_table)
{
expr = expr->replaceTrendVar();
assert(expr != nullptr);
}
}
void
Epilogue::writeEpilogueFile(const string &basename) const
{

View File

@ -1,5 +1,5 @@
/*
* Copyright © 2010-2018 Dynare Team
* Copyright © 2010-2019 Dynare Team
*
* This file is part of Dynare.
*
@ -89,6 +89,10 @@ public:
//! Checks that no variable is declared twice
void checkPass(WarningConsolidation &warnings) const;
//! Deal with trend variables in the epilogue block
void detrend(const map<int, expr_t> & trend_symbols_map,
const nonstationary_symbols_map_t & nonstationary_symbols_map);
//! Write the steady state file
void writeEpilogueFile(const string &basename) const;
};