Added support for equation tags (thanks to Pablo for providing a patch)
git-svn-id: https://www.dynare.org/svn/dynare/trunk@2880 ac1d8469-bf42-47a9-8791-bf33cf982152time-shift
parent
a56de57637
commit
9a1339ad11
|
@ -1923,6 +1923,14 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block, b
|
||||||
}
|
}
|
||||||
output << "]';" << endl;
|
output << "]';" << endl;
|
||||||
|
|
||||||
|
// Write equation tags
|
||||||
|
output << "M_.equations_tags = {" << endl;
|
||||||
|
for (int i = 0; i < equation_tags.size(); i++)
|
||||||
|
output << " " << equation_tags[i].first + 1 << " , '"
|
||||||
|
<< equation_tags[i].second.first << "' , '"
|
||||||
|
<< equation_tags[i].second.second << "' ;" << endl;
|
||||||
|
output << "};" << endl;
|
||||||
|
|
||||||
//In case of sparse model, writes the block structure of the model
|
//In case of sparse model, writes the block structure of the model
|
||||||
if (block)
|
if (block)
|
||||||
{
|
{
|
||||||
|
|
|
@ -474,6 +474,18 @@ equation : hand_side EQUAL hand_side ';'
|
||||||
{ $$ = driver.add_model_equal($1, $3); }
|
{ $$ = driver.add_model_equal($1, $3); }
|
||||||
| hand_side ';'
|
| hand_side ';'
|
||||||
{ $$ = driver.add_model_equal_with_zero_rhs($1); }
|
{ $$ = driver.add_model_equal_with_zero_rhs($1); }
|
||||||
|
| '[' tags_list ']' hand_side EQUAL hand_side ';'
|
||||||
|
{ $$ = driver.add_model_equal($4, $6); }
|
||||||
|
| '[' tags_list ']' hand_side ';'
|
||||||
|
{ $$ = driver.add_model_equal_with_zero_rhs($4); }
|
||||||
|
;
|
||||||
|
|
||||||
|
tags_list : tags_list COMMA tag_pair
|
||||||
|
| tag_pair
|
||||||
|
;
|
||||||
|
|
||||||
|
tag_pair : NAME EQUAL QUOTED_STRING
|
||||||
|
{ driver.add_equation_tags($1, $3); }
|
||||||
;
|
;
|
||||||
|
|
||||||
hand_side : '(' hand_side ')'
|
hand_side : '(' hand_side ')'
|
||||||
|
|
|
@ -279,3 +279,9 @@ ModelTree::addEquation(NodeID eq)
|
||||||
|
|
||||||
equations.push_back(beq);
|
equations.push_back(beq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ModelTree::addEquationTags(int i, const string &key, const string &value)
|
||||||
|
{
|
||||||
|
equation_tags.push_back(make_pair(i, make_pair(key, value)));
|
||||||
|
}
|
||||||
|
|
|
@ -36,6 +36,9 @@ protected:
|
||||||
//! Stores declared equations
|
//! Stores declared equations
|
||||||
vector<BinaryOpNode *> equations;
|
vector<BinaryOpNode *> equations;
|
||||||
|
|
||||||
|
//! Stores equation tags
|
||||||
|
vector<pair<int, pair<string, string> > > equation_tags;
|
||||||
|
|
||||||
//! Number of non-zero derivatives
|
//! Number of non-zero derivatives
|
||||||
int NNZDerivatives[3];
|
int NNZDerivatives[3];
|
||||||
|
|
||||||
|
@ -47,7 +50,6 @@ protected:
|
||||||
*/
|
*/
|
||||||
first_derivatives_type first_derivatives;
|
first_derivatives_type first_derivatives;
|
||||||
|
|
||||||
|
|
||||||
typedef map<pair<int, pair<int, int> >, NodeID> second_derivatives_type;
|
typedef map<pair<int, pair<int, int> >, NodeID> second_derivatives_type;
|
||||||
//! Second order derivatives
|
//! Second order derivatives
|
||||||
/*! First index is equation number, second and third are variables w.r. to which is computed the derivative.
|
/*! First index is equation number, second and third are variables w.r. to which is computed the derivative.
|
||||||
|
@ -98,6 +100,8 @@ public:
|
||||||
ModelTree(SymbolTable &symbol_table_arg, NumericalConstants &num_constants);
|
ModelTree(SymbolTable &symbol_table_arg, NumericalConstants &num_constants);
|
||||||
//! Declare a node as an equation of the model
|
//! Declare a node as an equation of the model
|
||||||
void addEquation(NodeID eq);
|
void addEquation(NodeID eq);
|
||||||
|
//! Adds tags to equation number i
|
||||||
|
void addEquationTags(int i, const string &key, const string &value);
|
||||||
//! Returns the number of equations in the model
|
//! Returns the number of equations in the model
|
||||||
int equation_number() const;
|
int equation_number() const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -144,6 +144,15 @@ ParsingDriver::declare_parameter(string *name, string *tex_name)
|
||||||
declare_symbol(name, eParameter, tex_name);
|
declare_symbol(name, eParameter, tex_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ParsingDriver::add_equation_tags(string *key, string *value)
|
||||||
|
{
|
||||||
|
int n = model_tree->equation_number();
|
||||||
|
model_tree->addEquationTags(n, *key, *value);
|
||||||
|
delete key;
|
||||||
|
delete value;
|
||||||
|
}
|
||||||
|
|
||||||
NodeID
|
NodeID
|
||||||
ParsingDriver::add_constant(string *constant)
|
ParsingDriver::add_constant(string *constant)
|
||||||
{
|
{
|
||||||
|
|
|
@ -193,6 +193,8 @@ public:
|
||||||
void declare_and_init_model_local_variable(string *name, NodeID rhs);
|
void declare_and_init_model_local_variable(string *name, NodeID rhs);
|
||||||
//! Changes type of a symbol
|
//! Changes type of a symbol
|
||||||
void change_type(SymbolType new_type, vector<string *> *var_list);
|
void change_type(SymbolType new_type, vector<string *> *var_list);
|
||||||
|
//! Adds a list of tags for the current equation
|
||||||
|
void add_equation_tags(string *key, string *value);
|
||||||
//! Adds a constant to DataTree
|
//! Adds a constant to DataTree
|
||||||
NodeID add_constant(string *constant);
|
NodeID add_constant(string *constant);
|
||||||
//! Adds a NaN constant to DataTree
|
//! Adds a NaN constant to DataTree
|
||||||
|
|
Loading…
Reference in New Issue