From 2b12f8c04b702139bc16eef2b75af818b50f47ea Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 6 Apr 1998 08:57:32 +0000 Subject: [PATCH] Make many signed integers unsigned and add some tons of 'const' specifiers. git-svn-id: https://svn.dealii.org/trunk@137 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/dfmatrix.h | 99 ++++++++------- deal.II/lac/include/lac/dsmatrix.h | 116 ++++++++++-------- deal.II/lac/include/lac/dvector.h | 106 +++++++++------- deal.II/lac/include/lac/ivector.h | 46 +++---- deal.II/lac/include/lac/vectorbase.h | 30 +++-- deal.II/lac/source/Makefile | 25 ++-- deal.II/lac/source/dfmatrix.cc | 168 ++++++++++++++----------- deal.II/lac/source/dsmatrix.cc | 169 ++++++++++++++------------ deal.II/lac/source/dvector.cc | 175 +++++++++++++++------------ deal.II/lac/source/ivector.cc | 37 +++--- 10 files changed, 540 insertions(+), 431 deletions(-) diff --git a/deal.II/lac/include/lac/dfmatrix.h b/deal.II/lac/include/lac/dfmatrix.h index 1662407659..82c9ecde43 100644 --- a/deal.II/lac/include/lac/dfmatrix.h +++ b/deal.II/lac/include/lac/dfmatrix.h @@ -38,31 +38,35 @@ class dFMatrix /** * Dimension. Actual number of Columns */ - int dim_range; + unsigned int dim_range; /** * Dimension. Actual number of Rows */ - int dim_image; + unsigned int dim_image; /** * Dimension. Determines amount of reserved memory */ - int val_size; + unsigned int val_size; /** * Initialization . initialize memory for Matrix

* ( m rows , n columns ) */ - void init(int m, int n); + void init (const unsigned int m, const unsigned int n); /** * Access Elements. returns A(i,j) */ - double& el(int i, int j) { return val[i*dim_range+j]; } + double& el (const unsigned int i, const unsigned int j) { + return val[i*dim_range+j]; + }; /** * Access Elements. returns A(i,j) */ - double el(int i, int j) const { return val[i*dim_range+j]; } + double el (const unsigned int i, const unsigned int j) const { + return val[i*dim_range+j]; + }; public: @@ -72,13 +76,13 @@ class dFMatrix * Constructor. Dimension = (n,n)

* -> quadratic matrix (n rows , n columns) */ - dFMatrix(int n = 1) { init(n,n); } + dFMatrix (const unsigned int n = 1) { init(n,n); } /** * Constructor. Dimension = (m,n)

* -> rectangular matrix (m rows , n columns) */ - dFMatrix(int m,int n) { init(m,n); } + dFMatrix (const unsigned int m,unsigned int n) { init(m,n); } /** * Copy constructor. Be very careful with @@ -86,7 +90,7 @@ class dFMatrix * huge amount of computing time for large * matrices!! */ - dFMatrix(const dFMatrix&); + dFMatrix (const dFMatrix&); /** * Destructor. Clears memory @@ -109,38 +113,39 @@ class dFMatrix /** * U(0-m,0-n) = s . Fill all elements */ - void fill(const dFMatrix& src, int i = 0, int j = 0); + void fill (const dFMatrix& src, + const unsigned int i=0, const unsigned int j=0); /** * Change Dimension. * Set dimension to (m,n)

* ( reinit rectangular matrix ) */ - void reinit(int m, int n); + void reinit (const unsigned int m, const unsigned int n); /** * Change Dimension. * Set dimension to (n,n)

* ( reinit quadratic matrix ) */ - void reinit(int n) { reinit(n,n); } + void reinit (const unsigned int n) { reinit(n,n); } /** * Adjust Dimension. * Set dimension to ( m(B),n(B) )

* ( adjust to dimensions of another matrix B ) */ - void reinit(const dFMatrix& B) { reinit(B.m(), B.n()); } + void reinit (const dFMatrix& B) { reinit(B.m(), B.n()); } /** * Inquire Dimension (Row) . returns Number of Rows */ - int m() const { return dim_image; } + unsigned int m() const { return dim_image; } /** * Inquire Dimension (Col) . returns Number of Columns */ - int n() const { return dim_range; } + unsigned int n () const { return dim_range; } //@} @@ -151,25 +156,25 @@ class dFMatrix * Access Elements. returns element at relative 'address' i

* ( -> access to A(i/n , i mod n) ) */ - double el(int i) const { return val[i]; } + double el (const unsigned int i) const { return val[i]; } /** * Access Elements. returns A(i,j) */ - double operator() (int i, int j) const + double operator() (const unsigned int i, const unsigned int j) const { - Assert ((i>=0) && (i=0) && (j=0) && (i=0) && (j * (application of transpose of this to a vector v) * flag adding=true : w=+A*v */ - void Tvmult(dVector& w,const dVector& v,const int adding=0) const; + void Tvmult (dVector& w, const dVector& v, const bool adding=false) const; /** * A=Inverse(A). Inversion of this by * Gauss-Jordan-algorithm */ - void gauss_jordan(); + void gauss_jordan (); /** * Computes the determinant of a matrix. @@ -258,37 +263,41 @@ class dFMatrix * A(i,1-n)+=s*A(j,1-n). * Simple addition of rows of this */ - void add_row(int i, double s, int j); + void add_row (const unsigned int i, const double s, const unsigned int j); /** * A(i,1-n)+=s*A(j,1-n)+t*A(k,1-n). * Multiple addition of rows of this */ - void add_row(int i, double s, int j, double t, int k); + void add_row (const unsigned int i, + const double s, const unsigned int j, + const double t, const unsigned int k); /** * A(1-n,i)+=s*A(1-n,j). * Simple addition of columns of this */ - void add_col(int i, double s, int j); + void add_col (const unsigned int i, const double s, const unsigned int j); /** * A(1-n,i)+=s*A(1-n,j)+t*A(1-n,k). * Multiple addition of columns of this */ - void add_col(int i, double s, int j, double t, int k); + void add_col (const unsigned int i, + const double s, const unsigned int j, + const double t, const unsigned int k); /** * Swap A(i,1-n) <-> A(j,1-n). * Swap rows i and j of this */ - void swap_row(int i, int j); + void swap_row (const unsigned int i, const unsigned int j); /** * Swap A(1-n,i) <-> A(1-n,j). * Swap columns i and j of this */ - void swap_col(int i, int j); + void swap_col (const unsigned int i, const unsigned int j); //@} @@ -300,17 +309,17 @@ class dFMatrix * w=b-A*v. * Residual calculation , returns |w| */ - double residual(dVector& w, const dVector& v, const dVector& b) const; + double residual (dVector& w, const dVector& v, const dVector& b) const; /** * Inversion of lower triangle . */ - void forward(dVector& dst, const dVector& src) const; + void forward (dVector& dst, const dVector& src) const; /** * Inversion of upper triangle . */ - void backward(dVector& dst, const dVector& src) const; + void backward (dVector& dst, const dVector& src) const; /** * QR - factorization of a matrix. @@ -320,38 +329,38 @@ class dFMatrix * triangle contains the resulting matrix R,

* the lower the incomplete factorization matrices. */ - void householder(dVector& y); + void householder (dVector& y); /** * Least - Squares - Approximation by QR-factorization. */ - double least_squares(dVector& dst, dVector& src); + double least_squares (dVector& dst, dVector& src); /** * A(i,i)+=B(i,1-n). Addition of complete * rows of B to diagonal-elements of this ;

* ( i = 1 ... m ) */ - void add_diag(double s, const dFMatrix& B); + void add_diag (const double s, const dFMatrix& B); /** * A(i,i)+=s i=1-m. * Add constant to diagonal elements of this */ - void diagadd(const double& src); + void diagadd (const double& src); /** * w+=part(A)*v. Conditional partial * Matrix-vector-multiplication

* (used elements of v determined by x) */ - void gsmult(dVector& w, const dVector& v,const iVector& x) const; + void gsmult (dVector& w, const dVector& v, const iVector& x) const; /** * Output of the matrix in user-defined format. */ - void print(FILE* fp, const char* format = 0) const; + void print (FILE* fp, const char* format = 0) const; //@} /** diff --git a/deal.II/lac/include/lac/dsmatrix.h b/deal.II/lac/include/lac/dsmatrix.h index 658980efda..9881a616d5 100644 --- a/deal.II/lac/include/lac/dsmatrix.h +++ b/deal.II/lac/include/lac/dsmatrix.h @@ -32,43 +32,46 @@ CLASS class dSMatrixStruct { friend class dSMatrix; - int max_dim; - int rows, cols; - int vec_len, max_vec_len; - int max_row_len; - int* rowstart; + unsigned int max_dim; + unsigned int rows, cols; + unsigned int vec_len, max_vec_len; + unsigned int max_row_len; + unsigned int* rowstart; int* colnums; - int compressed; + bool compressed; public: ////////// - void reinit(int m, int n, int max_per_row); + void reinit (const unsigned int m, const unsigned int n, + const unsigned int max_per_row); ////////// - dSMatrixStruct(int m, int n, int max_per_row); + dSMatrixStruct (const unsigned int m, const unsigned int n, + const unsigned int max_per_row); ////////// - dSMatrixStruct(int n, int max_per_row); + dSMatrixStruct (const unsigned int n, const unsigned int max_per_row); ////////// - ~dSMatrixStruct(); + ~dSMatrixStruct (); ////////// - void compress(); + void compress (); ////////// - int operator () (int i, int j); + int operator() (const unsigned int i, const unsigned int j); ////////// - void add(int i, int j); + void add (const unsigned int i, const unsigned int j); ////////// - void add_matrix(int n, int* rowcols); + void add_matrix (const unsigned int n, const int* rowcols); ////////// - void add_matrix(int m, int n, int* rows, int* cols); + void add_matrix (const unsigned int m, const unsigned int n, + const int* rows, const int* cols); ////////// - void add_matrix(const iVector& rowcols); + void add_matrix (const iVector& rowcols); ////////// - void add_matrix(const iVector& rows, const iVector& cols); + void add_matrix (const iVector& rows, const iVector& cols); void print_gnuplot (ostream &) const; - int n_rows () const; - int n_cols () const; - int bandwidth () const; + unsigned int n_rows () const; + unsigned int n_cols () const; + unsigned int bandwidth () const; /** * Return whether the structure is @@ -91,7 +94,7 @@ public: * avoid programs relying on outdated * information! */ - const int * get_rowstart_indices () const; + const unsigned int * get_rowstart_indices () const; /** * This is kind of an expert mode: get @@ -146,7 +149,7 @@ class dSMatrix { dSMatrixStruct * cols; double* val; - int max_len; + unsigned int max_len; public: /** @@ -161,14 +164,14 @@ class dSMatrix dSMatrix (); // - dSMatrix(dSMatrixStruct& c); + dSMatrix (dSMatrixStruct& c); // - ~dSMatrix(); + ~dSMatrix (); // - void reinit(); + void reinit (); // void reinit (dSMatrixStruct &); @@ -180,14 +183,16 @@ class dSMatrix void clear (); // - int m() const; + unsigned int m () const; // - int n() const; + unsigned int n () const; // - void set (int i, int j, double value); + void set (const unsigned int i, const unsigned int j, + const double value); // - void add (int i, int j, double value); + void add (const unsigned int i, const unsigned int j, + const double value); /** * Return the value of the entry (i,j). @@ -198,7 +203,7 @@ class dSMatrix * throws an exception if the wanted * element does not exist in the matrix. */ - double operator () (const int i, const int j) const; + double operator () (const unsigned int i, const unsigned int j) const; /** * Return the main diagonal element in @@ -213,7 +218,7 @@ class dSMatrix * involve searching for the right column * number. */ - double diag_element (const int i) const; + double diag_element (const unsigned int i) const; /** * This is kind of an expert mode: get @@ -232,33 +237,36 @@ class dSMatrix * avoid programs relying on outdated * information! */ - double global_entry (const int i) const; + double global_entry (const unsigned int i) const; /** * Same as above, but with write access. * You certainly know what you do? */ - double & global_entry (const int i); + double & global_entry (const unsigned int i); // void vmult (dVector& dst,const dVector& src) const; // - void Tvmult(dVector& dst,const dVector& src) const; + void Tvmult (dVector& dst,const dVector& src) const; // - double residual (dVector& dst,const dVector& x,const dVector& b); + double residual (dVector& dst, const dVector& x, const dVector& b); // - void Jacobi_precond(dVector& dst,const dVector& src,double om = 1.); + void Jacobi_precond (dVector& dst, const dVector& src, + const double om = 1.); // - void SSOR_precond(dVector& dst,const dVector& src,double om = 1.); + void SSOR_precond (dVector& dst, const dVector& src, + const double om = 1.); // - void SOR_precond(dVector& dst,const dVector& src,double om = 1.); + void SOR_precond (dVector& dst, const dVector& src, + const double om = 1.); // - void SSOR(dVector& dst,double om = 1.); + void SSOR (dVector& dst, const double om = 1.); // - void SOR(dVector& dst,double om = 1.); + void SOR (dVector& dst, const double om = 1.); // - void precondition(dVector& dst,const dVector& src) { dst=src; } + void precondition (dVector& dst, const dVector& src) { dst=src; } const dSMatrixStruct & get_sparsity_pattern () const; @@ -305,14 +313,14 @@ class dSMatrix /*---------------------- Inline functions -----------------------------------*/ inline -int dSMatrixStruct::n_rows () const { +unsigned int dSMatrixStruct::n_rows () const { return rows; }; inline -int dSMatrixStruct::n_cols () const { +unsigned int dSMatrixStruct::n_cols () const { return cols; }; @@ -326,7 +334,7 @@ bool dSMatrixStruct::is_compressed () const { inline -const int * dSMatrixStruct::get_rowstart_indices () const { +const unsigned int * dSMatrixStruct::get_rowstart_indices () const { return rowstart; }; @@ -342,7 +350,7 @@ const int * dSMatrixStruct::get_column_numbers () const { inline -int dSMatrix::m () const +unsigned int dSMatrix::m () const { return cols->rows; }; @@ -350,7 +358,7 @@ int dSMatrix::m () const inline -int dSMatrix::n () const +unsigned int dSMatrix::n () const { return cols->cols; }; @@ -358,7 +366,8 @@ int dSMatrix::n () const inline -void dSMatrix::set (int i, int j, double value) { +void dSMatrix::set (const unsigned int i, const unsigned int j, + const double value) { Assert (cols->operator()(i,j) != -1, ExcInvalidIndex(i,j)); val[cols->operator()(i,j)] = value; @@ -367,7 +376,8 @@ void dSMatrix::set (int i, int j, double value) { inline -void dSMatrix::add (int i, int j, double value) { +void dSMatrix::add (const unsigned int i, const unsigned int j, + const double value) { Assert (cols->operator()(i,j) != -1, ExcInvalidIndex(i,j)); val[cols->operator()(i,j)] += value; @@ -378,7 +388,7 @@ void dSMatrix::add (int i, int j, double value) { inline -double dSMatrix::operator () (const int i, const int j) const { +double dSMatrix::operator () (const unsigned int i, const unsigned int j) const { Assert (cols->operator()(i,j) != -1, ExcInvalidIndex(i,j)); return val[cols->operator()(i,j)]; @@ -387,9 +397,9 @@ double dSMatrix::operator () (const int i, const int j) const { inline -double dSMatrix::diag_element (const int i) const { +double dSMatrix::diag_element (const unsigned int i) const { Assert (m() == n(), ExcMatrixNotSquare()); - Assert ((0<=i) && (iDIM ! - int maxdim; + unsigned int maxdim; /// Component-array. double *val; @@ -56,23 +56,23 @@ class dVector : public VectorBase /** * Dummy-Constructor. Dimension=0 */ - dVector(); + dVector (); /** * Copy-Constructor. Dimension set to that of V ,

* all components are copied from V */ - dVector(const dVector& V); + dVector (const dVector& V); /** * Constructor. Dimension = N (>0) */ - dVector(int N); + dVector (const unsigned int N); /** * Destructor. Clears memory */ - ~dVector(); + ~dVector (); /** * Set all entries to zero. Equivalent to @@ -82,17 +82,17 @@ class dVector : public VectorBase /** * U(0-N) = s . Fill all components */ - dVector& operator=(double s); + dVector& operator= (const double s); /** * U = V . Copy all components */ - dVector& operator=(const dVector& V); + dVector& operator= (const dVector& V); /** * U = U * V . Scalar Produkt */ - double operator*(const dVector& V) const; + double operator* (const dVector& V) const; /** * Return square of the norm. @@ -103,24 +103,24 @@ class dVector : public VectorBase * Change Dimension.

* Set dimension to N

* ! reserved memory for This remains unchanged !

- * on fast=0 vector is filled by 0. + * on fast==false vector is filled by 0. */ - void reinit(int N, int fast = 0); + void reinit (const unsigned int N, const bool fast=false); /** * Adjust Dimension.

* Set dimension to n(V)

* ! reserved memory for This remains unchanged !

* ! components of V are not copied in any case !

- * on fast=0 vector is filled by 0. + * on fast==false vector is filled by 0. */ - void reinit(const dVector& V, int fast = 0); + void reinit (const dVector& V, const bool fast=false); /** * Inquire Dimension. returns Dimension , * INLINE */ - int n() const; + unsigned int n () const; //@} @@ -132,13 +132,13 @@ class dVector : public VectorBase * Access Components. returns U(i) , * INLINE */ - double operator()(int i) const; + double operator() (const unsigned int i) const; /** * Access Components. returns U(i) , * INLINE */ - double& operator()(int i); + double& operator() (const unsigned int i); //@} @@ -149,58 +149,62 @@ class dVector : public VectorBase /** * U(0-DIM)+=s . Addition of S to all components */ - void add(const double s); + void add (const double s); /** * U+=V . Simple addition */ - void add(const dVector& V); + void add (const dVector& V); /** * U+=a*V . Simple addition */ - void add(double a, const dVector& V); + void add (const double a, const dVector& V); /** * U+=a*V+b*W . Multiple addition */ - void add(double a, const dVector& V, double b, const dVector& W); + void add (const double a, const dVector& V, + const double b, const dVector& W); /** * U=s*U+V . Scaling + simple addition */ - void sadd(double s, const dVector& V); + void sadd (const double s, const dVector& V); /** * U=s*U+a*V . Scaling + simple addition */ - void sadd(double s, double a, const dVector& V); + void sadd (const double s, const double a, const dVector& V); /** * U=s*U+a*V+b*W . Scaling + multiple addition */ - void sadd(double s, double a, const dVector& V, double b, const dVector& W); + void sadd (const double s, const double a, + const dVector& V, const double b, const dVector& W); /** * U=s*U+a*V+b*W+c*X. Scaling + multiple addition */ - void sadd(double s, double a, const dVector& V, double b, const dVector& W, - double c, const dVector& X); + void sadd (const double s, const double a, + const dVector& V, const double b, const dVector& W, + const double c, const dVector& X); /** * U=s*U . Scaling */ - void equ(double s); + void equ (const double s); /** * U=a*V . Replacing */ - void equ(double a, const dVector& V); + void equ (const double a, const dVector& V); /** * U=a*V+b*W . Replacing by sum */ - void equ(double a, const dVector& V, double b, const dVector& W); + void equ (const double a, const dVector& V, + const double b, const dVector& W); //@} @@ -211,39 +215,51 @@ class dVector : public VectorBase /** * U(i)=0 . ONE Component only */ - void czero(int i); + void czero (const unsigned int i); /** * U(i)=a*V(j) . Replacing */ - void cequ(int i, const VectorBase& V, double a, int j); + void cequ(unsigned int i, const VectorBase& V, + double a, unsigned int j); /** * U(i)=a*V(j)+b*V(k) . Replacing by sum */ - void cequ(int i, const VectorBase& V, double a, int j, double b, int k); + void cequ (const unsigned int i, const VectorBase& V, + const double a, const unsigned int j, + const double b, const unsigned int k); /** * U(i)=a*V(j)+b*V(k)+c*V(l)+d*V(m) . Replacing by sum */ - void cequ(int i, const VectorBase& V, double a, int j, double b, - int k, double c, int l, double d, int m); + void cequ (const unsigned int i, const VectorBase& V, + const double a, const unsigned int j, + const double b, const unsigned int k, + const double c, const unsigned int l, + const double d, const unsigned int m); /** * U(i)+=a*V(j) . Simple addition */ - void cadd(int i, const VectorBase& V, double a, int j); + void cadd (const unsigned int i, const VectorBase& V, + const double a, const unsigned int j); /** * U(i)+=a*V(j)+b*V(k). Multiple addition */ - void cadd(int i, const VectorBase& V, double a, int j, double b, int k); + void cadd (const unsigned int i, const VectorBase& V, + const double a, const unsigned int j, + const double b, const unsigned int k); /** * U(i)+=a*V(j)+b*V(k)+c*V(l)+d*V(m) . Multiple addition */ - void cadd(int i, const VectorBase& V, double a, int j, double b, - int k, double c, int l, double d, int m); + void cadd (const unsigned int i, const VectorBase& V, + const double a, const unsigned int j, + const double b, const unsigned int k, + const double c, const unsigned int l, + const double d, const unsigned int m); //@} @@ -252,17 +268,17 @@ class dVector : public VectorBase */ //@{ /// - virtual const char* name() const; + virtual const char* name () const; /** * Output of vector in user-defined format. */ - void print(FILE* fp, const char* format = 0) const; + void print (FILE* fp, const char* format = 0) const; /** * Output of vector in user-defined format. */ - void print(const char* format = 0) const; + void print (const char* format = 0) const; /** * Print to given stream, one element per line. @@ -300,20 +316,20 @@ class dVector : public VectorBase -inline int dVector::n() const +inline unsigned int dVector::n () const { return dim; } -inline double dVector::operator() (int i) const +inline double dVector::operator() (const unsigned int i) const { - Assert ((i>=0) || (i=0) || (iDIM ! - int maxdim; + unsigned int maxdim; /// Component-array. int *val; @@ -46,50 +46,50 @@ protected: /** * Dummy-Constructor. Dimension=1 */ - iVector(); + iVector (); /** * Copy-Constructor. Dimension set to that of V ,

* all components are copied from V */ - iVector(const iVector& V); + iVector (const iVector& V); /** * Constructor. Dimension = N (>0) */ - iVector(int N); + iVector (const unsigned int N); /** * Destructor. Clears memory */ - ~iVector(); + ~iVector (); /** * U(0-N) = s . Fill all components */ - iVector& operator=(int s); + iVector& operator = (const int s); /** * U = V . Copy all components */ - iVector& operator=(const iVector& V); + iVector& operator = (const iVector& V); /** * Change Dimension.

* Set dimension to N

* ! reserved memory for This remains unchanged !

- * on fast=0 vector is filled by 0. + * on fast==false vector is filled by 0. */ - void reinit(int N, int fast = 0); + void reinit (const unsigned int N, const bool fast=false); /** * Adjust Dimension.

* Set dimension to n(V)

* ! reserved memory for This remains unchanged !

* ! components of V are not copied in any case !

- * on fast=0 vector is filled by 0. + * on fast==false vector is filled by 0. */ - void reinit(const iVector& V, int fast = 0); + void reinit (const iVector& V, const bool fast=false); /** * Set all elements to zero. @@ -100,7 +100,7 @@ protected: * Inquire Dimension. returns Dimension , * INLINE */ - int n() const; + unsigned int n () const; //@} @@ -111,13 +111,13 @@ protected: * Access Components. returns U(i) , * INLINE */ - int operator()(int i) const; + int operator() (const unsigned int i) const; /** * Access Components. returns U(i) , * INLINE */ - int& operator()(int i); + int& operator() (const unsigned int i); //@} @@ -127,17 +127,17 @@ protected: /** * U+=V . Simple addition */ - void add(const iVector& V); + void add (const iVector& V); /** * U+=a*V . Simple addition */ - void add(int a, const iVector& V); + void add (const unsigned int a, const iVector& V); /** * U=a*V . Replacing */ - void equ(int a, const iVector& V); + void equ (const unsigned int a, const iVector& V); //@} /** @@ -168,24 +168,24 @@ protected: -inline int iVector::n() const +inline unsigned int iVector::n() const { return dim; } -inline int iVector::operator() (int i) const +inline int iVector::operator() (unsigned int i) const { - Assert ((i>=0) || (i=0) || (i=0 ; i--) val[i] = 0; + for (unsigned int i=0; i=0;i--) + for (int i=nu-1; i>=0; --i) { s = src(i); - for (j=i+1;j= src.n() + j, ExcInvalidDestination(n(), src.n(), j)); Assert (m() >= src.m() + i, ExcInvalidDestination(m(), src.m(), i)); - for (int ii=0; ii=0 ; i--) val[i] += s * src.el(i); + const unsigned int size = n()*m(); + for (unsigned int i=0; i=0 ; i--) val[i] += s * src.el(i); + const unsigned int size = n()*m(); + for (unsigned int i=0; i -inline void swap(T* a, T* b) +inline void swap (T* a, T* b) { T x = *a; *a = *b; @@ -22,7 +22,7 @@ inline void swap(T* a, T* b) ////////// template -inline void simple_sort(long n, T* field) +inline void simple_sort (const long n, T* field) { long i,j; for (i=1;i -inline void heapsort_sift(T* a, long l, long r) +inline void heapsort_sift (T* a, const long l, const long r) { long i = l; long j = 2*i; @@ -61,7 +61,7 @@ inline void heapsort_sift(T* a, long l, long r) ////////// template -inline void heapsort(int n, T* field) +inline void heapsort (const int n, T* field) { field--; @@ -83,7 +83,7 @@ inline void heapsort(int n, T* field) ////////// template -inline void _quicksort(long r, T* a, long l) +inline void _quicksort (const long r, T* a, const long l) { long i = l; long j = r; @@ -105,7 +105,7 @@ inline void _quicksort(long r, T* a, long l) } template -inline void quicksort(long r, T* a) +inline void quicksort (const long r, T* a) { _quicksort(r,a,1); } @@ -116,7 +116,8 @@ inline void quicksort(long r, T* a) -dSMatrixStruct::dSMatrixStruct(int m, int n, int max_per_row) +dSMatrixStruct::dSMatrixStruct (const unsigned int m, const unsigned int n, + const unsigned int max_per_row) : max_dim(0), max_vec_len(0), rowstart(0), @@ -127,7 +128,8 @@ dSMatrixStruct::dSMatrixStruct(int m, int n, int max_per_row) -dSMatrixStruct::dSMatrixStruct(int n, int max_per_row) +dSMatrixStruct::dSMatrixStruct (const unsigned int n, + const unsigned int max_per_row) : max_dim(0), max_vec_len(0), rowstart(0), @@ -150,7 +152,8 @@ dSMatrixStruct::~dSMatrixStruct () void -dSMatrixStruct::reinit(int m, int n, int max_per_row) +dSMatrixStruct::reinit (const unsigned int m, const unsigned int n, + const unsigned int max_per_row) { Assert (m>0, ExcInvalidNumber(m)); Assert (n>0, ExcInvalidNumber(n)); @@ -164,7 +167,7 @@ dSMatrixStruct::reinit(int m, int n, int max_per_row) { if (rowstart) delete[] rowstart; max_dim = rows; - rowstart = new int[max_dim+1]; + rowstart = new unsigned int[max_dim+1]; } if (vec_len > max_vec_len) @@ -173,12 +176,14 @@ dSMatrixStruct::reinit(int m, int n, int max_per_row) max_vec_len = vec_len; colnums = new int[max_vec_len]; } - int i; - for (i=0;i<=rows;i++) rowstart[i] = i * max_per_row; - for (i = vec_len-1 ; i>=0 ; i--) colnums[i] = -1; + + for (unsigned int i=0; i<=rows; i++) + rowstart[i] = i * max_per_row; + for (int i = vec_len-1; i>=0; i--) + colnums[i] = -1; if (rows == cols) - for (i=0;i= 0) - if ((i!=entries[l]) || (rows!=cols)) - colnums[k++] = entries[l]; - } + if (entries[l]>=0) + if (((signed int)i!=entries[l]) || (rows!=cols)) + colnums[k++] = entries[l]; + rowstart[i] = s; s = k; } vec_len = rowstart[i] = s; - compressed = 1; + compressed = true; delete[] entries; } int -dSMatrixStruct::operator () (int i, int j) +dSMatrixStruct::operator () (const unsigned int i, const unsigned int j) { - for (int k=rowstart[i] ; k=0) && (i=0) && (j=0) out << i << " " << -colnums[j] << endl; } -int +unsigned int dSMatrixStruct::bandwidth () const { - int b=0; - for (int i=0; i=0) { - if (abs(i-colnums[j]) > b) + if ((unsigned int)abs(i-colnums[j]) > b) b = abs(i-colnums[j]); } else @@ -366,7 +371,7 @@ dSMatrix::~dSMatrix () void -dSMatrix::reinit() +dSMatrix::reinit () { Assert (cols != 0, ExcMatrixNotInitialized()); Assert (cols->compressed, ExcNotCompressed()); @@ -402,16 +407,16 @@ dSMatrix::clear () { void -dSMatrix::vmult(dVector& dst,const dVector& src) const +dSMatrix::vmult (dVector& dst, const dVector& src) const { Assert (cols != 0, ExcMatrixNotInitialized()); Assert(m() == dst.n(), ExcDimensionsDontMatch(m(),dst.n())); Assert(n() == src.n(), ExcDimensionsDontMatch(n(),src.n())); - for (int i=0;irowstart[i]; j < cols->rowstart[i+1] ;j++) + for (unsigned int j=cols->rowstart[i]; j < cols->rowstart[i+1] ;j++) { int p = cols->colnums[j]; s += val[j] * src(p); @@ -422,19 +427,19 @@ dSMatrix::vmult(dVector& dst,const dVector& src) const void -dSMatrix::Tvmult(dVector& dst,const dVector& src) const +dSMatrix::Tvmult (dVector& dst, const dVector& src) const { Assert (cols != 0, ExcMatrixNotInitialized()); Assert(n() == dst.n(), ExcDimensionsDontMatch(n(),dst.n())); Assert(m() == src.n(), ExcDimensionsDontMatch(m(),src.n())); - int i; + unsigned int i; for (i=0;irowstart[i]; jrowstart[i+1] ;j++) + for (unsigned int j=cols->rowstart[i]; jrowstart[i+1] ;j++) { int p = cols->colnums[j]; dst(p) += val[j] * src(i); @@ -443,7 +448,7 @@ dSMatrix::Tvmult(dVector& dst,const dVector& src) const } double -dSMatrix::residual(dVector& dst,const dVector& u,const dVector& b) +dSMatrix::residual (dVector& dst, const dVector& u, const dVector& b) { Assert (cols != 0, ExcMatrixNotInitialized()); Assert(m() == dst.n(), ExcDimensionsDontMatch(m(),dst.n())); @@ -452,10 +457,10 @@ dSMatrix::residual(dVector& dst,const dVector& u,const dVector& b) double s,norm=0.; - for (int i=0;irowstart[i]; jrowstart[i+1] ;j++) + for (unsigned int j=cols->rowstart[i]; jrowstart[i+1] ;j++) { int p = cols->colnums[j]; s -= val[j] * u(p); @@ -467,39 +472,42 @@ dSMatrix::residual(dVector& dst,const dVector& u,const dVector& b) } void -dSMatrix::Jacobi_precond(dVector& dst,const dVector& src,double om) +dSMatrix::Jacobi_precond (dVector& dst, const dVector& src, const double om) { Assert (cols != 0, ExcMatrixNotInitialized()); - int n = src.n(); + const unsigned int n = src.n(); - for (int i=0;irowstart[i]]; } } void -dSMatrix::SSOR_precond(dVector& dst,const dVector& src,double om) +dSMatrix::SSOR_precond (dVector& dst, const dVector& src, const double om) { Assert (cols != 0, ExcMatrixNotInitialized()); - int p,n = src.n(); - int i,j; + int p; + unsigned int n = src.n(); + unsigned int j; - for (i=0;irowstart[i]; jrowstart[i+1] ;j++) { p = cols->colnums[j]; - if (prowstart[i]]; } - for (i=0;irowstart[i]]; + for (unsigned int i=0; irowstart[i]]; - for (i=n-1;i>=0;i--) + for (int i=n-1; i>=0; i--) { for (j=cols->rowstart[i];jrowstart[i+1];j++) { @@ -511,7 +519,7 @@ dSMatrix::SSOR_precond(dVector& dst,const dVector& src,double om) } void -dSMatrix::SOR_precond(dVector& dst,const dVector& src,double om) +dSMatrix::SOR_precond (dVector& dst, const dVector& src, const double om) { Assert (cols != 0, ExcMatrixNotInitialized()); dst = src; @@ -519,19 +527,19 @@ dSMatrix::SOR_precond(dVector& dst,const dVector& src,double om) } void -dSMatrix::SOR(dVector& dst, double om) +dSMatrix::SOR (dVector& dst, const double om) { Assert (cols != 0, ExcMatrixNotInitialized()); Assert(n() == m(), ExcDimensionsDontMatch(n(),m())); Assert(m() == dst.n(), ExcDimensionsDontMatch(m(),dst.n())); - for (int i=0;irowstart[i]; jrowstart[i+1] ;j++) + for (unsigned int j=cols->rowstart[i]; jrowstart[i+1] ;j++) { int p = cols->colnums[j]; - if (prowstart[i]]; @@ -539,15 +547,16 @@ dSMatrix::SOR(dVector& dst, double om) } void -dSMatrix::SSOR(dVector& dst, double om) +dSMatrix::SSOR (dVector& dst, const double om) { Assert (cols != 0, ExcMatrixNotInitialized()); - int p,n = dst.n(); - int i,j; + int p; + unsigned int n = dst.n(); + unsigned int j; double s; - for (i=0;irowstart[i]; jrowstart[i+1] ;j++) @@ -562,7 +571,7 @@ dSMatrix::SSOR(dVector& dst, double om) dst(i) /= val[cols->rowstart[i]]; } - for (i=n-1;i>=0;i--) + for (int i=n-1; i>=0; i--) // this time, i is signed, but alsways positive! { s = 0.; for (j=cols->rowstart[i]; jrowstart[i+1] ;j++) @@ -570,7 +579,7 @@ dSMatrix::SSOR(dVector& dst, double om) p = cols->colnums[j]; if (p>=0) { - if (irowstart[i]]; @@ -588,7 +597,7 @@ const dSMatrixStruct & dSMatrix::get_sparsity_pattern () const { void dSMatrix::print (ostream &out) const { Assert (cols != 0, ExcMatrixNotInitialized()); - for (int i=0; irows; ++i) - for (int j=cols->rowstart[i]; jrowstart[i+1]; ++j) + for (unsigned int i=0; irows; ++i) + for (unsigned int j=cols->rowstart[i]; jrowstart[i+1]; ++j) out << "(" << i << "," << cols->colnums[j] << ") " << val[j] << endl; }; diff --git a/deal.II/lac/source/dvector.cc b/deal.II/lac/source/dvector.cc index 2fab74b805..d39bb93f53 100644 --- a/deal.II/lac/source/dvector.cc +++ b/deal.II/lac/source/dvector.cc @@ -7,14 +7,14 @@ #include #include -dVector::dVector() : +dVector::dVector () : dim(0), maxdim(0), val(0) {} -dVector::dVector(int n) : +dVector::dVector (const unsigned int n) : dim(n), maxdim(n), val(0) @@ -30,7 +30,7 @@ dVector::dVector(int n) : } -dVector::dVector(const dVector& v) : +dVector::dVector (const dVector& v) : VectorBase(v), dim(v.n()), maxdim(v.n()), @@ -40,14 +40,14 @@ dVector::dVector(const dVector& v) : { val = new double[maxdim]; Assert (val != 0, ExcOutOfMemory()); - for (int i=0; i0, ExcInvalidNumber(n)); if (n>maxdim) @@ -64,9 +64,9 @@ void dVector::reinit(int n, int fast) -void dVector::reinit(const dVector& v, int fast) +void dVector::reinit (const dVector& v, const bool fast) { - int n = v.n(); + const unsigned int n = v.n(); if (n>maxdim) { if (val) delete[] val; @@ -81,7 +81,7 @@ void dVector::reinit(const dVector& v, int fast) -dVector::~dVector() +dVector::~dVector () { if (val) delete[] val; } @@ -89,7 +89,7 @@ dVector::~dVector() void dVector::clear () { - for (int i=0; i=0) || (i=0) || (j=0) || (i=0) || (j=0) || (k=0) || (i=0) || (j=0) || (k=0) || (l=0) || (m=0) && (i=0) && (i=0) && (j=0) || (i=0) || (j=0) || (k=0) || (i=0) || (j=0) || (k=0) || (l=0) || (m0, ExcInvalidNumber(n)); if (n>maxdim) @@ -60,9 +59,9 @@ void iVector::reinit(int n, int fast) -void iVector::reinit(const iVector& v, int fast) +void iVector::reinit (const iVector& v, const bool fast) { - int n = v.n(); + const unsigned int n = v.n(); if (n>maxdim) { delete[] val; @@ -77,7 +76,7 @@ void iVector::reinit(const iVector& v, int fast) -iVector::~iVector() +iVector::~iVector () { if (val) delete[] val; @@ -86,36 +85,36 @@ iVector::~iVector() void iVector::clear () { - for (int i=0; i