Chaste Commit::1fd4e48e3990e67db148bc1bc4cf6991a0049d0c
VectorHelperFunctions.hpp File Reference
#include <cassert>
#include <vector>
#include <nvector/nvector_serial.h>
+ Include dependency graph for VectorHelperFunctions.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<typename VECTOR >
double GetVectorComponent (const VECTOR &rVec, unsigned index)
 
template<typename VECTOR >
void SetVectorComponent (VECTOR &rVec, unsigned index, double value)
 
template<typename VECTOR >
unsigned GetVectorSize (const VECTOR &rVec)
 
template<typename VECTOR >
void InitialiseEmptyVector (VECTOR &rVec)
 
template<typename VECTOR >
void CreateVectorIfEmpty (VECTOR &rVec, unsigned size)
 
template<typename VECTOR >
VECTOR CreateEmptyVector ()
 
template<typename VECTOR >
bool IsEmptyVector (VECTOR &rVec)
 
template<typename VECTOR >
void DeleteVector (VECTOR &rVec)
 
template<typename VECTOR >
VECTOR CopyVector (VECTOR &rVec)
 
template<typename VECTOR >
void CopyToStdVector (const VECTOR &rSrc, std::vector< double > &rDest)
 
template<typename VECTOR >
void CopyFromStdVector (const std::vector< double > &rSrc, VECTOR &rDest)
 
template<>
double GetVectorComponent (const std::vector< double > &rVec, unsigned index)
 
template<>
void SetVectorComponent (std::vector< double > &rVec, unsigned index, double value)
 
template<>
unsigned GetVectorSize (const std::vector< double > &rVec)
 
template<>
void InitialiseEmptyVector (std::vector< double > &rVec)
 
template<>
void CreateVectorIfEmpty (std::vector< double > &rVec, unsigned size)
 
template<>
std::vector< doubleCreateEmptyVector ()
 
template<>
bool IsEmptyVector (std::vector< double > &rVec)
 
template<>
void DeleteVector (std::vector< double > &rVec)
 
template<>
std::vector< doubleCopyVector (std::vector< double > &rVec)
 
template<>
void CopyToStdVector (const std::vector< double > &rSrc, std::vector< double > &rDest)
 
template<>
void CopyFromStdVector (const std::vector< double > &rSrc, std::vector< double > &rDest)
 
template<>
double GetVectorComponent (const N_Vector &rVec, unsigned index)
 
template<>
void SetVectorComponent (N_Vector &rVec, unsigned index, double value)
 
template<>
unsigned GetVectorSize (const N_Vector &rVec)
 
template<>
void InitialiseEmptyVector (N_Vector &rVec)
 
template<>
void CreateVectorIfEmpty (N_Vector &rVec, unsigned size)
 
template<>
N_Vector CreateEmptyVector ()
 
template<>
bool IsEmptyVector (N_Vector &rVec)
 
template<>
void DeleteVector (N_Vector &rVec)
 
template<>
N_Vector CopyVector (N_Vector &rVec)
 
template<>
void CopyToStdVector (const N_Vector &rSrc, std::vector< double > &rDest)
 
template<>
void CopyFromStdVector (const std::vector< double > &rSrc, N_Vector &rDest)
 
std::vector< doubleMakeStdVec (N_Vector v)
 
N_Vector MakeNVector (const std::vector< double > &rSrc)
 

Detailed Description

A selection of helper functions to be able to access std::vector<double> and CVODE's N_Vector types using the same interface. These are used by AbstractParameterisedSystem and some tests.

Definition in file VectorHelperFunctions.hpp.

Function Documentation

◆ CopyFromStdVector() [1/3]

template<>
void CopyFromStdVector ( const std::vector< double > &  rSrc,
N_Vector rDest 
)
inline

A helper function to copy a std::vector<double> into an N_Vector.

Parameters
rSrcsource vector
rDestdestination vector; must exist and be the correct size

