Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
AlephCudaMatrix.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* cnc_matrix.h (C) 2000-2012 */
9/* */
10/*---------------------------------------------------------------------------*/
11/*---------------------------------------------------------------------------*/
12#ifndef _CNC_INTERFACE_MATRIX_H_
13#define _CNC_INTERFACE_MATRIX_H_
14
15namespace Arcane
16{
21{
22 public:
23
24 double a;
25 long index;
26};
27
28//---------------------------------------------------------------------------//
29
31{
32 public:
33
34 bool operator()(const CNCCoeff& c1, const CNCCoeff& c2)
35 {
36 return c1.index < c2.index;
37 }
38};
39
40//---------------------------------------------------------------------------//
41
47class CNCSparseRowColumn
48{
49 public:
50
51 CNCSparseRowColumn()
52 {
53 coeff_ = CNCallocate<CNCCoeff>(2);
54 nb_coeffs_ = 0;
55 capacity_ = 2;
56 }
57 ~CNCSparseRowColumn() { CNCdeallocate<CNCCoeff>(coeff_); }
58 long nb_coeffs() const { return nb_coeffs_; }
59 CNCCoeff& coeff(long ii) { return coeff_[ii]; }
60 const CNCCoeff& coeff(long ii) const { return coeff_[ii]; }
61
63 void add(long index, double val)
64 {
65 CNCCoeff* coeff = NULL;
66 // Search for a_{index}
67 for (long ii = 0; ii < nb_coeffs_; ii++) {
68 if (coeff_[ii].index == index) {
69 coeff = &(coeff_[ii]);
70 break;
71 }
72 }
73 if (coeff != NULL) {
75 //#warning add is set//
77 // coeff->a += val ;
78 coeff->a = val;
79 }
80 else {
81 nb_coeffs_++;
82 if (nb_coeffs_ > capacity_) {
83 grow();
84 }
85 coeff = &(coeff_[nb_coeffs_ - 1]);
86 coeff->a = val;
87 coeff->index = index;
88 }
89 }
90
92 void sort()
93 {
94 CNCCoeff* begin = coeff_;
95 CNCCoeff* end = coeff_ + nb_coeffs_;
96 std::sort(begin, end, CNCCoeffIndexCompare());
97 }
98
103 void clear()
104 {
105 CNCdeallocate<CNCCoeff>(coeff_);
106 coeff_ = CNCallocate<CNCCoeff>(2);
107 nb_coeffs_ = 0;
108 capacity_ = 2;
109 }
110
116 void zero() { nb_coeffs_ = 0; }
117
118 protected:
119
120 void grow()
121 {
122 long old_capacity = capacity_;
123 capacity_ = capacity_ * 2;
124 CNCreallocate<CNCCoeff>(coeff_, old_capacity, capacity_);
125 }
126
127 private:
128
129 CNCCoeff* coeff_;
130 long nb_coeffs_;
131 long capacity_;
132};
133
134//---------------------------------------------------------------------------//
135
137{
138 public:
139
140 enum Storage
141 {
142 NONE,
143 ROWS,
144 COLUMNS,
145 ROWS_AND_COLUMNS
146 };
147
148 // constructors / destructor
149
154 CNC_Matrix(long m, long n, Storage storage = ROWS);
155
160 CNC_Matrix(long n);
161
168 CNC_Matrix(long n, Storage storage, bool symmetric_storage);
169
170 CNC_Matrix();
171
172 ~CNC_Matrix();
173
174 // access
175
176 long m() const;
177
178 long n() const;
179
180 long diag_size() const;
181
183 long nnz() const;
184
185 bool rows_are_stored() const;
186
187 bool columns_are_stored() const;
188
189 Storage storage() const;
190
191 bool has_symmetric_storage() const;
192
193 bool is_square() const;
194
195 bool is_symmetric() const;
196
201 void set_symmetric_tag(bool x);
202
203 CNCSparseRowColumn& row(long i);
204 const CNCSparseRowColumn& row(long i) const;
205 CNCSparseRowColumn& column(long j);
206 const CNCSparseRowColumn& column(long j) const;
207
211 double diag(long i) const;
212
216 void add(long i, long j, double val);
217
219 void sort();
220
225 void clear();
226
231 void zero();
232
233 void allocate(long m, long n, Storage storage, bool symmetric = false);
234
235 void deallocate();
236
237 private:
238
239 long m_;
240 long n_;
241 long diag_size_;
242
243 CNCSparseRowColumn* row_;
244 CNCSparseRowColumn* column_;
245 double* diag_;
246
247 Storage storage_;
248 bool rows_are_stored_;
249 bool columns_are_stored_;
250 bool symmetric_storage_;
251 bool symmetric_tag_;
252
253 // SparseMatrix cannot be copied.
254 CNC_Matrix(const CNC_Matrix& rhs);
255 CNC_Matrix& operator=(const CNC_Matrix& rhs);
256};
257
258} // namespace Arcane
259
260#endif
void add(long index, double val)
CNC_Matrix(long m, long n, Storage storage=ROWS)
void add(long i, long j, double val)
void set_symmetric_tag(bool x)
CNCSparseRowColumn & row(long i)
double diag(long i) const
CNCSparseRowColumn & column(long j)
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --