GEOSX
PetscVector.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_INTERFACES_PETSCVECTOR_HPP_
20 #define GEOS_LINEARALGEBRA_INTERFACES_PETSCVECTOR_HPP_
21 
23 
31 
33 extern "C" struct _p_Vec;
34 
36 
37 namespace geos
38 {
39 
44 class PetscVector final : private VectorBase< PetscVector >
45 {
46 public:
47 
52 
57 
62  PetscVector( PetscVector const & src );
63 
68  PetscVector( PetscVector && src ) noexcept;
69 
75  PetscVector & operator=( PetscVector const & src );
76 
82  PetscVector & operator=( PetscVector && src ) noexcept;
83 
88 
90 
95 
96  using VectorBase::setName;
97  using VectorBase::closed;
98  using VectorBase::ready;
99  using VectorBase::open;
100  using VectorBase::zero;
101  using VectorBase::values;
102 
106  virtual bool created() const override;
107 
108  virtual void create( localIndex const localSize,
109  MPI_Comm const & comm ) override;
110 
111  virtual void close() override;
112 
113  virtual void touch() override;
114 
115  virtual void reset() override;
116 
117  virtual void set( real64 const value ) override;
118 
119  virtual void rand( unsigned const seed ) override;
120 
121  virtual void scale( real64 const scalingFactor ) override;
122 
123  virtual void reciprocal() override;
124 
125  virtual real64 dot( PetscVector const & vec ) const override;
126 
127  virtual void copy( PetscVector const & x ) override;
128 
129  virtual void axpy( real64 const alpha,
130  PetscVector const & x ) override;
131 
132  virtual void axpby( real64 const alpha,
133  PetscVector const & x,
134  real64 const beta ) override;
135 
136  virtual void pointwiseProduct( PetscVector const & x,
137  PetscVector & y ) const override;
138 
142  virtual real64 norm1() const override;
143 
147  virtual real64 norm2() const override;
148 
152  virtual real64 normInf() const override;
153 
157  virtual globalIndex globalSize() const override;
158 
162  virtual localIndex localSize() const override;
163 
167  virtual globalIndex ilower() const override;
168 
172  virtual globalIndex iupper() const override;
173 
174  virtual void print( std::ostream & os = std::cout ) const override;
175 
176  virtual void write( string const & filename,
177  LAIOutputFormat const format = LAIOutputFormat::MATRIX_MARKET ) const override;
178 
182  virtual MPI_Comm comm() const override;
183 
185 
186 private:
187 
189  using Vec = struct _p_Vec *;
190 
191 public:
192 
197  const Vec & unwrapped() const;
198 
203  Vec & unwrapped();
204 
205 private:
206 
210  Vec m_vec;
211 };
212 
213 } // end geosx namespace
214 
215 #endif /*GEOS_LINEARALGEBRA_INTERFACES_PETSCVECTOR_HPP_*/
This class creates and provides basic support for Vec vector object type used in PETSc.
Definition: PetscVector.hpp:45
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:48
bool ready() const
Query vector ready status.
Definition: VectorBase.hpp:75
virtual arrayView1d< real64 > open()
Open the vector for modifying entries.
Definition: VectorBase.hpp:128
arrayView1d< real64 const > values() const
Definition: VectorBase.hpp:304
virtual void zero()
Set vector elements to zero.
Definition: VectorBase.hpp:180
bool closed() const
Query vector closed status.
Definition: VectorBase.hpp:63
void setName(string const &name)
Set a name for the vector (mainly used during various logging).
Definition: VectorBase.hpp:112
LAIOutputFormat
Definition: common.hpp:140
double real64
64-bit floating point type.
Definition: DataTypes.hpp:139
GEOSX_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:128
GEOSX_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125