Definition at line 467 of file VectorHelperFunctions.hpp.

◆ CopyFromStdVector() [2/3]

template<>
void CopyFromStdVector ( const std::vector< double > &  rSrc,
std::vector< double > &  rDest 
)
inline

Specialisation for std::vector<double>.

Parameters
rSrc
rDest

Definition at line 306 of file VectorHelperFunctions.hpp.

◆ CopyFromStdVector() [3/3]

template<typename VECTOR >
void CopyFromStdVector ( const std::vector< double > &  rSrc,
VECTOR &  rDest 
)
inline

A helper function to copy a std::vector<double> into a VECTOR.

This isn't a member so that we can specialise it without having to specialise the whole class.

Parameters
rSrcsource vector
rDestdestination vector; must exist and be the correct size

Referenced by AbstractCvodeSystem::load(), MakeNVector(), and OdeSolution::rGetDerivedQuantities().

◆ CopyToStdVector() [1/3]

template<>
void CopyToStdVector ( const N_Vector rSrc,
std::vector< double > &  rDest 
)
inline

A helper function to copy an N_Vector into a std::vector<double>.

Parameters
rSrcsource vector
rDestdestination vector; will be resized and filled

Definition at line 444 of file VectorHelperFunctions.hpp.

◆ CopyToStdVector() [2/3]

template<>
void CopyToStdVector ( const std::vector< double > &  rSrc,
std::vector< double > &  rDest 
)
inline

Specialisation for std::vector<double>.

Parameters
rSrc
rDest

Definition at line 295 of file VectorHelperFunctions.hpp.

◆ CopyToStdVector() [3/3]

template<typename VECTOR >
void CopyToStdVector ( const VECTOR &  rSrc,
std::vector< double > &  rDest 
)
inline

A helper function to copy a VECTOR into a std::vector<double>.

This isn't a member so that we can specialise it without having to specialise the whole class.

Parameters
rSrcsource vector
rDestdestination vector; will be resized and filled

Referenced by AbstractCvodeCell::GetStdVecStateVariables(), MakeStdVec(), OdeSolution::rGetDerivedQuantities(), SteadyStateRunner::RunToSteadyStateImplementation(), and AbstractParameterisedSystem< VECTOR >::SetDefaultInitialConditions().

◆ CopyVector() [1/3]

template<>
N_Vector CopyVector ( N_Vector rVec)
inline

Specialisation for CVODE's N_Vector type.

Parameters
rVec
Returns
copy

Definition at line 422 of file VectorHelperFunctions.hpp.

◆ CopyVector() [2/3]

template<>
std::vector< double > CopyVector ( std::vector< double > &  rVec)
inline

Specialisation for std::vector<double>.

Parameters
rVec
Returns
copy

Definition at line 284 of file VectorHelperFunctions.hpp.

◆ CopyVector() [3/3]

template<typename VECTOR >
VECTOR CopyVector ( VECTOR &  rVec)
inline

Helper function to create a fresh copy of a vector.

This isn't a member so that we can specialise it without having to specialise the whole class.

Parameters
rVecthe vector to copy
Returns
A copy

Referenced by AbstractParameterisedSystem< VECTOR >::GetStateVariables().

◆ CreateEmptyVector() [1/3]

template<typename VECTOR >
VECTOR CreateEmptyVector ( )
inline

Helper function to create a new empty/unset vector, useful for defining a default parameter value.

Returns
a new vector

◆ CreateEmptyVector() [2/3]

template<>
std::vector< double > CreateEmptyVector ( )
inline

Specialisation for std::vector<double>.

Returns
empty vector

Definition at line 253 of file VectorHelperFunctions.hpp.

◆ CreateEmptyVector() [3/3]

template<>
N_Vector CreateEmptyVector ( )
inline

Specialisation for CVODE's N_Vector type.

Returns
empty vector

Definition at line 386 of file VectorHelperFunctions.hpp.

