Commit 30d34f24 authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Preprocessor: only compute on demand the 2nd derivatives of residual and...

Preprocessor: only compute on demand the 2nd derivatives of residual and jacobian w.r.t. parameters and the derivative of hessian w.r.t. parameters
parent 4a23d931
......@@ -2764,47 +2764,50 @@ DynamicModel::writeParamsDerivativesFile(const string &basename) const
paramsDerivsFile << ";" << endl;
}
// Write parameter second derivatives
paramsDerivsFile << "rpp = zeros(" << equation_number() << ", " << symbol_table.param_nbr() << ", "
// Write jacobian derivatives
paramsDerivsFile << "gp = zeros(" << equation_number() << ", " << dynJacobianColsNbr << ", "
<< symbol_table.param_nbr() << ");" << endl;
for (second_derivatives_type::const_iterator it = residuals_params_second_derivatives.begin();
it != residuals_params_second_derivatives.end(); it++)
for (second_derivatives_type::const_iterator it = jacobian_params_derivatives.begin();
it != jacobian_params_derivatives.end(); it++)
{
int eq = it->first.first;
int param1 = it->first.second.first;
int param2 = it->first.second.second;
int var = it->first.second.first;
int param = it->first.second.second;
NodeID d2 = it->second;
int param1_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param1)) + 1;
int param2_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param2)) + 1;
int var_col = getDynJacobianCol(var) + 1;
int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1;
paramsDerivsFile << "rpp(" << eq+1 << ", " << param1_col << ", " << param2_col << ") = ";
paramsDerivsFile << "gp(" << eq+1 << ", " << var_col << ", " << param_col << ") = ";
d2->writeOutput(paramsDerivsFile, oMatlabDynamicModel, params_derivs_temporary_terms);
paramsDerivsFile << ";" << endl;
}
// Write jacobian derivatives
paramsDerivsFile << "gp = zeros(" << equation_number() << ", " << dynJacobianColsNbr << ", "
// If nargout >= 3...
paramsDerivsFile << "if nargout >= 3" << endl;
// Write parameter second derivatives (only if nargout >= 3)
paramsDerivsFile << "rpp = zeros(" << equation_number() << ", " << symbol_table.param_nbr() << ", "
<< symbol_table.param_nbr() << ");" << endl;
for (second_derivatives_type::const_iterator it = jacobian_params_derivatives.begin();
it != jacobian_params_derivatives.end(); it++)
for (second_derivatives_type::const_iterator it = residuals_params_second_derivatives.begin();
it != residuals_params_second_derivatives.end(); it++)
{
int eq = it->first.first;
int var = it->first.second.first;
int param = it->first.second.second;
int param1 = it->first.second.first;
int param2 = it->first.second.second;
NodeID d2 = it->second;
int var_col = getDynJacobianCol(var) + 1;
int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1;
int param1_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param1)) + 1;
int param2_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param2)) + 1;
paramsDerivsFile << "gp(" << eq+1 << ", " << var_col << ", " << param_col << ") = ";
paramsDerivsFile << "rpp(" << eq+1 << ", " << param1_col << ", " << param2_col << ") = ";
d2->writeOutput(paramsDerivsFile, oMatlabDynamicModel, params_derivs_temporary_terms);
paramsDerivsFile << ";" << endl;
}
// Write jacobian second derivatives
// Write jacobian second derivatives (only if nargout >= 3)
paramsDerivsFile << "gpp = zeros(" << equation_number() << ", " << dynJacobianColsNbr << ", "
<< symbol_table.param_nbr() << ", " << symbol_table.param_nbr() << ");" << endl;
......@@ -2826,7 +2829,11 @@ DynamicModel::writeParamsDerivativesFile(const string &basename) const
paramsDerivsFile << ";" << endl;
}
// Write hessian derivatives
// If nargout >= 5...
paramsDerivsFile << "end" << endl
<< "if nargout >= 5" << endl;
// Write hessian derivatives (only if nargout >= 5)
paramsDerivsFile << "hp = zeros(" << equation_number() << ", " << dynJacobianColsNbr << ", "
<< dynJacobianColsNbr << ", " << symbol_table.param_nbr() << ");" << endl;
......@@ -2848,6 +2855,8 @@ DynamicModel::writeParamsDerivativesFile(const string &basename) const
paramsDerivsFile << ";" << endl;
}
paramsDerivsFile << "end" << endl;
paramsDerivsFile.close();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment