Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
ProfiledFixedBlockMatrixBuilder.h
1/*
2 * Copyright 2020 IFPEN-CEA
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * SPDX-License-Identifier: Apache-2.0
17 */
18
19#pragma once
20
21#include <alien/data/IMatrix.h>
22#include <alien/utils/Precomp.h>
23
24#include <arccore/collections/Array2.h>
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29namespace Alien
30{
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35template <typename Scalar>
36class SimpleCSRMatrix;
37
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
40
42{
43 enum ResetFlag
44 {
45 eKeepValues,
46 eResetValues
47 };
48};
49
50/*---------------------------------------------------------------------------*/
51/*---------------------------------------------------------------------------*/
52
53namespace Common
54{
55
56 /*---------------------------------------------------------------------------*/
57 /*---------------------------------------------------------------------------*/
58
59 class ALIEN_EXPORT ProfiledFixedBlockMatrixBuilder
60 {
61 public:
62 class MatrixElement
63 {
64 public:
65 MatrixElement(const Integer iIndex, const Integer jIndex,
66 ProfiledFixedBlockMatrixBuilder& parent)
67 : m_iIndex(iIndex)
68 , m_jIndex(jIndex)
69 , m_parent(parent)
70 {}
71
72 inline void operator+=(ConstArray2View<Real> value)
73 {
74 m_parent.addData(m_iIndex, m_jIndex, value);
75 }
76
77 inline void operator-=(ConstArray2View<Real> value)
78 {
79 m_parent.addData(m_iIndex, m_jIndex, -1., value);
80 }
81
82 inline void operator=(ConstArray2View<Real> value)
83 {
84 m_parent.setData(m_iIndex, m_jIndex, value);
85 }
86
87 private:
88 const Integer m_iIndex;
89 const Integer m_jIndex;
90 ProfiledFixedBlockMatrixBuilder& m_parent;
91 };
92
93 public:
94 using ResetFlag = ProfiledBlockMatrixBuilderOptions::ResetFlag;
95
96 ProfiledFixedBlockMatrixBuilder(IMatrix& matrix, const ResetFlag reset_values);
97
98 virtual ~ProfiledFixedBlockMatrixBuilder();
99
100 private:
101 ProfiledFixedBlockMatrixBuilder(const ProfiledFixedBlockMatrixBuilder&);
102
103 public:
104 inline MatrixElement operator()(const Integer iIndex, const Integer jIndex)
105 {
106 return MatrixElement(iIndex, jIndex, *this);
107 }
108
109 void addData(const Integer iIndex, const Integer jIndex, ConstArray2View<Real> value);
110
111 void addData(const Integer iIndex, const Integer jIndex, const Real factor,
112 ConstArray2View<Real> value);
113
114 void setData(const Integer iIndex, const Integer jIndex, ConstArray2View<Real> value);
115
116 void finalize();
117
118 private:
119 bool isLocal(Integer jIndex)
120 {
121 return (jIndex >= m_local_offset) && (jIndex < m_next_offset);
122 }
123
124 IMatrix& m_matrix;
125 SimpleCSRMatrix<Real>* m_matrix_impl;
126
127 Integer m_local_offset;
128 Integer m_next_offset;
129 Integer m_local_size;
130 Integer m_block_size;
131 ConstArrayView<Integer> m_row_starts;
132 ConstArrayView<Integer> m_cols;
133 ConstArrayView<Integer> m_local_row_size;
134 ArrayView<Real> m_values;
135 bool m_finalized;
136 };
137
138 /*---------------------------------------------------------------------------*/
139 /*---------------------------------------------------------------------------*/
140
141} // namespace Common
142
143/*---------------------------------------------------------------------------*/
144/*---------------------------------------------------------------------------*/
145
146} // namespace Alien
147
148/*---------------------------------------------------------------------------*/
149/*---------------------------------------------------------------------------*/
IMatrix.h.
Interface for all matrices.
Definition IMatrix.h:51
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17