Alien  1.3.0
Developer 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 = m_matrix.blockSize() ;
52 if(m_block_size==1)
53 algebra.computeCxr(m_matrix,m_cxr_matrix,m_parent_lid) ;
54 else
55 algebra.computeCxr(m_matrix,m_cxr_matrix) ;
56 }
57 else
58 throw Arccore::FatalErrorException(A_FUNCINFO, "Using Algebra that does not implemented computeCxr Op");
59 }
60
61 template<typename AlgebraT>
62 void computeCxrMatrix(AlgebraT& algebra, VectorType const& diag)
63 {
64 m_use_diag_scal = true ;
65 m_cxr_diag_scal.init(diag.distribution(),true) ;
66 algebra.copy(diag,m_cxr_diag_scal) ;
67 m_block_size = algebra.computeCxr(m_matrix,m_cxr_matrix);
68 algebra.scal(m_cxr_diag_scal, m_cxr_matrix) ;
69 }
70
71
72 template<typename AlgebraT>
73 void get(AlgebraT& algebra, VectorType const& x,VectorType& cxr_x)
74 {
75 if(m_block_size==1)
76 algebra.copy(x,m_parent_lid, cxr_x) ;
77 else
78 algebra.copy(x,m_block_size,cxr_x,1);
79 /*
80 if(m_use_diag_scal)
81 {
82 algebra.pointwiseMult(m_cxr_diag_scal,cxr_x,cxr_x) ;
83 }*/
84 }
85
86
87 template<typename AlgebraT>
88 void scal(AlgebraT& algebra, VectorType& cxr_x)
89 {
90 if(m_use_diag_scal)
91 {
92 algebra.pointwiseMult(m_cxr_diag_scal,cxr_x,cxr_x) ;
93 }
94 }
95
96 template<typename AlgebraT>
97 void combine(AlgebraT& algebra, VectorType const& cxr_x, VectorType& x)
98 {
99 //std::cout<<"CXR OP COMBINE"<<std::endl ;
100 if(m_block_size==1)
101 algebra.axpy(1.,cxr_x,x,m_parent_lid);
102 else
103 algebra.axpy(1.,cxr_x,1,x,m_block_size);
104 }
105
106
107 template<typename AlgebraT>
108 void copy(AlgebraT& algebra, VectorType const& cxr_x, VectorType& x)
109 {
110 if (m_block_size == 1)
111 algebra.copy(cxr_x, x, m_parent_lid);
112 else
113 algebra.copy(cxr_x,1,x,m_block_size);
114 }
115
116private:
117 MatrixType const& m_matrix ;
118 MatrixType m_cxr_matrix ;
119 VectorType m_v;
120 int m_block_size = 1 ;
121 UniqueArray<int> m_parent_lid ;
122
123 bool m_use_diag_scal = false;
124 VectorType m_cxr_diag_scal ;
125 VectorType m_cxr_v;
126
127};
128
129}
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17