[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
|
||||
{
|
||||
|
||||
class FuncData;
|
||||
|
||||
/**
|
||||
* Exception thrown when a CVODES error is encountered.
|
||||
* @deprecated Unused. To be removed after Cantera 2.3.
|
||||
|
|
@ -109,7 +107,6 @@ private:
|
|||
double m_hmax, m_hmin;
|
||||
int m_maxsteps;
|
||||
int m_maxErrTestFails;
|
||||
std::unique_ptr<FuncData> m_fdata;
|
||||
N_Vector* m_yS;
|
||||
size_t m_np;
|
||||
int m_mupper, m_mlower;
|
||||
|
|
|
|||
|
|
@ -58,8 +58,13 @@ public:
|
|||
|
||||
//! Number of sensitivity parameters.
|
||||
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
|
||||
{
|
||||
|
||||
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" {
|
||||
/**
|
||||
* Function called by cvodes to evaluate ydot given y. The CVODE integrator
|
||||
|
|
@ -54,13 +42,11 @@ extern "C" {
|
|||
* evaluates the desired equations.
|
||||
* @ingroup odeGroup
|
||||
*/
|
||||
static int cvodes_rhs(realtype t, N_Vector y, N_Vector ydot,
|
||||
void* f_data)
|
||||
static int cvodes_rhs(realtype t, N_Vector y, N_Vector ydot, void* f_data)
|
||||
{
|
||||
try {
|
||||
FuncData* d = (FuncData*)f_data;
|
||||
FuncEval* f = d->m_func;
|
||||
f->eval(t, NV_DATA_S(y), NV_DATA_S(ydot), d->m_pars.data());
|
||||
FuncEval* f = (FuncEval*) f_data;
|
||||
f->eval(t, NV_DATA_S(y), NV_DATA_S(ydot), f->m_sens_params.data());
|
||||
} catch (CanteraError& err) {
|
||||
std::cerr << err.what() << std::endl;
|
||||
return 1; // possibly recoverable error
|
||||
|
|
@ -309,17 +295,14 @@ void CVodesIntegrator::initialize(double t0, FuncEval& func)
|
|||
}
|
||||
}
|
||||
|
||||
// pass a pointer to func in m_data
|
||||
m_fdata.reset(new FuncData(&func, func.nparams()));
|
||||
|
||||
flag = CVodeSetUserData(m_cvode_mem, m_fdata.get());
|
||||
flag = CVodeSetUserData(m_cvode_mem, &func);
|
||||
if (flag != CV_SUCCESS) {
|
||||
throw CanteraError("CVodesIntegrator::initialize",
|
||||
"CVodeSetUserData failed.");
|
||||
}
|
||||
if (func.nparams() > 0) {
|
||||
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);
|
||||
}
|
||||
applyOptions();
|
||||
|
|
|
|||
|
|
@ -266,6 +266,7 @@ void ReactorNet::registerSensitivityReaction(void* reactor,
|
|||
m_paramNames.push_back(name);
|
||||
m_sensOrder[R][reactionIndex] = m_ntotpar;
|
||||
m_ntotpar++;
|
||||
m_sens_params.push_back(1.0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue