@@ -225,19 +225,32 @@ namespace cadet
225225 cadet::AdJacobianParams{sim->_vecADres , sim->_vecADy , sim->numSensitivityAdDirections ()});
226226 }
227227
228- /*
229- int jacobianUpdateWrapper(N_Vector y, N_Vector yDot, N_Vector res, N_Vector tempv1, N_Vector tempv2, N_Vector tempv3, void* userData)
228+ /* *
229+ * @brief IDAS jacobian wrapper function to call the model's jacobian() method
230+ */
231+
232+ int jacobianUpdateWrapper (SUNLinearSolver LS, SUNMatrix A)
230233 {
231- cadet::Simulator* const sim = static_cast<cadet::Simulator*>(userData );
232- const double t = IDA_mem->ida_tn;
234+ cadet::Simulator* const sim = static_cast <cadet::Simulator*>(LS-> content );
235+
233236 const unsigned int secIdx = sim->getCurrentSection (t);
237+ double t;
238+ double alpha;
239+ N_Vector y;
240+ N_Vector yDot;
241+ N_Vector unused1;
242+ N_Vector unused2;
243+ N_Vector unused3;
244+ void * unused4;
245+ IDAGetErrWeights (sim->_idaMemBlock , sim->_linearSolverWeight );
246+ IDAGetNonlinearSystemData (sim->_idaMemBlock , &t, &unused1, &unused2, &y, &yDot, &unused3, &alpha, &unused4);
234247
235248 LOG (Trace) << " ==> Jacobian at t = " << t;
236249
237250 return sim->_model ->jacobian (cadet::SimulationTime{ t, secIdx }, cadet::ConstSimulationState{ NVEC_DATA (y), NVEC_DATA (yDot) }, NVEC_DATA (tempv1),
238251 cadet::AdJacobianParams{ sim->_vecADres , sim->_vecADy , sim->numSensitivityAdDirections () });
239252 }
240- */
253+
241254
242255 /* *
243256 * @brief Change the error weights in the state vector
@@ -367,21 +380,6 @@ namespace cadet
367380 return 0 ;
368381 }
369382
370- int linearSolverSetup (SUNLinearSolver, SUNMatrix)
371- {
372- return 0 ;
373- }
374-
375- int linearSolverSetATimes (SUNLinearSolver, void *, SUNATimesFn)
376- {
377- return 0 ;
378- }
379-
380- int linearSolverNumIters (SUNLinearSolver)
381- {
382- return 1 ;
383- }
384-
385383 N_Vector linearSolverResidual (SUNLinearSolver)
386384 {
387385 return nullptr ;
@@ -427,7 +425,7 @@ namespace cadet
427425 Simulator::Simulator () : _model(nullptr ), _solRecorder(nullptr ), _idaMemBlock(nullptr ), _vecStateY(nullptr ),
428426 _vecStateYdot (nullptr ), _vecFwdYs(nullptr ), _vecFwdYsDot(nullptr ),
429427 _relTolS(1.0e-9 ), _absTol(1 , 1.0e-12 ), _relTol(1.0e-9 ), _initStepSize(1 , 1.0e-6 ), _maxSteps(10000 ), _maxStepSize(0.0 ),
430- _nThreads(0 ), _sensErrorTestEnabled(true ), _maxNewtonIter(4 ), _maxErrorTestFail(10 ), _maxConvTestFail(10 ),
428+ _nThreads(0 ), _modifiedNewton( false ), _sensErrorTestEnabled(true ), _maxNewtonIter(4 ), _maxErrorTestFail(10 ), _maxConvTestFail(10 ),
431429 _maxNewtonIterSens(4 ), _curSec(0 ), _skipConsistencyStateY(false ), _skipConsistencySensitivity(false ),
432430 _consistentInitMode(ConsistentInitialization::Full), _consistentInitModeSens(ConsistentInitialization::Full),
433431 _vecADres(nullptr ), _vecADy(nullptr ), _lastIntTime(0.0 ), _notification(nullptr ), _linearSolver(nullptr ), _sunctx(nullptr )
@@ -533,6 +531,8 @@ namespace cadet
533531 _linearSolver->content = this ;
534532 _linearSolver->ops ->gettype = linearSolverGetType;
535533 _linearSolver->ops ->solve = linearSolverSolve;
534+ if (_modifiedNewton)
535+ _linearSolver->ops ->setup = jacobianUpdateWrapper;
536536
537537 // Attach user data structure
538538 IDASetUserData (_idaMemBlock, this );
0 commit comments