Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
dynare
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
119
Issues
119
List
Boards
Labels
Service Desk
Milestones
Merge Requests
5
Merge Requests
5
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dynare
dynare
Commits
6e1d5bdf
Commit
6e1d5bdf
authored
Oct 16, 2017
by
Houtan Bastani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
preprocessor: json: print steady_state_model file
parent
d4e3dbe3
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
194 additions
and
61 deletions
+194
-61
preprocessor/ExprNode.cc
preprocessor/ExprNode.cc
+58
-42
preprocessor/ExprNode.hh
preprocessor/ExprNode.hh
+27
-19
preprocessor/ModFile.cc
preprocessor/ModFile.cc
+30
-0
preprocessor/StaticModel.cc
preprocessor/StaticModel.cc
+32
-0
preprocessor/StaticModel.hh
preprocessor/StaticModel.hh
+1
-0
preprocessor/SteadyStateModel.cc
preprocessor/SteadyStateModel.cc
+44
-0
preprocessor/SteadyStateModel.hh
preprocessor/SteadyStateModel.hh
+2
-0
No files found.
preprocessor/ExprNode.cc
View file @
6e1d5bdf
...
...
@@ -195,7 +195,8 @@ ExprNode::writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output
void
ExprNode
::
writeJsonExternalFunctionOutput
(
vector
<
string
>
&
efout
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
{
// Nothing to do
}
...
...
@@ -340,7 +341,8 @@ NumConstNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
void
NumConstNode
::
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
{
output
<<
datatree
.
num_constants
.
get
(
id
);
}
...
...
@@ -640,7 +642,8 @@ VariableNode::containsExternalFunction() const
void
VariableNode
::
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
{
temporary_terms_t
::
const_iterator
it
=
temporary_terms
.
find
(
const_cast
<
VariableNode
*>
(
this
));
if
(
it
!=
temporary_terms
.
end
())
...
...
@@ -650,7 +653,7 @@ VariableNode::writeJsonOutput(ostream &output,
}
output
<<
datatree
.
symbol_table
.
getName
(
symb_id
);
if
(
lag
!=
0
)
if
(
isdynamic
&&
lag
!=
0
)
output
<<
"("
<<
lag
<<
")"
;
}
...
...
@@ -1892,7 +1895,8 @@ UnaryOpNode::containsExternalFunction() const
void
UnaryOpNode
::
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
{
temporary_terms_t
::
const_iterator
it
=
temporary_terms
.
find
(
const_cast
<
UnaryOpNode
*>
(
this
));
if
(
it
!=
temporary_terms
.
end
())
...
...
@@ -1966,7 +1970,7 @@ UnaryOpNode::writeJsonOutput(ostream &output,
break
;
case
oSteadyState
:
output
<<
"("
;
arg
->
writeJsonOutput
(
output
,
temporary_terms
,
tef_terms
);
arg
->
writeJsonOutput
(
output
,
temporary_terms
,
tef_terms
,
isdynamic
);
output
<<
")"
;
return
;
case
oSteadyStateParamDeriv
:
...
...
@@ -2017,7 +2021,7 @@ UnaryOpNode::writeJsonOutput(ostream &output,
}
// Write argument
arg
->
writeJsonOutput
(
output
,
temporary_terms
,
tef_terms
);
arg
->
writeJsonOutput
(
output
,
temporary_terms
,
tef_terms
,
isdynamic
);
if
(
close_parenthesis
)
output
<<
")"
;
...
...
@@ -2227,9 +2231,10 @@ UnaryOpNode::writeExternalFunctionOutput(ostream &output, ExprNodeOutputType out
void
UnaryOpNode
::
writeJsonExternalFunctionOutput
(
vector
<
string
>
&
efout
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
{
arg
->
writeJsonExternalFunctionOutput
(
efout
,
temporary_terms
,
tef_terms
);
arg
->
writeJsonExternalFunctionOutput
(
efout
,
temporary_terms
,
tef_terms
,
isdynamic
);
}
void
...
...
@@ -3300,7 +3305,8 @@ BinaryOpNode::containsExternalFunction() const
void
BinaryOpNode
::
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
{
// If current node is a temporary term
temporary_terms_t
::
const_iterator
it
=
temporary_terms
.
find
(
const_cast
<
BinaryOpNode
*>
(
this
));
...
...
@@ -3323,9 +3329,9 @@ BinaryOpNode::writeJsonOutput(ostream &output,
default:
;
}
arg1
->
writeJsonOutput
(
output
,
temporary_terms
,
tef_terms
);
arg1
->
writeJsonOutput
(
output
,
temporary_terms
,
tef_terms
,
isdynamic
);
output
<<
","
;
arg2
->
writeJsonOutput
(
output
,
temporary_terms
,
tef_terms
);
arg2
->
writeJsonOutput
(
output
,
temporary_terms
,
tef_terms
,
isdynamic
);
output
<<
")"
;
return
;
}
...
...
@@ -3333,9 +3339,9 @@ BinaryOpNode::writeJsonOutput(ostream &output,
if
(
op_code
==
oPowerDeriv
)
{
output
<<
"get_power_deriv("
;
arg1
->
writeJsonOutput
(
output
,
temporary_terms
,
tef_terms
);
arg1
->
writeJsonOutput
(
output
,
temporary_terms
,
tef_terms
,
isdynamic
);
output
<<
","
;
arg2
->
writeJsonOutput
(
output
,
temporary_terms
,
tef_terms
);
arg2
->
writeJsonOutput
(
output
,
temporary_terms
,
tef_terms
,
isdynamic
);
output
<<
","
<<
powerDerivOrder
<<
")"
;
return
;
}
...
...
@@ -3355,7 +3361,7 @@ BinaryOpNode::writeJsonOutput(ostream &output,
}
// Write left argument
arg1
->
writeJsonOutput
(
output
,
temporary_terms
,
tef_terms
);
arg1
->
writeJsonOutput
(
output
,
temporary_terms
,
tef_terms
,
isdynamic
);
if
(
close_parenthesis
)
output
<<
")"
;
...
...
@@ -3422,7 +3428,7 @@ BinaryOpNode::writeJsonOutput(ostream &output,
}
// Write right argument
arg2
->
writeJsonOutput
(
output
,
temporary_terms
,
tef_terms
);
arg2
->
writeJsonOutput
(
output
,
temporary_terms
,
tef_terms
,
isdynamic
);
if
(
close_parenthesis
)
output
<<
")"
;
...
...
@@ -3620,10 +3626,11 @@ BinaryOpNode::writeExternalFunctionOutput(ostream &output, ExprNodeOutputType ou
void
BinaryOpNode
::
writeJsonExternalFunctionOutput
(
vector
<
string
>
&
efout
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
{
arg1
->
writeJsonExternalFunctionOutput
(
efout
,
temporary_terms
,
tef_terms
);
arg2
->
writeJsonExternalFunctionOutput
(
efout
,
temporary_terms
,
tef_terms
);
arg1
->
writeJsonExternalFunctionOutput
(
efout
,
temporary_terms
,
tef_terms
,
isdynamic
);
arg2
->
writeJsonExternalFunctionOutput
(
efout
,
temporary_terms
,
tef_terms
,
isdynamic
);
}
void
...
...
@@ -4578,7 +4585,8 @@ TrinaryOpNode::containsExternalFunction() const
void
TrinaryOpNode
::
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
{
// If current node is a temporary term
temporary_terms_t
::
const_iterator
it
=
temporary_terms
.
find
(
const_cast
<
TrinaryOpNode
*>
(
this
));
...
...
@@ -4598,11 +4606,11 @@ TrinaryOpNode::writeJsonOutput(ostream &output,
break
;
}
arg1
->
writeJsonOutput
(
output
,
temporary_terms
,
tef_terms
);
arg1
->
writeJsonOutput
(
output
,
temporary_terms
,
tef_terms
,
isdynamic
);
output
<<
","
;
arg2
->
writeJsonOutput
(
output
,
temporary_terms
,
tef_terms
);
arg2
->
writeJsonOutput
(
output
,
temporary_terms
,
tef_terms
,
isdynamic
);
output
<<
","
;
arg3
->
writeJsonOutput
(
output
,
temporary_terms
,
tef_terms
);
arg3
->
writeJsonOutput
(
output
,
temporary_terms
,
tef_terms
,
isdynamic
);
output
<<
")"
;
}
...
...
@@ -4685,11 +4693,12 @@ TrinaryOpNode::writeExternalFunctionOutput(ostream &output, ExprNodeOutputType o
void
TrinaryOpNode
::
writeJsonExternalFunctionOutput
(
vector
<
string
>
&
efout
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
{
arg1
->
writeJsonExternalFunctionOutput
(
efout
,
temporary_terms
,
tef_terms
);
arg2
->
writeJsonExternalFunctionOutput
(
efout
,
temporary_terms
,
tef_terms
);
arg3
->
writeJsonExternalFunctionOutput
(
efout
,
temporary_terms
,
tef_terms
);
arg1
->
writeJsonExternalFunctionOutput
(
efout
,
temporary_terms
,
tef_terms
,
isdynamic
);
arg2
->
writeJsonExternalFunctionOutput
(
efout
,
temporary_terms
,
tef_terms
,
isdynamic
);
arg3
->
writeJsonExternalFunctionOutput
(
efout
,
temporary_terms
,
tef_terms
,
isdynamic
);
}
void
...
...
@@ -5298,7 +5307,8 @@ AbstractExternalFunctionNode::writeExternalFunctionArguments(ostream &output, Ex
void
AbstractExternalFunctionNode
::
writeJsonExternalFunctionArguments
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
{
for
(
vector
<
expr_t
>::
const_iterator
it
=
arguments
.
begin
();
it
!=
arguments
.
end
();
it
++
)
...
...
@@ -5306,7 +5316,7 @@ AbstractExternalFunctionNode::writeJsonExternalFunctionArguments(ostream &output
if
(
it
!=
arguments
.
begin
())
output
<<
","
;
(
*
it
)
->
writeJsonOutput
(
output
,
temporary_terms
,
tef_terms
);
(
*
it
)
->
writeJsonOutput
(
output
,
temporary_terms
,
tef_terms
,
isdynamic
);
}
}
...
...
@@ -5476,7 +5486,8 @@ ExternalFunctionNode::compileExternalFunctionOutput(ostream &CompileCode, unsign
void
ExternalFunctionNode
::
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
{
temporary_terms_t
::
const_iterator
it
=
temporary_terms
.
find
(
const_cast
<
ExternalFunctionNode
*>
(
this
));
if
(
it
!=
temporary_terms
.
end
())
...
...
@@ -5486,7 +5497,7 @@ ExternalFunctionNode::writeJsonOutput(ostream &output,
}
output
<<
datatree
.
symbol_table
.
getName
(
symb_id
)
<<
"("
;
writeJsonExternalFunctionArguments
(
output
,
temporary_terms
,
tef_terms
);
writeJsonExternalFunctionArguments
(
output
,
temporary_terms
,
tef_terms
,
isdynamic
);
output
<<
")"
;
}
...
...
@@ -5602,14 +5613,15 @@ ExternalFunctionNode::writeExternalFunctionOutput(ostream &output, ExprNodeOutpu
void
ExternalFunctionNode
::
writeJsonExternalFunctionOutput
(
vector
<
string
>
&
efout
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
{
int
first_deriv_symb_id
=
datatree
.
external_functions_table
.
getFirstDerivSymbID
(
symb_id
);
assert
(
first_deriv_symb_id
!=
eExtFunSetButNoNameProvided
);
for
(
vector
<
expr_t
>::
const_iterator
it
=
arguments
.
begin
();
it
!=
arguments
.
end
();
it
++
)
(
*
it
)
->
writeJsonExternalFunctionOutput
(
efout
,
temporary_terms
,
tef_terms
);
(
*
it
)
->
writeJsonExternalFunctionOutput
(
efout
,
temporary_terms
,
tef_terms
,
isdynamic
);
if
(
!
alreadyWrittenAsTefTerm
(
symb_id
,
tef_terms
))
{
...
...
@@ -5629,7 +5641,7 @@ ExternalFunctionNode::writeJsonExternalFunctionOutput(vector<string> &efout,
ef
<<
",
\"
external_function_term_dd
\"
:
\"
TEFDD_"
<<
indx
<<
"
\"
"
;
ef
<<
",
\"
value
\"
:
\"
"
<<
datatree
.
symbol_table
.
getName
(
symb_id
)
<<
"("
;
writeJsonExternalFunctionArguments
(
ef
,
temporary_terms
,
tef_terms
);
writeJsonExternalFunctionArguments
(
ef
,
temporary_terms
,
tef_terms
,
isdynamic
);
ef
<<
")
\"
}}"
;
efout
.
push_back
(
ef
.
str
());
}
...
...
@@ -5719,7 +5731,8 @@ FirstDerivExternalFunctionNode::composeDerivatives(const vector<expr_t> &dargs)
void
FirstDerivExternalFunctionNode
::
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
{
// If current node is a temporary term
temporary_terms_t
::
const_iterator
it
=
temporary_terms
.
find
(
const_cast
<
FirstDerivExternalFunctionNode
*>
(
this
));
...
...
@@ -5934,7 +5947,8 @@ FirstDerivExternalFunctionNode::writeExternalFunctionOutput(ostream &output, Exp
void
FirstDerivExternalFunctionNode
::
writeJsonExternalFunctionOutput
(
vector
<
string
>
&
efout
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
{
int
first_deriv_symb_id
=
datatree
.
external_functions_table
.
getFirstDerivSymbID
(
symb_id
);
assert
(
first_deriv_symb_id
!=
eExtFunSetButNoNameProvided
);
...
...
@@ -5944,7 +5958,7 @@ FirstDerivExternalFunctionNode::writeJsonExternalFunctionOutput(vector<string> &
if
(
first_deriv_symb_id
==
symb_id
)
{
expr_t
parent
=
datatree
.
AddExternalFunction
(
symb_id
,
arguments
);
parent
->
writeJsonExternalFunctionOutput
(
efout
,
temporary_terms
,
tef_terms
);
parent
->
writeJsonExternalFunctionOutput
(
efout
,
temporary_terms
,
tef_terms
,
isdynamic
);
return
;
}
...
...
@@ -5967,7 +5981,7 @@ FirstDerivExternalFunctionNode::writeJsonExternalFunctionOutput(vector<string> &
<<
",
\"
value
\"
:
\"
"
<<
datatree
.
symbol_table
.
getName
(
first_deriv_symb_id
)
<<
"("
;
}
writeJsonExternalFunctionArguments
(
ef
,
temporary_terms
,
tef_terms
);
writeJsonExternalFunctionArguments
(
ef
,
temporary_terms
,
tef_terms
,
isdynamic
);
ef
<<
")
\"
}}"
;
efout
.
push_back
(
ef
.
str
());
}
...
...
@@ -6100,7 +6114,8 @@ SecondDerivExternalFunctionNode::composeDerivatives(const vector<expr_t> &dargs)
void
SecondDerivExternalFunctionNode
::
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
{
// If current node is a temporary term
temporary_terms_t
::
const_iterator
it
=
temporary_terms
.
find
(
const_cast
<
SecondDerivExternalFunctionNode
*>
(
this
));
...
...
@@ -6293,7 +6308,8 @@ SecondDerivExternalFunctionNode::writeExternalFunctionOutput(ostream &output, Ex
void
SecondDerivExternalFunctionNode
::
writeJsonExternalFunctionOutput
(
vector
<
string
>
&
efout
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
{
int
second_deriv_symb_id
=
datatree
.
external_functions_table
.
getSecondDerivSymbID
(
symb_id
);
assert
(
second_deriv_symb_id
!=
eExtFunSetButNoNameProvided
);
...
...
@@ -6303,7 +6319,7 @@ SecondDerivExternalFunctionNode::writeJsonExternalFunctionOutput(vector<string>
if
(
second_deriv_symb_id
==
symb_id
)
{
expr_t
parent
=
datatree
.
AddExternalFunction
(
symb_id
,
arguments
);
parent
->
writeJsonExternalFunctionOutput
(
efout
,
temporary_terms
,
tef_terms
);
parent
->
writeJsonExternalFunctionOutput
(
efout
,
temporary_terms
,
tef_terms
,
isdynamic
);
return
;
}
...
...
@@ -6327,7 +6343,7 @@ SecondDerivExternalFunctionNode::writeJsonExternalFunctionOutput(vector<string>
<<
",
\"
value
\"
:
\"
"
<<
datatree
.
symbol_table
.
getName
(
second_deriv_symb_id
)
<<
"("
;
}
writeJsonExternalFunctionArguments
(
ef
,
temporary_terms
,
tef_terms
);
writeJsonExternalFunctionArguments
(
ef
,
temporary_terms
,
tef_terms
,
isdynamic
);
ef
<<
")
\"
}}"
<<
endl
;
efout
.
push_back
(
ef
.
str
());
}
...
...
preprocessor/ExprNode.hh
View file @
6e1d5bdf
...
...
@@ -223,7 +223,7 @@ enum ExprNodeOutputType
void
writeOutput
(
ostream
&
output
,
ExprNodeOutputType
output_type
,
const
temporary_terms_t
&
temporary_terms
)
const
;
//! Writes output of node in JSON syntax
virtual
void
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
=
0
;
virtual
void
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
=
true
)
const
=
0
;
virtual
int
precedenceJson
(
const
temporary_terms_t
&
temporary_terms
)
const
;
...
...
@@ -236,7 +236,8 @@ enum ExprNodeOutputType
//! Allows the insertion of commas if necessary
virtual
void
writeJsonExternalFunctionOutput
(
vector
<
string
>
&
efout
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
=
true
)
const
;
virtual
void
compileExternalFunctionOutput
(
ostream
&
CompileCode
,
unsigned
int
&
instruction_number
,
bool
lhs_rhs
,
const
temporary_terms_t
&
temporary_terms
,
...
...
@@ -490,7 +491,7 @@ public:
};
virtual
void
prepareForDerivation
();
virtual
void
writeOutput
(
ostream
&
output
,
ExprNodeOutputType
output_type
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
void
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
void
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
;
virtual
bool
containsExternalFunction
()
const
;
virtual
void
collectDynamicVariables
(
SymbolType
type_arg
,
set
<
pair
<
int
,
int
>
>
&
result
)
const
;
virtual
void
collectTemporary_terms
(
const
temporary_terms_t
&
temporary_terms
,
temporary_terms_inuse_t
&
temporary_terms_inuse
,
int
Curr_Block
)
const
;
...
...
@@ -540,7 +541,7 @@ public:
VariableNode
(
DataTree
&
datatree_arg
,
int
symb_id_arg
,
int
lag_arg
);
virtual
void
prepareForDerivation
();
virtual
void
writeOutput
(
ostream
&
output
,
ExprNodeOutputType
output_type
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
void
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
void
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
;
virtual
bool
containsExternalFunction
()
const
;
virtual
void
collectDynamicVariables
(
SymbolType
type_arg
,
set
<
pair
<
int
,
int
>
>
&
result
)
const
;
virtual
void
computeTemporaryTerms
(
map
<
expr_t
,
int
>
&
reference_count
,
...
...
@@ -620,14 +621,15 @@ public:
map
<
NodeTreeReference
,
temporary_terms_t
>
&
temp_terms_map
,
bool
is_matlab
,
NodeTreeReference
tr
)
const
;
virtual
void
writeOutput
(
ostream
&
output
,
ExprNodeOutputType
output_type
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
void
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
void
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
;
virtual
bool
containsExternalFunction
()
const
;
virtual
void
writeExternalFunctionOutput
(
ostream
&
output
,
ExprNodeOutputType
output_type
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
void
writeJsonExternalFunctionOutput
(
vector
<
string
>
&
efout
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
;
virtual
void
compileExternalFunctionOutput
(
ostream
&
CompileCode
,
unsigned
int
&
instruction_number
,
bool
lhs_rhs
,
const
temporary_terms_t
&
temporary_terms
,
const
map_idx_t
&
map_idx
,
bool
dynamic
,
bool
steady_dynamic
,
...
...
@@ -712,14 +714,15 @@ public:
map
<
NodeTreeReference
,
temporary_terms_t
>
&
temp_terms_map
,
bool
is_matlab
,
NodeTreeReference
tr
)
const
;
virtual
void
writeOutput
(
ostream
&
output
,
ExprNodeOutputType
output_type
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
void
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
void
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
;
virtual
bool
containsExternalFunction
()
const
;
virtual
void
writeExternalFunctionOutput
(
ostream
&
output
,
ExprNodeOutputType
output_type
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
void
writeJsonExternalFunctionOutput
(
vector
<
string
>
&
efout
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
;
virtual
void
compileExternalFunctionOutput
(
ostream
&
CompileCode
,
unsigned
int
&
instruction_number
,
bool
lhs_rhs
,
const
temporary_terms_t
&
temporary_terms
,
const
map_idx_t
&
map_idx
,
bool
dynamic
,
bool
steady_dynamic
,
...
...
@@ -821,14 +824,15 @@ public:
map
<
NodeTreeReference
,
temporary_terms_t
>
&
temp_terms_map
,
bool
is_matlab
,
NodeTreeReference
tr
)
const
;
virtual
void
writeOutput
(
ostream
&
output
,
ExprNodeOutputType
output_type
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
void
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
void
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
;
virtual
bool
containsExternalFunction
()
const
;
virtual
void
writeExternalFunctionOutput
(
ostream
&
output
,
ExprNodeOutputType
output_type
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
void
writeJsonExternalFunctionOutput
(
vector
<
string
>
&
efout
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
;
virtual
void
compileExternalFunctionOutput
(
ostream
&
CompileCode
,
unsigned
int
&
instruction_number
,
bool
lhs_rhs
,
const
temporary_terms_t
&
temporary_terms
,
const
map_idx_t
&
map_idx
,
bool
dynamic
,
bool
steady_dynamic
,
...
...
@@ -895,7 +899,7 @@ protected:
int
getIndxInTefTerms
(
int
the_symb_id
,
deriv_node_temp_terms_t
&
tef_terms
)
const
throw
(
UnknownFunctionNameAndArgs
);
//! Helper function to write output arguments of any given external function
void
writeExternalFunctionArguments
(
ostream
&
output
,
ExprNodeOutputType
output_type
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
void
writeJsonExternalFunctionArguments
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
void
writeJsonExternalFunctionArguments
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
;
public:
AbstractExternalFunctionNode
(
DataTree
&
datatree_arg
,
int
symb_id_arg
,
const
vector
<
expr_t
>
&
arguments_arg
);
...
...
@@ -904,14 +908,15 @@ public:
map
<
NodeTreeReference
,
temporary_terms_t
>
&
temp_terms_map
,
bool
is_matlab
,
NodeTreeReference
tr
)
const
=
0
;
virtual
void
writeOutput
(
ostream
&
output
,
ExprNodeOutputType
output_type
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
=
0
;
virtual
void
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
=
0
;
virtual
void
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
=
true
)
const
=
0
;
virtual
bool
containsExternalFunction
()
const
;
virtual
void
writeExternalFunctionOutput
(
ostream
&
output
,
ExprNodeOutputType
output_type
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
=
0
;
virtual
void
writeJsonExternalFunctionOutput
(
vector
<
string
>
&
efout
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
=
0
;
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
=
true
)
const
=
0
;
virtual
void
compileExternalFunctionOutput
(
ostream
&
CompileCode
,
unsigned
int
&
instruction_number
,
bool
lhs_rhs
,
const
temporary_terms_t
&
temporary_terms
,
const
map_idx_t
&
map_idx
,
bool
dynamic
,
bool
steady_dynamic
,
...
...
@@ -974,13 +979,14 @@ public:
map
<
NodeTreeReference
,
temporary_terms_t
>
&
temp_terms_map
,
bool
is_matlab
,
NodeTreeReference
tr
)
const
;
virtual
void
writeOutput
(
ostream
&
output
,
ExprNodeOutputType
output_type
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
void
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
void
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
;
virtual
void
writeExternalFunctionOutput
(
ostream
&
output
,
ExprNodeOutputType
output_type
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
void
writeJsonExternalFunctionOutput
(
vector
<
string
>
&
efout
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
;
virtual
void
compileExternalFunctionOutput
(
ostream
&
CompileCode
,
unsigned
int
&
instruction_number
,
bool
lhs_rhs
,
const
temporary_terms_t
&
temporary_terms
,
const
map_idx_t
&
map_idx
,
bool
dynamic
,
bool
steady_dynamic
,
...
...
@@ -1018,7 +1024,7 @@ public:
vector
<
vector
<
temporary_terms_t
>
>
&
v_temporary_terms
,
int
equation
)
const
;
virtual
void
writeOutput
(
ostream
&
output
,
ExprNodeOutputType
output_type
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
void
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
void
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
;
virtual
void
compile
(
ostream
&
CompileCode
,
unsigned
int
&
instruction_number
,
bool
lhs_rhs
,
const
temporary_terms_t
&
temporary_terms
,
const
map_idx_t
&
map_idx
,
bool
dynamic
,
bool
steady_dynamic
,
...
...
@@ -1028,7 +1034,8 @@ public:
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
void
writeJsonExternalFunctionOutput
(
vector
<
string
>
&
efout
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
;
virtual
void
compileExternalFunctionOutput
(
ostream
&
CompileCode
,
unsigned
int
&
instruction_number
,
bool
lhs_rhs
,
const
temporary_terms_t
&
temporary_terms
,
const
map_idx_t
&
map_idx
,
bool
dynamic
,
bool
steady_dynamic
,
...
...
@@ -1061,7 +1068,7 @@ public:
vector
<
vector
<
temporary_terms_t
>
>
&
v_temporary_terms
,
int
equation
)
const
;
virtual
void
writeOutput
(
ostream
&
output
,
ExprNodeOutputType
output_type
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
void
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
void
writeJsonOutput
(
ostream
&
output
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
;
virtual
void
compile
(
ostream
&
CompileCode
,
unsigned
int
&
instruction_number
,
bool
lhs_rhs
,
const
temporary_terms_t
&
temporary_terms
,
const
map_idx_t
&
map_idx
,
bool
dynamic
,
bool
steady_dynamic
,
...
...
@@ -1071,7 +1078,8 @@ public:
deriv_node_temp_terms_t
&
tef_terms
)
const
;
virtual
void
writeJsonExternalFunctionOutput
(
vector
<
string
>
&
efout
,
const
temporary_terms_t
&
temporary_terms
,
deriv_node_temp_terms_t
&
tef_terms
)
const
;
deriv_node_temp_terms_t
&
tef_terms
,
const
bool
isdynamic
)
const
;
virtual
void
compileExternalFunctionOutput
(
ostream
&
CompileCode
,
unsigned
int
&
instruction_number
,
bool
lhs_rhs
,
const
temporary_terms_t
&
temporary_terms
,
const
map_idx_t
&
map_idx
,
bool
dynamic
,
bool
steady_dynamic
,
...
...
preprocessor/ModFile.cc
View file @
6e1d5bdf
...
...
@@ -1382,6 +1382,12 @@ ModFile::writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType
original_model_output
<<
"}"
<<
endl
;
}
ostringstream
steady_state_model_output
;
steady_state_model_output
<<
""
;
if
(
dynamic_model
.
equation_number
()
>
0
)
steady_state_model
.
writeJsonSteadyStateFile
(
steady_state_model_output
,
transformpass
||
computingpass
);
if
(
json_output_mode
==
standardout
)
{
if
(
transformpass
||
computingpass
)
...
...
@@ -1391,6 +1397,8 @@ ModFile::writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType
cout
<<
output
.
str
();
if
(
!
original_model_output
.
str
().
empty
())
cout
<<
",
\"
original_model
\"
: "
<<
original_model_output
.
str
();
if
(
!
steady_state_model_output
.
str
().
empty
())
cout
<<
",
\"
steady_state_model
\"
: "
<<
steady_state_model_output
.
str
();
}
else
{
...
...
@@ -1438,6 +1446,28 @@ ModFile::writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType
jsonOutputFile
<<
original_model_output
.
str
();
jsonOutputFile
.
close
();
}
if
(
!
steady_state_model_output
.
str
().
empty
())
{
if
(
basename
.
size
())
{
string
fname
(
basename
);
fname
+=
"_steady_state_model.json"
;
jsonOutputFile
.
open
(
fname
.
c_str
(),
ios
::
out
|
ios
::
binary
);
if
(
!
jsonOutputFile
.
is_open
())
{
cerr
<<
"ERROR: Can't open file "
<<
fname
<<
" for writing"
<<
endl
;
exit
(
EXIT_FAILURE
);
}
}
else
{
cerr
<<
"ERROR: Missing file name"
<<
endl
;
exit
(
EXIT_FAILURE
);
}
jsonOutputFile
<<
steady_state_model_output
.
str
();
jsonOutputFile
.
close
();
}
}
}
...
...
preprocessor/StaticModel.cc
View file @
6e1d5bdf
...
...
@@ -2197,6 +2197,38 @@ StaticModel::writeLatexAuxVarRecursiveDefinitions(ostream &output) const
}
}
void
StaticModel
::
writeJsonAuxVarRecursiveDefinitions
(
ostream
&
output
)
const
{
deriv_node_temp_terms_t
tef_terms
;
temporary_terms_t
temporary_terms
;
for
(
int
i
=
0
;
i
<
(
int
)
aux_equations
.
size
();
i
++
)
if
(
dynamic_cast
<
ExprNode
*>
(
aux_equations
[
i
])
->
containsExternalFunction
())
{
vector
<
string
>
efout
;
dynamic_cast
<
ExprNode
*>
(
aux_equations
[
i
])
->
writeJsonExternalFunctionOutput
(
efout
,
temporary_terms
,
tef_terms
,
false
);
for
(
vector
<
string
>::
const_iterator
it
=
efout
.
begin
();
it
!=
efout
.
end
();
it
++
)
{
if
(
it
!=
efout
.
begin
())
output
<<
", "
;
output
<<
*
it
;
}
}
for
(
int
i
=
0
;
i
<
(
int
)
aux_equations
.
size
();
i
++
)
{
output
<<
", {
\"
lhs
\"
:
\"
"
;
aux_equations
[
i
]
->
get_arg1
()
->
writeJsonOutput
(
output
,
temporary_terms
,
tef_terms
,
false
);
output
<<
"
\"
,
\"
rhs
\"
:
\"
"
;
dynamic_cast
<
BinaryOpNode
*>
(
aux_equations
[
i
]
->
substituteStaticAuxiliaryDefinition
())
->
get_arg2
()
->
writeJsonOutput
(
output
,
temporary_terms
,
tef_terms
,
false
);
output
<<
"
\"
}"
;
}
}
void
StaticModel
::
writeParamsDerivativesFile
(
const
string
&
basename
,
bool
julia
)
const
{
...
...
preprocessor/StaticModel.hh
View file @
6e1d5bdf
...
...
@@ -192,6 +192,7 @@ public:
void
writeSetAuxiliaryVariables
(
const
string
&
basename
,
const
bool
julia
)
const
;
void
writeAuxVarRecursiveDefinitions
(
ostream
&
output
,
ExprNodeOutputType
output_type
)
const
;
void
writeLatexAuxVarRecursiveDefinitions
(
ostream
&
output
)
const
;
void
writeJsonAuxVarRecursiveDefinitions
(
ostream
&
output
)
const
;
//! To ensure that no exogenous is present in the planner objective
//! See #1264
...
...
preprocessor/SteadyStateModel.cc
View file @
6e1d5bdf
...
...
@@ -270,3 +270,47 @@ SteadyStateModel::writeSteadyStateFileC(const string &basename, bool ramsey_mode
static_model
.
writeAuxVarInitval
(
output
,
oCSteadyStateFile
);
output
<<
"}"
<<
endl
;
}
void
SteadyStateModel
::
writeJsonSteadyStateFile
(
ostream
&
output
,
bool
transformComputingPass
)
const
{
if
(
def_table
.
size
()
==
0
)
return
;
deriv_node_temp_terms_t
tef_terms
;
vector
<
pair
<
string
,
string
>
>
eqtags
;
temporary_terms_t
tt_empty
;
output
<<
"{
\"
steady_state_model
\"
: ["
;
for
(
size_t
i
=
0
;
i
<
def_table
.
size
();
i
++
)
{
const
vector
<
int
>
&
symb_ids
=
def_table
[
i
].
first
;
if
(
i
!=
0
)
output
<<
","
;
output
<<
"{
\"
lhs
\"
: "
;
if
(
symb_ids
.
size
()
>
1
)
output
<<
"["
;
for
(
size_t
j
=
0
;
j
<
symb_ids
.
size
();
j
++
)
{
if
(
j
!=
0
)
output
<<
","
;
variable_node_map_t
::
const_iterator
it
=
variable_node_map
.
find
(
make_pair
(
symb_ids
[
j
],
0
));
assert
(
it
!=
variable_node_map
.
end
());
output
<<
"
\"
"
;
dynamic_cast
<
ExprNode
*>
(
it
->
second
)
->
writeJsonOutput
(
output
,
tt_empty
,
tef_terms
,
false
);
output
<<
"
\"
"
;