roadrunner
2.6.0
Fast simulator for SBML models
|
base class to steady state solvers from the Sundials package. More...
#include <KinsolSteadyStateSolver.h>
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 | |
![]() | |
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) | |
![]() | |
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 ExecutableModel * | getModel () 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... | |
![]() | |
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 Solver * | construct (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 | |
![]() | |
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, Setting > | solverStats |
![]() | |
ExecutableModel * | mModel = nullptr |
non-owning pointer to model | |
Additional Inherited Members | |
![]() | |
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 > |
![]() | |
SettingsList | sorted_settings |
SettingsMap | settings |
DisplayNameMap | display_names_ |
HintMap | hints |
DescriptionMap | descriptions |
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.
|
explicit |
constructor for creating KinsolSteadyStateSolver from an executable model only.
This constructor should be inherited by subclasses
|
default |
The default constructor for constructing without a model.
useful only for testing.
|
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.
|
protectedvirtual |
Destory kinsol objects.
Destroys the kinsol objects that are shared among KinsolSteadyStateSolvers
Reimplemented in rr::NewtonIteration, and rr::FixedPointIteration.
void * rr::KinsolSteadyStateSolver::getKinsolMemory | ( | ) | const |
getter for the underlying memory block that is used by kinsol.
mostly useful in testing.
std::unordered_map< std::string, Setting > & rr::KinsolSteadyStateSolver::getSolverStats | ( | ) |
return a mapping containing solver statistics.
only filled once solve has been called.
|
inlinestatic |
kinsol callback function that implements system equations
This is the function that gets called by the kinsol KINSol
command for solving the system.
void rr::KinsolSteadyStateSolver::setFScale | ( | const std::vector< double > & | value | ) |
set elements of the fscale variable to
value | . |
value | should have the same size as the state std::vector |
void rr::KinsolSteadyStateSolver::setFScale | ( | double | value | ) |
set all elements of the fscale variable to
value | . |
void rr::KinsolSteadyStateSolver::setUScale | ( | double | value | ) |
set all elements of the uscale variable to
value | . |
void rr::KinsolSteadyStateSolver::setUScale | ( | std::vector< double > | value | ) |
set elements of the uscale variable to value.
value | should have the same size as the state std::vector |
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.
solverInstance | pointer (non owning) to instance of subclass of KinsolSteadyStateSolver. |
kinsolStrategy | one of:
|
|
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.
|
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.
|
protected |
vector of constraints used to ensure positive solution.
only in effect when allow_negative option set to false
|
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.
|
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
|
protected |
kinsol output variables.
fileld when
|
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).