9#include <alien/kernels/simple_csr/SimpleCSRMatrix.h>
10#include <alien/kernels/simple_csr/SimpleCSRVector.h>
12#ifdef ALIEN_USE_EIGEN3
19#include "NormalizeOpt.h"
27using namespace Arccore;
55 FatalErrorException(A_FUNCINFO, String::format(
"Unhandle option type: ", opt));
87 _normalize(A00, A01, m(0, 1).impl()->hasFeature(
"transposed"), eq_ids, b0);
93 _normalize(A11, eq_ids, A10, m(1, 0).impl()->hasFeature(
"transposed"), b1);
111 for (Integer irow = 0; irow < m_local_size; ++irow) {
112 Integer off = m_row_offset[irow];
113 Real diag = m_matrix[off];
114 for (Integer col = off; col < m_row_offset[irow + 1]; ++col) {
115 m_matrix[col] /= diag;
130#ifdef ALIEN_USE_EIGEN3
132 using namespace Eigen;
133 typedef Eigen::Matrix<Real, N, N, RowMajor>
MatrixType;
135 const Integer NxN = N * N;
138 UniqueArray<Real> block(NxN);
139 UniqueArray<Real> vect(N);
140 Map<MatrixType> m(block.data());
141 Map<VectorType> v(vect.data());
146 Map<MatrixType> diag(&
m_matrix[off * NxN]);
147 if (diag.determinant() == 0) {
148 std::cout <<
"Non inversible diagonal : row=" << irow << std::endl;
149 std::cout <<
" DIAG :" << std::endl;
150 std::cout << diag << std::endl;
158 for (Integer col = off + 1; col <
m_row_offset[irow + 1]; ++col) {
159 block.copy(ArrayView<Real>(NxN, &
m_matrix[col * NxN]));
160 Map<MatrixType> matrix(&
m_matrix[col * NxN]);
161 matrix = inv_diag * m;
167 vect.copy(ArrayView<Real>(N, &
m_rhs[irow * N]));
168 Map<VectorType> rhs(&
m_rhs[irow * N]);
183 Map<MatrixType> diag(&
m_matrix[off * NxN]);
184 if (diag.determinant() == 0) {
185 std::cout <<
"Non inversible diagonal : row=" << irow << std::endl;
186 std::cout <<
" DIAG :" << std::endl;
187 std::cout << diag << std::endl;
195 for (Integer col =
m_row_offset[irow]; col < off; ++col) {
196 block.copy(ArrayView<Real>(NxN, &
m_matrix[col * NxN]));
197 Map<MatrixType> matrix(&
m_matrix[col * NxN]);
198 matrix = inv_diag * m;
203 for (Integer col = off + 1; col <
m_row_offset[irow + 1]; ++col) {
204 block.copy(ArrayView<Real>(NxN, &
m_matrix[col * NxN]));
205 Map<MatrixType> matrix(&
m_matrix[col * NxN]);
206 matrix = inv_diag * m;
212 vect.copy(ArrayView<Real>(N, &
m_rhs[irow * N]));
213 Map<VectorType> rhs(&
m_rhs[irow * N]);
232 Real* diag = &
m_matrix[off * N * N];
236 for (Integer col = off + 1; col <
m_row_offset[irow + 1]; ++col) {
237 lu.template solve<N, false>(&
m_matrix[col * N * N]);
241 lu.template solve<1, true>(&
m_rhs[irow * N]);
253 Real* diag = &
m_matrix[off * N * N];
257 for (Integer col =
m_row_offset[irow]; col < off; ++col) {
258 lu.template solve<N, false>(&
m_matrix[col * N * N]);
261 for (Integer col = off + 1; col <
m_row_offset[irow + 1]; ++col) {
262 lu.template solve<N, false>(&
m_matrix[col * N * N]);
265 lu.template solve<1, true>(&
m_rhs[irow * N]);
323 for (Integer irow = 0; irow < m_local_size; ++irow) {
324 Integer off = m_row_offset[irow];
325 Real diag = m_matrix[off];
326 for (Integer col = off + 1; col < m_row_offset[irow + 1]; ++col) {
327 m_matrix[col] /= diag;
336 for (Integer i = 0; i < m_eq_ids.size(); ++i) {
337 Integer ieq = m_eq_ids[i];
338 for (Integer k = m_extra_eq_row_offset[ieq]; k < m_extra_eq_row_offset[ieq + 1];
340 Integer irow = m_extra_eq_cols[k];
341 Integer off = m_row_offset[irow];
342 Real diag = m_matrix[off];
343 m_extra_eq_matrix[k] /= diag;
347 for (Integer i = 0; i < m_eq_ids.size(); ++i) {
348 Integer irow = m_eq_ids[i];
349 Integer off = m_row_offset[irow];
350 Real diag = m_matrix[off];
351 for (Integer k = m_extra_eq_row_offset[irow];
352 k < m_extra_eq_row_offset[irow + 1]; ++k) {
353 m_extra_eq_matrix[k] /= diag;
359 for (Integer irow = 0; irow < m_local_size; ++irow) {
360 Integer off_diag = m_row_offset[irow];
361 m_matrix[off_diag] = m_keep_diag ? 1. : 0.;
368 for (Integer irow = 0; irow < m_local_size; ++irow) {
369 Integer off_diag = m_upper_diag_offset[irow];
370 Real diag = m_matrix[off_diag];
371 for (Integer col = m_row_offset[irow]; col < off_diag; ++col) {
372 m_matrix[col] /= diag;
374 for (Integer col = off_diag + 1; col < m_row_offset[irow + 1]; ++col) {
375 m_matrix[col] /= diag;
384 for (Integer i = 0; i < m_eq_ids.size(); ++i) {
385 Integer ieq = m_eq_ids[i];
386 for (Integer k = m_extra_eq_row_offset[ieq]; k < m_extra_eq_row_offset[ieq + 1];
388 Integer irow = m_extra_eq_cols[k];
389 Integer off = m_upper_diag_offset[irow];
390 Real diag = m_matrix[off];
391 m_extra_eq_matrix[k] /= diag;
395 for (Integer i = 0; i < m_eq_ids.size(); ++i) {
396 Integer irow = m_eq_ids[i];
397 Integer off = m_upper_diag_offset[irow];
398 Real diag = m_matrix[off];
399 for (Integer k = m_extra_eq_row_offset[irow];
400 k < m_extra_eq_row_offset[irow + 1]; ++k) {
401 m_extra_eq_matrix[k] /= diag;
407 for (Integer irow = 0; irow < m_local_size; ++irow) {
408 Integer off_diag = m_upper_diag_offset[irow];
409 m_matrix[off_diag] = m_keep_diag ? 1. : 0.;
418 for (Integer i = 0; i < m_eq_ids.size(); ++i) {
419 Integer ieq = m_eq_ids[i];
420 Real diag = m_matrix[ieq];
421 for (Integer j = m_extra_eq_row_offset[ieq]; j < m_extra_eq_row_offset[ieq + 1];
423 for (Integer k = 0; k < m_nuk2; ++k)
424 m_extra_eq_matrix[j * m_nuk2 + k] /= diag;
446 Real* diag = &
m_matrix[off * N * N];
450 for (Integer col = off + 1; col <
m_row_offset[irow + 1]; ++col) {
451 lu.template solve<N, false>(&
m_matrix[col * N * N]);
455 lu.template solve<1, true>(&
m_rhs[irow * N]);
462 for (Integer i = 0; i <
m_eq_ids.size(); ++i) {
468 Real* diag = &
m_matrix[off * N * N];
469 LU<N> lu(diag,
false);
475 for (Integer i = 0; i <
m_eq_ids.size(); ++i) {
478 Real* diag = &
m_matrix[off * N * N];
479 LU<N> lu(diag,
false);
492 Real* diag = &
m_matrix[off * N * N];
493 LU<N> lu(diag,
false);
500 Real* diag = &
m_matrix[off * N * N];
501 LU<N> lu(diag,
false);
512 Real* diag = &
m_matrix[off * N * N];
516 for (Integer col =
m_row_offset[irow]; col < off; ++col) {
517 lu.template solve<N, false>(&
m_matrix[col * N * N]);
520 for (Integer col = off + 1; col <
m_row_offset[irow + 1]; ++col) {
521 lu.template solve<N, false>(&
m_matrix[col * N * N]);
524 lu.template solve<1, true>(&
m_rhs[irow * N]);
530 for (Integer i = 0; i <
m_eq_ids.size(); ++i) {
537 Real* diag = &
m_matrix[off * N * N];
538 LU<N> lu(diag,
false);
544 for (Integer i = 0; i <
m_eq_ids.size(); ++i) {
547 Real* diag = &
m_matrix[off * N * N];
548 LU<N> lu(diag,
false);
562 Real* diag = &
m_matrix[off * N * N];
563 LU<N> lu(diag,
false);
570 Real* diag = &
m_matrix[off * N * N];
571 LU<N> lu(diag,
false);
581 for (Integer i = 0; i <
m_eq_ids.size(); ++i) {
586 for (Integer k = 0; k < N; ++k)
600 ConstArrayView<Integer> eq_ids,
VectorImpl& x)
const
633 switch (x.block()->size()) {
Arccore::Integer size() const
Get square block size.
Composite matrix for heterogenous matrices.
MultiMatrixImpl * impl()
Get the multimatrix implementation.
Composite vector for heterogenous vector.
MultiVectorImpl * impl()
Get the multivector implementation.
virtual const Block * block() const
Get block datas of the matrix.
Interface for all matrices.
virtual MultiMatrixImpl * impl()=0
Get the multimatrix implementation.
virtual const Block * block() const
Get block datas of the vector.
Interface for all vectors.
virtual MultiVectorImpl * impl()=0
Get the multivector implementation.
const AlgebraTraits< tag >::matrix_type & get() const
Get a specific matrix implementation.
const AlgebraTraits< tag >::vector_type & get() const
Get a specific vector implementation.
void setIdentity()
Set identity.
Normalize operator for composite matrices.
Arccore::ConstArrayView< Arccore::Integer > m_eq_ids
Ids of the equations.
Arccore::ConstArrayView< Arccore::Integer > m_extra_eq_cols
Pointer on extra equations unknowns columns.
bool m_trans
Transposed flag.
Arccore::ConstArrayView< Arccore::Integer > m_extra_eq_row_offset
Pointer on extra equations unknowns rows.
void multInvDiag()
Invert diagonal.
bool m_submatrix2
Whether or not the second submatrix should be normalized.
Arccore::Real * m_extra_eq_matrix
Pointer of extra equations datas.
bool m_submatrix1
Whether or not the first submatrix should be normalized.
Arccore::Integer m_local_size
The local size.
Arccore::Real * m_rhs
The rhs.
Arccore::Integer m_local_offset
The local offset.
eAlgoType m_algo
The algorithm type.
void multInvDiag()
Invert diagonal.
bool m_keep_diag
Whether or not diagonal should be kept.
Arccore::ConstArrayView< Arccore::Integer > m_upper_diag_offset
The indices of the upper diagonal.
Arccore::ConstArrayView< Arccore::Integer > m_row_offset
The rows offset.
Arccore::Real * m_matrix
The matrix.
bool m_diag_first
Whether or not the diagonal entry is stored first.
void setAlgo(eAlgoType algo)
Set the type of algorithm.
eErrorType
Type of the error.
eAlgoType
Type of algorithm.
eOptType
Type of the options.
SimpleCSRVector< Arccore::Real > VectorImpl
Type of the vector implementation.
eErrorType normalize(IMatrix &matrix, IVector &vector) const
Normalize the linear system.
bool m_sum_first_eq
Flag to sum the fist equation.
SimpleCSRMatrix< Arccore::Real > MatrixImpl
Type of the matrix implementation.
NormalizeOpt()
Constructor.
eErrorType _normalize(MatrixImpl &matrix, VectorImpl &vector) const
Normalize a linear system.
void setOpt(eOptType opt, bool flag)
Set the options.
eAlgoType m_algo
The algorithm.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --