Main Page
Related Pages
Classes
Files
File List
File Members
src
ccolmatrix.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 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,
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
);
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
Reference manual for Ion Beam Simulator 1.0.5b
Generated on by
Doxygen
1.8.1.2 on Mon Sep 24 2012 12:38:28.