roadrunner  2.6.0
Fast simulator for SBML models
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
rr::KinsolSteadyStateSolver Class Reference

base class to steady state solvers from the Sundials package. More...

#include <KinsolSteadyStateSolver.h>

Inheritance diagram for rr::KinsolSteadyStateSolver:
rr::SteadyStateSolver rr::Solver rr::Registrable rr::FixedPointIteration rr::NewtonIteration rr::BasicNewtonIteration rr::LinesearchNewtonIteration

Public Member Functions

 KinsolSteadyStateSolver (ExecutableModel *executableModel)
 constructor for creating KinsolSteadyStateSolver from an executable model only. More...
 
 KinsolSteadyStateSolver ()=default
 The default constructor for constructing without a model. More...
 
 ~KinsolSteadyStateSolver () override=default
 virtual destructor
 
void syncWithModel (ExecutableModel *m) override
 implementation of Solver::syncWithModel. More...
 
void setFScale (double value)
 set all elements of the fscale variable to More...
 
void setFScale (const std::vector< double > &value)
 set elements of the fscale variable to More...
 
void setUScale (double value)
 set all elements of the uscale variable to More...
 
void setUScale (std::vector< double > value)
 set elements of the uscale variable to value. More...
 
double solveForSteadyState (KinsolSteadyStateSolver *solverInstance, int kinsolStrategy)
 Generic solver method. More...
 
void * getKinsolMemory () const
 getter for the underlying memory block that is used by kinsol. More...
 
std::unordered_map< std::string, Setting > & getSolverStats ()
 return a mapping containing solver statistics. More...
 
void printSolverStats ()
 display solver stats to console
 
- Public Member Functions inherited from rr::SteadyStateSolver
virtual double solve ()=0
 
virtual void loadConfigSettings ()
 
std::string toString () const override
 Return a std::string representation of the solver. More...
 
std::string toRepr () const override
 Return std::string representation a la Python repr method. More...
 
void resetSettings () override
 Implements settings shared by all steady state solvers.
 
 Solver ()=default
 
 Solver (ExecutableModel *model)
 
- Public Member Functions inherited from rr::Solver
 Solver (ExecutableModel *model)
 
void updateSettings (Dictionary *inputSettings)
 Update settings values. More...
 
std::vector< std::string > getSettings () const
 Get a list of all settings for this solver. More...
 
std::unordered_map< std::string, Setting > & getSettingsMap ()
 get settings for this solver More...
 
virtual Setting getValue (const std::string &key) const
 Get the value of an integrator setting. More...
 
virtual Setting hasValue (const std::string &key) const
 Return true if this setting is supported by the integrator. More...
 
virtual size_t getNumParams () const
 Get the number of parameters. More...
 
virtual std::string getParamName (size_t n) const
 Get the name of the parameter at index n. More...
 
virtual std::string getParamDisplayName (int n) const
 Get the display name of the parameter at index n. More...
 
virtual std::string getParamHint (int n) const
 Get the hint of the parameter at index n. More...
 
virtual std::string getParamDesc (int n) const
 Get the description of the parameter at index n. More...
 
virtual std::string getValueAsString (const std::string &key)
 Wrapper for getValue which converts output to a specific type. More...
 
virtual void setValue (const std::string &key, Setting value)
 
virtual std::string getSettingsRepr () const
 Get the solver settings as a std::string. More...
 
virtual std::string settingsPyDictRepr () const
 Python dictionary-style std::string representation of settings. More...
 
const std::string & getDisplayName (const std::string &key) const
 Gets the hint associated with a given key. More...
 
const std::string & getHint (const std::string &key) const
 Gets the hint associated with a given key. More...
 
const std::string & getDescription (const std::string &key) const
 Gets the description associated with a given key. More...
 
Setting::TypeId getType (const std::string &key) const
 Gets the type associated with a given key. More...
 
virtual ExecutableModelgetModel () const
 returns the pointer to the ExecutableModel
 
virtual std::string getName () const=0
 Gets the name associated with this Solver type. More...
 
virtual std::string getHint () const=0
 Gets the hint associated with this Solver type. More...
 
virtual std::string getDescription () const=0
 Gets the description associated with this Solver type. More...
 
- Public Member Functions inherited from rr::Registrable
virtual std::string getName () const =0
 Gets the name associated with this Solver type. More...
 
virtual std::string getDescription () const =0
 Gets the description associated with this Solver type. More...
 
virtual std::string getHint () const =0
 Gets the hint associated with this Solver type. More...
 
virtual Solverconstruct (ExecutableModel *model) const =0
 Constructs a new Solver of a given type. More...
 

Static Public Member Functions

