From 5d4794c32fc8a63c040a9b80c2c01b297d4c09bd Mon Sep 17 00:00:00 2001 From: michael Date: Mon, 7 Jun 2021 20:10:55 +0200 Subject: [PATCH] Class GenericMatrix no longer uses DoubleTab --- CDMATH/base/inc/GenericMatrix.hxx | 15 +-------- CDMATH/base/inc/Matrix.hxx | 22 ++++++++++++ CDMATH/base/src/GenericMatrix.cxx | 44 +----------------------- CDMATH/base/src/Matrix.cxx | 56 +++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 57 deletions(-) mode change 100644 => 100755 CDMATH/base/inc/Matrix.hxx mode change 100644 => 100755 CDMATH/base/src/Matrix.cxx diff --git a/CDMATH/base/inc/GenericMatrix.hxx b/CDMATH/base/inc/GenericMatrix.hxx index 77735d5..52f3db9 100755 --- a/CDMATH/base/inc/GenericMatrix.hxx +++ b/CDMATH/base/inc/GenericMatrix.hxx @@ -17,7 +17,7 @@ */ #include - +#include #include "DoubleTab.hxx" class GenericMatrix @@ -45,18 +45,8 @@ class GenericMatrix */ int getNumberOfColumns ( void ) const ; - const DoubleTab& getValues( void ) const ; - - DoubleTab getValues( void ) ; - - void setValues(const DoubleTab& values) ; - virtual double operator ()( int i, int j ) const = 0; - double max() const; - - double min() const; - virtual bool isSymmetric(double tol=1e-6) const ; bool isSquare() const ; @@ -65,8 +55,6 @@ class GenericMatrix virtual bool containsPetscMatrix() const { return false; }; - int coefficient(int index) const ; - void view() const ; protected: //---------------------------------------------------------------- @@ -83,7 +71,6 @@ class GenericMatrix bool _isSparseMatrix ; - DoubleTab _values ; }; #endif /* GENERICMATRIX_HXX_ */ diff --git a/CDMATH/base/inc/Matrix.hxx b/CDMATH/base/inc/Matrix.hxx old mode 100644 new mode 100755 index 13b13bd..bfb7985 --- a/CDMATH/base/inc/Matrix.hxx +++ b/CDMATH/base/inc/Matrix.hxx @@ -60,6 +60,21 @@ class Matrix: public GenericMatrix */ virtual ~Matrix ( void ) ; + const DoubleTab& getValues( void ) const ; + + DoubleTab getValues( void ) ; + + void setValues(const DoubleTab& values) ; + + //returns the array of matrix coefficients + std::vector< double > getArray(); + + //returns the maximum coefficient + double max() const; + + //returns the minimum coefficient + double min() const; + bool isSparseMatrix( void ) const ; double& operator () ( int i, int j ) ; @@ -100,6 +115,13 @@ class Matrix: public GenericMatrix friend std::ostream& operator<<(std::ostream& out, const Matrix& matrix ) ; + + protected: //---------------------------------------------------------------- + + DoubleTab _values ; + + //This function is used in the computation of the determinant + int coefficient(int index) const ; }; #endif /* MATRIX_HXX_ */ diff --git a/CDMATH/base/src/GenericMatrix.cxx b/CDMATH/base/src/GenericMatrix.cxx index 0d2f5eb..d81c273 100755 --- a/CDMATH/base/src/GenericMatrix.cxx +++ b/CDMATH/base/src/GenericMatrix.cxx @@ -6,6 +6,7 @@ */ #include +#include #include "GenericMatrix.hxx" #include "CdmathException.hxx" @@ -42,26 +43,6 @@ GenericMatrix::getNumberOfColumns() const return _numberOfColumns ; } -const DoubleTab& -GenericMatrix::getValues( void ) const -{ - return _values; -} - -//---------------------------------------------------------------------- -DoubleTab -GenericMatrix::getValues() -//---------------------------------------------------------------------- -{ - return _values; -} - -void -GenericMatrix::setValues(const DoubleTab& values) -{ - _values=values; -} - bool GenericMatrix::isSymmetric(double tol) const { @@ -90,29 +71,6 @@ GenericMatrix::isSquare() const return false; } -int -GenericMatrix::coefficient(int index) const -{ - if(! (index % 2) ) - return (1); - return (-1); -} - - -double -GenericMatrix::max() const -{ - return _values.max(); -} - - -double -GenericMatrix::min() const -{ - return _values.max(); -} - - void GenericMatrix::view() const { diff --git a/CDMATH/base/src/Matrix.cxx b/CDMATH/base/src/Matrix.cxx old mode 100644 new mode 100755 index 50f4781..20dfed6 --- a/CDMATH/base/src/Matrix.cxx +++ b/CDMATH/base/src/Matrix.cxx @@ -5,6 +5,7 @@ * Authors: CDMATH */ #include +#include #include "Matrix.hxx" #include "Vector.hxx" @@ -46,6 +47,53 @@ Matrix::Matrix(const Matrix& matrix) _values=DoubleTab (_numberOfRows*_numberOfColumns,matrix.getValues().getValues()); } +const DoubleTab& +Matrix::getValues( void ) const +{ + return _values; +} + +//---------------------------------------------------------------------- +DoubleTab +Matrix::getValues() +//---------------------------------------------------------------------- +{ + return _values; +} + +void +Matrix::setValues(const DoubleTab& values) +{ + _values=values; +} + +double +Matrix::max() const +{ + return _values.max(); +} + +double +Matrix::min() const +{ + return _values.max(); +} + +std::vector< double > +Matrix::getArray() +{ + int numberOfRows =getNumberOfRows(); + int numberOfColums=getNumberOfColumns(); + int size=_numberOfRows*numberOfColums; + + vector< double > result(size); + double* values = result.data(); + + memcpy(values,_values.getPointer(),size*sizeof(double)) ; + + return result; +} + bool Matrix::isSparseMatrix( void ) const { @@ -140,6 +188,14 @@ Matrix::partMatrix(int row, int column) const return res; } +int +Matrix::coefficient(int index) const +{ + if(! (index % 2) ) + return (1); + return (-1); +} + double Matrix::determinant() const { -- 2.39.2