GEOS
PetscVector.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_PETSCVECTOR_HPP_
21 #define GEOS_LINEARALGEBRA_INTERFACES_PETSCVECTOR_HPP_
22 
24 
32 
34 extern "C" struct _p_Vec;
35 
37 
38 namespace geos
39 {
40 
45 class PetscVector final : private VectorBase< PetscVector >
46 {
47 public:
48 
53 
58 
63  PetscVector( PetscVector const & src );
64 
69  PetscVector( PetscVector && src ) noexcept;
70 
76  PetscVector & operator=( PetscVector const & src );
77 
83  PetscVector & operator=( PetscVector && src ) noexcept;
84 
89 
91 
96 
97  using VectorBase::setName;
98  using VectorBase::closed;
99  using VectorBase::ready;
100  using VectorBase::open;
101  using VectorBase::zero;
102  using VectorBase::values;
103 
107  virtual bool created() const override;
108 
109  virtual void create( localIndex const localSize,
110  MPI_Comm const & comm ) override;
111 
112  virtual void close() override;
113 
114  virtual void touch() override;
115 
116  virtual void reset() override;
117 
118  virtual void set( real64 const value ) override;
119 
120  virtual void rand( unsigned const seed ) override;
121 
122  virtual void scale( real64 const scalingFactor ) override;
123 
124  virtual void reciprocal() override;
125 
126  virtual real64 dot( PetscVector const & vec ) const override;
127 
128  virtual void copy( PetscVector const & x ) override;
129 
130  virtual void axpy( real64 const alpha,
131  PetscVector const & x ) override;
132 
133  virtual void axpby( real64 const alpha,
134  PetscVector const & x,
135  real64 const beta ) override;
136 
137  virtual void pointwiseProduct( PetscVector const & x,
138  PetscVector & y ) const override;
139 
143  virtual real64 norm1() const override;
144 
148  virtual real64 norm2() const override;
149 
153  virtual real64 normInf() const override;
154 
158  virtual globalIndex globalSize() const override;
159 
163  virtual localIndex localSize() const override;
164 
168  virtual globalIndex ilower() const override;
169 
173  virtual globalIndex iupper() const override;
174 
175  virtual void print( std::ostream & os = std::cout ) const override;
176 
177  virtual void write( string const & filename,
178  LAIOutputFormat const format = LAIOutputFormat::MATRIX_MARKET ) const override;
179 
183  virtual MPI_Comm comm() const override;
184 
186 
187 private:
188 
190  using Vec = struct _p_Vec *;
191 
192 public:
193 
198  const Vec & unwrapped() const;
199 
204  Vec & unwrapped();
205 
206 private:
207 
211  Vec m_vec;
212 };
213 
214 } // end geos namespace
215 
216 #endif /*GEOS_LINEARALGEBRA_INTERFACES_PETSCVECTOR_HPP_*/
This class creates and provides basic support for Vec vector object type used in PETSc.
Definition: PetscVector.hpp:46
virtual bool created() const override
Query vector creation status.
virtual void touch() override
Notify the vector about external modification through direct data pointer.
virtual void close() override
Close vector for modification.
const Vec & unwrapped() const
Returns a const pointer to the underlying Vec.
virtual void axpby(real64 const alpha, PetscVector const &x, real64 const beta) override
Update vector y as y = alpha*x + beta*y.
PetscVector(PetscVector &&src) noexcept
Move constructor.
virtual void print(std::ostream &os=std::cout) const override
Print the vector in Trilinos format to the terminal.
PetscVector()
Empty vector constructor.
virtual MPI_Comm comm() const override
Get the communicator used by this vector.
virtual real64 dot(PetscVector const &vec) const override
Dot product with the vector vec.
Vec & unwrapped()
Returns a non-const pointer to the underlying Vec.
PetscVector & operator=(PetscVector &&src) noexcept
Move assignment.
virtual void axpy(real64 const alpha, PetscVector const &x) override
Update vector y as y = alpha*x + y.
virtual void pointwiseProduct(PetscVector const &x, PetscVector &y) const override
Compute the component-wise multiplication y = v * x.
virtual globalIndex globalSize() const override
Returns the global of the vector.
virtual real64 norm1() const override
1-norm of the vector.
virtual void scale(real64 const scalingFactor) override
Multiply all elements by factor.
virtual real64 normInf() const override
Infinity-norm of the vector.
virtual void set(real64 const value) override
Set all elements to a constant value.
virtual void reciprocal() override
Replace vector elements by their reciprocals.
~PetscVector()
Destructor.
virtual globalIndex ilower() const override
Get lower bound of local partition.
virtual void copy(PetscVector const &x) override
Update vector y as y = x.
virtual void write(string const &filename, LAIOutputFormat const format=LAIOutputFormat::MATRIX_MARKET) const override
Write the vector to a file.
virtual void create(localIndex const localSize, MPI_Comm const &comm) override
Create a vector based on local number of elements.
virtual globalIndex iupper() const override
Get upper bound of local partition.
PetscVector(PetscVector const &src)
Copy constructor.
virtual void reset() override
Reset the vector to default state.
virtual real64 norm2() const override
2-norm of the vector.
PetscVector & operator=(PetscVector const &src)
Copy assignment.
virtual void rand(unsigned const seed) override
Set vector elements to random entries.
virtual localIndex localSize() const override
Returns the local size of the vector.
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:305
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:88
LAIOutputFormat
Definition: common.hpp:142
double real64
64-bit floating point type.
Definition: DataTypes.hpp:99
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:85