Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
BaseBlockVectorWriter.h
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#pragma once
20
21#include <alien/utils/Precomp.h>
22
25#include <alien/kernels/simple_csr/SimpleCSRVector.h>
26
27#include <alien/data/IVector.h>
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32namespace Alien
33{
34
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
37
38template <typename T>
39class SimpleCSRVector;
40
41/*---------------------------------------------------------------------------*/
42/*---------------------------------------------------------------------------*/
43
44namespace Common
45{
46
47 /*---------------------------------------------------------------------------*/
48 /*---------------------------------------------------------------------------*/
49
50 template <typename ValueT>
51 class BlockVectorWriterBaseT
52 {
53 public:
54 explicit BlockVectorWriterBaseT(IVector& vector);
55
56 virtual ~BlockVectorWriterBaseT() { end(); }
57
58 void end();
59
60 BlockVectorWriterBaseT& operator=(const ValueT v);
61
62 protected:
63 IVector& m_vector;
64 ArrayView<ValueT> m_values;
65 SimpleCSRVector<ValueT>* m_vector_impl;
66 const Block* m_block;
67 const VBlock* m_vblock;
68 bool m_finalized;
69 bool m_changed;
70 };
71
72 /*---------------------------------------------------------------------------*/
73
74 template <typename ValueT>
75 class LocalBlockVectorWriterT : public BlockVectorWriterBaseT<ValueT>
76 {
77 public:
78 explicit LocalBlockVectorWriterT(IVector& vector);
79
80 ~LocalBlockVectorWriterT() = default;
81
82 using BlockVectorWriterBaseT<ValueT>::operator=;
83
84 ArrayView<ValueT> operator[](Integer iIndex)
85 {
86 this->m_changed = true;
87 if (this->m_block)
88 return this->m_values.subView(
89 iIndex * this->m_block->size(), this->m_block->size());
90 else if (this->m_vblock) {
91 const VBlock* block_sizes = this->m_vblock;
92 const Integer size = block_sizes->size(iIndex);
93 const Integer offset = this->m_vector_impl->vblockImpl().offset(iIndex);
94 return this->m_values.subView(offset, size);
95 }
96 else
97 throw FatalErrorException(A_FUNCINFO, "No block infos");
98 }
99 };
100
101 /*---------------------------------------------------------------------------*/
102
103 template <typename ValueT>
104 class BlockVectorWriterT : public BlockVectorWriterBaseT<ValueT>
105 {
106 public:
107 explicit BlockVectorWriterT(IVector& vector);
108
109 ~BlockVectorWriterT() = default;
110
111 using BlockVectorWriterBaseT<ValueT>::operator=;
112
113 ArrayView<ValueT> operator[](Integer iIndex)
114 {
115 this->m_changed = true;
116 if (this->m_block)
117 return this->m_values.subView(
118 (iIndex - m_local_offset) * this->m_block->size(), this->m_block->size());
119 else if (this->m_vblock) {
120 const VBlock* block_sizes = this->m_vblock;
121 // const Integer size = block_sizes.size(iIndex-m_local_offset);
122 const Integer size = block_sizes->size(iIndex);
123 const Integer offset = this->m_vector_impl->vblockImpl().offset(iIndex);
124 return this->m_values.subView(offset, size);
125 }
126 else
127 throw FatalErrorException(A_FUNCINFO, "No block infos");
128 }
129
130 private:
131 Integer m_local_offset;
132 };
133
134 /*---------------------------------------------------------------------------*/
135 /*---------------------------------------------------------------------------*/
136
137 using BlockVectorWriter = BlockVectorWriterT<Real>;
138 using LocalBlockVectorWriter = LocalBlockVectorWriterT<Real>;
139
140 /*---------------------------------------------------------------------------*/
141 /*---------------------------------------------------------------------------*/
142
143} // namespace Common
144
145} // namespace Alien
146
147/*---------------------------------------------------------------------------*/
148/*---------------------------------------------------------------------------*/
149
150#include "BlockVectorWriterT.h"
151
152/*---------------------------------------------------------------------------*/
153/*---------------------------------------------------------------------------*/
Block.h.
IVector.h.
VBlock.h.
Block elements for block matrices.
Definition Block.h:45
Interface for all vectors.
Definition IVector.h:51
Variable size block elements for block matrices.
Definition VBlock.h:46
Arccore::Integer size(Arccore::Integer index) const
Get the size of a block.
Definition VBlock.cc:162
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17