◆ CreateVectorIfEmpty() [1/3]

template<>
void CreateVectorIfEmpty ( N_Vector rVec,
unsigned  size 
)
inline

Specialisation for CVODE's N_Vector type.

Parameters
rVec
size

Definition at line 369 of file VectorHelperFunctions.hpp.

◆ CreateVectorIfEmpty() [2/3]

template<>
void CreateVectorIfEmpty ( std::vector< double > &  rVec,
unsigned  size 
)
inline

Specialisation for std::vector<double>.

Parameters
rVec
size

Definition at line 240 of file VectorHelperFunctions.hpp.

◆ CreateVectorIfEmpty() [3/3]

template<typename VECTOR >
void CreateVectorIfEmpty ( VECTOR &  rVec,
unsigned  size 
)
inline

If the given vector is empty, set it to have a particular size, allocating memory if necessary. It is a no-op if the vector is non-empty.

This isn't a member so that we can specialise it without having to specialise the whole class.

Parameters
rVecthe empty vector
sizethe size to create it as

Referenced by AbstractParameterisedSystem< VECTOR >::CheckParametersOnLoad(), MakeNVector(), AbstractCvodeSystem::RecordStoppingPoint(), and CvodeAdaptor::RecordStoppingPoint().

◆ DeleteVector() [1/3]

template<>
void DeleteVector ( N_Vector rVec)
inline

Specialisation for CVODE's N_Vector type.

Parameters
rVec

Definition at line 407 of file VectorHelperFunctions.hpp.

◆ DeleteVector() [2/3]

template<>
void DeleteVector ( std::vector< double > &  rVec)
inline

Specialisation for std::vector<double>.

Parameters
rVec

Definition at line 274 of file VectorHelperFunctions.hpp.

◆ DeleteVector() [3/3]

template<typename VECTOR >
void DeleteVector ( VECTOR &  rVec)
inline

◆ GetVectorComponent() [1/3]

template<>
double GetVectorComponent ( const N_Vector rVec,
unsigned  index 
)
inline

Specialisation for CVODE's N_Vector type.

Parameters
rVec
index
Returns
the vector component

Definition at line 322 of file VectorHelperFunctions.hpp.

◆ GetVectorComponent() [2/3]

template<>
double GetVectorComponent ( const std::vector< double > &  rVec,
unsigned  index 
)
inline

Specialisation for std::vector<double>.

Parameters
rVec
index
Returns
vector component

Definition at line 195 of file VectorHelperFunctions.hpp.

◆ GetVectorComponent() [3/3]

template<typename VECTOR >
double GetVectorComponent ( const VECTOR &  rVec,
unsigned  index 
)
inline
Returns
The vector component Helper function to get a vector component.

This isn't a member so that we can specialise it without having to specialise the whole class.

Parameters
rVecthe vector to access
indexthe index of the component to get

Referenced by AbstractParameterisedSystem< VECTOR >::GetAnyVariable(), AbstractCvodeSystem::RecordStoppingPoint(), CvodeAdaptor::RecordStoppingPoint(), CvodeAdaptor::SetupCvode(), and AbstractCvodeSystem::SetupCvode().

◆ GetVectorSize() [1/3]

template<>
unsigned GetVectorSize ( const N_Vector rVec)
inline

Specialisation for CVODE's N_Vector type.

Parameters
rVec
Returns
size

Definition at line 347 of file VectorHelperFunctions.hpp.

◆ GetVectorSize() [2/3]

template<>
unsigned GetVectorSize ( const std::vector< double > &  rVec)
inline

Specialisation for std::vector<double>.

Parameters
rVec
Returns
size

Definition at line 220 of file VectorHelperFunctions.hpp.

◆ GetVectorSize() [3/3]

◆ InitialiseEmptyVector() [1/3]

template<>
void InitialiseEmptyVector ( N_Vector rVec)
inline

Specialisation for CVODE's N_Vector type.

