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 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_PETSCVECTOR_HPP_
20 #define GEOSX_LINEARALGEBRA_INTERFACES_PETSCVECTOR_HPP_
21 
23 
30 
33 extern "C" struct _p_Vec;
34 
36 
37 namespace geosx
38 {
39 
44 class PetscVector final : private VectorBase< PetscVector >
45 {
46 public:
47 
49  using Vec = struct _p_Vec *;
50 
54 
59  PetscVector();
60 
65  PetscVector( PetscVector const & src );
66 
71  PetscVector( PetscVector && src ) noexcept;
72 
78  PetscVector & operator=( PetscVector const & src );
79 
85  PetscVector & operator=( PetscVector && src ) noexcept;
86 
90  ~PetscVector();
91 
93 
97 
99  using VectorBase::closed;
100  using VectorBase::ready;
101  using VectorBase::extract;
102 
106  virtual bool created() const override;
107 
108  virtual void createWithLocalSize( localIndex const localSize,
109  MPI_Comm const & comm ) override;
110 
111  virtual void createWithGlobalSize( globalIndex const globalSize,
112  MPI_Comm const & comm ) override;
113 
114  virtual void create( arrayView1d< real64 const > const & localValues,
115  MPI_Comm const & comm ) override;
116 
117  virtual void open() override;
118 
119  virtual void close() override;
120 
121  virtual void reset() override;
122 
123  virtual void set( globalIndex const globalRow,
124  real64 const value ) override;
125 
126  virtual void add( globalIndex const globalRow,
127  real64 const value ) override;
128 
129  virtual void set( globalIndex const * globalIndices,
130  real64 const * values,
131  localIndex size ) override;
132 
133  virtual void add( globalIndex const * globalIndices,
134  real64 const * values,
135  localIndex size ) override;
136 
137  virtual void set( arraySlice1d< globalIndex const > const & globalIndices,
138  arraySlice1d< real64 const > const & values ) override;
139 
140  virtual void add( arraySlice1d< globalIndex const > const & globalIndices,
141  arraySlice1d< real64 const > const & values ) override;
142 
143  virtual void set( real64 const value ) override;
144 
145  virtual void zero() override;
146 
147  virtual void rand( unsigned const seed = 1984 ) override;
148 
149  virtual void scale( real64 const scalingFactor ) override;
150 
151  virtual void reciprocal() override;
152 
153  virtual real64 dot( PetscVector const & vec ) const override;
154 
155  virtual void copy( PetscVector const & x ) override;
156 
157  virtual void axpy( real64 const alpha,
158  PetscVector const & x ) override;
159 
160  virtual void axpby( real64 const alpha,
161  PetscVector const & x,
162  real64 const beta ) override;
163 
164  virtual void pointwiseProduct( PetscVector const & x,
165  PetscVector & y ) const override;
166 
170  virtual real64 norm1() const override;
171 
175  virtual real64 norm2() const override;
176 
180  virtual real64 normInf() const override;
181 
185  virtual globalIndex globalSize() const override;
186 
190  virtual localIndex localSize() const override;
191 
195  virtual globalIndex ilower() const override;
196 
200  virtual globalIndex iupper() const override;
201 
202  virtual real64 get( globalIndex const globalRow ) const override;
203 
204  void get( arraySlice1d< globalIndex const > const & globalIndices,
205  arraySlice1d< real64 > const & values ) const override;
206 
207  virtual void print( std::ostream & os = std::cout ) const override;
208 
209  virtual void write( string const & filename,
210  LAIOutputFormat const format = LAIOutputFormat::MATRIX_MARKET ) const override;
211 
212  virtual localIndex getLocalRowID( globalIndex const globalRow ) const override;
213 
214  virtual globalIndex getGlobalRowID( localIndex const localRow ) const override;
215 
219  virtual real64 const * extractLocalVector() const override;
220 
224  virtual real64 * extractLocalVector() override;
225 
229  virtual MPI_Comm getComm() const override;
230 
232 
237  const Vec & unwrapped() const;
238 
243  Vec & unwrapped();
244 
245 protected:
246 
251 };
252 
253 } // end geosx namespace
254 
255 #endif /*GEOSX_LINEARALGEBRA_INTERFACES_PETSCVECTOR_HPP_*/
Common base template for all vector wrapper types.
Definition: VectorBase.hpp:47
virtual void copy(PetscVector const &x) override
Update vector y as y = x.
virtual real64 dot(PetscVector const &vec) const override
Dot product with the vector vec.
virtual bool created() const override
Query vector creation status.
virtual real64 norm2() const override
2-norm of the vector.
virtual globalIndex ilower() const override
Get lower bound of local partition.
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
This class serves to provide a sliced multidimensional interface to the family of LvArray classes...
Definition: ArraySlice.hpp:89
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.
struct _p_Vec * Vec
Alias for PETSc vector struct pointer.
Definition: PetscVector.hpp:49
virtual void close() override
Assemble vector.
This class serves to provide a "view" of a multidimensional array.
Definition: ArrayView.hpp:67
PetscVector()
Empty vector constructor.
double real64
64-bit floating point type.
Definition: DataTypes.hpp:136
virtual void rand(unsigned const seed=1984) override
Set vector elements to random entries.
virtual void open() override
Open the vector for modifying entries.
This class creates and provides basic support for Vec vector object type used in PETSc.
Definition: PetscVector.hpp:44
virtual void reset() override
Reset the matrix to default state.
virtual void add(globalIndex const globalRow, real64 const value) override
Add into vector value.
~PetscVector()
Destructor.
virtual real64 norm1() const override
1-norm of the vector.
virtual void write(string const &filename, LAIOutputFormat const format=LAIOutputFormat::MATRIX_MARKET) const override
Write the vector to a file.
LAIOutputFormat
Definition: common.hpp:139
virtual void pointwiseProduct(PetscVector const &x, PetscVector &y) const override
Compute the componentwise multiplication y = v * x.
virtual globalIndex globalSize() const override
Returns the global of the vector.
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.
std::ptrdiff_t localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
virtual globalIndex getGlobalRowID(localIndex const localRow) const override
Map a local row index to global row index.
virtual localIndex getLocalRowID(globalIndex const globalRow) const override
Map a global row index to local row index.
virtual localIndex localSize() const override
Returns the local size of the vector.
PetscVector & operator=(PetscVector const &src)
Copy assignment.
virtual void scale(real64 const scalingFactor) override
Multiply all elements by scalingFactor.
virtual real64 normInf() const override
Infinity-norm of the vector.
virtual void create(arrayView1d< real64 const > const &localValues, MPI_Comm const &comm) override
Construct parallel vector from a local array.
virtual void axpy(real64 const alpha, PetscVector const &x) override
Update vector y as y = alpha*x + y.
virtual MPI_Comm getComm() const override
Get the communicator used by this vector.
virtual void createWithLocalSize(localIndex const localSize, MPI_Comm const &comm) override
Create a vector based on local number of elements.
virtual real64 const * extractLocalVector() const override
Extract a view of the local portion of the array.
const Vec & unwrapped() const
Returns a const pointer to the underlying Vec.
virtual void print(std::ostream &os=std::cout) const override
Print the vector in Trilinos format to the terminal.
virtual void reciprocal() override
Replace vector elements by their reciprocals.
bool ready() const
Query vector ready status.
Definition: VectorBase.hpp:116
virtual void axpby(real64 const alpha, PetscVector const &x, real64 const beta) override
Update vector y as y = alpha*x + beta*y.