Alien  1.3.0
User documentation
Loading...
Searching...
No Matches
CxrOperator.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 CxrOperator
14{
15public:
16 using MatrixType = MatrixT ;
17 using VectorType = VectorT ;
18
19
20 CxrOperator(MatrixT const& matrix)
21 : m_matrix(matrix)
22 , m_cxr_matrix(matrix.impls()->clone())
23 {}
24
25 virtual ~CxrOperator()
26 {}
27
28 template<typename AlgebraT>
29 void apply(AlgebraT& algebra, const VectorType &x, VectorType &y)
30 {
31 if(m_v.getAllocSize()==0)
32 algebra.allocate(AlgebraT::resource(m_matrix),m_v);
33 algebra.mult(m_matrix,x,m_v) ;
34
35 get(algebra,m_v,y) ;
36 }
37
38 MatrixType const& getCxrMatrix() const {
39 return m_cxr_matrix ;
40 }
41
42 MatrixType& getCxrMatrix() {
43 return m_cxr_matrix ;
44 }
45
46 template<typename AlgebraT>
47 void computeCxrMatrix(AlgebraT& algebra)
48 {
49 if constexpr (requires{algebra.computeCxr(m_matrix,m_cxr_matrix) ;})
50 {
51 m_block_size = algebra.computeCxr(m_matrix,m_cxr_matrix) ;
52 }
53 else
54 throw Arccore::FatalErrorException(A_FUNCINFO, "Using Algebra that does not implemented computeCxr Op");
55 }
56
57 template<typename AlgebraT>
58 void computeCxrMatrix(AlgebraT& algebra, VectorType const& diag)
59 {
60 m_use_diag_scal = true ;
61 m_cxr_diag_scal.init(diag.distribution(),true) ;
62 algebra.copy(diag,m_cxr_diag_scal) ;
63 m_block_size = algebra.computeCxr(m_matrix,m_cxr_matrix);
64 algebra.scal(m_cxr_diag_scal, m_cxr_matrix) ;
65 }
66
67
68 template<typename AlgebraT>
69 void get(AlgebraT& algebra, VectorType const& x,VectorType& cxr_x)
70 {
71 algebra.copy(x,m_block_size,cxr_x,1);
72 /*
73 if(m_use_diag_scal)
74 {
75 algebra.pointwiseMult(m_cxr_diag_scal,cxr_x,cxr_x) ;
76 }*/
77 }
78
79
80 template<typename AlgebraT>
81 void scal(AlgebraT& algebra, VectorType& cxr_x)
82 {
83 if(m_use_diag_scal)
84 {
85 algebra.pointwiseMult(m_cxr_diag_scal,cxr_x,cxr_x) ;
86 }
87 }
88
89 template<typename AlgebraT>
90 void combine(AlgebraT& algebra, VectorType const& cxr_x, VectorType& x)
91 {
92 algebra.axpy(1.,cxr_x,1,x,m_block_size);
93 }
94
95
96 template<typename AlgebraT>
97 void copy(AlgebraT& algebra, VectorType const& cxr_x, VectorType& x)
98 {
99 algebra.copy(cxr_x,1,x,m_block_size);
100 }
101
102private:
103 MatrixType const& m_matrix ;
104 MatrixType m_cxr_matrix ;
105 VectorType m_v;
106 int m_block_size = 1 ;
107
108 bool m_use_diag_scal = false;
109 VectorType m_cxr_diag_scal ;
110 VectorType m_cxr_v;
111
112};
113
114}
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17