Main Page
Related Pages
Classes
Files
File List
File Members
src
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
122
CRowMatrix
(
int
n,
int
m,
int
nz,
123
int
*
ptr
,
int
*
col
,
double
*
val
);
124
127
CRowMatrix
(
const
CRowMatrix
&mat );
128
134
CRowMatrix
(
const
class
CColMatrix
&mat );
135
138
CRowMatrix
(
const
class
CoordMatrix
&mat );
139
142
CRowMatrix
(
const
class
Matrix
&mat );
143
146
~CRowMatrix
();
147
148
/* ************************************** *
149
* Access and information *
150
* ************************************** */
151
154
int
columns
(
void
)
const
{
return
( _m ); }
155
158
int
rows
(
void
)
const
{
return
( _n ); }
159
163
void
size
(
int
&n,
int
&m )
const
{ n = _n; m = _m; }
164
167
int
nz_elements
(
void
)
const
{
return
( _nz ); }
168
171
int
capacity
(
void
)
const
{
return
( _asize ); }
172
173
/* ************************************** *
174
* User level control *
175
* ************************************** */
176
181
void
resize
(
int
n,
int
m );
182
189
void
merge
(
CRowMatrix
&mat );
190
193
void
clear
(
void
);
194
199
void
clear
(
int
i,
int
j );
200
203
void
reserve
(
int
size
);
204
208
void
order_ascending
(
void
);
209
213
bool
check_ascending
(
void
);
214
217
void
debug_print
( std::ostream &os )
const
;
218
219
/* ************************************** *
220
* User level matrix element access *
221
* ************************************** */
222
228
double
get
(
int
i,
int
j )
const
;
229
248
double
&
set
(
int
i,
int
j );
249
258
void
set_row
(
int
i,
int
N,
const
int
*col,
const
double
*val );
259
275
void
construct_add
(
int
i,
int
j,
double
val );
276
277
/* ************************************** *
278
* Low level access *
279
* ************************************** */
280
284
int
&
ptr
(
int
i ) {
return
( _ptr[i] ); }
285
289
int
&
col
(
int
i ) {
return
( _col[i] ); }
290
294
double
&
val
(
int
i ) {
return
( _val[i] ); }
295
299
const
int
&
ptr
(
int
i )
const
{
return
( _ptr[i] ); }
300
304
const
int
&
col
(
int
i )
const
{
return
( _col[i] ); }
305
309
const
double
&
val
(
int
i )
const
{
return
( _val[i] ); }
310
318
void
set_nz
(
int
nz );
319
320
/* ************************************** *
321
* Assignent operators *
322
* ************************************** */
323
326
CRowMatrix
&
operator=
(
const
CRowMatrix
&mat );
327
334
CRowMatrix
&
operator=
(
const
class
CColMatrix
&mat );
335
338
CRowMatrix
&
operator=
(
const
class
CoordMatrix
&mat );
339
343
CRowMatrix
&
operator=
(
const
class
Matrix
&mat );
344
345
/* ************************************** *
346
* Matrix-Vector operations *
347
* ************************************** */
348
349
/* \brief Calculates \a x = \a A*b.
350
*/
351
void
multiply_by_vector
(
Vector
&x,
const
Vector
&b )
const
;
352
358
void
lower_unit_solve
(
Vector
&x,
const
Vector
&b )
const
;
359
366
void
upper_diag_solve
(
Vector
&x,
const
Vector
&b )
const
;
367
368
369
friend
class
CColMatrix
;
370
friend
class
CoordMatrix
;
371
friend
class
Vector
;
372
};
373
374
375
inline
double
CRowMatrix::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
&
CRowMatrix::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
CRowMatrix::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
Reference manual for Ion Beam Simulator 1.0.5b
Generated on by
Doxygen
1.8.1.2 on Mon Sep 24 2012 12:37:00.