10 #include "GmshConfig.h"
27 if(!size)
return (
nullptr);
32 static void *
CSRRealloc(
void *ptr,
size_t size) {
return realloc(ptr, size); }
38 if(liste->
array ==
nullptr) {
63 if(incr <= 0) incr = 1;
72 liste->
array =
nullptr;
80 if(liste !=
nullptr) {
91 memcpy(&liste->
array[(liste->
n - 1) * liste->
size], data, liste->
size);
98 if(_entriesPreAllocated)
return;
99 if(_sparsity.getNbRows() == 0)
return;
101 int nbRows = _b->size();
102 for(
int i = 0; i < nbRows; i++) {
104 _sparsity.getRow(i, nInRow);
114 for(
int i = 0; i < nbRows; i++) {
116 const int *row = _sparsity.getRow(i, nInRow);
117 for(
int j = 0; j < nInRow; j++) {
122 if(nInRow != 0) ptr[nnz - 1] = 0;
124 something[i] = (nInRow == 0 ? 0 : 1);
126 _entriesPreAllocated =
true;
131 double *a = (
double *)_a->array;
132 for(
int i = 0; i < nnz; i++) {
139 if(_entriesPreAllocated)
return;
140 if(_sparsity.getNbRows() == 0)
return;
142 int nbRows = _b->size();
143 for(
int i = 0; i < nbRows; i++) {
145 _sparsity.getRow(i, nInRow);
155 for(
int i = 0; i < nbRows; i++) {
157 const int *row = _sparsity.getRow(i, nInRow);
158 for(
int j = 0; j < nInRow; j++) {
163 if(nInRow != 0) ptr[nnz - 1] = 0;
165 something[i] = (nInRow == 0 ? 0 : 1);
167 _entriesPreAllocated =
true;
172 std::complex<double> *a = (std::complex<double> *)_a->array;
173 for(
int i = 0; i < nnz; i++) {
174 a[i] = std::complex<double>();
207 something =
new char[nbRows];
209 for(
int i = 0; i < nbRows; i++) something[i] = 0;
211 _b =
new std::vector<double>(nbRows);
212 _x =
new std::vector<double>(nbRows);
239 _a =
CSRList_Create(nbRows, nbRows,
sizeof(std::complex<double>));
244 something =
new char[nbRows];
246 for(
int i = 0; i < nbRows; i++) something[i] = 0;
248 _b =
new std::vector<std::complex<double> >(nbRows);
249 _x =
new std::vector<std::complex<double> >(nbRows);
258 free((
char *)(v + nl - 1));
265 v = (
int *)malloc((
size_t)((nh - nl + 2) *
sizeof(
int)));
266 if(!v) fprintf(stderr,
"allocation failure in ivector()\n");
272 if(ai < bi)
return -1;
273 if(ai > bi)
return 1;
274 if(aj < bj)
return -1;
275 if(aj > bj)
return 1;
279 template <
class scalar>
283 unsigned long i, ir = n, j, k, l = 1;
284 int *istack, jstack = 0;
292 for(j = l + 1; j <= ir; j++) {
296 for(i = j - 1; i >= 1; i--) {
297 if(
cmpij(ai[i - 1], aj[i - 1], b,
c) <= 0)
break;
298 arr[i + 1 - 1] = arr[i - 1];
299 ai[i + 1 - 1] = ai[i - 1];
300 aj[i + 1 - 1] = aj[i - 1];
311 l = istack[jstack - 1];
316 SWAP(arr[k - 1], arr[l + 1 - 1])
317 SWAPI(ai[k - 1], ai[l + 1 - 1])
318 SWAPI(aj[k - 1], aj[l + 1 - 1])
319 if(
cmpij(ai[l + 1 - 1], aj[l + 1 - 1], ai[ir - 1], aj[ir - 1]) > 0) {
320 SWAP(arr[l + 1 - 1], arr[ir - 1])
321 SWAPI(ai[l + 1 - 1], ai[ir - 1])
322 SWAPI(aj[l + 1 - 1], aj[ir - 1])
324 if(
cmpij(ai[l - 1], aj[l - 1], ai[ir - 1], aj[ir - 1]) > 0) {
325 SWAP(arr[l - 1], arr[ir - 1])
326 SWAPI(ai[l - 1], ai[ir - 1])
327 SWAPI(aj[l - 1], aj[ir - 1])
329 if(
cmpij(ai[l + 1 - 1], aj[l + 1 - 1], ai[l - 1], aj[l - 1]) > 0) {
330 SWAP(arr[l + 1 - 1], arr[l - 1])
331 SWAPI(ai[l + 1 - 1], ai[l - 1])
332 SWAPI(aj[l + 1 - 1], aj[l - 1])
342 while(
cmpij(ai[i - 1], aj[i - 1], b,
c) < 0);
345 while(
cmpij(ai[j - 1], aj[j - 1], b,
c) > 0);
347 SWAP(arr[i - 1], arr[j - 1])
348 SWAPI(ai[i - 1], ai[j - 1])
349 SWAPI(aj[i - 1], aj[j - 1])
351 arr[l - 1] = arr[j - 1];
353 ai[l - 1] = ai[j - 1];
355 aj[l - 1] = aj[j - 1];
359 Msg::Error(
"NSTACK too small while sorting the columns of the matrix");
362 if(ir - i + 1 >= j - l) {
364 istack[jstack - 1] = i;
368 istack[jstack] = j - 1;
369 istack[jstack - 1] = l;
376 template <
class scalar>
381 int *count =
new int[NbLines];
383 for(
int i = 0; i < NbLines; i++) {
389 _position = ptr[_position];
390 ptr[_position_temp] = i;
391 if(_position == 0)
break;
394 _sort2_xkws<scalar>(nnz, a, ptr, ai);
396 for(
int i = 1; i <= NbLines; i++) {
397 jptr[i] = jptr[i - 1] + count[i - 1];
400 for(
int i = 0; i < NbLines; i++) {
401 for(
int j = jptr[i]; j < jptr[i + 1] - 1; j++) {
404 if(jptr[i + 1] != jptr[i]) ptr[jptr[i + 1] - 1] = 0;
416 a = (
double *)_a->array;
430 a = (
double *)_a->array;
433 ai, (std::complex<double> *)a);
437 #if defined(HAVE_GMM)
439 #undef BB // can be defined by FlGui.h, and clashes with gmm arg name
447 (
double *)_a->array);
450 gmm::csr_matrix_ref<double *, INDEX_TYPE *, INDEX_TYPE *, 0> ref(
452 _b->size(), _b->size());
453 gmm::csr_matrix<double> M;
457 gmm::ilu_precond<gmm::csr_matrix<double> > P(M);
458 gmm::iteration iter(_tol);
459 iter.set_noisy(_noisy);
460 if(_method ==
"gmres")
461 gmm::gmres(M, *_x, *_b, P, 100, iter);
463 gmm::cg(M, *_x, *_b, P, iter);
464 if(!iter.converged())
465 Msg::Warning(
"Iterative linear solver has not converged (res = %g)",