From: Eric F. <efe...@ph...> - 2008-09-18 03:57:46
|
Hi, I want to encapsulate the odeSolver data structures and integratorInstance in a C++ class but integration segfaults in some conditions. class Engine { private: odeModel_t* odeModel; cvodeSettings_t* settings; integratorInstance_t* engine; double simTime; public: Engine(odeModel_t*, double); ~Engine(); void integrateSimple(); }; ---> in the constructor I build the integratorInstance and try to integrate one step: Engine::Engine(odeModel_t* om, double time) : odeModel(om), simTime(time) { cout << "Engine Constr" << endl; // Create the settings and the integrator instance cvodeSettings_t* settings = CvodeSettings_createWith(simTime, simTime * PSFACTOR, ABS_ERR, REL_ERR, 10000, 0, 0, 1, 0, 0, 0, 1, 0, 2); CvodeSettings_setCompileFunctions(settings, 1); CvodeSettings_setSteadyStateThreshold(settings, 1e-11); CvodeSettings_setResetCvodeOnEvent(settings, 1); integratorInstance_t* engine = IntegratorInstance_create(om, settings); IntegratorInstance_integrateOneStep(engine); //// TESTING cout << IntegratorInstance_getTime(engine) << endl; } ----> this works: my constructor creates the engine object and integrates one step succesfully. ----> However, if my constructor calls : Engine::Engine(odeModel_t* om, double time) : odeModel(om), simTime(time) { cout << "Engine Constr" << endl; // Create the settings and the integrator instance cvodeSettings_t* settings = CvodeSettings_createWith(simTime, simTime * PSFACTOR, ABS_ERR, REL_ERR, 10000, 0, 0, 1, 0, 0, 0, 1, 0, 2); CvodeSettings_setCompileFunctions(settings, 1); CvodeSettings_setSteadyStateThreshold(settings, 1e-11); CvodeSettings_setResetCvodeOnEvent(settings, 1); integratorInstance_t* engine = IntegratorInstance_create(om, settings); integrateSimple(); } void Engine::integrateSimple() { cout << IntegratorInstance_getTime(engine) << endl; //OK cout << "DNA: " << IntegratorInstance_getVariableValue(engine, ODEModel_getVariableIndex(odeModel, "dna")) << endl; // OK IntegratorInstance_integrateOneStep(engine); // SEGFAULTS!! } This crash also occurs if, of course, I create an Engine instance in another class or main and try to call integrateSimple() independently from the constructor. This call inside the constructor was just for testing purpose. Am I doing something wrong there ? There must be something obvious I overlooked there but cannot find it. Eric |