Navigation

Main Page
Download
Support
Installation
Tutorial
Examples
Reference Manual
   Version 1.0.6dev
      Class Index
      File List
   Version 1.0.6
   Version 1.0.5new_solver
   Version 1.0.5dev
   Version 1.0.5b
   Version 1.0.4dev
   Version 1.0.4
Publications


Hosted by Get Ion Beam Simulator at SourceForge.net. Fast, secure and Free Open Source software downloads
crowmatrix.hpp
Go to the documentation of this file.
1 
5 /* Copyright (c) 2005-2011 Taneli Kalvas. All rights reserved.
6  *
7  * You can redistribute this software and/or modify it under the terms
8  * of the GNU General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this library (file "COPYING" included in the package);
19  * if not, write to the Free Software Foundation, Inc., 51 Franklin
20  * Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  * If you have questions about your rights to use or distribute this
23  * software, please contact Berkeley Lab's Technology Transfer
24  * Department at TTD@lbl.gov. Other questions, comments and bug
25  * reports should be sent directly to the author via email at
26  * taneli.kalvas@jyu.fi.
27  *
28  * NOTICE. This software was developed under partial funding from the
29  * U.S. Department of Energy. As such, the U.S. Government has been
30  * granted for itself and others acting on its behalf a paid-up,
31  * nonexclusive, irrevocable, worldwide license in the Software to
32  * reproduce, prepare derivative works, and perform publicly and
33  * display publicly. Beginning five (5) years after the date
34  * permission to assert copyright is obtained from the U.S. Department
35  * of Energy, and subject to any subsequent five (5) year renewals,
36  * the U.S. Government is granted for itself and others acting on its
37  * behalf a paid-up, nonexclusive, irrevocable, worldwide license in
38  * the Software to reproduce, prepare derivative works, distribute
39  * copies to the public, perform publicly and display publicly, and to
40  * permit others to do so.
41  */
42 
43 #ifndef CROWMATRIX_HPP
44 #define CROWMATRIX_HPP 1
45 
46 
47 #include <cstdlib>
48 #include <iostream>
49 #include "matrix.hpp"
50 #include "error.hpp"
51 
52 
76 class CRowMatrix : public Matrix {
77  int _n;
78  int _m;
79  int _nz;
80  int _asize;
81  int *_ptr;
82  int *_col;
83  double *_val;
84 
85  void reallocate( void );
86  void allocate( void );
87 
88  double get_check( int i, int j ) const;
89  double &set_check( int i, int j );
90  double get_no_check( int i, int j ) const;
91  double &set_no_check( int i, int j );
92 
93  void clear_check( int i, int j );
94  void clear_no_check( int i, int j );
95 
96  void build( const class CColMatrix &mat );
97  void build( const class CRowMatrix &mat );
98  void build( const class CoordMatrix &mat );
99 
100 public:
101 
102 /* ************************************** *
103  * Constructors and destructor *
104  * ************************************** */
105 
108  CRowMatrix();
109 
112  CRowMatrix( int n, int m );
113 
124  CRowMatrix( int n, int m, int nz, int asize,
125  int *ptr, int *col, double *val );
126 
129  CRowMatrix( const CRowMatrix &mat );
130 
136  CRowMatrix( const class CColMatrix &mat );
137 
140  CRowMatrix( const class CoordMatrix &mat );
141 
144  CRowMatrix( const class Matrix &mat );
145 
148  ~CRowMatrix();
149 
150 /* ************************************** *
151  * Access and information *
152  * ************************************** */
153 
156  int columns( void ) const { return( _m ); }
157 
160  int rows( void ) const { return( _n ); }
161 
165  void size( int &n, int &m ) const { n = _n; m = _m; }
166 
169  int nz_elements( void ) const { return( _nz ); }
170 
173  int capacity( void ) const { return( _asize ); }
174 
175 /* ************************************** *
176  * User level control *
177  * ************************************** */
178 
183  void resize( int n, int m );
184 
191  void merge( CRowMatrix &mat );
192 
195  void clear( void );
196 
201  void clear( int i, int j );
202 
205  void reserve( int size );
206 
210  void order_ascending( void );
211 
215  bool check_ascending( void ) const;
216 
219  void debug_print( std::ostream &os ) const;
220 
221 /* ************************************** *
222  * User level matrix element access *
223  * ************************************** */
224 
230  double get( int i, int j ) const;
231 
250  double &set( int i, int j );
251 
260  void set_row( int i, int N, const int *col, const double *val );
261 
277  void construct_add( int i, int j, double val );
278 
279 /* ************************************** *
280  * Low level access *
281  * ************************************** */
282 
286  int &ptr( int i ) { return( _ptr[i] ); }
287 
291  int &col( int i ) { return( _col[i] ); }
292 
296  double &val( int i ) { return( _val[i] ); }
297 
301  const int &ptr( int i ) const { return( _ptr[i] ); }
302 
306  const int &col( int i ) const { return( _col[i] ); }
307 
311  const double &val( int i ) const { return( _val[i] ); }
312 
320  void set_nz( int nz );
321 
322 /* ************************************** *
323  * Assignent operators *
324  * ************************************** */
325 
328  CRowMatrix &operator=( const CRowMatrix &mat );
329 
336  CRowMatrix &operator=( const class CColMatrix &mat );
337 
340  CRowMatrix &operator=( const class CoordMatrix &mat );
341 
345  CRowMatrix &operator=( const class Matrix &mat );
346 
347 /* ************************************** *
348  * Matrix-Vector operations *
349  * ************************************** */
350 
351  /* \brief Calculates \a x = \a A*b.
352  */
353  void multiply_by_vector( Vector &x, const Vector &b ) const;
354 
360  void lower_unit_solve( Vector &x, const Vector &b ) const;
361 
368  void upper_diag_solve( Vector &x, const Vector &b ) const;
369 
379  void LU_solve( Vector &x, const Vector &b ) const;
380 
381  friend class CColMatrix;
382  friend class CoordMatrix;
383  friend class Vector;
384 };
385 
386 
387 inline double CRowMatrix::get( int i, int j ) const
388 {
389 #ifdef SPM_RANGE_CHECK
390  return( get_check( i, j ) );
391 #else
392  return( get_no_check( i, j ) );
393 #endif
394 }
395 
396 
397 inline double &CRowMatrix::set( int i, int j )
398 {
399 #ifdef SPM_RANGE_CHECK
400  return( set_check( i, j ) );
401 #else
402  return( set_no_check( i, j ) );
403 #endif
404 }
405 
406 
407 inline void CRowMatrix::clear( int i, int j )
408 {
409 #ifdef SPM_RANGE_CHECK
410  clear_check( i, j );
411 #else
412  clear_no_check( i, j );
413 #endif
414 }
415 
416 
417 #endif
Compressed column sparse matrix class.
Definition: ccolmatrix.hpp:75
Compressed row sparse matrix class.
Definition: crowmatrix.hpp:76
const int & ptr(int i) const
Returns a const reference to the to the internal pointer index data ptr of the matrix.
Definition: crowmatrix.hpp:301
double & set(int i, int j)
Function to get a reference to matrix element value at (i,j).
Definition: crowmatrix.hpp:397
int & ptr(int i)
Returns a reference to the to the internal pointer index data ptr of the matrix.
Definition: crowmatrix.hpp:286
void clear(void)
Clear non-zero matrix elements, set all elements to zero.
Definition: crowmatrix.cpp:360
void debug_print(std::ostream &os) const
Print debugging information to os.
Definition: crowmatrix.cpp:583
int nz_elements(void) const
Returns the number of non-zero elements in the matrix.
Definition: crowmatrix.hpp:169
bool check_ascending(void) const
Check if matrix data is in ascending column index order within each row.
Definition: crowmatrix.cpp:451
void lower_unit_solve(Vector &x, const Vector &b) const
Solves A*x = b for lower unit diagonal matrix.
Definition: crowmatrix.cpp:640
int rows(void) const
Returns the number of rows in the matrix.
Definition: crowmatrix.hpp:160
int & col(int i)
Returns a reference to the to the internal column data of the matrix.
Definition: crowmatrix.hpp:291
void order_ascending(void)
Order (sort) matrix data in ascending column index order within each row.
Definition: crowmatrix.cpp:443
void LU_solve(Vector &x, const Vector &b) const
Solves A*x = b for packed LU matrix.
Definition: crowmatrix.cpp:677
void resize(int n, int m)
Resizes the matrix to size n x m.
Definition: crowmatrix.cpp:334
~CRowMatrix()
Destructor.
Definition: crowmatrix.cpp:326
void upper_diag_solve(Vector &x, const Vector &b) const
Solves A*x = b for upper diagonal matrix.
Definition: crowmatrix.cpp:657
int capacity(void) const
Returns the number of elements allocated for matrix.
Definition: crowmatrix.hpp:173
void set_nz(int nz)
Set number of non-zero elements in the matrix.
Definition: crowmatrix.cpp:415
const int & col(int i) const
Returns a const reference to the to the internal column data of the matrix.
Definition: crowmatrix.hpp:306
int columns(void) const
Returns the number of columns in the matrix.
Definition: crowmatrix.hpp:156
const double & val(int i) const
Returns a const reference to the to the internal value data of the matrix.
Definition: crowmatrix.hpp:311
CRowMatrix & operator=(const CRowMatrix &mat)
Assignment operator.
Definition: crowmatrix.cpp:184
void reserve(int size)
Reserve memory for size matrix elements.
Definition: crowmatrix.cpp:406
CRowMatrix()
Default constructor.
Definition: crowmatrix.cpp:132
double get(int i, int j) const
Function to get a matrix element value at (i,j).
Definition: crowmatrix.hpp:387
void set_row(int i, int N, const int *col, const double *val)
Function to set matrix row elements.
Definition: crowmatrix.cpp:523
double & val(int i)
Returns a reference to the to the internal value data of the matrix.
Definition: crowmatrix.hpp:296
void construct_add(int i, int j, double val)
Adds an element to matrix while constructing the whole matrix.
Definition: crowmatrix.cpp:565
void size(int &n, int &m) const
Returns the number of columns and number of columns in nn and mm.
Definition: crowmatrix.hpp:165
void merge(CRowMatrix &mat)
Merges matrix mat into the matrix leaving mat empty.
Definition: crowmatrix.cpp:425
Coordinate sparse matrix class.
Definition: coordmatrix.hpp:72
Base matrix class.
Definition: matrix.hpp:76
Dense math vector class.
Definition: mvector.hpp:71
Error classes and handling
Basis for matrix implementations.


Reference manual for Ion Beam Simulator 1.0.6dev
Generated by Doxygen 1.9.1 on Thu Sep 11 2025 09:37:24.