[Reactor] Move sensitivity parameter vector into FuncEval
This eliminates the need for class FuncData, and makes it possible to introduce sensitivity parameters which have a nominal values other than 1.0.
This commit is contained in:
parent
51b0e46277
commit
032bb9c363
4 changed files with 12 additions and 26 deletions
|
|
@ -14,8 +14,6 @@
|
||||||
namespace Cantera
|
namespace Cantera
|
||||||
{
|
{
|
||||||
|
|
||||||
class FuncData;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exception thrown when a CVODES error is encountered.
|
* Exception thrown when a CVODES error is encountered.
|
||||||
* @deprecated Unused. To be removed after Cantera 2.3.
|
* @deprecated Unused. To be removed after Cantera 2.3.
|
||||||
|
|
@ -109,7 +107,6 @@ private:
|
||||||
double m_hmax, m_hmin;
|
double m_hmax, m_hmin;
|
||||||
int m_maxsteps;
|
int m_maxsteps;
|
||||||
int m_maxErrTestFails;
|
int m_maxErrTestFails;
|
||||||
std::unique_ptr<FuncData> m_fdata;
|
|
||||||
N_Vector* m_yS;
|
N_Vector* m_yS;
|
||||||
size_t m_np;
|
size_t m_np;
|
||||||
int m_mupper, m_mlower;
|
int m_mupper, m_mlower;
|
||||||
|
|
|
||||||
|
|
@ -58,8 +58,13 @@ public:
|
||||||
|
|
||||||
//! Number of sensitivity parameters.
|
//! Number of sensitivity parameters.
|
||||||
virtual size_t nparams() {
|
virtual size_t nparams() {
|
||||||
return 0;
|
return m_sens_params.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Values for the problem parameters for which sensitivities are computed
|
||||||
|
//! This is the array which is perturbed and passed back as the fourth
|
||||||
|
//! argument to eval().
|
||||||
|
vector_fp m_sens_params;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,18 +33,6 @@ typedef long int sd_size_t;
|
||||||
namespace Cantera
|
namespace Cantera
|
||||||
{
|
{
|
||||||
|
|
||||||
class FuncData
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
FuncData(FuncEval* f, size_t npar = 0) {
|
|
||||||
m_pars.resize(npar, 1.0);
|
|
||||||
m_func = f;
|
|
||||||
}
|
|
||||||
virtual ~FuncData() {}
|
|
||||||
vector_fp m_pars;
|
|
||||||
FuncEval* m_func;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
/**
|
/**
|
||||||
* Function called by cvodes to evaluate ydot given y. The CVODE integrator
|
* Function called by cvodes to evaluate ydot given y. The CVODE integrator
|
||||||
|
|
@ -54,13 +42,11 @@ extern "C" {
|
||||||
* evaluates the desired equations.
|
* evaluates the desired equations.
|
||||||
* @ingroup odeGroup
|
* @ingroup odeGroup
|
||||||
*/
|
*/
|
||||||
static int cvodes_rhs(realtype t, N_Vector y, N_Vector ydot,
|
static int cvodes_rhs(realtype t, N_Vector y, N_Vector ydot, void* f_data)
|
||||||
void* f_data)
|
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
FuncData* d = (FuncData*)f_data;
|
FuncEval* f = (FuncEval*) f_data;
|
||||||
FuncEval* f = d->m_func;
|
f->eval(t, NV_DATA_S(y), NV_DATA_S(ydot), f->m_sens_params.data());
|
||||||
f->eval(t, NV_DATA_S(y), NV_DATA_S(ydot), d->m_pars.data());
|
|
||||||
} catch (CanteraError& err) {
|
} catch (CanteraError& err) {
|
||||||
std::cerr << err.what() << std::endl;
|
std::cerr << err.what() << std::endl;
|
||||||
return 1; // possibly recoverable error
|
return 1; // possibly recoverable error
|
||||||
|
|
@ -309,17 +295,14 @@ void CVodesIntegrator::initialize(double t0, FuncEval& func)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// pass a pointer to func in m_data
|
flag = CVodeSetUserData(m_cvode_mem, &func);
|
||||||
m_fdata.reset(new FuncData(&func, func.nparams()));
|
|
||||||
|
|
||||||
flag = CVodeSetUserData(m_cvode_mem, m_fdata.get());
|
|
||||||
if (flag != CV_SUCCESS) {
|
if (flag != CV_SUCCESS) {
|
||||||
throw CanteraError("CVodesIntegrator::initialize",
|
throw CanteraError("CVodesIntegrator::initialize",
|
||||||
"CVodeSetUserData failed.");
|
"CVodeSetUserData failed.");
|
||||||
}
|
}
|
||||||
if (func.nparams() > 0) {
|
if (func.nparams() > 0) {
|
||||||
sensInit(t0, func);
|
sensInit(t0, func);
|
||||||
flag = CVodeSetSensParams(m_cvode_mem, m_fdata->m_pars.data(),
|
flag = CVodeSetSensParams(m_cvode_mem, func.m_sens_params.data(),
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
}
|
}
|
||||||
applyOptions();
|
applyOptions();
|
||||||
|
|
|
||||||
|
|
@ -266,6 +266,7 @@ void ReactorNet::registerSensitivityReaction(void* reactor,
|
||||||
m_paramNames.push_back(name);
|
m_paramNames.push_back(name);
|
||||||
m_sensOrder[R][reactionIndex] = m_ntotpar;
|
m_sensOrder[R][reactionIndex] = m_ntotpar;
|
||||||
m_ntotpar++;
|
m_ntotpar++;
|
||||||
|
m_sens_params.push_back(1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue