From: Wolfgang Bangerth Date: Wed, 18 Mar 1998 16:00:56 +0000 (+0000) Subject: Restructuring and more error checks X-Git-Tag: v8.0.0~23168 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1fc9daed753b14830ff7347908adea79a69f9596;p=dealii.git Restructuring and more error checks git-svn-id: https://svn.dealii.org/trunk@83 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/dsmatrix.h b/deal.II/lac/include/lac/dsmatrix.h index 46b188952e..d6c3ec9c60 100644 --- a/deal.II/lac/include/lac/dsmatrix.h +++ b/deal.II/lac/include/lac/dsmatrix.h @@ -1,4 +1,9 @@ -// $Id$ +/*---------------------------- dsmatrix.h ---------------------------*/ +/* */ +#ifndef __dsmatrix_H +#define __dsmatrix_H +/*---------------------------- dsmatrix.h ---------------------------*/ + // This file is part of the DEAL Library // DEAL is Copyright(1995) by @@ -41,24 +46,13 @@ class dSMatrixStruct public: ////////// void reinit(int m, int n, int max_per_row); - ////////// - dSMatrixStruct(int m, int n, int max_per_row) - : max_dim(0), max_vec_len(0), rowstart(0), colnums(0) - { - reinit(m,n,max_per_row); - } - ////////// - dSMatrixStruct(int n, int max_per_row) - : max_dim(0), max_vec_len(0), rowstart(0), colnums(0) - { - reinit(n,n,max_per_row); - } - ////////// - ~dSMatrixStruct() - { - delete[] rowstart; - delete[] colnums; - } + ////////// + dSMatrixStruct(int m, int n, int max_per_row); + + ////////// + dSMatrixStruct(int n, int max_per_row); + ////////// + ~dSMatrixStruct(); ////////// void compress(); ////////// @@ -74,10 +68,10 @@ public: ////////// void add_matrix(const iVector& rows, const iVector& cols); - void print_gnuplot (ostream &) const; - int n_rows () const { return rows; }; - int n_cols () const { return cols; }; - int bandwidth () const; + void print_gnuplot (ostream &) const; + int n_rows () const; + int n_cols () const; + int bandwidth () const; friend class ConstraintMatrix; friend class DoFHandler<1>; @@ -108,8 +102,6 @@ public: - - /* CLASS dSMatrix @@ -133,17 +125,11 @@ class dSMatrix dSMatrix (); // - dSMatrix(dSMatrixStruct& c) - : cols(&c), val(0), max_len(0) - { - reinit(); - } + dSMatrix(dSMatrixStruct& c); + // - ~dSMatrix() - { - delete[] val; - } - + ~dSMatrix(); + // void reinit(); @@ -151,23 +137,15 @@ class dSMatrix void reinit (dSMatrixStruct &); // - int m() const { return cols->rows; } + int m() const; // - int n() const { return cols->cols; } + int n() const; // - void set(int i,int j,double value) { - Assert (cols->operator()(i,j) != -1, - ExcInvalidIndex(i,j)); - val[cols->operator()(i,j)] = value; - } + void set (int i, int j, double value); // - void add(int i,int j,double value) { - Assert (cols->operator()(i,j) != -1, - ExcInvalidIndex(i,j)); - val[cols->operator()(i,j)]+= value; - } - + void add (int i, int j, double value); + // void vmult (dVector& dst,const dVector& src) const; // @@ -217,4 +195,73 @@ class dSMatrix friend class ConstraintMatrix; }; + + + + + +/*---------------------- Inline functions -----------------------------------*/ + +inline +int dSMatrixStruct::n_rows () const { + return rows; +}; + + + +inline +int dSMatrixStruct::n_cols () const { + return cols; +}; + + + + + +inline +int dSMatrix::m () const +{ + return cols->rows; +}; + + + +inline +int dSMatrix::n () const +{ + return cols->cols; +}; + + + +inline +void dSMatrix::set (int i, int j, double value) { + Assert (cols->operator()(i,j) != -1, + ExcInvalidIndex(i,j)); + val[cols->operator()(i,j)] = value; +}; + + + +inline +void dSMatrix::add (int i, int j, double value) { + Assert (cols->operator()(i,j) != -1, + ExcInvalidIndex(i,j)); + val[cols->operator()(i,j)]+= value; +}; + + + + + + + + + + + + +/*---------------------------- dsmatrix.h ---------------------------*/ +/* end of #ifndef __dsmatrix_H */ #endif +/*---------------------------- dsmatrix.h ---------------------------*/ diff --git a/deal.II/lac/source/dsmatrix.cc b/deal.II/lac/source/dsmatrix.cc index d70f3826b3..b0d90fddd5 100644 --- a/deal.II/lac/source/dsmatrix.cc +++ b/deal.II/lac/source/dsmatrix.cc @@ -115,6 +115,40 @@ inline void quicksort(long r, T* a) + +dSMatrixStruct::dSMatrixStruct(int m, int n, int max_per_row) + : max_dim(0), + max_vec_len(0), + rowstart(0), + colnums(0) +{ + reinit (m,n,max_per_row); +}; + + + +dSMatrixStruct::dSMatrixStruct(int n, int max_per_row) + : max_dim(0), + max_vec_len(0), + rowstart(0), + colnums(0) +{ + reinit (n,n,max_per_row); +}; + + + +dSMatrixStruct::~dSMatrixStruct () +{ + if (rowstart != 0) + delete[] rowstart; + if (colnums != 0) + delete[] colnums; +} + + + + void dSMatrixStruct::reinit(int m, int n, int max_per_row) { @@ -150,6 +184,7 @@ dSMatrixStruct::reinit(int m, int n, int max_per_row) compressed = 0; } + void dSMatrixStruct::compress() { @@ -191,6 +226,7 @@ dSMatrixStruct::compress() delete[] entries; } + int dSMatrixStruct::operator () (int i, int j) { @@ -199,6 +235,7 @@ dSMatrixStruct::operator () (int i, int j) return -1; } + void dSMatrixStruct::add (int i, int j) { @@ -224,6 +261,8 @@ dSMatrixStruct::add (int i, int j) Assert (false, ExcNotEnoughSpace(i)); } + + void dSMatrixStruct::add_matrix(int n, int* rowcols) { @@ -234,6 +273,7 @@ dSMatrixStruct::add_matrix(int n, int* rowcols) } + void dSMatrixStruct::add_matrix(int m, int n, int* rows, int* cols) { @@ -243,6 +283,8 @@ dSMatrixStruct::add_matrix(int m, int n, int* rows, int* cols) add(rows[i], cols[j]); } + + void dSMatrixStruct::add_matrix(const iVector& rowcols) { @@ -253,6 +295,7 @@ dSMatrixStruct::add_matrix(const iVector& rowcols) } + void dSMatrixStruct::add_matrix(const iVector& rows, const iVector& cols) { @@ -263,6 +306,7 @@ dSMatrixStruct::add_matrix(const iVector& rows, const iVector& cols) } + void dSMatrixStruct::print_gnuplot (ostream &out) const { @@ -273,6 +317,7 @@ dSMatrixStruct::print_gnuplot (ostream &out) const } + int dSMatrixStruct::bandwidth () const { @@ -304,13 +349,29 @@ dSMatrix::dSMatrix () : max_len(0) {}; + +dSMatrix::dSMatrix (dSMatrixStruct &c) + : cols(&c), val(0), max_len(0) +{ + reinit(); +}; + + + +dSMatrix::~dSMatrix () +{ + delete[] val; +}; + + + void dSMatrix::reinit() { Assert (cols != 0, ExcMatrixNotInitialized()); Assert (cols->compressed, ExcNotCompressed()); - if(max_lenvec_len) + if (max_lenvec_len) { if (val) delete[] val; val = new double[cols->vec_len]; @@ -350,6 +411,7 @@ dSMatrix::vmult(dVector& dst,const dVector& src) const } } + void dSMatrix::Tvmult(dVector& dst,const dVector& src) const {