GEOSX
HypreVector.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 Total, S.A
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 GEOSX_LINEARALGEBRA_INTERFACES_HYPREVECTOR_HPP_
20 #define GEOSX_LINEARALGEBRA_INTERFACES_HYPREVECTOR_HPP_
21 
23 
30 
33 extern "C" struct hypre_IJVector_struct;
34 
36 using HYPRE_IJVector = hypre_IJVector_struct *;
37 
39 extern "C" struct hypre_ParVector_struct;
40 
42 using HYPRE_ParVector = hypre_ParVector_struct *;
43 
45 
46 namespace geosx
47 {
48 
55 class HypreVector final : private VectorBase< HypreVector >
56 {
57 public:
58 
62 
68  HypreVector();
69 
74  HypreVector( HypreVector const & src );
75 
80  HypreVector( HypreVector && src ) noexcept;
81 
87  HypreVector & operator=( HypreVector const & src );
88 
94  HypreVector & operator=( HypreVector && src ) noexcept;
95 
99  ~HypreVector();
100 
102 
106 
108  using VectorBase::closed;
109  using VectorBase::ready;
110  using VectorBase::extract;
111 
115  virtual bool created() const override;
116 
117  virtual void createWithLocalSize( localIndex const localSize,
118  MPI_Comm const & comm ) override;
119 
120  virtual void createWithGlobalSize( globalIndex const globalSize,
121  MPI_Comm const & comm ) override;
122 
123  virtual void create( arrayView1d< real64 const > const & localValues,
124  MPI_Comm const & comm ) override;
125 
126  virtual void open() override;
127 
128  virtual void close() override;
129 
130  virtual void reset() override;
131 
132  virtual void set( globalIndex const globalRowIndex,
133  real64 const value ) override;
134 
135  virtual void add( globalIndex const globalRowIndex,
136  real64 const value ) override;
137 
138  virtual void set( globalIndex const * globalRowIndices,
139  real64 const * values,
140  localIndex size ) override;
141 
142  virtual void add( globalIndex const * globalRowIndices,
143  real64 const * values,
144  localIndex const size ) override;
145 
146  virtual void set( arraySlice1d< globalIndex const > const & globalRowIndices,
147  arraySlice1d< real64 const > const & values ) override;
148 
149  virtual void add( arraySlice1d< globalIndex const > const & globalRowIndices,
150  arraySlice1d< real64 const > const & values ) override;
151 
152  virtual void set( real64 const value ) override;
153 
154  virtual void zero() override;
155 
156  virtual void rand( unsigned const seed = 1984 ) override;
157 
158  virtual void scale( real64 const scalingFactor ) override;
159 
160  virtual void reciprocal() override;
161 
162  virtual real64 dot( HypreVector const & vec ) const override;
163 
164  virtual void copy( HypreVector const & x ) override;
165 
166  virtual void axpy( real64 const alpha,
167  HypreVector const & x ) override;
168 
169  virtual void axpby( real64 const alpha,
170  HypreVector const & x,
171  real64 const beta ) override;
172 
173  virtual void pointwiseProduct( HypreVector const & x,
174  HypreVector & y ) const override;
175 
179  virtual real64 norm1() const override;
180 
184  virtual real64 norm2() const override;
185 
189  virtual real64 normInf() const override;
190 
194  virtual globalIndex globalSize() const override;
195 
199  virtual localIndex localSize() const override;
200 
204  virtual globalIndex ilower() const override;
205 
209  virtual globalIndex iupper() const override;
210 
211  virtual real64 get( globalIndex globalRow ) const override;
212 
213  virtual void get( arraySlice1d< globalIndex const > const & globalRowIndices,
214  arraySlice1d< real64 > const & values ) const override;
215 
216  virtual localIndex getLocalRowID( globalIndex const globalRowIndex ) const override;
217 
218  virtual globalIndex getGlobalRowID( localIndex const localRowIndex ) const override;
219 
223  virtual real64 const * extractLocalVector() const override;
224 
228  virtual real64 * extractLocalVector() override;
229 
233  virtual MPI_Comm getComm() const override;
234 
235  virtual void print( std::ostream & os = std::cout ) const override;
236 
237  virtual void write( string const & filename,
238  LAIOutputFormat const format = LAIOutputFormat::MATRIX_MARKET ) const override;
239 
241 
246  HYPRE_ParVector const & unwrapped() const;
247 
252  HYPRE_IJVector const & unwrappedIJ() const;
253 
254 private:
255 
259  HYPRE_IJVector m_ij_vector;
260 
264  HYPRE_ParVector m_par_vector;
265 
266 };
267 
268 }// end namespace geosx
269 
270 #endif /*GEOSX_LINEARALGEBRA_INTERFACES_HYPREVECTOR_HPP_*/
Wrapper class for hypre&#39;s ParVector.
Definition: HypreVector.hpp:55
virtual void add(globalIndex const globalRowIndex, real64 const value) override
Add into vector value.
Common base template for all vector wrapper types.
Definition: VectorBase.hpp:47
virtual void copy(HypreVector const &x) override
Update vector y as y = x.
virtual void createWithLocalSize(localIndex const localSize, MPI_Comm const &comm) override
Create a vector based on local number of elements.
virtual void rand(unsigned const seed=1984) override
Set vector elements to random entries.
virtual void extract(arrayView1d< real64 > const &localVector) const
Extract local solution by copying into a user-provided array.
Definition: VectorBase.hpp:423
long long int globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:128
virtual MPI_Comm getComm() const override
Get the communicator used by this vector.
virtual void axpby(real64 const alpha, HypreVector const &x, real64 const beta) override
Update vector y as y = alpha*x + beta*y.
virtual void write(string const &filename, LAIOutputFormat const format=LAIOutputFormat::MATRIX_MARKET) const override
Write the vector to a file.
virtual void create(arrayView1d< real64 const > const &localValues, MPI_Comm const &comm) override
Construct parallel vector from a local array.
This class serves to provide a sliced multidimensional interface to the family of LvArray classes...
Definition: ArraySlice.hpp:89
virtual void reciprocal() override
Replace vector elements by their reciprocals.
virtual globalIndex globalSize() const override
Returns the global of the vector.
bool closed() const
Query vector closed status.
Definition: VectorBase.hpp:104
std::string format(int NDIM, INDEX_TYPE const *const dims)
This function returns a string that may be used as the "type" in a call to TV_ttf_add_row(). This will either be a single value or an array.
Definition: tv_helpers.hpp:37
virtual void zero() override
Set vector elements to zero.
HypreVector()
Empty vector constructor. Create an empty (distributed) vector.
virtual bool created() const override
Query vector creation status.
hypre_IJVector_struct * HYPRE_IJVector
IJVector pointer alias.
Definition: HypreVector.hpp:36
virtual globalIndex getGlobalRowID(localIndex const localRowIndex) const override
Map a local row index to global row index.
virtual void scale(real64 const scalingFactor) override
Multiply all elements by scalingFactor.
virtual real64 dot(HypreVector const &vec) const override
Dot product with the vector vec.
virtual globalIndex ilower() const override
Get lower bound of local partition.
This class serves to provide a "view" of a multidimensional array.
Definition: ArrayView.hpp:67
virtual localIndex localSize() const override
Returns the local size of the vector.
virtual real64 norm2() const override
2-norm of the vector.
double real64
64-bit floating point type.
Definition: DataTypes.hpp:136
virtual void reset() override
Reset the matrix to default state.
virtual real64 const * extractLocalVector() const override
Extract a view of the local portion of the array.
virtual real64 normInf() const override
Infinity-norm of the vector.
HypreVector & operator=(HypreVector const &src)
Copy assignment.
virtual globalIndex iupper() const override
Get upper bound of local partition.
virtual void createWithGlobalSize(globalIndex const globalSize, MPI_Comm const &comm) override
Create a vector based on global number of elements.
hypre_ParVector_struct * HYPRE_ParVector
ParVector pointer alias.
Definition: HypreVector.hpp:42
virtual real64 norm1() const override
1-norm of the vector.
virtual void pointwiseProduct(HypreVector const &x, HypreVector &y) const override
Compute the componentwise multiplication y = v * x.
HYPRE_IJVector const & unwrappedIJ() const
Returns a pointer to the implementation.
LAIOutputFormat
Definition: common.hpp:139
virtual void axpy(real64 const alpha, HypreVector const &x) override
Update vector y as y = alpha*x + y.
~HypreVector()
Destructor.
virtual localIndex getLocalRowID(globalIndex const globalRowIndex) const override
Map a global row index to local row index.
virtual void close() override
Assemble vector.
std::ptrdiff_t localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
bool ready() const
Query vector ready status.
Definition: VectorBase.hpp:116
HYPRE_ParVector const & unwrapped() const
Returns a pointer to the implementation.
virtual void open() override
Open the vector for modifying entries.
virtual void print(std::ostream &os=std::cout) const override
Print the vector in Trilinos format to the terminal.