Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
AlephCudaMatrix.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 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
15
16ARCANE_BEGIN_NAMESPACE
17
21class CNCCoeff {
22public:
23 double a ;
24 long index ;
25} ;
26
27//---------------------------------------------------------------------------//
28
30public:
31 bool operator()(const CNCCoeff& c1, const CNCCoeff& c2) {
32 return c1.index < c2.index ;
33 }
34};
35
36//---------------------------------------------------------------------------//
37
44public:
46 coeff_ = CNCallocate<CNCCoeff>(2) ;
47 nb_coeffs_ = 0 ;
48 capacity_ = 2 ;
49 }
51 long nb_coeffs() const { return nb_coeffs_ ; }
52 CNCCoeff& coeff(long ii) {return coeff_[ii] ; }
53 const CNCCoeff& coeff(long ii) const { return coeff_[ii] ; }
54
56 void add(long index, double val){
57 CNCCoeff* coeff = NULL ;
58 // Search for a_{index}
59 for(long ii=0; ii < nb_coeffs_; ii++) {
60 if(coeff_[ii].index == index) {
61 coeff = &(coeff_[ii]) ;
62 break ;
63 }
64 }
65 if(coeff != NULL) {
67//#warning add is set//
69// coeff->a += val ;
70 coeff->a = val ;
71 } else {
72 nb_coeffs_++ ;
73 if(nb_coeffs_ > capacity_) {
74 grow() ;
75 }
76 coeff = &(coeff_[nb_coeffs_ - 1]) ;
77 coeff->a = val ;
78 coeff->index = index ;
79 }
80 }
81
83 void sort() {
84 CNCCoeff* begin = coeff_ ;
85 CNCCoeff* end = coeff_ + nb_coeffs_ ;
86 std::sort(begin, end, CNCCoeffIndexCompare()) ;
87 }
88
93 void clear() {
95 coeff_ = CNCallocate<CNCCoeff>(2) ;
96 nb_coeffs_ = 0 ;
97 capacity_ = 2 ;
98 }
99
105 void zero() { nb_coeffs_ = 0 ; }
106
107protected:
108 void grow(){
109 long old_capacity = capacity_ ;
110 capacity_ = capacity_ * 2 ;
111 CNCreallocate<CNCCoeff>(coeff_, old_capacity, capacity_) ;
112 }
113
114private:
115 CNCCoeff* coeff_ ;
116 long nb_coeffs_ ;
117 long capacity_ ;
118} ;
119
120
121//---------------------------------------------------------------------------//
122
123
125public:
126
127 enum Storage {NONE, ROWS, COLUMNS, ROWS_AND_COLUMNS} ;
128
129 // constructors / destructor
130
135 CNC_Matrix(long m, long n, Storage storage = ROWS) ;
136
141 CNC_Matrix(long n ) ;
142
149 CNC_Matrix(long n, Storage storage, bool symmetric_storage) ;
150
151 CNC_Matrix() ;
152
153 ~CNC_Matrix() ;
154
155 // access
156
157 long m() const;
158
159 long n() const ;
160
161 long diag_size() const ;
162
164 long nnz() const ;
165
166 bool rows_are_stored() const;
167
168 bool columns_are_stored() const ;
169
170 Storage storage() const ;
171
172 bool has_symmetric_storage() const ;
173
174 bool is_square() const;
175
176 bool is_symmetric() const ;
177
182 void set_symmetric_tag(bool x);
183
184 CNCSparseRowColumn& row(long i) ;
185 const CNCSparseRowColumn& row(long i) const ;
186 CNCSparseRowColumn& column(long j) ;
187 const CNCSparseRowColumn& column(long j) const ;
188
189
193 double diag(long i) const;
194
198 void add(long i, long j, double val) ;
199
200
202 void sort() ;
203
204
209 void clear() ;
210
215 void zero() ;
216
217 void allocate(long m, long n, Storage storage, bool symmetric = false) ;
218
219 void deallocate() ;
220
221private:
222 long m_ ;
223 long n_ ;
224 long diag_size_ ;
225
226 CNCSparseRowColumn* row_ ;
227 CNCSparseRowColumn* column_ ;
228 double* diag_ ;
229
230 Storage storage_ ;
231 bool rows_are_stored_ ;
232 bool columns_are_stored_ ;
233 bool symmetric_storage_ ;
234 bool symmetric_tag_ ;
235
236 // SparseMatrix cannot be copied.
237 CNC_Matrix(const CNC_Matrix& rhs) ;
238 CNC_Matrix& operator=(const CNC_Matrix& rhs) ;
239} ;
240
241
242ARCANE_END_NAMESPACE
243
244#endif
void add(long index, double val)
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120