Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
Ones.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/functional/Ones.h>
20
21#include <alien/ref/data/block/BlockVector.h>
22#include <alien/ref/data/block/VBlockVector.h>
23#include <alien/ref/data/scalar/Vector.h>
24#include <alien/ref/handlers/block/BlockVectorWriter.h>
25#include <alien/ref/handlers/block/VBlockVectorWriter.h>
26#include <alien/ref/handlers/scalar/VectorWriter.h>
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31namespace Alien
32{
33
34/*---------------------------------------------------------------------------*/
35/*---------------------------------------------------------------------------*/
36
38ones(Integer size, IMessagePassingMng* pm)
39{
40 Vector v(size, pm);
41 {
42 Alien::VectorWriter w(v);
43 w = 1.;
44 }
45 return v;
46}
47
48/*---------------------------------------------------------------------------*/
49
51ones(Integer size, const Block& bloc, IMessagePassingMng* pm)
52{
53 BlockVector v(size, bloc, pm);
54 const Integer offset = v.distribution().offset();
55 {
56 Alien::BlockVectorWriter w(v);
57 for (Integer i = offset; i < v.distribution().localSize() + offset; ++i) {
58 ArrayView<Real> values = w[i];
59 for (Integer j = 0; j < bloc.size(); ++j)
60 values[j] = 1.;
61 }
62 }
63 return v;
64}
65
66/*---------------------------------------------------------------------------*/
67
69ones(Integer size, const VBlock& bloc, IMessagePassingMng* pm)
70{
71 VBlockVector v(size, bloc, pm);
72 const Integer offset = v.distribution().offset();
73 {
74 Alien::VBlockVectorWriter w(v);
75 for (Integer i = offset; i < v.distribution().localSize() + offset; ++i) {
76 ArrayView<Real> values = w[i];
77 for (Integer j = 0; j < bloc.size(i); ++j)
78 values[j] = 1.;
79 }
80 }
81 return v;
82}
83
84/*---------------------------------------------------------------------------*/
85/*---------------------------------------------------------------------------*/
86
87} // namespace Alien
Block elements for block matrices.
Definition Block.h:45
Variable size block elements for block matrices.
Definition VBlock.h:46
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17