template<class KinsolSteadyStateSolverType >
static int kinsolDyDtFcn (N_Vector stateVecIn, N_Vector stateVecOut, void *userData)
 kinsol callback function that implements system equations More...
 

Protected Member Functions

virtual void freeKinsol ()
 Destory kinsol objects. More...
 
virtual void updateKinsol ()
 Calls methods for updating options in kinsol. More...
 
virtual void createKinsol ()
 Initialize kinsol objects. More...
 
void resetSettings () override
 add settings to the Solver::settings std::map when called for the first time or reset the settings std::map back to default values when called subsequent times.
 
virtual void getSolverStatsFromKinsol ()
 after solve() has been called, this method collects some details such as number of function evals
 
- Protected Member Functions inherited from rr::Solver
void addSetting (const std::string &name, const Setting &val, const std::string &display_name, const std::string &hint, const std::string &description)
 

Protected Attributes

void * mKinsol_Memory = nullptr
 Pointer to the kinsol memory block.
 
N_Vector mStateVector = nullptr
 a sundials N_Vector for storing system state variables
 
N_Vector fscale = nullptr
 std::vector containing diagonal elements of scaling matrix DF for F(u) chosen so that the components of D_F*F(u) (as a matrix multiplication) all have roughly the same magnitude when u is not too near a root of F(u). More...
 
N_Vector uscale = nullptr
 std::vector containing diagonal elements of scaling matrix Du for std::vector u chosen so that the components of D_u*u (as a matrix multiplication) all have roughly the same magnitude when u is close to a root of F(u). More...
 
N_Vector constraints = nullptr
 vector of constraints used to ensure positive solution. More...
 
long int numFuncEvals
 kinsol output variables. More...
 
long int numNolinSolvIters
 
long int numBetaCondFails
 
long int numBacktrackOps
 
double funcNorm
 
double stepLength
 
long int numJacEvals
 
long int numJtimesEvals
 
long int numLinConvFails
 
long int numLinFuncEvals
 
long int numLinIters
 
long int numNonlinSolvIters
 
long int numPrecEvals
 
long int numPrecSolves
 
long int nSolverIterations = 0
 stores the number of iterations required by the solver to converge. More...
 
std::unordered_map< std::string, SettingsolverStats
 
- Protected Attributes inherited from rr::Solver
ExecutableModelmModel = nullptr
 non-owning pointer to model
 

Additional Inherited Members

- Public Types inherited from rr::Solver
using SettingsList = std::vector< std::string >
 
using SettingsMap = std::unordered_map< std::string, Setting >
 
using DisplayNameMap = std::unordered_map< std::string, std::string >
 
using HintMap = std::unordered_map< std::string, std::string >
 
using DescriptionMap = std::unordered_map< std::string, std::string >
 
- Public Attributes inherited from rr::Solver
SettingsList sorted_settings
 
SettingsMap settings
 
DisplayNameMap display_names_
 
HintMap hints
 
DescriptionMap descriptions
 

Detailed Description

base class to steady state solvers from the Sundials package.

The steady state solver in Sundials is called Kinsol. They have multiple different strategies some which require model integration, and some that do not.

Constructor & Destructor Documentation

◆ KinsolSteadyStateSolver() [1/2]

rr::KinsolSteadyStateSolver::KinsolSteadyStateSolver ( ExecutableModel executableModel)
explicit

constructor for creating KinsolSteadyStateSolver from an executable model only.

This constructor should be inherited by subclasses

◆ KinsolSteadyStateSolver() [2/2]

rr::KinsolSteadyStateSolver::KinsolSteadyStateSolver ( )
default

The default constructor for constructing without a model.

useful only for testing.

Member Function Documentation

◆ createKinsol()

void rr::KinsolSteadyStateSolver::createKinsol ( )
protectedvirtual

Initialize kinsol objects.

All subclasses require some of the same initial calls (such as N_VNew_Serial and KINCreate).

Reimplemented in rr::NewtonIteration, and rr::FixedPointIteration.

◆ freeKinsol()

void rr::KinsolSteadyStateSolver::freeKinsol ( )
protectedvirtual

Destory kinsol objects.

Destroys the kinsol objects that are shared among KinsolSteadyStateSolvers

Reimplemented in rr::NewtonIteration, and rr::FixedPointIteration.

◆ getKinsolMemory()

void * rr::KinsolSteadyStateSolver::getKinsolMemory ( ) const

getter for the underlying memory block that is used by kinsol.

mostly useful in testing.

◆ getSolverStats()

std::unordered_map< std::string, Setting > & rr::KinsolSteadyStateSolver::getSolverStats ( )

return a mapping containing solver statistics.

only filled once solve has been called.

See also
getSolverStatsFromKinsol which actually collects the data from kinsol. Whereas this method returns the data in a unordered_map

