Alien  1.3.0
User documentation
Loading...
Searching...
No Matches
FILU0Preconditioner.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#pragma once
9
10namespace Alien
11{
12template <typename MatrixT, typename VectorT>
13class FLUFactorisationAlgo
14: public LUFactorisationAlgo<MatrixT, VectorT>
15{
16 public:
17 // clang-format off
18 typedef LUFactorisationAlgo<MatrixT,VectorT> BaseType ;
19 typedef MatrixT MatrixType;
20 typedef VectorT VectorType;
21 typedef typename MatrixType::ProfileType ProfileType ;
22 typedef typename MatrixType::ValueType ValueType;
23 typedef typename MatrixType::TagType TagType ;
24 // clang-format on
25
26 FLUFactorisationAlgo()
27 {}
28
29 virtual ~FLUFactorisationAlgo()
30 {}
31
32 void setParameter(std::string param, int value)
33 {
34 if (param.compare("nb-factor-iter") == 0)
36 else if (param.compare("nb-solver-iter") == 0)
37 m_nb_solver_iter = value;
38 }
39
40 void setParameter(std::string param, double value)
41 {
42 if (param.compare("tol") == 0)
43 m_tol = value;
44 }
45
46 template <typename AlgebraT>
47 void init(AlgebraT& algebra, MatrixT const& matrix)
48 {
49 BaseType::baseInit(algebra, matrix);
50 algebra.allocate(AlgebraT::resource(matrix), m_xk);
51
52 if (m_nb_factorization_iter == 0) {
53 if(this->m_block_size==1)
54 BaseType::factorize(*this->m_lu_matrix, true);
55 else
56 {
57 BaseType::blockFactorize(*this->m_lu_matrix);
58 }
59 }
60 else {
61 factorizeMultiIter(*this->m_lu_matrix);
62 }
63 this->m_work.clear();
64
65 if(this->m_block_size==1)
66 {
67 algebra.allocate(AlgebraT::resource(matrix), m_inv_diag);
68 algebra.assign(m_inv_diag, 1.);
69 algebra.computeInvDiag(*this->m_lu_matrix, m_inv_diag);
70 }
71 else
72 {
73 m_inv_diag.setBlockSize(this->m_block_size*this->m_block_size) ;
74 algebra.allocate(AlgebraT::resource(matrix), m_inv_diag);
75 algebra.computeInvDiag(*this->m_lu_matrix, m_inv_diag);
76
77 }
78
79 if (MatrixType::on_host_only) {
80 if (this->m_is_parallel) {
81 // Need to manage ghost and communications
82 this->m_x.resize((Integer)this->m_alloc_size);
83 m_xk.resize((Integer)this->m_alloc_size);
84 }
85 }
86 }
87
88 ///////////////////////////////////////////////////////////////////////
89 //
90 // FACTORIZATION
91 //
92 void factorizeIter(std::size_t nrows,
93 int const* kcol,
94 int const* dcol,
95 int const* cols,
96 ValueType* values,
97 ValueType* values0)
98 {
99 /*
100 *
101 For i = 1, . . . ,N Do:
102 For k = 1, . . . , i - 1 and if (i, k) 2 NZ(A) Do:
103 Compute aik := aik/akj
104 For j = k + 1, . . . and if (i, j) 2 NZ(A), Do:
105 compute aij := aij - aik.ak,j.
106 EndFor
107 EndFor
108 EndFor
109 *
110 */
111
112 for (std::size_t irow = 1; irow < nrows; ++irow) // i=1->nrow
113 {
114 _factorizeRow(irow, kcol, dcol, cols, values, values0);
115 }
116 }
117
118 void factorizeMultiIter(MatrixT const& matrix)
119 {
120 CSRModifierViewT<MatrixT> modifier(*this->m_lu_matrix);
121
122 // clang-format off
123 auto nrows = modifier.nrows() ;
124 auto nnz = modifier.nnz() ;
125 auto kcol = modifier.kcol() ;
126 auto dcol = modifier.dcol() ;
127 auto cols = modifier.cols() ;
128 auto values = modifier.data() ;
129 // clang-format on
130
131 if (this->m_lu_matrix->isParallel()) {
132 typename LUSendRecvTraits<TagType>::matrix_op_type op(*this->m_lu_matrix, this->m_distribution, this->m_work);
133 for (int iter = 0; iter < m_nb_factorization_iter; ++iter) {
134 auto matrix_values = CSRConstViewT<MatrixT>(matrix).data();
135 std::vector<ValueType> guest_values(nnz);
136 std::copy(values, values + nnz, guest_values.data());
137 std::copy(matrix_values, matrix_values + nnz, values);
138 op.recvLowerNeighbLUData(values);
139 op.sendUpperNeighbLUData(guest_values.data());
140 factorizeIter(nrows, kcol, dcol, cols, values, guest_values.data());
141 }
142 }
143 else {
144 for (int iter = 0; iter < m_nb_factorization_iter; ++iter) {
145 auto matrix_values = CSRConstViewT<MatrixT>(matrix).data();
146 std::vector<ValueType> guest_values(nnz);
147 std::copy(values, values + nnz, guest_values.data());
148 std::copy(matrix_values, matrix_values + nnz, values);
149 factorizeIter(nrows, kcol, dcol, cols, values, guest_values.data());
150 }
151 }
152 }
153
154 ///////////////////////////////////////////////////////////////////////
155 //
156 // TRIANGULAR RESOLUTION
157 //
158 template <typename AlgebraT>
159 void solveL(AlgebraT& algebra,
160 VectorType const& y,
161 VectorType& x,
162 VectorType& xk) const
163 {
164#ifdef ALIEN_USE_PERF_TIMER
165 typename MatrixType::SentryType sentry(this->m_lu_matrix->timer(), "SolveL");
166#endif
167 if constexpr (MatrixType::on_host_only)
168 {
169 CSRConstViewT<MatrixT> view(*this->m_lu_matrix);
170 // clang-format off
171 auto nrows = view.nrows();
172 auto kcol = view.kcol();
173 auto dcol = view.dcol();
174 auto cols = view.cols();
175 auto values = view.data();
176
177 auto y_ptr = y.data();
178 auto x_ptr = x.data();
179 auto xk_ptr = xk.data();
180 // clang-format on
181
182 std::copy(x_ptr, x_ptr + nrows, xk_ptr);
183 if (this->m_is_parallel)
184 {
185 typedef typename LUSendRecvTraits<TagType>::vector_op_type SendRecvOpType;
186 SendRecvOpType op(xk_ptr,
187 this->m_lu_matrix->getDistStructInfo().m_send_info,
188 this->m_lu_matrix->getSendPolicy(),
189 xk_ptr,
190 this->m_lu_matrix->getDistStructInfo().m_recv_info,
191 this->m_lu_matrix->getRecvPolicy(),
192 this->m_lu_matrix->getParallelMng(),
193 nullptr);
194
195 auto& local_row_size = this->m_lu_matrix->getDistStructInfo().m_local_row_size;
196 int first_upper_ghost_index = this->m_lu_matrix->getDistStructInfo().m_first_upper_ghost_index;
197 op.lowerRecv();
198 op.upperSend();
199 for (std::size_t irow = 0; irow < nrows; ++irow) {
200 ValueType val = y_ptr[irow];
201 for (int k = kcol[irow]; k < dcol[irow]; ++k)
202 val -= values[k] * xk_ptr[cols[k]];
203 for (int k = kcol[irow] + local_row_size[irow]; k < kcol[irow + 1]; ++k) {
204 if (cols[k] < first_upper_ghost_index)
205 val -= values[k] * xk_ptr[cols[k]];
206 }
207 x_ptr[irow] = val;
208 }
209 }
210 else
211 {
212 for (std::size_t irow = 0; irow < nrows; ++irow) {
213 ValueType val = y_ptr[irow];
214 for (int k = kcol[irow]; k < dcol[irow]; ++k)
215 val -= values[k] * xk_ptr[cols[k]];
216 x_ptr[irow] = val;
217 }
218 }
219 }
220 else
221 {
222 algebra.copy(x, xk);
223 algebra.copy(y, x);
224 algebra.addLMult(-1, *this->m_lu_matrix, xk, x);
225 }
226 }
227
228 template <typename AlgebraT>
229 void blockSolveL(AlgebraT& algebra,
230 VectorType const& y,
231 VectorType& x,
232 VectorType& xk) const
233 {
234#ifdef ALIEN_USE_PERF_TIMER
235 typename MatrixType::SentryType sentry(this->m_lu_matrix->timer(), "SolveL");
236#endif
237 if constexpr (MatrixType::on_host_only)
238 {
239#if defined (ALIEN_USE_EIGEN3) && !defined(EIGEN3_DISABLED)
240 using namespace Eigen;
241 using Block2D = Eigen::Matrix<ValueType,Eigen::Dynamic,Eigen::Dynamic,Eigen::RowMajor> ;
242 using Block2DView = Eigen::Map<Block2D> ;
243 using Block1D = Eigen::Matrix<ValueType,Dynamic,1> ;
244 using Block1DView = Eigen::Map<Block1D> ;
245
246 int N = this->m_block_size ;
247 int NxN = N*N;
248
249 Block1D val(N);
250 CSRConstViewT<MatrixT> view(*this->m_lu_matrix);
251 // clang-format off
252 auto nrows = view.nrows();
253 auto kcol = view.kcol();
254 auto dcol = view.dcol();
255 auto cols = view.cols();
256 auto values = view.data();
257
258 auto y_ptr = y.data();
259 auto x_ptr = x.data();
260 auto xk_ptr = xk.data();
261 // clang-format on
262
263 std::copy(x_ptr, x_ptr + nrows*N, xk_ptr);
264 if (this->m_is_parallel)
265 {
266 typedef typename LUSendRecvTraits<TagType>::vector_op_type SendRecvOpType;
267 SendRecvOpType op(xk_ptr,
268 this->m_lu_matrix->getDistStructInfo().m_send_info,
269 this->m_lu_matrix->getSendPolicy(),
270 xk_ptr,
271 this->m_lu_matrix->getDistStructInfo().m_recv_info,
272 this->m_lu_matrix->getRecvPolicy(),
273 this->m_lu_matrix->getParallelMng(),
274 nullptr);
275
276 auto& local_row_size = this->m_lu_matrix->getDistStructInfo().m_local_row_size;
277 int first_upper_ghost_index = this->m_lu_matrix->getDistStructInfo().m_first_upper_ghost_index;
278 op.lowerRecv();
279 op.upperSend();
280 for (std::size_t irow = 0; irow < nrows; ++irow)
281 {
282 //ValueType val = y_ptr[irow];
283 val = Block1DView(const_cast<ValueType*>(y_ptr+irow*N),N) ;
284 for (int k = kcol[irow]; k < dcol[irow]; ++k)
285 {
286 //val -= values[k] * xk_ptr[cols[k]];
287 val -= Block2DView(const_cast<ValueType*>(values+k*NxN),N,N) * Block1DView(xk_ptr+cols[k]*N,N) ;
288 }
289 for (int k = kcol[irow] + local_row_size[irow]; k < kcol[irow + 1]; ++k)
290 {
291 if (cols[k] < first_upper_ghost_index)
292 {
293 //val -= values[k] * xk_ptr[cols[k]];
294 val -= Block2DView(const_cast<ValueType*>(values+k*NxN),N,N) * Block1DView(xk_ptr+cols[k]*N,N) ;
295 }
296 }
297 //x_ptr[irow] = val;
298 Block1DView(x_ptr+irow*N,N) = val ;
299 }
300 }
301 else
302 {
303#ifdef PRINT_DEBUG_INFO
304 for (std::size_t irow = 0; irow < nrows; ++irow)
305 {
306 std::cout<<"XK["<<irow<<"]=\n";
307 for(int i=0;i<N;++i)
308 std::cout<<xk_ptr[irow*N+i]<<std::endl;
309 }
310#endif
311 for (std::size_t irow = 0; irow < nrows; ++irow)
312 {
313 //ValueType val = y_ptr[irow];
314 val = Block1DView(const_cast<ValueType*>(y_ptr+irow*N),N) ;
315#ifdef PRINT_DEBUG_INFO
316 std::cout<<"LSOLVE MAT["<<irow<<"]:"<<std::endl;
317#endif
318 for (int k = kcol[irow]; k < dcol[irow]; ++k)
319 {
320 //val -= values[k] * xk_ptr[cols[k]];
321 val -= Block2DView(const_cast<ValueType*>(values+k*NxN),N,N) * Block1DView(xk_ptr+cols[k]*N,N) ;
322#ifdef PRINT_DEBUG_INFO
323 std::cout<<Block2DView(const_cast<ValueType*>(values+k*NxN),N,N)<<std::endl;
324#endif
325 }
326 //x_ptr[irow] = val;
327 Block1DView(x_ptr+irow*N,N) = val ;
328#ifdef PRINT_DEBUG_INFO
329 std::cout<<"Y =\n"<<val<<std::endl ;
330#endif
331 }
332 }
333#endif
334 }
335 else
336 {
337 algebra.copy(x, xk);
338 algebra.copy(y, x);
339 algebra.addLMult(-1, *this->m_lu_matrix, xk, x);
340 }
341 }
342
343 template <typename AlgebraT>
344 void solveU(AlgebraT& algebra, VectorType const& y, VectorType& x, VectorType& xk) const
345 {
346#ifdef ALIEN_USE_PERF_TIMER
347 typename MatrixType::SentryType sentry(this->m_lu_matrix->timer(), "SolveU");
348#endif
349 if constexpr (MatrixType::on_host_only)
350 {
351 CSRConstViewT<MatrixT> view(*this->m_lu_matrix);
352 // clang-format off
353 auto nrows = view.nrows();
354 auto kcol = view.kcol();
355 auto dcol = view.dcol();
356 auto cols = view.cols();
357 auto values = view.data();
358
359 auto y_ptr = y.data();
360 auto x_ptr = x.data();
361 auto xk_ptr = xk.data();
362 // clang-format on
363
364 std::copy(x_ptr, x_ptr + nrows, xk_ptr);
365 if (this->m_is_parallel) {
366 auto& local_row_size = this->m_lu_matrix->getDistStructInfo().m_local_row_size;
367 int first_upper_ghost_index = this->m_lu_matrix->getDistStructInfo().m_first_upper_ghost_index;
368
369 typedef typename LUSendRecvTraits<TagType>::vector_op_type SendRecvOpType;
370 SendRecvOpType op(xk_ptr,
371 this->m_lu_matrix->getDistStructInfo().m_send_info,
372 this->m_lu_matrix->getSendPolicy(),
373 xk_ptr,
374 this->m_lu_matrix->getDistStructInfo().m_recv_info,
375 this->m_lu_matrix->getRecvPolicy(),
376 this->m_lu_matrix->getParallelMng(),
377 nullptr);
378 op.upperRecv();
379 op.lowerSend();
380 for (std::size_t irow = 0; irow < nrows; ++irow) {
381 int dk = dcol[irow];
382 ValueType val = y_ptr[irow];
383 for (int k = dk + 1; k < kcol[irow] + local_row_size[irow]; ++k) {
384 val -= values[k] * xk_ptr[cols[k]];
385 }
386 for (int k = kcol[irow] + local_row_size[irow]; k < kcol[irow + 1]; ++k) {
387 if (cols[k] >= first_upper_ghost_index)
388 val -= values[k] * xk_ptr[cols[k]];
389 }
390 val = val / values[dk];
391 x_ptr[irow] = val;
392 }
393 }
394 else {
395 for (std::size_t irow = 0; irow < nrows; ++irow) {
396 int dk = dcol[irow];
397 ValueType val = y_ptr[irow];
398 for (int k = dk + 1; k < kcol[irow + 1]; ++k) {
399 val -= values[k] * xk_ptr[cols[k]];
400 }
401 val = val / values[dk];
402 x_ptr[irow] = val;
403 }
404 }
405 }
406 else
407 {
408 algebra.copy(x, xk);
409 algebra.copy(y, x);
410 algebra.addUMult(-1., *this->m_lu_matrix, xk, x);
411 algebra.pointwiseMult(m_inv_diag, x, x);
412 //algebra.multInvDiag(*this->m_lu_matrix,x) ;
413 }
414 }
415
416 template <typename AlgebraT>
417 void blockSolveU(AlgebraT& algebra, VectorType const& y, VectorType& x, VectorType& xk) const
418 {
419#ifdef ALIEN_USE_PERF_TIMER
420 typename MatrixType::SentryType sentry(this->m_lu_matrix->timer(), "SolveU");
421#endif
422 if constexpr (MatrixType::on_host_only)
423 {
424#if defined (ALIEN_USE_EIGEN3) && !defined(EIGEN3_DISABLED)
425 using namespace Eigen;
426 using Block2D = Eigen::Matrix<ValueType,Eigen::Dynamic,Eigen::Dynamic,Eigen::RowMajor> ;
427 using Block2DView = Eigen::Map<Block2D> ;
428 using Block1D = Eigen::Matrix<ValueType,Dynamic,1> ;
429 using Block1DView = Eigen::Map<Block1D> ;
430
431 int N = this->m_block_size ;
432 int NxN = N*N;
433
434 Block1D val(N);
435
436 CSRConstViewT<MatrixT> view(*this->m_lu_matrix);
437 // clang-format off
438 auto nrows = view.nrows();
439 auto kcol = view.kcol();
440 auto dcol = view.dcol();
441 auto cols = view.cols();
442 auto values = view.data();
443
444 auto y_ptr = y.data();
445 auto x_ptr = x.data();
446 auto xk_ptr = xk.data();
447 // clang-format on
448
449 std::copy(x_ptr, x_ptr + nrows*N, xk_ptr);
450 if (this->m_is_parallel) {
451 auto& local_row_size = this->m_lu_matrix->getDistStructInfo().m_local_row_size;
452 int first_upper_ghost_index = this->m_lu_matrix->getDistStructInfo().m_first_upper_ghost_index;
453
454 typedef typename LUSendRecvTraits<TagType>::vector_op_type SendRecvOpType;
455 SendRecvOpType op(xk_ptr,
456 this->m_lu_matrix->getDistStructInfo().m_send_info,
457 this->m_lu_matrix->getSendPolicy(),
458 xk_ptr,
459 this->m_lu_matrix->getDistStructInfo().m_recv_info,
460 this->m_lu_matrix->getRecvPolicy(),
461 this->m_lu_matrix->getParallelMng(),
462 nullptr);
463 op.upperRecv();
464 op.lowerSend();
465 for (std::size_t irow = 0; irow < nrows; ++irow) {
466 int dk = dcol[irow];
467 //ValueType val = y_ptr[irow];
468 val = Block1DView(const_cast<ValueType*>(y_ptr+irow*N),N) ;
469 for (int k = dk + 1; k < kcol[irow] + local_row_size[irow]; ++k) {
470 //val -= values[k] * xk_ptr[cols[k]];
471 val -= Block2DView(const_cast<ValueType*>(values+k*NxN),N,N) * Block1DView(xk_ptr+cols[k]*N,N) ;
472 }
473 for (int k = kcol[irow] + local_row_size[irow]; k < kcol[irow + 1]; ++k) {
474 if (cols[k] >= first_upper_ghost_index)
475 {
476 //val -= values[k] * xk_ptr[cols[k]];
477 val -= Block2DView(const_cast<ValueType*>(values+k*NxN),N,N) * Block1DView(xk_ptr+cols[k]*N,N) ;
478 }
479 }
480 //val = val / values[dk];
481 //x_ptr[irow] = val;
482 Block1DView(x_ptr+irow*N,N) = BaseType::inv(Block2DView(const_cast<ValueType*>(values+dk*NxN),N,N)) * val;
483 }
484 }
485 else
486 {
487
488#ifdef PRINT_DEBUG_INFO
489 for (std::size_t irow = 0; irow < nrows; ++irow)
490 {
491 std::cout<<"XK["<<irow<<"]=\n";
492 for(int i=0;i<N;++i)
493 std::cout<<xk_ptr[irow*N+i]<<std::endl;
494 }
495#endif
496 for (std::size_t irow = 0; irow < nrows; ++irow)
497 {
498#ifdef PRINT_DEBUG_INFO
499 std::cout<<"U SOLVE MAT["<<irow<<"]:"<<std::endl ;
500#endif
501 int dk = dcol[irow];
502 //ValueType val = y_ptr[irow];
503 val = Block1DView(const_cast<ValueType*>(y_ptr+irow*N),N) ;
504 for (int k = dk + 1; k < kcol[irow + 1]; ++k) {
505 //val -= values[k] * xk_ptr[cols[k]];
506 val -= Block2DView(const_cast<ValueType*>(values+k*NxN),N,N) * Block1DView(xk_ptr+cols[k]*N,N) ;
507#ifdef PRINT_DEBUG_INFO
508 std::cout<<Block2DView(const_cast<ValueType*>(values+k*NxN),N,N)<<std::endl;
509#endif
510 }
511 //val = val / values[dk];
512 //x_ptr[irow] = val;
513 Block1DView(x_ptr+irow*N,N) = BaseType::inv(Block2DView(const_cast<ValueType*>(values+dk*NxN),N,N)) * val;
514#ifdef PRINT_DEBUG_INFO
515 std::cout<<"Y["<<irow<<"]=\n"<<val<<std::endl;
516#endif
517 }
518
519#ifdef PRINT_DEBUG_INFO
520 for (std::size_t irow = 0; irow < nrows; ++irow)
521 {
522 int dk = dcol[irow];
523 std::cout<<"INV DIAG["<<irow<<"]\n"<<BaseType::inv(Block2DView(const_cast<ValueType*>(values+dk*NxN),N,N))<<std::endl ;
524 std::cout<<"Y["<<irow<<"]=\n";
525 for(int i=0;i<N;++i)
526 std::cout<<x_ptr[irow*N+i]<<std::endl;
527 }
528#endif
529 }
530#endif
531 }
532 else
533 {
534 algebra.copy(x, xk);
535 algebra.copy(y, x);
536 algebra.addUMult(-1., *this->m_lu_matrix, xk, x);
537 algebra.copy(x, xk);
538 algebra.multDiag(m_inv_diag, xk, x);
539 //algebra.multInvDiag(*this->m_lu_matrix,x) ;
540 }
541 }
542
543 template <typename AlgebraT>
544 void solve(AlgebraT& algebra, VectorType const& x, VectorType& y) const
545 {
546
547 //////////////////////////////////////////////////////////////////////////
548 //
549 // L.X1 = Y
550 //
551 algebra.copy(x, this->m_x);
552 if(this->m_block_size==1)
553 {
554 for (int iter = 0; iter < m_nb_solver_iter; ++iter) {
555 solveL(algebra, x, this->m_x, m_xk);
556 }
557 }
558 else
559 {
560 for (int iter = 0; iter < m_nb_solver_iter; ++iter) {
561 blockSolveL(algebra, x, this->m_x, m_xk);
562 }
563 }
564
565 //////////////////////////////////////////////////////////////////////
566 //
567 // Solve U.X = L-1(Y)
568 //
569 algebra.copy(this->m_x, y);
570 if(this->m_block_size==1)
571 {
572 for (int iter = 0; iter < m_nb_solver_iter; ++iter) {
573 solveU(algebra, this->m_x, y, m_xk);
574 }
575 }
576 else
577 {
578 for (int iter = 0; iter < m_nb_solver_iter; ++iter) {
579 blockSolveU(algebra, this->m_x, y, m_xk);
580 }
581 }
582 }
583
584 private:
585 void _factorizeRow(std::size_t irow,
586 int const* kcol,
587 int const* dcol,
588 int const* cols,
589 ValueType* values,
590 ValueType* values0)
591 {
592 /*
593 *
594 For k = 1, . . . , i - 1 and if (i, k) 2 NZ(A) Do:
595 Compute aik := aik/akj
596 For j = k + 1, . . . and if (i, j) 2 NZ(A), Do:
597 compute aij := aij - aik.ak,j.
598 EndFor
599 EndFor
600 *
601 */
602
603 for (int k = kcol[irow]; k < dcol[irow]; ++k) // k=1 ->i-1
604 {
605 int krow = cols[k];
606 typename BaseType::ValueType aik = values[k] / values0[dcol[krow]];
607 values[k] = aik; // aik = aik/akk
608 for (int l = kcol[krow]; l < kcol[krow + 1]; ++l)
609 this->m_work[cols[l]] = l;
610 for (int j = k + 1; j < kcol[irow + 1]; ++j) // j=k+1->n
611 {
612 int jcol = cols[j];
613 int kj = this->m_work[jcol];
614 if (kj != -1) {
615 values[j] -= aik * values0[kj]; // aij = aij - aik*akj
616 }
617 }
618 for (int l = kcol[krow]; l < kcol[krow + 1]; ++l)
619 this->m_work[cols[l]] = -1;
620 }
621 }
622
623 // clang-format off
624 mutable VectorType m_xk ;
625 mutable VectorType m_inv_diag ;
626 // clang-format on
627
628 public:
629 //!PARAMETERS
630 // clang-format off
632 int m_nb_solver_iter = 0 ;
633 ValueType m_tol = 0 ;
634 // clang-format on
635};
636
637template <typename AlgebraT>
638class FILU0Preconditioner
639{
640 public:
641 // clang-format off
642 typedef AlgebraT AlgebraType ;
643 typedef typename AlgebraType::Matrix MatrixType;
644 typedef typename AlgebraType::Vector VectorType;
645 typedef typename MatrixType::ValueType ValueType;
646 // clang-format on
647
649
650 FILU0Preconditioner(AlgebraType& algebra,
651 MatrixType const& matrix,
652 ITraceMng* trace_mng = nullptr)
653 : m_algebra(algebra)
654 , m_matrix(matrix)
655 , m_trace_mng(trace_mng)
656 {}
657
658 virtual ~FILU0Preconditioner()
659 {}
660
661 void setParameter(std::string param, int value)
662 {
663 m_algo.setParameter(param, value);
664 }
665
666 void setParameter(std::string param, double value)
667 {
668 m_algo.setParameter(param, value);
669 }
670
671 void init()
672 {
673 m_algo.init(m_algebra, m_matrix);
674 if (m_trace_mng) {
675 m_trace_mng->info() << "FILU Preconditioner :";
676 m_trace_mng->info() << " Nb Factor iter :" << m_algo.m_nb_factorization_iter;
677 m_trace_mng->info() << " Nb Solver iter :" << m_algo.m_nb_solver_iter;
678 m_trace_mng->info() << " Tolerance :" << m_algo.m_tol;
679 }
680 }
681
682 void solve(VectorType const& y, VectorType& x) const
683 {
684 m_algo.solve(m_algebra, y, x);
685 }
686
687 void solve(AlgebraType& algebra, VectorType const& y, VectorType& x) const
688 {
689 m_algo.solve(algebra, y, x);
690 }
691
692 private:
693 // clang-format off
694 AlgebraType& m_algebra ;
695 MatrixType const& m_matrix;
696 AlgoType m_algo ;
697
698 ITraceMng* m_trace_mng = nullptr ;
699 bool m_verbose = false ;
700 // clang-format on
701};
702
703} // namespace Alien
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17