GEOS
BlockVector.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 Total, S.A
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
20 #ifndef GEOS_LINEARALGEBRA_UTILITIES_BLOCKVECTOR_HPP_
21 #define GEOS_LINEARALGEBRA_UTILITIES_BLOCKVECTOR_HPP_
22 
24 
25 namespace geos
26 {
27 
35 template< typename VECTOR >
36 class BlockVector : public BlockVectorView< VECTOR >
37 {
38 public:
39 
42 
47  explicit BlockVector( localIndex const nBlocks )
48  : Base( nBlocks ),
49  m_vectorStorage( nBlocks )
50  {
51  setPointers();
52  }
53 
57  explicit BlockVector()
58  : BlockVector( 0 )
59  {}
60 
65  BlockVector( BlockVector const & rhs )
66  : Base( rhs ),
67  m_vectorStorage( rhs.m_vectorStorage )
68  {
69  setPointers();
70  }
71 
77  : Base( std::move( rhs ) ),
78  m_vectorStorage( std::move( rhs.m_vectorStorage ) )
79  {
80  setPointers();
81  }
82 
88  explicit BlockVector( BlockVectorView< VECTOR > const & rhs )
89  : Base( rhs.blockSize() )
90  {
91  for( localIndex i = 0; i < rhs.blockSize(); ++i )
92  {
93  m_vectorStorage.emplace_back( rhs.block( i ) );
94  }
95  setPointers();
96  }
97 
104  {
105  m_vectorStorage = x.m_vectorStorage;
106  setPointers();
107  return *this;
108  }
109 
115  BlockVector & operator=( BlockVector && x ) noexcept
116  {
117  m_vectorStorage = std::move( x.m_vectorStorage );
118  setPointers();
119  return *this;
120  }
121 
125  virtual ~BlockVector() override = default;
126 
134  void resize( localIndex const nBlocks )
135  {
136  m_vectorStorage.resize( nBlocks );
137  setPointers();
138  }
139 
140 private:
141 
142  void setPointers()
143  {
144  Base::resize( m_vectorStorage.size() );
145  for( localIndex i = 0; i < m_vectorStorage.size(); ++i )
146  {
147  this->setPointer( i, &m_vectorStorage[i] );
148  }
149  }
150 
152  array1d< VECTOR > m_vectorStorage;
153 };
154 
155 } //namespace geos
156 
157 #endif //GEOS_LINEARALGEBRA_UTILITIES_BLOCKVECTOR_HPP_
Concrete representation of a block vector.
Definition: BlockVector.hpp:37
BlockVector(BlockVectorView< VECTOR > const &rhs)
Conversion constructor from a compatible view with a deep copy of each sub-vector.
Definition: BlockVector.hpp:88
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:65
BlockVector(localIndex const nBlocks)
Create a vector of nBlocks blocks.
Definition: BlockVector.hpp:47
void resize(localIndex const nBlocks)
Resize to a different number of blocks.
BlockVector()
Create a vector of nBlocks blocks.
Definition: BlockVector.hpp:57
BlockVector(BlockVector &&rhs)
Move constructor.
Definition: BlockVector.hpp:76
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.
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:85