Alien  1.3.0
User documentation
Loading...
Searching...
No Matches
kernels/composite/CompositeMatrix.cc
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#include "CompositeMatrix.h"
20#include "CompositeMultiMatrixImpl.h"
21#include "CompositeSpace.h"
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26namespace Alien
27{
28
29using namespace Arccore;
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
34namespace CompositeKernel
35{
36
37 /*---------------------------------------------------------------------------*/
38 /*---------------------------------------------------------------------------*/
39
41 : IMatrixImpl(multi_impl, AlgebraTraits<BackEnd::tag::composite>::name())
42 , m_nb_composite(0)
43 {
44 alien_fatal([&] {
45 cout() << "CompositeMatrix(const Alien::MultiMatrixImpl*) : Not implemented";
46 });
47 }
48
49 /*---------------------------------------------------------------------------*/
50
52 : IMatrixImpl(multi_impl, AlgebraTraits<BackEnd::tag::composite>::name())
53 , m_nb_composite(0)
54 , m_row_space(multi_impl->rowSpace())
55 , m_col_space(multi_impl->colSpace())
56 {
57 alien_debug([&] { cout() << "Construct CompositeMatrix " << this; });
58 }
59
60 /*---------------------------------------------------------------------------*/
61
63 {
64 alien_debug([&] { cout() << "Clear CompositeMatrix" << this; });
65
66 for (auto& m : m_matrices) {
67 if (m->impl())
68 m->impl()->clear();
69 }
70 }
71
72 /*---------------------------------------------------------------------------*/
73
74 void Matrix::free()
75 {
76 alien_debug([&] { cout() << "Free CompositeMatrix" << this; });
77
78 for (auto& m : m_matrices) {
79 if (m->impl())
80 m->impl()->free();
81 }
82 }
83
84 /*---------------------------------------------------------------------------*/
85
86 void Matrix::resize(Integer nc)
87 {
88 alien_debug([&] {
89 cout() << "Resize CompositeMatrix" << this;
90 cout() << " - old size = " << m_nb_composite;
91 cout() << " - new size = " << nc;
92 });
93
94 m_row_space.resizeSubSpace(nc);
95 m_col_space.resizeSubSpace(nc);
96
97 m_nb_composite = nc;
98
99 m_matrices.resize(nc * nc);
100 }
101
102 /*---------------------------------------------------------------------------*/
103
104 Integer Matrix::size() const { return m_nb_composite; }
105
106 /*---------------------------------------------------------------------------*/
107
108 MatrixElement Matrix::element(Integer i, Integer j)
109 {
110 ALIEN_ASSERT(i < size(), "Bound error");
111 ALIEN_ASSERT(j < size(), "Bound error");
112 return MatrixElement(
113 m_matrices[i + j * m_nb_composite], m_row_space[i], m_col_space[j], *this);
114 }
115
116 /*---------------------------------------------------------------------------*/
117
118 IMatrix& Matrix::operator()(Integer i, Integer j)
119 {
120 ALIEN_ASSERT(i < size(), "Bound error");
121 ALIEN_ASSERT(j < size(), "Bound error");
122 return *m_matrices[i + j * m_nb_composite];
123 }
124
125 /*---------------------------------------------------------------------------*/
126
127 const IMatrix& Matrix::operator()(Integer i, Integer j) const
128 {
129 ALIEN_ASSERT(i < size(), "Bound error");
130 ALIEN_ASSERT(j < size(), "Bound error");
131 return *m_matrices[i + j * m_nb_composite];
132 }
133
134 /*---------------------------------------------------------------------------*/
135
136 void Matrix::setComposite(Integer i, Integer j, IMatrix* m)
137 {
138 ALIEN_ASSERT(i < size(), "Bound error");
139 ALIEN_ASSERT(j < size(), "Bound error");
140 m_matrices[i + j * m_nb_composite].reset(m);
141 }
142
143 /*---------------------------------------------------------------------------*/
144 /*---------------------------------------------------------------------------*/
145
146} // namespace CompositeKernel
147
148/*---------------------------------------------------------------------------*/
149/*---------------------------------------------------------------------------*/
150
151} // namespace Alien
152
153/*---------------------------------------------------------------------------*/
154/*---------------------------------------------------------------------------*/
Matrix(MultiMatrixImpl *multi_impl)
Constructor from a composite.
virtual const ISpace & rowSpace() const
Get the row space associated to the matrix \ returns The row space.
virtual const ISpace & colSpace() const
Get the row space associated to the matrix \ returns The row space.
IMatrixImpl(const MultiMatrixImpl *multi_impl, BackEndId backend="")
Constructor.
Multi matrices representation container.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17