NewMatVector.h
Go to the documentation of this file.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 #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
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 }
00161
00162 }
00163
00164 }
00165
00166 #endif