GEOSX
BlockVector.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University
7  * Copyright (c) 2018-2020 TotalEnergies
8  * Copyright (c) 2019- GEOSX Contributors
9  * All rights reserved
10  *
11  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
12  * ------------------------------------------------------------------------------------------------------------
13  */
14 
19 #ifndef GEOS_LINEARALGEBRA_UTILITIES_BLOCKVECTOR_HPP_
20 #define GEOS_LINEARALGEBRA_UTILITIES_BLOCKVECTOR_HPP_
21 
23 
24 namespace geos
25 {
26 
34 template< typename VECTOR >
35 class BlockVector : public BlockVectorView< VECTOR >
36 {
37 public:
38 
41 
46  explicit BlockVector( localIndex const nBlocks )
47  : Base( nBlocks ),
48  m_vectorStorage( nBlocks )
49  {
50  setPointers();
51  }
52 
56  explicit BlockVector()
57  : BlockVector( 0 )
58  {}
59 
64  BlockVector( BlockVector const & rhs )
65  : Base( rhs ),
66  m_vectorStorage( rhs.m_vectorStorage )
67  {
68  setPointers();
69  }
70 
76  : Base( std::move( rhs ) ),
77  m_vectorStorage( std::move( rhs.m_vectorStorage ) )
78  {
79  setPointers();
80  }
81 
87  explicit BlockVector( BlockVectorView< VECTOR > const & rhs )
88  : Base( rhs.blockSize() )
89  {
90  for( localIndex i = 0; i < rhs.blockSize(); ++i )
91  {
92  m_vectorStorage.emplace_back( rhs.block( i ) );
93  }
94  setPointers();
95  }
96 
103  {
104  m_vectorStorage = x.m_vectorStorage;
105  setPointers();
106  return *this;
107  }
108 
114  BlockVector & operator=( BlockVector && x ) noexcept
115  {
116  m_vectorStorage = std::move( x.m_vectorStorage );
117  setPointers();
118  return *this;
119  }
120 
124  virtual ~BlockVector() override = default;
125 
133  void resize( localIndex const nBlocks )
134  {
135  m_vectorStorage.resize( nBlocks );
136  setPointers();
137  }
138 
139 private:
140 
141  void setPointers()
142  {
143  Base::resize( m_vectorStorage.size() );
144  for( localIndex i = 0; i < m_vectorStorage.size(); ++i )
145  {
146  this->setPointer( i, &m_vectorStorage[i] );
147  }
148  }
149 
151  array1d< VECTOR > m_vectorStorage;
152 };
153 
154 } //namespace geos
155 
156 #endif //GEOS_LINEARALGEBRA_UTILITIES_BLOCKVECTOR_HPP_
Concrete representation of a block vector.
Definition: BlockVector.hpp:36
BlockVector(BlockVectorView< VECTOR > const &rhs)
Conversion constructor from a compatible view with a deep copy of each sub-vector.
Definition: BlockVector.hpp:87
BlockVector & operator=(BlockVector &&x) noexcept
Move assignment.
virtual ~BlockVector() override=default
Destructor.
BlockVector & operator=(BlockVector const &x)
Copy assignment.
BlockVector(BlockVector const &rhs)
Copy constructor that performs a deep copy of each sub-vector.
Definition: BlockVector.hpp:64
BlockVector(localIndex const nBlocks)
Create a vector of nBlocks blocks.
Definition: BlockVector.hpp:46
void resize(localIndex const nBlocks)
Resize to a different number of blocks.
BlockVector()
Create a vector of nBlocks blocks.
Definition: BlockVector.hpp:56
BlockVector(BlockVector &&rhs)
Move constructor.
Definition: BlockVector.hpp:75
Abstract view of a block vector.
VECTOR const & block(localIndex const blockIndex) const
Get a reference to the vector corresponding to block blockRowIndex.
void setPointer(localIndex i, VECTOR *vec)
Set pointer to a vector.
void resize(localIndex const size)
Resize to a new number of blocks.
localIndex blockSize() const
Get block size.
GEOSX_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125