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
ccolmatrix.hpp
Go to the documentation of this file.
1 
5 /* Copyright (c) 2005-2012 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 CCOLMATRIX_HPP
44 #define CCOLMATRIX_HPP 1
45 
46 
47 #include <cstdlib>
48 #include <iostream>
49 #include "matrix.hpp"
50 #include "error.hpp"
51 
52 
75 class CColMatrix : public Matrix {
76  int _n;
77  int _m;
78  int _nz;
79  int _asize;
80  int *_ptr;
81  int *_row;
82  double *_val;
83 
84  void reallocate( void );
85  void allocate( void );
86 
87  double get_check( int i, int j ) const;
88  double &set_check( int i, int j );
89  double get_no_check( int i, int j ) const;
90  double &set_no_check( int i, int j );
91 
92  void clear_check( int i, int j );
93  void clear_no_check( int i, int j );
94 
95  void build( const class CColMatrix &mat );
96  void build( const class CRowMatrix &mat );
97  void build( const class CoordMatrix &mat );
98 
99 public:
100 
101 /* ************************************** *
102  * Constructors and destructor *
103  * ************************************** */
104 
107  CColMatrix();
108 
111  CColMatrix( int n, int m );
112 
121  CColMatrix( int n, int m, int nz, int asize,
122  int *ptr, int *row, double *val );
123 
126  CColMatrix( const CColMatrix &mat );
127 
133  CColMatrix( const class CRowMatrix &mat );
134 
137  CColMatrix( const class CoordMatrix &mat );
138 
141  CColMatrix( const class Matrix &mat );
142 
145  ~CColMatrix();
146 
147 /* ************************************** *
148  * Access and information *
149  * ************************************** */
150 
153  int columns( void ) const { return( _m ); }
154 
157  int rows( void ) const { return( _n ); }
158 
161  void size( int &n, int &m ) const { n = _n; m = _m; }
162 
165  int nz_elements( void ) const { return( _nz ); }
166 
169  int capacity( void ) const { return( _asize ); }
170 
171 /* ************************************** *
172  * User level control *
173  * ************************************** */
174 
179  void resize( int n, int m );
180 
187  void merge( CColMatrix &mat );
188 
191  void clear( void );
192 
197  void clear( int i, int j );
198 
201  void reserve( int size );
202 
206  void order_ascending( void );
207 
211  bool check_ascending( void ) const;
212 
215  void debug_print( std::ostream &os ) const;
216 
217 /* ************************************** *
218  * User level matrix element access *
219  * ************************************** */
220 
226  double get( int i, int j ) const;
227 
246  double &set( int i, int j );
247 
256  void set_column( int j, int N, const int *row, const double *val );
257 
273  void construct_add( int i, int j, double val );
274 
275 /* ************************************** *
276  * Low level access *
277  * ************************************** */
278 
282  int &ptr( int i ) { return( _ptr[i] ); }
283 
287  int &row( int i ) { return( _row[i] ); }
288 
292  double &val( int i ) { return( _val[i] ); }
293 
297  const int &ptr( int i ) const { return( _ptr[i] ); }
298 
302  const int &row( int i ) const { return( _row[i] ); }
303 
307  const double &val( int i ) const { return( _val[i] ); }
308 
316  void set_nz( int nz );
317 
318 /* ************************************** *
319  * Assignent operators *
320  * ************************************** */
321 
324  CColMatrix &operator=( const CColMatrix &mat );
325 
332  CColMatrix &operator=( const class CRowMatrix &mat );
333 
337  CColMatrix &operator=( const class CoordMatrix &mat );
338 
342  CColMatrix &operator=( const Matrix &mat );
343 
344 /* ************************************** *
345  * Matrix-Vector operations *
346  * ************************************** */
347 
348  /* \brief Calculates \a x = \a A*b.
349  */
350  void multiply_by_vector( Vector &x, const Vector &b ) const;
351 
357  void lower_unit_solve( Vector &x, const Vector &b ) const;
358 
365  void upper_diag_solve( Vector &x, const Vector &b ) const;
366 
367 
368  friend class CRowMatrix;
369  friend class CoordMatrix;
370  friend class Vector;
371  friend class HBIO;
372 };
373 
374 
375 inline double CColMatrix::get( int i, int j ) const
376 {
377 #ifdef SPM_RANGE_CHECK
378  return( get_check( i, j ) );
379 #else
380  return( get_no_check( i, j ) );
381 #endif
382 }
383 
384 
385 inline double &CColMatrix::set( int i, int j )
386 {
387 #ifdef SPM_RANGE_CHECK
388  return( set_check( i, j ) );
389 #else
390  return( set_no_check( i, j ) );
391 #endif
392 }
393 
394 
395 inline void CColMatrix::clear( int i, int j )
396 {
397 #ifdef SPM_RANGE_CHECK
398  clear_check( i, j );
399 #else
400  clear_no_check( i, j );
401 #endif
402 }
403 
404 
405 #endif
406 
407 
408 
409 
410 
411 
412 
413 
414 
415 
416 
417 
418 
419 
420 
421 
422 
423 
424 
425 
426 
427 
Compressed column sparse matrix class.
Definition: ccolmatrix.hpp:75
double & set(int i, int j)
Function to get a reference to matrix element value at (i,j).
Definition: ccolmatrix.hpp:385
const int & row(int i) const
Returns a const reference to the to the internal row data of the matrix.
Definition: ccolmatrix.hpp:302
const int & ptr(int i) const
Returns a const reference to the to the internal pointer index data ptr of the matrix.
Definition: ccolmatrix.hpp:297
int capacity(void) const
Returns the number of elements allocated for matrix.
Definition: ccolmatrix.hpp:169
const double & val(int i) const
Returns a const reference to the to the internal value data of the matrix.
Definition: ccolmatrix.hpp:307
int nz_elements(void) const
Returns the number of non-zero elements in the matrix.
Definition: ccolmatrix.hpp:165
double & val(int i)
Returns a reference to the to the internal value data of the matrix.
Definition: ccolmatrix.hpp:292
void lower_unit_solve(Vector &x, const Vector &b) const
Solves A*x = b for lower unit diagonal matrix.
Definition: ccolmatrix.cpp:640
void order_ascending(void)
Order (sort) matrix data in ascending row index order within each column.
Definition: ccolmatrix.cpp:443
bool check_ascending(void) const
Check if matrix data is in ascending row index order within each column.
Definition: ccolmatrix.cpp:451
void set_nz(int nz)
Set number of non-zero elements in the matrix.
Definition: ccolmatrix.cpp:415
CColMatrix & operator=(const CColMatrix &mat)
Assignment operator.
Definition: ccolmatrix.cpp:184
int & row(int i)
Returns a reference to the to the internal column data of the matrix.
Definition: ccolmatrix.hpp:287
~CColMatrix()
Destructor.
Definition: ccolmatrix.cpp:326
int rows(void) const
Returns the number of rows in the matrix.
Definition: ccolmatrix.hpp:157
void construct_add(int i, int j, double val)
Adds an element to matrix while constructing the whole matrix.
Definition: ccolmatrix.cpp:565
void size(int &n, int &m) const
Returns the number of columns and number of columns in n and m.
Definition: ccolmatrix.hpp:161
void clear(void)
Clear non-zero matrix elements, set all elements to zero.
Definition: ccolmatrix.cpp:360
void resize(int n, int m)
Resizes the matrix to size n x m.
Definition: ccolmatrix.cpp:334
void reserve(int size)
Reserve memory for size matrix elements.
Definition: ccolmatrix.cpp:406
void upper_diag_solve(Vector &x, const Vector &b) const
Solves A*x = b for upper diagonal matrix.
Definition: ccolmatrix.cpp:659
void set_column(int j, int N, const int *row, const double *val)
Function to set matrix column elements.
Definition: ccolmatrix.cpp:523
void debug_print(std::ostream &os) const
Print debugging information to os.
Definition: ccolmatrix.cpp:584
double get(int i, int j) const
Function to get a matrix element value at (i,j).
Definition: ccolmatrix.hpp:375
void merge(CColMatrix &mat)
Merges matrix mat into the matrix leaving mat empty.
Definition: ccolmatrix.cpp:425
CColMatrix()
Default constructor.
Definition: ccolmatrix.cpp:132
int columns(void) const
Returns the number of columns in the matrix.
Definition: ccolmatrix.hpp:153
int & ptr(int i)
Returns a reference to the to the internal pointer index data ptr of the matrix.
Definition: ccolmatrix.hpp:282
Compressed row sparse matrix class.
Definition: crowmatrix.hpp:76
Coordinate sparse matrix class.
Definition: coordmatrix.hpp:72
Harwell Boeing sparse matrix file format I/O class.
Definition: hbio.hpp:66
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.