◆ kinsolDyDtFcn()

template<class KinsolSteadyStateSolverType >
static int rr::KinsolSteadyStateSolver::kinsolDyDtFcn ( N_Vector  stateVecIn,
N_Vector  stateVecOut,
void *  userData 
)
inlinestatic

kinsol callback function that implements system equations

This is the function that gets called by the kinsol KINSol command for solving the system.

Note
this member must be static in order to be used as a function pointer by KINInit.

◆ setFScale() [1/2]

void rr::KinsolSteadyStateSolver::setFScale ( const std::vector< double > &  value)

set elements of the fscale variable to

Parameters
value.
valueshould have the same size as the state std::vector

◆ setFScale() [2/2]

void rr::KinsolSteadyStateSolver::setFScale ( double  value)

set all elements of the fscale variable to

Parameters
value.

◆ setUScale() [1/2]

void rr::KinsolSteadyStateSolver::setUScale ( double  value)

set all elements of the uscale variable to

Parameters
value.

◆ setUScale() [2/2]

void rr::KinsolSteadyStateSolver::setUScale ( std::vector< double >  value)

set elements of the uscale variable to value.

Parameters
valueshould have the same size as the state std::vector

◆ solveForSteadyState()

double rr::KinsolSteadyStateSolver::solveForSteadyState ( KinsolSteadyStateSolver solverInstance,
int  kinsolStrategy 
)

Generic solver method.

When this method is called sundials steady state algorithms solver for steady state. Subclasses use specialized versions of this template using their desired kinsol strategy.

this method cannot be called solve() since that is already taken with different signature requirements.

Parameters
solverInstancepointer (non owning) to instance of subclass of KinsolSteadyStateSolver.
kinsolStrategyone of:
  • KIN_NONE: basic newton iteration
  • KIN_LINESEARCH: newton iteration with linesearch globalization
  • KIN_FP: Fixed point iteration, with anderson acceleration (no linear solver is used)
  • KIN_PICCARD: Piccad iteration, with anderson aceleration (with linear solver) These options are macro's defined by sundials. They correspond to : KIN_NONE 0 KIN_LINESEARCH 1 KIN_PICARD 2 KIN_FP 3

◆ syncWithModel()

void rr::KinsolSteadyStateSolver::syncWithModel ( ExecutableModel m)
overridevirtual

implementation of Solver::syncWithModel.

called by the main RoadRunner class to syncronize the model with its solvers (to be sure were not simulating an out of date model).

Implements rr::Solver.

◆ updateKinsol()

void rr::KinsolSteadyStateSolver::updateKinsol ( )
protectedvirtual

Calls methods for updating options in kinsol.

The settings configuration system in roadrunner make this particular aspect of interacting with sundials libraries a little akward.

User passes in arguments like uScale and they are stored at the class level. This method passed them on to kinsol.

When a user updates a setting with setValue, they are only updating the value in roadrunner. The change doesn't occur in sundials until we call the corresponding sundials function with the new value. We cannot use regular "setters" because they won't get called when a user changes a value. Instead, here we update all kinsol options at once, and this method is called before we call KIN_Solve.

Reimplemented in rr::NewtonIteration, and rr::FixedPointIteration.

Member Data Documentation

◆ constraints

N_Vector rr::KinsolSteadyStateSolver::constraints = nullptr
protected

vector of constraints used to ensure positive solution.

only in effect when allow_negative option set to false

◆ fscale

N_Vector rr::KinsolSteadyStateSolver::fscale = nullptr
protected

std::vector containing diagonal elements of scaling matrix DF for F(u) chosen so that the components of D_F*F(u) (as a matrix multiplication) all have roughly the same magnitude when u is not too near a root of F(u).

In the case of a fixed-point iteration, consider F(u) = G(u) - u.

Note
here u is mStateVector, F is the std::vector of rate functions and D_u an internal variable inside kinsol

◆ nSolverIterations

long int rr::KinsolSteadyStateSolver::nSolverIterations = 0
protected

stores the number of iterations required by the solver to converge.

empty until after solve() has been called. This method uses kinsol's KINGetNumNonlinSolvIters function

◆ numFuncEvals

long int rr::KinsolSteadyStateSolver::numFuncEvals
protected

kinsol output variables.

fileld when

◆ uscale

N_Vector rr::KinsolSteadyStateSolver::uscale = nullptr
protected

std::vector containing diagonal elements of scaling matrix Du for std::vector u chosen so that the components of D_u*u (as a matrix multiplication) all have roughly the same magnitude when u is close to a root of F(u).

Note
here u is mStateVector, F is the std::vector of rate functions and D_u an internal variable inside kinsol

The documentation for this class was generated from the following files: