Mercurial > fem-fenics-eugenio
comparison src/uBLAS_factory.cc @ 247:8ca45824938e
Add factories hierarchy for matrices' and vectors' assembly
author | Eugenio Gianniti <eugenio.gianniti@mail.polimi.it> |
---|---|
date | Sat, 12 Jul 2014 12:30:13 +0200 |
parents | |
children | 61830a4f9ab9 |
comparison
equal
deleted
inserted
replaced
246:a2991e2a085b | 247:8ca45824938e |
---|---|
1 /* | |
2 Copyright (C) 2014 Eugenio Gianniti <eugenio.gianniti@mail.polimi.it> | |
3 | |
4 This program is free software; you can redistribute it and/or modify it under | |
5 the terms of the GNU General Public License as published by the Free Software | |
6 Foundation; either version 3 of the License, or (at your option) any later | |
7 version. | |
8 | |
9 This program is distributed in the hope that it will be useful, but WITHOUT | |
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | |
12 details. | |
13 | |
14 You should have received a copy of the GNU General Public License along with | |
15 this program; if not, see <http://www.gnu.org/licenses/>. | |
16 */ | |
17 | |
18 #include "uBLAS_factory.h" | |
19 | |
20 femfenics_base_factory const& | |
21 uBLAS_factory::instance (void) | |
22 { | |
23 static uBLAS_factory const theinstance; | |
24 return theinstance; | |
25 } | |
26 | |
27 octave_value | |
28 uBLAS_factory::matrix (dolfin::Matrix const& A) const | |
29 { | |
30 octave_value retval; | |
31 | |
32 // Get capacity of the dolfin sparse matrix | |
33 boost::tuples::tuple<const std::size_t*, | |
34 const std::size_t*, | |
35 const double*, int> | |
36 aa = A.data (); | |
37 | |
38 int nnz = aa.get<3> (); | |
39 std::size_t nr = A.size (0), nc = A.size (1); | |
40 std::vector<double> data_tmp; | |
41 std::vector<std::size_t> cidx_tmp; | |
42 | |
43 dim_vector dims (nnz, 1); | |
44 octave_idx_type nz = 0, ii = 0; | |
45 Array<octave_idx_type> | |
46 ridx (dims, 0), | |
47 cidx (dims, 0); | |
48 Array<double> data (dims, 0); | |
49 | |
50 octave_idx_type* orow = ridx.fortran_vec (); | |
51 octave_idx_type* oc = cidx.fortran_vec (); | |
52 double* ov = data.fortran_vec (); | |
53 | |
54 for (std::size_t i = 0; i < nr; ++i) | |
55 { | |
56 A.getrow (i, cidx_tmp, data_tmp); | |
57 nz += cidx_tmp.size (); | |
58 | |
59 for (octave_idx_type j = 0; | |
60 j < cidx_tmp.size (); ++j) | |
61 { | |
62 orow [ii + j] = i; | |
63 oc [ii + j] = cidx_tmp [j]; | |
64 ov [ii + j] = data_tmp [j]; | |
65 } | |
66 | |
67 ii = nz; | |
68 } | |
69 | |
70 dims(0) = ii; | |
71 ridx.resize (dims); | |
72 cidx.resize (dims); | |
73 data.resize (dims); | |
74 | |
75 SparseMatrix sm (data, ridx, cidx, nr, nc); | |
76 retval = sm; | |
77 | |
78 return retval; | |
79 } | |
80 | |
81 octave_value | |
82 uBLAS_factory::vector (dolfin::Vector const& b) const | |
83 { | |
84 octave_value retval; | |
85 | |
86 dim_vector dims; | |
87 dims.resize (2); | |
88 dims(0) = b.size (); | |
89 dims(1) = 1; | |
90 Array<double> myb (dims); | |
91 | |
92 for (std::size_t i = 0; i < b.size (); ++i) | |
93 myb.xelem (i) = b[i]; | |
94 | |
95 retval = myb; | |
96 | |
97 return retval; | |
98 } |