2008-01-11 14:42:14 +01:00
|
|
|
/*
|
2012-01-23 16:52:27 +01:00
|
|
|
* Copyright (C) 2003-2012 Dynare Team
|
2008-01-11 14:42:14 +01: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/>.
|
|
|
|
*/
|
|
|
|
|
2006-11-05 00:31:17 +01:00
|
|
|
#ifndef _NUMERICALINITIALIZATION_HH
|
|
|
|
#define _NUMERICALINITIALIZATION_HH
|
2006-12-12 12:54:30 +01:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2006-11-05 00:31:17 +01:00
|
|
|
#include <string>
|
2009-02-27 13:19:25 +01:00
|
|
|
#include <vector>
|
2006-12-12 12:54:30 +01:00
|
|
|
#include <map>
|
|
|
|
|
2006-11-05 00:31:17 +01:00
|
|
|
#include "SymbolTable.hh"
|
2007-03-09 18:27:46 +01:00
|
|
|
#include "ExprNode.hh"
|
2006-12-12 12:54:30 +01:00
|
|
|
#include "Statement.hh"
|
|
|
|
|
|
|
|
class InitParamStatement : public Statement
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
2006-12-12 12:54:30 +01:00
|
|
|
private:
|
2009-02-27 13:19:25 +01:00
|
|
|
const int symb_id;
|
2010-09-16 19:18:45 +02:00
|
|
|
const expr_t param_value;
|
2006-11-28 12:56:02 +01:00
|
|
|
const SymbolTable &symbol_table;
|
2006-12-12 12:54:30 +01:00
|
|
|
public:
|
2010-09-16 19:18:45 +02:00
|
|
|
InitParamStatement(int symb_id_arg, const expr_t param_value_arg,
|
2006-12-12 12:54:30 +01:00
|
|
|
const SymbolTable &symbol_table_arg);
|
2012-01-23 16:52:27 +01:00
|
|
|
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
2006-12-19 00:28:52 +01:00
|
|
|
virtual void writeOutput(ostream &output, const string &basename) const;
|
2009-02-27 13:19:25 +01:00
|
|
|
//! Fill eval context with parameter value
|
2010-09-16 19:00:48 +02:00
|
|
|
void fillEvalContext(eval_context_t &eval_context) const;
|
2006-12-12 12:54:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class InitOrEndValStatement : public Statement
|
|
|
|
{
|
|
|
|
public:
|
2006-11-05 00:31:17 +01:00
|
|
|
/*!
|
2006-12-12 12:54:30 +01:00
|
|
|
We use a vector instead of a map, since the order of declaration matters:
|
|
|
|
an initialization can depend on a previously initialized variable inside the block
|
2006-11-05 00:31:17 +01:00
|
|
|
*/
|
2010-09-16 19:18:45 +02:00
|
|
|
typedef vector<pair<int, expr_t> > init_values_t;
|
2006-12-12 12:54:30 +01:00
|
|
|
protected:
|
2010-09-16 19:00:48 +02:00
|
|
|
const init_values_t init_values;
|
2006-12-12 12:54:30 +01:00
|
|
|
const SymbolTable &symbol_table;
|
2012-10-31 15:23:02 +01:00
|
|
|
const bool all_values_required;
|
2006-12-12 12:54:30 +01:00
|
|
|
public:
|
2010-09-16 19:00:48 +02:00
|
|
|
InitOrEndValStatement(const init_values_t &init_values_arg,
|
2012-10-31 15:23:02 +01:00
|
|
|
const SymbolTable &symbol_table_arg,
|
|
|
|
const bool &all_values_required_arg);
|
|
|
|
//! Return set of unused variables by type
|
|
|
|
set<int> getUninitializedVariables(SymbolType type);
|
2009-02-27 13:19:25 +01:00
|
|
|
//! Fill eval context with variables values
|
2010-09-16 19:00:48 +02:00
|
|
|
void fillEvalContext(eval_context_t &eval_context) const;
|
2006-12-12 12:54:30 +01:00
|
|
|
protected:
|
|
|
|
void writeInitValues(ostream &output) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class InitValStatement : public InitOrEndValStatement
|
|
|
|
{
|
|
|
|
public:
|
2010-09-16 19:00:48 +02:00
|
|
|
InitValStatement(const init_values_t &init_values_arg,
|
2012-10-31 15:23:02 +01:00
|
|
|
const SymbolTable &symbol_table_arg,
|
|
|
|
const bool &all_values_required_arg);
|
|
|
|
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
2006-12-19 00:28:52 +01:00
|
|
|
virtual void writeOutput(ostream &output, const string &basename) const;
|
2011-12-28 11:11:06 +01:00
|
|
|
//! Writes initializations for oo_.exo_simul and oo_.exo_det_simul
|
2009-09-30 17:10:31 +02:00
|
|
|
void writeOutputPostInit(ostream &output) const;
|
2006-12-12 12:54:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class EndValStatement : public InitOrEndValStatement
|
|
|
|
{
|
|
|
|
public:
|
2010-09-16 19:00:48 +02:00
|
|
|
EndValStatement(const init_values_t &init_values_arg,
|
2012-10-31 15:23:02 +01:00
|
|
|
const SymbolTable &symbol_table_arg,
|
|
|
|
const bool &all_values_required_arg);
|
2009-10-29 18:16:10 +01:00
|
|
|
//! Workaround for trac ticket #35
|
2012-01-23 16:52:27 +01:00
|
|
|
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
2006-12-19 00:28:52 +01:00
|
|
|
virtual void writeOutput(ostream &output, const string &basename) const;
|
2006-12-12 12:54:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class HistValStatement : public Statement
|
|
|
|
{
|
|
|
|
public:
|
2006-11-05 00:31:17 +01:00
|
|
|
/*!
|
2006-12-12 12:54:30 +01:00
|
|
|
Contrary to Initval and Endval, we use a map, since it is impossible to reuse
|
|
|
|
a given initialization value in a second initialization inside the block.
|
2010-09-16 19:18:45 +02:00
|
|
|
Maps pairs (symbol_id, lag) to expr_t
|
2006-11-05 00:31:17 +01:00
|
|
|
*/
|
2010-09-16 19:18:45 +02:00
|
|
|
typedef map<pair<int, int>, expr_t> hist_values_t;
|
2006-12-12 12:54:30 +01:00
|
|
|
private:
|
2010-09-16 19:00:48 +02:00
|
|
|
const hist_values_t hist_values;
|
2006-12-12 12:54:30 +01:00
|
|
|
const SymbolTable &symbol_table;
|
|
|
|
public:
|
2010-09-16 19:00:48 +02:00
|
|
|
HistValStatement(const hist_values_t &hist_values_arg,
|
2006-12-12 12:54:30 +01:00
|
|
|
const SymbolTable &symbol_table_arg);
|
2011-02-04 12:38:12 +01:00
|
|
|
//! Workaround for trac ticket #157
|
2012-01-23 16:52:27 +01:00
|
|
|
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
2006-12-19 00:28:52 +01:00
|
|
|
virtual void writeOutput(ostream &output, const string &basename) const;
|
2006-11-05 00:31:17 +01:00
|
|
|
};
|
2006-12-12 12:54:30 +01:00
|
|
|
|
2008-04-14 09:22:10 +02:00
|
|
|
class InitvalFileStatement : public Statement
|
|
|
|
{
|
|
|
|
private:
|
2008-04-14 11:17:15 +02:00
|
|
|
const string filename;
|
2008-04-14 09:22:10 +02:00
|
|
|
public:
|
2008-04-14 11:17:15 +02:00
|
|
|
InitvalFileStatement(const string &filename_arg);
|
2008-04-14 09:22:10 +02:00
|
|
|
virtual void writeOutput(ostream &output, const string &basename) const;
|
|
|
|
};
|
|
|
|
|
2007-11-26 17:31:48 +01:00
|
|
|
class HomotopyStatement : public Statement
|
|
|
|
{
|
|
|
|
public:
|
2008-04-03 18:22:52 +02:00
|
|
|
//! Stores the declarations of homotopy_setup
|
2010-09-16 19:18:45 +02:00
|
|
|
/*! Order matter so we use a vector. First expr_t can be NULL if no initial value given. */
|
|
|
|
typedef vector<pair<int, pair<expr_t, expr_t> > > homotopy_values_t;
|
2007-11-26 17:31:48 +01:00
|
|
|
private:
|
2010-09-16 19:00:48 +02:00
|
|
|
const homotopy_values_t homotopy_values;
|
2007-11-26 17:31:48 +01:00
|
|
|
const SymbolTable &symbol_table;
|
|
|
|
public:
|
2010-09-16 19:00:48 +02:00
|
|
|
HomotopyStatement(const homotopy_values_t &homotopy_values_arg,
|
2008-03-31 18:19:16 +02:00
|
|
|
const SymbolTable &symbol_table_arg);
|
2007-11-26 17:31:48 +01:00
|
|
|
virtual void writeOutput(ostream &output, const string &basename) const;
|
|
|
|
};
|
2009-02-27 13:19:25 +01:00
|
|
|
|
|
|
|
class SaveParamsAndSteadyStateStatement : public Statement
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
const string filename;
|
|
|
|
public:
|
|
|
|
SaveParamsAndSteadyStateStatement(const string &filename_arg);
|
|
|
|
virtual void writeOutput(ostream &output, const string &basename) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class LoadParamsAndSteadyStateStatement : public Statement
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
const SymbolTable &symbol_table;
|
2009-03-24 17:29:58 +01:00
|
|
|
//! Content of the file
|
|
|
|
/*! Maps symbol ID to numeric value (stored as string) */
|
|
|
|
map<int, string> content;
|
2009-02-27 13:19:25 +01:00
|
|
|
public:
|
2009-03-24 17:29:58 +01:00
|
|
|
LoadParamsAndSteadyStateStatement(const string &filename,
|
2012-01-23 16:52:27 +01:00
|
|
|
const SymbolTable &symbol_table_arg,
|
|
|
|
WarningConsolidation &warnings);
|
2009-02-27 13:19:25 +01:00
|
|
|
virtual void writeOutput(ostream &output, const string &basename) const;
|
|
|
|
//! Fill eval context with parameters/variables values
|
2010-09-16 19:00:48 +02:00
|
|
|
void fillEvalContext(eval_context_t &eval_context) const;
|
2009-02-27 13:19:25 +01:00
|
|
|
};
|
|
|
|
|
2006-11-05 00:31:17 +01:00
|
|
|
#endif
|