36#ifndef VECTORHELPERFUNCTIONS_HPP_
37#define VECTORHELPERFUNCTIONS_HPP_
52#include <nvector/nvector_serial.h>
54#if CHASTE_SUNDIALS_VERSION >= 60000
55#include "CvodeContextManager.hpp"
70template <
typename VECTOR>
83template <
typename VECTOR>
95template <
typename VECTOR>
106template <
typename VECTOR>
119template <
typename VECTOR>
127template <
typename VECTOR>
136template <
typename VECTOR>
147template <
typename VECTOR>
159template <
typename VECTOR>
171template <
typename VECTOR>
183template <
typename VECTOR>
197 assert(index < rVec.size());
210 assert(index < rVec.size());
255 return std::vector<double>();
284inline std::vector<double>
CopyVector(std::vector<double>& rVec)
295inline void CopyToStdVector(
const std::vector<double>& rSrc, std::vector<double>& rDest)
324 assert(rVec !=
nullptr);
325 return NV_Ith_S(rVec, index);
337 assert(rVec !=
nullptr);
338 NV_Ith_S(rVec, index) = value;
349 assert(rVec !=
nullptr);
350 return NV_LENGTH_S(rVec);
373#if CHASTE_SUNDIALS_VERSION >= 60000
374 rVec = N_VNew_Serial(size, CvodeContextManager::Instance()->GetSundialsContext());
376 rVec = N_VNew_Serial(size);
399 return rVec ==
nullptr;
411 rVec->ops->nvdestroy(rVec);
427 copy = N_VClone(rVec);
428 unsigned size = NV_LENGTH_S(rVec);
429 for (
unsigned i = 0; i < size; i++)
431 NV_Ith_S(copy, i) = NV_Ith_S(rVec, i);
447 realtype* p_src = NV_DATA_S(rSrc);
448 if (!rDest.empty() && p_src == &(rDest[0]))
451 long size = NV_LENGTH_S(rSrc);
454 for (
long i = 0; i < size; i++)
470 realtype* p_dest = NV_DATA_S(rDest);
471 if (p_dest == &(rSrc[0]))
return;
474 long size = NV_LENGTH_S(rDest);
475 assert(size == (
long)rSrc.size());
478 for (
long i = 0; i < size; i++)
492 std::vector<double> sv;
void DeleteVector(VECTOR &rVec)
void CreateVectorIfEmpty(VECTOR &rVec, unsigned size)
void SetVectorComponent(VECTOR &rVec, unsigned index, double value)
double GetVectorComponent(const VECTOR &rVec, unsigned index)
VECTOR CreateEmptyVector()
std::vector< double > MakeStdVec(N_Vector v)
unsigned GetVectorSize(const VECTOR &rVec)
N_Vector MakeNVector(const std::vector< double > &rSrc)
bool IsEmptyVector(VECTOR &rVec)
VECTOR CopyVector(VECTOR &rVec)
void InitialiseEmptyVector(VECTOR &rVec)
void CopyFromStdVector(const std::vector< double > &rSrc, VECTOR &rDest)
void CopyToStdVector(const VECTOR &rSrc, std::vector< double > &rDest)