Streamline some function names
parent
a541d23055
commit
9e6c01f132
|
@ -1036,21 +1036,16 @@ DynamicModel::writeDynamicMFile(const string &basename) const
|
|||
|
||||
ostringstream init_output, end_output;
|
||||
init_output << "residual = zeros(" << equations.size() << ", 1);";
|
||||
writeDynamicModelHelper(basename, "dynamic_resid", "residual",
|
||||
"dynamic_resid_tt",
|
||||
writeDynamicMFileHelper(basename, "dynamic_resid", "residual", "dynamic_resid_tt",
|
||||
temporary_terms_mlv.size() + temporary_terms_derivatives[0].size(),
|
||||
"", init_output, end_output,
|
||||
d_output[0], tt_output[0]);
|
||||
"", init_output, end_output, d_output[0], tt_output[0]);
|
||||
|
||||
init_output.str("");
|
||||
init_output << "g1 = zeros(" << equations.size() << ", " << getJacobianColsNbr() << ");";
|
||||
writeDynamicModelHelper(basename, "dynamic_g1", "g1",
|
||||
"dynamic_g1_tt",
|
||||
writeDynamicMFileHelper(basename, "dynamic_g1", "g1", "dynamic_g1_tt",
|
||||
temporary_terms_mlv.size() + temporary_terms_derivatives[0].size() + temporary_terms_derivatives[1].size(),
|
||||
"dynamic_resid_tt",
|
||||
init_output, end_output,
|
||||
d_output[1], tt_output[1]);
|
||||
writeWrapperFunctions(basename, "g1");
|
||||
"dynamic_resid_tt", init_output, end_output, d_output[1], tt_output[1]);
|
||||
writeDynamicMWrapperFunction(basename, "g1");
|
||||
|
||||
// For order ≥ 2
|
||||
int ncols{getJacobianColsNbr()};
|
||||
|
@ -1075,17 +1070,14 @@ DynamicModel::writeDynamicMFile(const string &basename) const
|
|||
}
|
||||
else
|
||||
init_output << gname << " = sparse([],[],[]," << equations.size() << "," << ncols << ");";
|
||||
writeDynamicModelHelper(basename, "dynamic_" + gname, gname,
|
||||
"dynamic_" + gname + "_tt",
|
||||
ntt,
|
||||
"dynamic_" + gprevname + "_tt",
|
||||
init_output, end_output,
|
||||
writeDynamicMFileHelper(basename, "dynamic_" + gname, gname, "dynamic_" + gname + "_tt", ntt,
|
||||
"dynamic_" + gprevname + "_tt", init_output, end_output,
|
||||
d_output[i], tt_output[i]);
|
||||
if (i <= 3)
|
||||
writeWrapperFunctions(basename, gname);
|
||||
writeDynamicMWrapperFunction(basename, gname);
|
||||
}
|
||||
|
||||
writeDynamicMatlabCompatLayer(basename);
|
||||
writeDynamicMCompatFile(basename);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1655,7 +1647,7 @@ DynamicModel::writeDynamicBlockCFile(const string &basename) const
|
|||
}
|
||||
|
||||
void
|
||||
DynamicModel::writeWrapperFunctions(const string &basename, const string &ending) const
|
||||
DynamicModel::writeDynamicMWrapperFunction(const string &basename, const string &ending) const
|
||||
{
|
||||
string name;
|
||||
if (ending == "g1")
|
||||
|
@ -1706,12 +1698,11 @@ DynamicModel::writeWrapperFunctions(const string &basename, const string &ending
|
|||
}
|
||||
|
||||
void
|
||||
DynamicModel::writeDynamicModelHelper(const string &basename,
|
||||
DynamicModel::writeDynamicMFileHelper(const string &basename,
|
||||
const string &name, const string &retvalname,
|
||||
const string &name_tt, size_t ttlen,
|
||||
const string &previous_tt_name,
|
||||
const ostringstream &init_s,
|
||||
const ostringstream &end_s,
|
||||
const ostringstream &init_s, const ostringstream &end_s,
|
||||
const ostringstream &s, const ostringstream &s_tt) const
|
||||
{
|
||||
string filename = packageDir(basename) + "/" + name_tt + ".m";
|
||||
|
@ -1793,7 +1784,7 @@ DynamicModel::writeDynamicModelHelper(const string &basename,
|
|||
}
|
||||
|
||||
void
|
||||
DynamicModel::writeDynamicMatlabCompatLayer(const string &basename) const
|
||||
DynamicModel::writeDynamicMCompatFile(const string &basename) const
|
||||
{
|
||||
string filename = packageDir(basename) + "/dynamic.m";
|
||||
ofstream output{filename, ios::out | ios::binary};
|
||||
|
@ -1821,7 +1812,7 @@ DynamicModel::writeDynamicMatlabCompatLayer(const string &basename) const
|
|||
}
|
||||
|
||||
void
|
||||
DynamicModel::writeDynamicJacobianNonZeroElts(const string &basename) const
|
||||
DynamicModel::writeDynamicJacobianNonZeroEltsFile(const string &basename) const
|
||||
{
|
||||
vector<pair<int, int>> nzij_pred, nzij_current, nzij_fwrd; // pairs (tsid, equation)
|
||||
for (const auto &[indices, d1] : derivatives[1])
|
||||
|
|
|
@ -213,17 +213,18 @@ private:
|
|||
//! Write reverse cross references
|
||||
void writeRevXrefs(ostream &output, const map<pair<int, int>, set<int>> &xrefmap, const string &type) const;
|
||||
|
||||
void writeWrapperFunctions(const string &name, const string &ending) const;
|
||||
void writeDynamicModelHelper(const string &basename,
|
||||
// Writes MATLAB/Octave wrapper function for computing residuals and derivatives at the same time
|
||||
void writeDynamicMWrapperFunction(const string &name, const string &ending) const;
|
||||
// Helper for writing MATLAB/Octave functions for residuals/derivatives and their temporary terms
|
||||
void writeDynamicMFileHelper(const string &basename,
|
||||
const string &name, const string &retvalname,
|
||||
const string &name_tt, size_t ttlen,
|
||||
const string &previous_tt_name,
|
||||
const ostringstream &init_s,
|
||||
const ostringstream &end_s,
|
||||
const ostringstream &init_s, const ostringstream &end_s,
|
||||
const ostringstream &s, const ostringstream &s_tt) const;
|
||||
|
||||
//! Create a legacy *_dynamic.m file for Matlab/Octave not yet using the temporary terms array interface
|
||||
void writeDynamicMatlabCompatLayer(const string &basename) const;
|
||||
//! Create a legacy *_dynamic.m file for MATLAB/Octave not yet using the temporary terms array interface
|
||||
void writeDynamicMCompatFile(const string &basename) const;
|
||||
|
||||
//! Internal helper for the copy constructor and assignment operator
|
||||
/*! Copies all the structures that contain ExprNode*, by the converting the
|
||||
|
@ -399,7 +400,7 @@ public:
|
|||
|
||||
//! Writes file containing coordinates of non-zero elements in the Jacobian
|
||||
/*! Used by the perfect_foresight_problem MEX */
|
||||
void writeDynamicJacobianNonZeroElts(const string &basename) const;
|
||||
void writeDynamicJacobianNonZeroEltsFile(const string &basename) const;
|
||||
|
||||
//! Creates mapping for variables and equations they are present in
|
||||
void createVariableMapping();
|
||||
|
|
|
@ -1079,7 +1079,7 @@ ModFile::writeMOutput(const string &basename, bool clear_all, bool clear_global,
|
|||
|
||||
dynamic_model.writeParamsDerivativesFile<false>(basename);
|
||||
|
||||
dynamic_model.writeDynamicJacobianNonZeroElts(basename);
|
||||
dynamic_model.writeDynamicJacobianNonZeroEltsFile(basename);
|
||||
}
|
||||
|
||||
// Create steady state file
|
||||
|
|
|
@ -843,7 +843,7 @@ StaticModel::writeStaticMFile(const string &basename) const
|
|||
end_output << "if ~isreal(residual)" << endl
|
||||
<< " residual = real(residual)+imag(residual).^2;" << endl
|
||||
<< "end";
|
||||
writeStaticModelHelper(basename, "static_resid", "residual", "static_resid_tt",
|
||||
writeStaticMFileHelper(basename, "static_resid", "residual", "static_resid_tt",
|
||||
temporary_terms_mlv.size() + temporary_terms_derivatives[0].size(),
|
||||
"", init_output, end_output,
|
||||
d_output[0], tt_output[0]);
|
||||
|
@ -854,12 +854,12 @@ StaticModel::writeStaticMFile(const string &basename) const
|
|||
end_output << "if ~isreal(g1)" << endl
|
||||
<< " g1 = real(g1)+2*imag(g1);" << endl
|
||||
<< "end";
|
||||
writeStaticModelHelper(basename, "static_g1", "g1", "static_g1_tt",
|
||||
writeStaticMFileHelper(basename, "static_g1", "g1", "static_g1_tt",
|
||||
temporary_terms_mlv.size() + temporary_terms_derivatives[0].size() + temporary_terms_derivatives[1].size(),
|
||||
"static_resid_tt",
|
||||
init_output, end_output,
|
||||
d_output[1], tt_output[1]);
|
||||
writeWrapperFunctions(basename, "g1");
|
||||
writeStaticMWrapperFunction(basename, "g1");
|
||||
|
||||
// For order ≥ 2
|
||||
int ncols{symbol_table.endo_nbr()};
|
||||
|
@ -884,21 +884,21 @@ StaticModel::writeStaticMFile(const string &basename) const
|
|||
}
|
||||
else
|
||||
init_output << gname << " = sparse([],[],[]," << equations.size() << "," << ncols << ");";
|
||||
writeStaticModelHelper(basename, "static_" + gname, gname,
|
||||
writeStaticMFileHelper(basename, "static_" + gname, gname,
|
||||
"static_" + gname + "_tt",
|
||||
ntt,
|
||||
"static_" + gprevname + "_tt",
|
||||
init_output, end_output,
|
||||
d_output[i], tt_output[i]);
|
||||
if (i <= 3)
|
||||
writeWrapperFunctions(basename, gname);
|
||||
writeStaticMWrapperFunction(basename, gname);
|
||||
}
|
||||
|
||||
writeStaticMatlabCompatLayer(basename);
|
||||
writeStaticMCompatFile(basename);
|
||||
}
|
||||
|
||||
void
|
||||
StaticModel::writeWrapperFunctions(const string &basename, const string &ending) const
|
||||
StaticModel::writeStaticMWrapperFunction(const string &basename, const string &ending) const
|
||||
{
|
||||
string name;
|
||||
if (ending == "g1")
|
||||
|
@ -949,7 +949,7 @@ StaticModel::writeWrapperFunctions(const string &basename, const string &ending)
|
|||
}
|
||||
|
||||
void
|
||||
StaticModel::writeStaticModelHelper(const string &basename,
|
||||
StaticModel::writeStaticMFileHelper(const string &basename,
|
||||
const string &name, const string &retvalname,
|
||||
const string &name_tt, size_t ttlen,
|
||||
const string &previous_tt_name,
|
||||
|
@ -1026,7 +1026,7 @@ StaticModel::writeStaticModelHelper(const string &basename,
|
|||
}
|
||||
|
||||
void
|
||||
StaticModel::writeStaticMatlabCompatLayer(const string &basename) const
|
||||
StaticModel::writeStaticMCompatFile(const string &basename) const
|
||||
{
|
||||
string filename = packageDir(basename) + "/static.m";
|
||||
ofstream output{filename, ios::out | ios::binary};
|
||||
|
|
|
@ -100,17 +100,18 @@ private:
|
|||
//! Computes chain rule derivatives of the Jacobian w.r. to endogenous variables
|
||||
void computeChainRuleJacobian();
|
||||
|
||||
//! Helper functions for writeStaticModel
|
||||
void writeStaticModelHelper(const string &basename,
|
||||
// Helper for writing MATLAB/Octave functions for residuals/derivatives and their temporary terms
|
||||
void writeStaticMFileHelper(const string &basename,
|
||||
const string &name, const string &retvalname,
|
||||
const string &name_tt, size_t ttlen,
|
||||
const string &previous_tt_name,
|
||||
const ostringstream &init_s, const ostringstream &end_s,
|
||||
const ostringstream &s, const ostringstream &s_tt) const;
|
||||
void writeWrapperFunctions(const string &basename, const string &ending) const;
|
||||
// Writes MATLAB/Octave wrapper function for computing residuals and derivatives at the same time
|
||||
void writeStaticMWrapperFunction(const string &basename, const string &ending) const;
|
||||
|
||||
//! Create a legacy *_static.m file for Matlab/Octave not yet using the temporary terms array interface
|
||||
void writeStaticMatlabCompatLayer(const string &name) const;
|
||||
//! Create a legacy *_static.m file for MATLAB/Octave not yet using the temporary terms array interface
|
||||
void writeStaticMCompatFile(const string &name) const;
|
||||
|
||||
public:
|
||||
StaticModel(SymbolTable &symbol_table_arg,
|
||||
|
|
Loading…
Reference in New Issue