GEOS
HypreVector.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 TotalEnergies
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_INTERFACES_HYPREVECTOR_HPP_
21 #define GEOS_LINEARALGEBRA_INTERFACES_HYPREVECTOR_HPP_
22 
24 
32 
33 extern "C"
34 {
36 struct hypre_IJVector_struct;
37 
39 struct hypre_ParVector_struct;
40 }
41 
43 
44 namespace geos
45 {
46 
53 class HypreVector final : private VectorBase< HypreVector >
54 {
55 public:
56 
61 
67 
72  HypreVector( HypreVector const & src );
73 
78  HypreVector( HypreVector && src ) noexcept;
79 
85  HypreVector & operator=( HypreVector const & src );
86 
92  HypreVector & operator=( HypreVector && src ) noexcept;
93 
98 
100 
105 
106  using VectorBase::setName;
107  using VectorBase::closed;
108  using VectorBase::ready;
109  using VectorBase::open;
110  using VectorBase::zero;
111  using VectorBase::values;
112 
116  virtual bool created() const override;
117 
118  virtual void create( localIndex const localSize,
119  MPI_Comm const & comm ) override;
120 
121  virtual void close() override;
122 
123  virtual void touch() override;
124 
125  virtual void reset() override;
126 
127  virtual void set( real64 const value ) override;
128 
129  virtual void rand( unsigned const seed ) override;
130 
131  virtual void scale( real64 const scalingFactor ) override;
132 
133  virtual void reciprocal() override;
134 
135  virtual real64 dot( HypreVector const & vec ) const override;
136 
137  virtual void copy( HypreVector const & x ) override;
138 
139  virtual void axpy( real64 const alpha,
140  HypreVector const & x ) override;
141 
142  virtual void axpby( real64 const alpha,
143  HypreVector const & x,
144  real64 const beta ) override;
145 
149  virtual void pointwiseProduct( HypreVector const & x ) override;
150 
154  virtual void pointwiseDivide( HypreVector const & x ) override;
155 
159  virtual real64 norm1() const override;
160 
164  virtual real64 norm2() const override;
165 
169  virtual real64 normInf() const override;
170 
174  virtual globalIndex globalSize() const override;
175 
179  virtual localIndex localSize() const override;
180 
184  virtual globalIndex ilower() const override;
185 
189  virtual globalIndex iupper() const override;
190 
194  virtual MPI_Comm comm() const override;
195 
196  virtual void print( std::ostream & os = std::cout ) const override;
197 
198  virtual void write( string const & filename,
199  LAIOutputFormat const format = LAIOutputFormat::MATRIX_MARKET ) const override;
200 
202 
203 private:
204 
206  using HYPRE_IJVector = struct hypre_IJVector_struct *;
207 
209  using HYPRE_ParVector = struct hypre_ParVector_struct *;
210 
211 public:
212 
217  HYPRE_ParVector const & unwrapped() const;
218 
223  HYPRE_IJVector const & unwrappedIJ() const;
224 
225 private:
226 
231  void parVectorToIJ( HYPRE_ParVector const & parVector );
232 
236  HYPRE_IJVector m_ij_vec;
237 
241  HYPRE_ParVector m_vec;
242 
243 };
244 
245 }// end namespace geos
246 
247 #endif /*GEOS_LINEARALGEBRA_INTERFACES_HYPREVECTOR_HPP_*/
Wrapper class for hypre's ParVector.
Definition: HypreVector.hpp:54
~HypreVector()
Destructor.
virtual bool created() const override
Query vector creation status.
HypreVector & operator=(HypreVector &&src) noexcept
Move assignment.
virtual real64 normInf() const override
Infinity-norm of the vector.
HYPRE_IJVector const & unwrappedIJ() const
Returns a pointer to the IJ wrapper implementation.
HypreVector(HypreVector &&src) noexcept
Move constructor.
virtual void create(localIndex const localSize, MPI_Comm const &comm) override
Create a vector based on local number of elements.
virtual void print(std::ostream &os=std::cout) const override
Print the vector in Trilinos format to the terminal.
virtual void close() override
Close vector for modification.
virtual void pointwiseProduct(HypreVector const &x) override
Element-wise multiplication of this vector with another vector.
virtual localIndex localSize() const override
Returns the local size of the vector.
virtual void axpby(real64 const alpha, HypreVector const &x, real64 const beta) override
Update vector y as y = alpha*x + beta*y.
virtual real64 dot(HypreVector const &vec) const override
Dot product with the vector vec.
virtual void reciprocal() override
Replace vector elements by their reciprocals.
virtual void set(real64 const value) override
Set all elements to a constant value.
virtual MPI_Comm comm() const override
Get the communicator used by this vector.
HypreVector()
Empty vector constructor. Create an empty (distributed) vector.
virtual void copy(HypreVector const &x) override
Update vector y as y = x.
virtual void rand(unsigned const seed) override
Set vector elements to random entries.
virtual real64 norm2() const override
2-norm of the vector.
virtual void pointwiseDivide(HypreVector const &x) override
Element-wise division of this vector by another vector.
virtual void touch() override
Notify the vector about external modification through direct data pointer.
virtual void write(string const &filename, LAIOutputFormat const format=LAIOutputFormat::MATRIX_MARKET) const override
Write the vector to a file.
virtual globalIndex globalSize() const override
Returns the global of the vector.
virtual globalIndex ilower() const override
Get lower bound of local partition.
virtual void scale(real64 const scalingFactor) override
Multiply all elements by factor.
virtual globalIndex iupper() const override
Get upper bound of local partition.
virtual real64 norm1() const override
1-norm of the vector.
virtual void axpy(real64 const alpha, HypreVector const &x) override
Update vector y as y = alpha*x + y.
HypreVector(HypreVector const &src)
Copy constructor.
virtual void reset() override
Reset the vector to default state.
HYPRE_ParVector const & unwrapped() const
Returns a pointer to the implementation.
HypreVector & operator=(HypreVector const &src)
Copy assignment.
Common base template for all vector wrapper types.
Definition: VectorBase.hpp:49
bool ready() const
Query vector ready status.
Definition: VectorBase.hpp:76
virtual arrayView1d< real64 > open()
Open the vector for modifying entries.
Definition: VectorBase.hpp:129
arrayView1d< real64 const > values() const
Definition: VectorBase.hpp:311
virtual void zero()
Set vector elements to zero.
Definition: VectorBase.hpp:181
bool closed() const
Query vector closed status.
Definition: VectorBase.hpp:64
void setName(string const &name)
Set a name for the vector (mainly used during various logging).
Definition: VectorBase.hpp:113
GEOS_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:87
LAIOutputFormat
Definition: common.hpp:142
double real64
64-bit floating point type.
Definition: DataTypes.hpp:98
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:84