clean up writing of static model

issue#70
Houtan Bastani 2015-07-27 15:59:13 +02:00
parent f3c14ec396
commit 6fc6f2f7d1
4 changed files with 34 additions and 17 deletions

View File

@ -1195,7 +1195,7 @@ PlannerObjectiveStatement::computingPass()
void
PlannerObjectiveStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const
{
model_tree->writeStaticFile(basename + "_objective", false, false, false);
model_tree->writeStaticFile(basename + "_objective", false, false, false, false);
}
BVARDensityStatement::BVARDensityStatement(int maxnlags_arg, const OptionsList &options_list_arg) :

View File

@ -810,7 +810,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo
{
if (!no_static)
{
static_model.writeStaticFile(basename, block, byte_code, use_dll);
static_model.writeStaticFile(basename, block, byte_code, use_dll, false);
static_model.writeParamsDerivativesFile(basename);
}
@ -854,7 +854,7 @@ ModFile::writeExternalFilesC(const string &basename, FileOutputType output) cons
dynamic_model.writeDynamicFile(basename, block, byte_code, use_dll, mod_file_struct.order_option);
if (!no_static)
static_model.writeStaticFile(basename, false, false, true);
static_model.writeStaticFile(basename, false, false, true, false);
// static_model.writeStaticCFile(basename, block, byte_code, use_dll);
@ -959,7 +959,7 @@ ModFile::writeExternalFilesCC(const string &basename, FileOutputType output) con
dynamic_model.writeDynamicFile(basename, block, byte_code, use_dll, mod_file_struct.order_option);
if (!no_static)
static_model.writeStaticFile(basename, false, false, true);
static_model.writeStaticFile(basename, false, false, true, false);
// static_model.writeStaticCFile(basename, block, byte_code, use_dll);
// static_model.writeParamsDerivativesFileC(basename, cuda);
@ -1083,6 +1083,7 @@ ModFile::writeExternalFilesJulia(const string &basename, FileOutputType output)
<< "##" << endl
<< "using DynareModel" << endl
<< "using Utils" << endl
<< "using " << basename << "Static" << endl
<< "export dynamicmodel!, staticmodel!, steadystate!" << endl
<< "export model__" << endl
<< "model__ = model()" << endl
@ -1115,9 +1116,10 @@ ModFile::writeExternalFilesJulia(const string &basename, FileOutputType output)
if (dynamic_model.equation_number() > 0)
if (!no_static)
static_model.writeStaticFile(basename, false, false, false, &jlOutputFile);
static_model.writeStaticFile(basename, false, false, false, true);
jlOutputFile << "end" << endl;
jlOutputFile << "model__.static = " << basename << "Static.getStaticFunction()" << endl
<< "end" << endl;
jlOutputFile.close();
cout << "done" << endl;
}

View File

@ -1560,16 +1560,31 @@ StaticModel::writeStaticCFile(const string &func_name) const
}
void
StaticModel::writeStaticJuliaFile(ofstream &jlOutputFile) const
StaticModel::writeStaticJuliaFile(const string &basename) const
{
jlOutputFile << "model__.static = function static(y, x, params)" << endl;
writeStaticModel(jlOutputFile, false, true);
jlOutputFile << "(residual, g1, g2, g3)" << endl
<< "end" << endl;
string filename = basename + "Static.jl";
ofstream output;
output.open(filename.c_str(), ios::out | ios::binary);
if (!output.is_open())
{
cerr << "ERROR: Can't open file " << filename << " for writing" << endl;
exit(EXIT_FAILURE);
}
output << "module " << basename << "Static" << endl << endl
<< "export getStaticFunction" << endl << endl
<< "function getStaticFunction()" << endl
<< " static" << endl
<< "end" << endl << endl
<< "function static(y, x, params)" << endl;
writeStaticModel(output, false, true);
output << "(residual, g1, g2, g3)" << endl
<< "end" << endl
<< "end" << endl;
}
void
StaticModel::writeStaticFile(const string &basename, bool block, bool bytecode, bool use_dll, ofstream *jlOutputFile) const
StaticModel::writeStaticFile(const string &basename, bool block, bool bytecode, bool use_dll, bool julia) const
{
int r;
@ -1598,8 +1613,8 @@ StaticModel::writeStaticFile(const string &basename, bool block, bool bytecode,
}
else if(use_dll)
writeStaticCFile(basename);
else if (jlOutputFile != NULL)
writeStaticJuliaFile(*jlOutputFile);
else if (julia)
writeStaticJuliaFile(basename);
else
writeStaticMFile(basename);
writeAuxVarRecursiveDefinitions(basename);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2003-2012 Dynare Team
* Copyright (C) 2003-2015 Dynare Team
*
* This file is part of Dynare.
*
@ -51,7 +51,7 @@ private:
void writeStaticCFile(const string &func_name) const;
//! Writes static model file (Julia version)
void writeStaticJuliaFile(ofstream &jlOutputFile) const;
void writeStaticJuliaFile(const string &basename) const;
//! Writes the static model equations and its derivatives
void writeStaticModel(ostream &StaticOutput, bool use_dll, bool julia) const;
@ -171,7 +171,7 @@ public:
int &u_count_int, bool &file_open) const;
//! Writes static model file
void writeStaticFile(const string &basename, bool block, bool bytecode, bool use_dll, ofstream *jlOutputFile = NULL) const;
void writeStaticFile(const string &basename, bool block, bool bytecode, bool use_dll, bool julia) const;
//! Writes file containing static parameters derivatives
void writeParamsDerivativesFile(const string &basename) const;