IBSimu 1.0.4
|
00001 00005 /* Copyright (c) 2005-2010 Taneli Kalvas. All rights reserved. 00006 * 00007 * You can redistribute this software and/or modify it under the terms 00008 * of the GNU General Public License as published by the Free Software 00009 * Foundation; either version 2 of the License, or (at your option) 00010 * any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, but 00013 * WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this library (file "COPYING" included in the package); 00019 * if not, write to the Free Software Foundation, Inc., 51 Franklin 00020 * Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 * 00022 * If you have questions about your rights to use or distribute this 00023 * software, please contact Berkeley Lab's Technology Transfer 00024 * Department at TTD@lbl.gov. Other questions, comments and bug 00025 * reports should be sent directly to the author via email at 00026 * taneli.kalvas@jyu.fi. 00027 * 00028 * NOTICE. This software was developed under partial funding from the 00029 * U.S. Department of Energy. As such, the U.S. Government has been 00030 * granted for itself and others acting on its behalf a paid-up, 00031 * nonexclusive, irrevocable, worldwide license in the Software to 00032 * reproduce, prepare derivative works, and perform publicly and 00033 * display publicly. Beginning five (5) years after the date 00034 * permission to assert copyright is obtained from the U.S. Department 00035 * of Energy, and subject to any subsequent five (5) year renewals, 00036 * the U.S. Government is granted for itself and others acting on its 00037 * behalf a paid-up, nonexclusive, irrevocable, worldwide license in 00038 * the Software to reproduce, prepare derivative works, distribute 00039 * copies to the public, perform publicly and display publicly, and to 00040 * permit others to do so. 00041 */ 00042 00043 #ifndef CCOLMATRIX_HPP 00044 #define CCOLMATRIX_HPP 1 00045 00046 00047 #include <cstdlib> 00048 #include <iostream> 00049 #include "matrix.hpp" 00050 #include "error.hpp" 00051 00052 00075 class CColMatrix : public Matrix { 00076 int _n; 00077 int _m; 00078 int _nz; 00079 int _asize; 00080 int *_ptr; 00081 int *_row; 00082 double *_val; 00083 00084 void reallocate( void ); 00085 void allocate( void ); 00086 00087 double get_check( int i, int j ) const; 00088 double &set_check( int i, int j ); 00089 double get_no_check( int i, int j ) const; 00090 double &set_no_check( int i, int j ); 00091 00092 void clear_check( int i, int j ); 00093 void clear_no_check( int i, int j ); 00094 00095 void build( const class CColMatrix &mat ); 00096 void build( const class CRowMatrix &mat ); 00097 void build( const class CoordMatrix &mat ); 00098 00099 public: 00100 00101 /* ************************************** * 00102 * Constructors and destructor * 00103 * ************************************** */ 00104 00107 CColMatrix(); 00108 00111 CColMatrix( int n, int m ); 00112 00121 CColMatrix( int n, int m, int nz, 00122 int *ptr, int *row, double *val ); 00123 00126 CColMatrix( const CColMatrix &mat ); 00127 00133 CColMatrix( const class CRowMatrix &mat ); 00134 00137 CColMatrix( const class CoordMatrix &mat ); 00138 00141 CColMatrix( const class Matrix &mat ); 00142 00145 ~CColMatrix(); 00146 00147 /* ************************************** * 00148 * Access and information * 00149 * ************************************** */ 00150 00153 int columns( void ) const { return( _m ); } 00154 00157 int rows( void ) const { return( _n ); } 00158 00161 void size( int &n, int &m ) const { n = _n; m = _m; } 00162 00165 int nz_elements( void ) const { return( _nz ); } 00166 00169 int capacity( void ) const { return( _asize ); } 00170 00171 /* ************************************** * 00172 * User level control * 00173 * ************************************** */ 00174 00179 void resize( int n, int m ); 00180 00187 void merge( CColMatrix &mat ); 00188 00191 void clear( void ); 00192 00197 void clear( int i, int j ); 00198 00201 void reserve( int size ); 00202 00206 void order_ascending( void ); 00207 00211 bool check_ascending( void ); 00212 00215 void debug_print( void ) const; 00216 00217 /* ************************************** * 00218 * User level matrix element access * 00219 * ************************************** */ 00220 00226 double get( int i, int j ) const; 00227 00246 double &set( int i, int j ); 00247 00256 void set_column( int j, int N, const int *row, const double *val ); 00257 00273 void construct_add( int i, int j, double val ); 00274 00275 /* ************************************** * 00276 * Low level access * 00277 * ************************************** */ 00278 00282 int &ptr( int i ) { return( _ptr[i] ); } 00283 00287 int &row( int i ) { return( _row[i] ); } 00288 00292 double &val( int i ) { return( _val[i] ); } 00293 00297 const int &ptr( int i ) const { return( _ptr[i] ); } 00298 00302 const int &row( int i ) const { return( _row[i] ); } 00303 00307 const double &val( int i ) const { return( _val[i] ); } 00308 00316 void set_nz( int nz ); 00317 00318 /* ************************************** * 00319 * Assignent operators * 00320 * ************************************** */ 00321 00324 CColMatrix &operator=( const CColMatrix &mat ); 00325 00332 CColMatrix &operator=( const class CRowMatrix &mat ); 00333 00337 CColMatrix &operator=( const class CoordMatrix &mat ); 00338 00342 CColMatrix &operator=( const Matrix &mat ); 00343 00344 /* ************************************** * 00345 * Matrix-Vector operations * 00346 * ************************************** */ 00347 00348 /* \brief Calculates \a x = \a A*b. 00349 */ 00350 void multiply_by_vector( Vector &x, const Vector &b ) const; 00351 00357 void lower_unit_solve( Vector &x, const Vector &b ) const; 00358 00365 void upper_diag_solve( Vector &x, const Vector &b ) const; 00366 00367 00368 friend class CRowMatrix; 00369 friend class CoordMatrix; 00370 friend class Vector; 00371 friend class HBIO; 00372 }; 00373 00374 00375 inline double CColMatrix::get( int i, int j ) const 00376 { 00377 #ifdef SPM_RANGE_CHECK 00378 return( get_check( i, j ) ); 00379 #else 00380 return( get_no_check( i, j ) ); 00381 #endif 00382 } 00383 00384 00385 inline double &CColMatrix::set( int i, int j ) 00386 { 00387 #ifdef SPM_RANGE_CHECK 00388 return( set_check( i, j ) ); 00389 #else 00390 return( set_no_check( i, j ) ); 00391 #endif 00392 } 00393 00394 00395 inline void CColMatrix::clear( int i, int j ) 00396 { 00397 #ifdef SPM_RANGE_CHECK 00398 clear_check( i, j ); 00399 #else 00400 clear_no_check( i, j ); 00401 #endif 00402 } 00403 00404 00405 #endif 00406 00407 00408 00409 00410 00411 00412 00413 00414 00415 00416 00417 00418 00419 00420 00421 00422 00423 00424 00425 00426