00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef VECTORHELPERFUNCTIONS_HPP_
00030 #define VECTORHELPERFUNCTIONS_HPP_
00031
00040 #include <cassert>
00041 #include <vector>
00042
00043 #ifdef CHASTE_CVODE
00044
00045 #include <nvector/nvector_serial.h>
00046 #endif
00047
00057 template<typename VECTOR>
00058 inline double GetVectorComponent(const VECTOR& rVec, unsigned index);
00059
00070 template<typename VECTOR>
00071 inline void SetVectorComponent(VECTOR& rVec, unsigned index, double value);
00072
00082 template<typename VECTOR>
00083 inline unsigned GetVectorSize(const VECTOR& rVec);
00084
00093 template<typename VECTOR>
00094 inline void InitialiseEmptyVector(VECTOR& rVec);
00095
00104 template<typename VECTOR>
00105 inline void DeleteVector(VECTOR& rVec);
00106
00107
00108
00109
00110
00116 template<>
00117 inline double GetVectorComponent(const std::vector<double>& rVec, unsigned index)
00118 {
00119 assert(index < rVec.size());
00120 return rVec[index];
00121 }
00122
00129 template<>
00130 inline void SetVectorComponent(std::vector<double>& rVec, unsigned index, double value)
00131 {
00132 assert(index < rVec.size());
00133 rVec[index] = value;
00134 }
00135
00140 template<>
00141 inline unsigned GetVectorSize(const std::vector<double>& rVec)
00142 {
00143 return rVec.size();
00144 }
00145
00150 template<>
00151 inline void InitialiseEmptyVector(std::vector<double>& rVec)
00152 {
00153 }
00154
00159 template<>
00160 inline void DeleteVector(std::vector<double>& rVec)
00161 {
00162 }
00163
00164
00165
00166
00167
00168 #ifdef CHASTE_CVODE
00169
00175 template<>
00176 inline double GetVectorComponent(const N_Vector& rVec, unsigned index)
00177 {
00178 assert(rVec != NULL);
00179 return NV_Ith_S(rVec, index);
00180 }
00181
00188 template<>
00189 inline void SetVectorComponent(N_Vector& rVec, unsigned index, double value)
00190 {
00191 assert(rVec != NULL);
00192 NV_Ith_S(rVec, index) = value;
00193 }
00194
00199 template<>
00200 inline unsigned GetVectorSize(const N_Vector& rVec)
00201 {
00202 assert(rVec != NULL);
00203 return NV_LENGTH_S(rVec);
00204 }
00205
00210 template<>
00211 inline void InitialiseEmptyVector(N_Vector& rVec)
00212 {
00213 rVec = NULL;
00214 }
00215
00220 template<>
00221 inline void DeleteVector(N_Vector& rVec)
00222 {
00223 if (rVec)
00224 {
00225 rVec->ops->nvdestroy(rVec);
00226 rVec = NULL;
00227 }
00228 }
00229 #endif // CHASTE_CVODE
00230
00231
00232
00233
00234
00235
00236 #endif