Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
data/CompositeVector.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/CompositeMultiVectorImpl.h>
26#include <alien/kernels/composite/CompositeVector.h>
27
29#include <alien/functional/NullVector.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(CompositeVector& v, Integer i)
46{
47 return v.composite(i);
48}
49
50/*---------------------------------------------------------------------------*/
51/*---------------------------------------------------------------------------*/
52
56
57/*---------------------------------------------------------------------------*/
58/*---------------------------------------------------------------------------*/
59
61: m_impl(new CompositeKernel::MultiVectorImpl())
62, m_composite_vector(m_impl->get<Alien::BackEnd::tag::composite>(false))
63{
64 m_impl->setFeature("composite");
65
66 if (nc > 0)
67 resize(nc);
68}
69
70/*---------------------------------------------------------------------------*/
71/*---------------------------------------------------------------------------*/
72
74{
75 v.accept(m_impl);
76}
77
78/*---------------------------------------------------------------------------*/
79/*---------------------------------------------------------------------------*/
80
82{
84
85 for (Integer i = 0; i < size; ++i)
86 m_composite_vector.setComposite(i, new NullVector());
87}
88
89/*---------------------------------------------------------------------------*/
90/*---------------------------------------------------------------------------*/
91
92Integer
94{
95 return m_composite_vector.size();
96}
97
98/*---------------------------------------------------------------------------*/
99/*---------------------------------------------------------------------------*/
100
101const ISpace&
103{
104 return m_impl->space();
105}
106
107/*---------------------------------------------------------------------------*/
108/*---------------------------------------------------------------------------*/
109
112{
113 return m_composite_vector.element(i);
114}
115
116/*---------------------------------------------------------------------------*/
117/*---------------------------------------------------------------------------*/
118
119IVector&
121{
122 return m_composite_vector[i];
123}
124
125/*---------------------------------------------------------------------------*/
126/*---------------------------------------------------------------------------*/
127
128const IVector&
129CompositeVector::operator[](Integer i) const
130{
131 return m_composite_vector[i];
132}
133
134/*---------------------------------------------------------------------------*/
135/*---------------------------------------------------------------------------*/
136
138{
139 m_impl->setFeature(feature);
140}
141
142/*---------------------------------------------------------------------------*/
143/*---------------------------------------------------------------------------*/
144
145bool CompositeVector::hasUserFeature(String feature) const
146{
147 return m_impl->hasFeature(feature);
148}
149
150/*---------------------------------------------------------------------------*/
151/*---------------------------------------------------------------------------*/
152
155{
156 if (!m_impl) {
157 m_impl.reset(new MultiVectorImpl());
158 }
159 // TOCHECK : to remove or not ?
160 /* JMG ????
161 else if (!m_impl.unique()) { // Need to clone due to other references.
162 m_impl.reset(m_impl->clone());
163 } */
164 return m_impl.get();
165}
166
167/*---------------------------------------------------------------------------*/
168/*---------------------------------------------------------------------------*/
169
170const MultiVectorImpl*
172{
173 return m_impl.get();
174}
175
176/*---------------------------------------------------------------------------*/
177/*---------------------------------------------------------------------------*/
178
180{
181 for (Integer i = 0; i < this->size(); ++i)
182 if (m_composite_vector[i].impl())
183 m_composite_vector[i].impl()->free();
184}
185
186/*---------------------------------------------------------------------------*/
187/*---------------------------------------------------------------------------*/
188
190{
191 for (Integer i = 0; i < this->size(); ++i)
192 if (m_composite_vector[i].impl())
193 m_composite_vector[i].impl()->clear();
194}
195
196/*---------------------------------------------------------------------------*/
197/*---------------------------------------------------------------------------*/
198
199} // namespace Alien
200
201/*---------------------------------------------------------------------------*/
202/*---------------------------------------------------------------------------*/
MultiVectorImpl.h.
Composite vector for heterogenous vector.
IVector & operator[](Arccore::Integer i)
Get the i-th subvector.
MultiVectorImpl * impl()
Get the multivector implementation.
CompositeKernel::Vector & m_composite_vector
The composite vector.
void resize(Arccore::Integer nc)
Resize the number of submatrices.
void visit(ICopyOnWriteVector &) const
Visit method.
CompositeKernel::VectorElement Element
Type of submatrix element.
void setUserFeature(Arccore::String feature)
Add a feature to the composite vector.
Element composite(Arccore::Integer i)
Get the i-th element.
std::shared_ptr< MultiVectorImpl > m_impl
The multivector implementation.
Arccore::Integer size() const
Get the number of subvectors.
bool hasUserFeature(Arccore::String feature) const
Check if the composite vector has a feature.
void free()
Free resources.
void clear()
Clear resources.
const ISpace & space() const
Get the space of the global vector.
Interface for algebraic space objects.
Definition ISpace.h:44
Interface for all vectors.
Definition IVector.h:51
CompositeVector.h.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17