Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
dweindl committed Sep 28, 2024
1 parent 4939c94 commit 5980e49
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
9 changes: 0 additions & 9 deletions include/amici/steadystateproblem.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,6 @@ class SteadystateProblem {
*/
void getNewtonStep(Model& model);

/**
* @brief SUNDIALS context.
*
* We use a different context here, because we might
* use a different solver than the one used for the simulation, and we
* shouldn't use multiple solvers on the same context.
*/
// TODO: attach error handler?
sundials::Context sunctx_;
/** newton step */
AmiVector delta_;
/** previous newton step */
Expand Down
8 changes: 6 additions & 2 deletions src/newton_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ NewtonSolver::getSolver(Solver const& simulationSolver, Model const& model) {

/* DIRECT SOLVERS */
case LinearSolver::dense:
solver.reset(new NewtonSolverDense(model, simulationSolver.getSunContext()));
solver.reset(
new NewtonSolverDense(model, simulationSolver.getSunContext())
);
break;

case LinearSolver::band:
Expand Down Expand Up @@ -55,7 +57,9 @@ NewtonSolver::getSolver(Solver const& simulationSolver, Model const& model) {
case LinearSolver::SuperLUMT:
throw NewtonFailure(AMICI_NOT_IMPLEMENTED, "getSolver");
case LinearSolver::KLU:
solver.reset(new NewtonSolverSparse(model, simulationSolver.getSunContext()));
solver.reset(
new NewtonSolverSparse(model, simulationSolver.getSunContext())
);
break;
default:
throw NewtonFailure(AMICI_NOT_IMPLEMENTED, "getSolver");
Expand Down
36 changes: 20 additions & 16 deletions src/steadystateproblem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,29 @@ namespace amici {
constexpr realtype conv_thresh = 1.0;

SteadystateProblem::SteadystateProblem(Solver const& solver, Model const& model)
: delta_(model.nx_solver, sunctx_)
, delta_old_(model.nx_solver, sunctx_)
, ewt_(model.nx_solver, sunctx_)
, ewtQB_(model.nplist(), sunctx_)
, x_old_(model.nx_solver, sunctx_)
, xdot_(model.nx_solver, sunctx_)
, sdx_(model.nx_solver, model.nplist(), sunctx_)
, xB_(model.nJ * model.nx_solver, sunctx_)
, xQ_(model.nJ * model.nx_solver, sunctx_)
, xQB_(model.nplist(), sunctx_)
, xQBdot_(model.nplist(), sunctx_)
, steadystate_mask_(AmiVector(model.get_steadystate_mask(), sunctx_))
: delta_(model.nx_solver, solver.getSunContext())
, delta_old_(model.nx_solver, solver.getSunContext())
, ewt_(model.nx_solver, solver.getSunContext())
, ewtQB_(model.nplist(), solver.getSunContext())
, x_old_(model.nx_solver, solver.getSunContext())
, xdot_(model.nx_solver, solver.getSunContext())
, sdx_(model.nx_solver, model.nplist(), solver.getSunContext())
, xB_(model.nJ * model.nx_solver, solver.getSunContext())
, xQ_(model.nJ * model.nx_solver, solver.getSunContext())
, xQB_(model.nplist(), solver.getSunContext())
, xQBdot_(model.nplist(), solver.getSunContext())
, steadystate_mask_(
AmiVector(model.get_steadystate_mask(), solver.getSunContext())
)
, max_steps_(solver.getNewtonMaxSteps())
, dJydx_(model.nJ * model.nx_solver * model.nt(), 0.0)
, state_(
{INFINITY, // t
AmiVector(model.nx_solver, sunctx_), // x
AmiVector(model.nx_solver, sunctx_), // dx
AmiVectorArray(model.nx_solver, model.nplist(), sunctx_), // sx
{INFINITY, // t
AmiVector(model.nx_solver, solver.getSunContext()), // x
AmiVector(model.nx_solver, solver.getSunContext()), // dx
AmiVectorArray(
model.nx_solver, model.nplist(), solver.getSunContext()
), // sx
model.getModelState()}
)
, // state
Expand Down

0 comments on commit 5980e49

Please sign in to comment.