VectorHelperFunctions.hpp

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2010
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 */
00028 
00029 #ifndef VECTORHELPERFUNCTIONS_HPP_
00030 #define VECTORHELPERFUNCTIONS_HPP_
00031 
00040 #include <cassert>
00041 #include <vector>
00042 
00043 #ifdef CHASTE_CVODE
00044 // CVODE headers
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 // Specialisations for std::vector<double>
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 // Specialisations for N_Vector
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 // End of helper functions
00233 //
00234 
00235 
00236 #endif /*VECTORHELPERFUNCTIONS_HPP_*/

Generated on Mon Nov 1 12:35:16 2010 for Chaste by  doxygen 1.5.5