Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
BlockVector.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 <alien/ref/data/block/BlockVector.h>
20
21#include <alien/ref/AlienRefSemantic.h>
22#include <alien/utils/ICopyOnWriteObject.h>
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27namespace Alien
28{
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33BlockVector::BlockVector()
34: m_impl(new MultiVectorImpl(std::make_shared<Space>(0),
35 std::make_shared<VectorDistribution>(VectorDistribution())))
36{}
37
38/*---------------------------------------------------------------------------*/
39
40BlockVector::BlockVector(const Block& block, const VectorDistribution& dist)
41: m_impl(new MultiVectorImpl(dist.space().clone(), dist.clone()))
42{
43 m_impl->setBlockInfos(&block);
44}
45
46/*---------------------------------------------------------------------------*/
47
48BlockVector::BlockVector(Integer nrows, Integer nrows_local, const Block& block,
49 IMessagePassingMng* parallel_mng)
50: m_impl(new MultiVectorImpl(std::make_shared<Space>(nrows),
51 std::make_shared<VectorDistribution>(
52 VectorDistribution(nrows, nrows_local, parallel_mng))))
53{
54 m_impl->setBlockInfos(&block);
55}
56
57/*---------------------------------------------------------------------------*/
58
59BlockVector::BlockVector(
60Integer nrows, const Block& block, IMessagePassingMng* parallel_mng)
61: m_impl(new MultiVectorImpl(std::make_shared<Space>(nrows),
62 std::make_shared<VectorDistribution>(VectorDistribution(nrows, parallel_mng))))
63{
64 m_impl->setBlockInfos(&block);
65}
66
67/*---------------------------------------------------------------------------*/
68
69BlockVector::BlockVector(BlockVector&& vector)
70: m_impl(std::move(vector.m_impl))
71{}
72
73/*---------------------------------------------------------------------------*/
74
75BlockVector&
76BlockVector::operator=(BlockVector&& vector)
77{
78 m_impl = std::move(vector.m_impl);
79 return *this;
80}
81
82/*---------------------------------------------------------------------------*/
83
84void BlockVector::init(const Block& block, const VectorDistribution& dist)
85{
86 m_impl.reset(new MultiVectorImpl(dist.space().clone(), dist.clone()));
87 m_impl->setBlockInfos(&block);
88}
89
90/*---------------------------------------------------------------------------*/
91
92void BlockVector::free()
93{
94 m_impl->free();
95}
96
97/*---------------------------------------------------------------------------*/
98
99void BlockVector::clear()
100{
101 m_impl->clear();
102}
103
104/*---------------------------------------------------------------------------*/
105
106const ISpace&
108{
109 return m_impl->space();
110}
111
112/*---------------------------------------------------------------------------*/
113
115{
116 v.accept(m_impl);
117}
118
119/*---------------------------------------------------------------------------*/
120
122BlockVector::distribution() const
123{
124 return m_impl->distribution();
125}
126
127/*---------------------------------------------------------------------------*/
128
129void BlockVector::setUserFeature(String feature)
130{
131 m_impl->setFeature(feature);
132}
133
134/*---------------------------------------------------------------------------*/
135
136bool BlockVector::hasUserFeature(String feature) const
137{
138 return m_impl->hasFeature(feature);
139}
140
141const Block&
142BlockVector::block() const
143{
144 const Block* block = m_impl->block();
145 if (block)
146 return *block;
147 else
148 throw FatalErrorException(
149 A_FUNCINFO, "Requesting for block information but none was provided");
150}
151
152/*---------------------------------------------------------------------------*/
153
154MultiVectorImpl*
156{
157 if (!m_impl) {
158 m_impl.reset(new MultiVectorImpl());
159 }
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
169const MultiVectorImpl*
171{
172 return m_impl.get();
173}
174
175/*---------------------------------------------------------------------------*/
176/*---------------------------------------------------------------------------*/
177
178} // namespace Alien
179
180/*---------------------------------------------------------------------------*/
181/*---------------------------------------------------------------------------*/
const ISpace & space() const override
Get the space associated to the vector.
MultiVectorImpl * impl() override
Get the multivector implementation.
void visit(ICopyOnWriteVector &) const override
Visit method.
Implementation of an algebraic space.
Definition Space.h:47
Computes a vector distribution.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17