MUQ  0.4.3
muq::Modeling::RootfindingIVP Class Reference

A rootfinding initial value problem — find the root of a function along an orbit of an ODE. More...

#include <RootfindingIVP.h>

Inheritance diagram for muq::Modeling::RootfindingIVP:

Detailed Description

A rootfinding initial value problem — find the root of a function along an orbit of an ODE.

Definition at line 9 of file RootfindingIVP.h.

Public Member Functions

 RootfindingIVP (std::shared_ptr< WorkPiece > rhs, std::shared_ptr< WorkPiece > root, boost::property_tree::ptree const &pt, std::shared_ptr< muq::Utilities::AnyAlgebra > algebra=std::make_shared< muq::Utilities::AnyAlgebra >())
 
virtual ~RootfindingIVP ()
 

Constructor & Destructor Documentation

◆ RootfindingIVP()

RootfindingIVP::RootfindingIVP ( std::shared_ptr< WorkPiece rhs,
std::shared_ptr< WorkPiece root,
boost::property_tree::ptree const &  pt,
std::shared_ptr< muq::Utilities::AnyAlgebra >  algebra = std::make_shared<muq::Utilities::AnyAlgebra>() 
)

The first input is the initial state (at \(t=0\)). It is also the first input to the both right hand side and the root muq::Modeling::WorkPiece. The type must be the same in both sub-models (if it is known). This must a N_Vector type (the vectors that Sundials uses).

The next set of inputs are the inputs to the right hand side muq::Modeling::WorkPiece. If the right hand side input takes 2 inputs besides the state, these correspond to inputs 2 and 3 of the root finder. Their types are known if the types are known by the rhs muq::Modeling::WorkPiece.

The next set of inputs are the inputs to the root muq::Modeling::WorkPiece. If the root input takes 2 inputs besides the state, these correspond to inputs 4 and 5 of the root finder. Their types are known if the types are known by the rhs muq::Modeling::WorkPiece.

An optional final input is a vector of times to save the state. If the user gives muq::Modeling::RootfinderIVP this (optional) input it integrates until it finds a root, saving the state at each of these times.

The first output is the state at the root. This output has the same type as the first input to the right hand side and the root (if either is known). Note that the "the root" is the first state such that any one of the outputs from the root function is zero. It is boost::none if no root was found.

The second output is the time at which the root (first output) was obtained.

The third output exists if the user gives muq::Modeling::RootfinderIVP times to save the state (optional final input). This output is a vector — std::vector<StateType> — of states at the specified times.

Parameters options (for boost::property_tree::ptree):

  1. All the parameter listed in muq::Modeling::ODEBase
  2. The maximum number of steps (Rootfinder.MaxSteps)
    • Defaults to \(10^{10}\)
  3. The maximum amount of time to integrate (Rootfinder.MaxTime)
    • Defaults to \(10^{3}\)
  4. The maximum number of error tests (Rootfinder.MaxErrorTests)
    • Defaults to \(100\)
Parameters
[in]rhsA muq::Modeling::WorkPiece that evaluates the right hand side of the ODE
[in]rootA muq::Modeling::WorkPiece whose outputs are double's — we integrate the ODE until we find the first root of one of these outputs
[in]ptA boost::property_tree::ptree with options/tolerances for the ODE integrator
[in]algebraA muq::Utilities::AnyAlgebra used to manipulate the state and input parameters (defaults to the MUQ default)

Definition at line 12 of file RootfindingIVP.cpp.

References root, and UpdateInputOutputTypes().

◆ ~RootfindingIVP()

RootfindingIVP::~RootfindingIVP ( )
virtual

Definition at line 24 of file RootfindingIVP.cpp.

Member Function Documentation

◆ EvaluateImpl()

void RootfindingIVP::EvaluateImpl ( ref_vector< boost::any > const &  inputs)
overrideprivatevirtual

Integrate the ODE until we find a root.

Parameters
[in]inputsThe inputs (first: state, next group: rhs inputs, next group: root inputs, final: eval times (optional))

Definition at line 163 of file RootfindingIVP.cpp.

References FindRoot().

◆ EvaluateRoot()

int RootfindingIVP::EvaluateRoot ( realtype  t,
N_Vector  state,
realtype *  root,
void *  user_data 
)
staticprivate

Evaluate the root function.

Parameters
[in]tThe current time
[in]stateThe state
[out]rootThe roots
[in]user_dataA pointer to an muq::Modeling::ODEData

Definition at line 282 of file RootfindingIVP.cpp.

References muq::Modeling::ODEData::inputs, muq::Modeling::ODEData::rhs, muq::Modeling::ODEData::root, and root.

Referenced by FindRoot().

◆ FindRoot()

Eigen::VectorXi RootfindingIVP::FindRoot ( ref_vector< boost::any > const &  inputs,
int const  wrtIn = -1,
int const  wrtOut = -1,
DerivativeMode const &  mode = DerivativeMode::Jac 
)
private

Run the CVODES integrator.

Parameters
[in]inputsThe inputs (first: state, next group: rhs inputs, next group: root inputs, final: eval times (optional))
[in]wrtInWe are computing the derivative with repsect to this parameter
[in]wrtOutWe are computing the derivative of this output
[in]modeAre we computing the Jacobian, Jacobian action, or Jacobian transpose action?
Returns
A vector of length root->numOutputs, 0 indicates that output is not zero (no root found), 1 indicates that output is zero (a root was found)

Definition at line 26 of file RootfindingIVP.cpp.

References EvaluateRoot(), maxErrorTests, maxSteps, maxTime, and root.

Referenced by EvaluateImpl(), and JacobianImpl().

◆ JacobianImpl()

void RootfindingIVP::JacobianImpl ( unsigned int const  wrtIn,
unsigned int const  wrtOut,
ref_vector< boost::any > const &  inputs 
)
overrideprivatevirtual

Compute the Jacobian of the state at the root.

Parameters
[in]wrtInWe are computing the derivative with repsect to this parameter
[in]wrtOutWe are computing the derivative of this output
[in]inputsThe inputs (first: state, next group: rhs inputs, next group: root inputs, final: eval times (optional))

Definition at line 168 of file RootfindingIVP.cpp.

References FindRoot(), and root.

◆ UpdateInputOutputTypes()

void RootfindingIVP::UpdateInputOutputTypes ( )
private

Update the input and output types based on the rhs and root muq::Modeling::WorkPiece's.

Add the root input types to the inputs and set the second output type. Note the (optional) third output (the vector of state's at specified times) is std::vector<StateType> but we can't set this.

Definition at line 257 of file RootfindingIVP.cpp.

References root.

Referenced by RootfindingIVP().

Member Data Documentation

◆ maxErrorTests

const unsigned int muq::Modeling::RootfindingIVP::maxErrorTests
private

The maximum number of error test failures.

Definition at line 103 of file RootfindingIVP.h.

Referenced by FindRoot().

◆ maxSteps

const unsigned int muq::Modeling::RootfindingIVP::maxSteps
private

The maximum number of steps the timesteper can take.

Definition at line 97 of file RootfindingIVP.h.

Referenced by FindRoot().

◆ maxTime

const double muq::Modeling::RootfindingIVP::maxTime
private

The maximum amount of time to integrate.

Definition at line 100 of file RootfindingIVP.h.

Referenced by FindRoot().

◆ root

std::shared_ptr<WorkPiece> muq::Modeling::RootfindingIVP::root
private

The root function.

Definition at line 94 of file RootfindingIVP.h.

Referenced by EvaluateRoot(), FindRoot(), JacobianImpl(), RootfindingIVP(), and UpdateInputOutputTypes().


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