Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
data/CompositeMatrix.cc
Go to the documentation of this file.
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
23
25#include <alien/kernels/composite/CompositeMatrix.h>
26#include <alien/kernels/composite/CompositeMultiMatrixImpl.h>
27
29#include <alien/functional/NullMatrix.h>
30#include <alien/kernels/composite/CompositeSpace.h>
31#include <alien/utils/ICopyOnWriteObject.h>
32
33/*---------------------------------------------------------------------------*/
34/*---------------------------------------------------------------------------*/
35
36namespace Alien
37{
38
39using namespace Arccore;
40
41/*---------------------------------------------------------------------------*/
42/*---------------------------------------------------------------------------*/
43
45CompositeElement(CompositeMatrix& m, Integer i, Integer j)
46{
47 return m.composite(i, j);
48}
49
50/*---------------------------------------------------------------------------*/
51/*---------------------------------------------------------------------------*/
52
56
57/*---------------------------------------------------------------------------*/
58/*---------------------------------------------------------------------------*/
59
61: m_impl(new CompositeKernel::MultiMatrixImpl())
62, m_composite_matrix(m_impl->get<Alien::BackEnd::tag::composite>(false))
63{
64 m_impl->setFeature("composite");
65
66 resize(nc);
67}
68
69/*---------------------------------------------------------------------------*/
70/*---------------------------------------------------------------------------*/
71
73{
74 v.accept(m_impl);
75}
76
77/*---------------------------------------------------------------------------*/
78/*---------------------------------------------------------------------------*/
79
81{
82 m_composite_matrix.resize(nc);
83
84 for (Integer i = 0; i < nc; ++i)
85 for (Integer j = 0; j < nc; ++j)
86 m_composite_matrix.setComposite(i, j, new NullMatrix());
87}
88
89/*---------------------------------------------------------------------------*/
90/*---------------------------------------------------------------------------*/
91
92Integer
94{
95 return m_composite_matrix.size();
96}
97
98/*---------------------------------------------------------------------------*/
99/*---------------------------------------------------------------------------*/
100
101const ISpace&
103{
104 return m_impl->rowSpace();
105}
106
107/*---------------------------------------------------------------------------*/
108/*---------------------------------------------------------------------------*/
109
110const ISpace&
112{
113 return m_impl->colSpace();
114}
115
116/*---------------------------------------------------------------------------*/
117/*---------------------------------------------------------------------------*/
118
120CompositeMatrix::composite(Integer i, Integer j)
121{
122 return m_composite_matrix.element(i, j);
123}
124
125/*---------------------------------------------------------------------------*/
126/*---------------------------------------------------------------------------*/
127
128IMatrix&
129CompositeMatrix::operator()(Integer i, Integer j)
130{
131 return m_composite_matrix(i, j);
132}
133
134/*---------------------------------------------------------------------------*/
135/*---------------------------------------------------------------------------*/
136
137const IMatrix&
138CompositeMatrix::operator()(Integer i, Integer j) const
139{
140 return m_composite_matrix(i, j);
141}
142
143/*---------------------------------------------------------------------------*/
144/*---------------------------------------------------------------------------*/
145
147{
148 m_impl->setFeature(feature);
149}
150
151/*---------------------------------------------------------------------------*/
152/*---------------------------------------------------------------------------*/
153
154bool CompositeMatrix::hasUserFeature(String feature) const
155{
156 return m_impl->hasFeature(feature);
157}
158
159/*---------------------------------------------------------------------------*/
160/*---------------------------------------------------------------------------*/
161
164{
165 if (!m_impl) {
167 }
168 // TOCHECK : needs to be removed or not ?
169 /* JMG ????
170 else if (!m_impl.unique()) { // Need to clone due to other references.
171 m_impl.reset(m_impl->clone());
172 } */
173 return m_impl.get();
174}
175
176/*---------------------------------------------------------------------------*/
177/*---------------------------------------------------------------------------*/
178
179const MultiMatrixImpl*
181{
182 return m_impl.get();
183}
184
185/*---------------------------------------------------------------------------*/
186/*---------------------------------------------------------------------------*/
187
189{
190 for (Integer i = 0; i < this->size(); ++i)
191 for (Integer j = 0; j < this->size(); ++j) {
192 if (m_composite_matrix(i, j).impl())
193 m_composite_matrix(i, j).impl()->free();
194 }
195}
196
197/*---------------------------------------------------------------------------*/
198/*---------------------------------------------------------------------------*/
199
201{
202 for (Integer i = 0; i < this->size(); ++i)
203 for (Integer j = 0; j < this->size(); ++j) {
204 if (m_composite_matrix(i, j).impl())
205 m_composite_matrix(i, j).impl()->clear();
206 }
207}
208
209/*---------------------------------------------------------------------------*/
210/*---------------------------------------------------------------------------*/
211
212} // namespace Alien
213
214/*---------------------------------------------------------------------------*/
215/*---------------------------------------------------------------------------*/
MultiMatrixImpl.h.
Composite matrix for heterogenous matrices.
Element composite(Arccore::Integer i, Arccore::Integer j)
Get the (i,j) element.
void visit(ICopyOnWriteMatrix &visit) const
Visit method.
const ISpace & colSpace() const
Get the col space of the global matrix.
const ISpace & rowSpace() const
Get the row space of the global matrix.
MultiMatrixImpl * impl()
Get the multimatrix implementation.
CompositeKernel::Matrix & m_composite_matrix
The composite matrix.
void free()
Free the composite matrix.
void clear()
Clear the composite matrix.
void resize(Arccore::Integer nc)
Resize the number of submatrices.
void setUserFeature(Arccore::String feature)
Add a feature to the composite matrix.
CompositeKernel::MatrixElement Element
Type of submatrix element.
std::shared_ptr< CompositeKernel::MultiMatrixImpl > m_impl
The multimatrix implementation.
Arccore::Integer size() const
Get the number of submatrices.
IMatrix & operator()(Arccore::Integer i, Arccore::Integer j)
Get the (i,j) submatrix.
bool hasUserFeature(Arccore::String feature) const
Check if the composite matrix has a feature.
Interface for all matrices.
Definition IMatrix.h:51
Interface for algebraic space objects.
Definition ISpace.h:44
Multi matrices representation container.
CompositeMatrix.h.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17