Parameters
rVec

Definition at line 358 of file VectorHelperFunctions.hpp.

◆ InitialiseEmptyVector() [2/3]

template<>
void InitialiseEmptyVector ( std::vector< double > &  rVec)
inline

Specialisation for std::vector<double>.

Parameters
rVec

Definition at line 230 of file VectorHelperFunctions.hpp.

◆ InitialiseEmptyVector() [3/3]

template<typename VECTOR >
void InitialiseEmptyVector ( VECTOR &  rVec)
inline

Helper function to initialise a vector to be empty/unset.

This isn't a member so that we can specialise it without having to specialise the whole class.

Parameters
rVecthe vector

Referenced by AbstractParameterisedSystem< VECTOR >::AbstractParameterisedSystem().

◆ IsEmptyVector() [1/3]

template<>
bool IsEmptyVector ( N_Vector rVec)
inline

Specialisation for CVODE's N_Vector type.

Parameters
rVec
Returns
true if empty

Definition at line 397 of file VectorHelperFunctions.hpp.

◆ IsEmptyVector() [2/3]

template<>
bool IsEmptyVector ( std::vector< double > &  rVec)
inline

Specialisation for std::vector<double>.

Parameters
rVec
Returns
true if empty

Definition at line 264 of file VectorHelperFunctions.hpp.

◆ IsEmptyVector() [3/3]

template<typename VECTOR >
bool IsEmptyVector ( VECTOR &  rVec)
inline

Helper function to test whether a vector is empty/unset.

Parameters
rVecthe vector
Returns
true if empty

◆ MakeNVector()

N_Vector MakeNVector ( const std::vector< double > &  rSrc)
inline

Make an N_Vector from a standard vector

Parameters
rSrca std::vector to copy the entries from
Returns
an N_Vector of the entries from the std::vector.

Definition at line 503 of file VectorHelperFunctions.hpp.

References CopyFromStdVector(), and CreateVectorIfEmpty().

Referenced by AbstractCvodeCell::SetStateVariables().

◆ MakeStdVec()

std::vector< double > MakeStdVec ( N_Vector  v)
inline

Make a standard vector from an N_Vector

Parameters
vA CVODE N_Vector to copy the entries from
Returns
a std::vector of the entries of the N_Vector.

Definition at line 490 of file VectorHelperFunctions.hpp.

References CopyToStdVector().

Referenced by AbstractCvodeSystem::CvodeError(), AbstractCvodeSystem::save(), and AbstractCvodeSystem::Solve().

◆ SetVectorComponent() [1/3]

template<>
void SetVectorComponent ( N_Vector rVec,
unsigned  index,
double  value 
)
inline

Specialisation for CVODE's N_Vector type.

Parameters
rVec
index
value

Definition at line 335 of file VectorHelperFunctions.hpp.

◆ SetVectorComponent() [2/3]

template<>
void SetVectorComponent ( std::vector< double > &  rVec,
unsigned  index,
double  value 
)
inline

Specialisation for std::vector<double>.

Parameters
rVec
index
value

Definition at line 208 of file VectorHelperFunctions.hpp.

◆ SetVectorComponent() [3/3]

template<typename VECTOR >
void SetVectorComponent ( VECTOR &  rVec,
unsigned  index,
double  value 
)
inline

Helper function to set a vector component.

This isn't a member so that we can specialise it without having to specialise the whole class.

Parameters
rVecthe vector to modify
indexthe index of the component to set
valuethe new value

Referenced by AbstractParameterisedSystem< N_Vector >::CheckParametersOnLoad(), AbstractParameterisedSystem< N_Vector >::GetParameter(), AbstractCvodeSystem::RecordStoppingPoint(), CvodeAdaptor::RecordStoppingPoint(), AbstractParameterisedSystem< VECTOR >::SetAnyVariable(), and AbstractParameterisedSystem< VECTOR >::SetParameter().