NewMatVector.h

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This library is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU Lesser General Public License as published by    *
00007 * the Free Software Foundation; either version 2.1 of the License, or (at     *
00008 * your option) any later version.                                             *
00009 *                                                                             *
00010 * This library is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
00013 * for more details.                                                           *
00014 *                                                                             *
00015 * You should have received a copy of the GNU Lesser General Public License    *
00016 * along with this library; if not, write to the Free Software Foundation,     *
00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
00018 *******************************************************************************
00019 *                               SOFA :: Modules                               *
00020 *                                                                             *
00021 * Authors: The SOFA Team and external contributors (see Authors.txt)          *
00022 *                                                                             *
00023 * Contact information: contact@sofa-framework.org                             *
00024 ******************************************************************************/
00025 #ifndef SOFA_COMPONENT_LINEARSOLVER_NEWMATVECTOR_H
00026 #define SOFA_COMPONENT_LINEARSOLVER_NEWMATVECTOR_H
00027 
00028 #include <newmat/newmat.h>
00029 #define WANT_STREAM
00030 #include <newmat/newmatio.h>
00031 #include <sofa/defaulttype/BaseVector.h>
00032 
00033 namespace sofa
00034 {
00035 
00036 namespace component
00037 {
00038 
00039 namespace linearsolver
00040 {
00041 
00042 class NewMatVector : public NEWMAT::ColumnVector, public defaulttype::BaseVector
00043 {
00044 public:
00045     
00046     typedef NEWMAT::ColumnVector SubVector;
00047 
00048     NewMatVector()
00049     {
00050     }
00051 
00052     virtual ~NewMatVector()
00053     {
00054     }
00055 
00056     virtual void resize(int dim)
00057     {
00058             ReSize(dim);
00059             (*this) = 0.0;
00060     }
00061 
00062     virtual SReal element(int i) const
00063     {
00064             return NEWMAT::ColumnVector::element(i);
00065     }
00066     
00067     void set(int i, SReal v)
00068     {
00069         NEWMAT::ColumnVector::element(i) = v;
00070     }
00071     
00072     void add(int i, SReal v)
00073     {
00074         NEWMAT::ColumnVector::element(i) += v;
00075     }
00076     
00077     SReal& operator[](int i)
00078     {
00079             return NEWMAT::ColumnVector::element(i);
00080     }
00081 
00082     SReal operator[](int i) const
00083     {
00084             return NEWMAT::ColumnVector::element(i);
00085     }
00086 
00087     int size() const
00088     {
00089             return Nrows();
00090     }
00091     
00092     NEWMAT::GetSubMatrix sub(int i, int n)
00093     {
00094         return NEWMAT::ColumnVector::SubMatrix(i+1,i+n,1,1);
00095     }
00096     
00097     template<class T>
00098     void getsub(int i, int n, T& v)
00099     {
00100         v = NEWMAT::ColumnVector::SubMatrix(i+1,i+n,1,1);
00101     }
00102     
00103     template<class T>
00104     void setsub(int i, int n, const T& v)
00105     {
00106         NEWMAT::ColumnVector::SubMatrix(i+1,i+n,1,1) = v;
00107     }
00108     
00110     void clear()
00111     {
00112         (*this) = 0.0;
00113     }
00114 
00116     void eq(const NewMatVector& a)
00117     {
00118         (*this) = a;
00119     }
00120 
00122     void peq(const NewMatVector& a, double f=1.0)
00123     {
00124         (*this) += a*f;
00125     }
00127     void teq(double f)
00128     {
00129         (*this) *= f;
00130     }
00132     double dot(const NewMatVector& a) const
00133     {
00134         return NEWMAT::DotProduct(*this,a);
00135     }
00136 
00138     double norm() const
00139     {
00140         return NormFrobenius();
00141     }
00142 
00143     //void operator=(double f) { NewMAT::ColumnVector::operator=(f); }
00144 
00145     template<class T>
00146     void operator=(const T& m) { NEWMAT::ColumnVector::operator=(m); }
00147 
00148     friend std::ostream& operator << (std::ostream& out, const NewMatVector& v )
00149     {
00150         for (int i=0,s=v.Nrows();i<s;++i)
00151         {
00152             if (i) out << ' ';
00153             out << v[i];
00154         }
00155         return out;
00156     }
00157 
00158 };
00159 
00160 } // namespace linearsolver
00161 
00162 } // namespace component
00163 
00164 } // namespace sofa
00165 
00166 #endif

Generated on Sun Nov 23 03:25:11 2008 for Sofa by  doxygen 1.5.7.1