DOLFIN-X
DOLFIN-X C++ interface
PETScVector.h
1 // Copyright (C) 2004-2018 Johan Hoffman, Johan Jansson, Anders Logg and Garth
2 // N. Wells
3 //
4 // This file is part of DOLFINX (https://www.fenicsproject.org)
5 //
6 // SPDX-License-Identifier: LGPL-3.0-or-later
7 
8 #pragma once
9 
10 #include "utils.h"
11 #include <Eigen/Dense>
12 #include <array>
13 #include <cstdint>
14 #include <petscvec.h>
15 
16 namespace dolfinx
17 {
18 namespace la
19 {
20 class IndexMap;
21 }
22 namespace la
23 {
24 
30 
32 {
33 public:
35  PETScVector(const common::IndexMap& map);
36 
39  MPI_Comm comm, std::array<std::int64_t, 2> range,
40  const Eigen::Array<std::int64_t, Eigen::Dynamic, 1>& ghost_indices,
41  int block_size);
42 
43  // Delete copy constructor to avoid accidental copying of 'heavy' data
44  PETScVector(const PETScVector& x) = delete;
45 
47  PETScVector(PETScVector&& x) noexcept;
48 
54  explicit PETScVector(Vec x, bool inc_ref_count);
55 
57  virtual ~PETScVector();
58 
59  // Assignment operator (disabled)
60  PETScVector& operator=(const PETScVector& x) = delete;
61 
63  PETScVector& operator=(PETScVector&& x);
64 
66  PETScVector copy() const;
67 
69  std::int64_t size() const;
70 
72  std::int32_t local_size() const;
73 
75  std::array<std::int64_t, 2> local_range() const;
76 
81  void apply_ghosts();
82 
85  void update_ghosts();
86 
88  MPI_Comm mpi_comm() const;
89 
91  PetscReal norm(la::Norm norm_type) const;
92 
94  void set_options_prefix(std::string options_prefix);
95 
98  std::string get_options_prefix() const;
99 
101  void set_from_options();
102 
104  Vec vec() const;
105 
106 private:
107  // PETSc Vec pointer
108  Vec _x;
109 };
110 } // namespace la
111 } // namespace dolfinx
dolfinx::la::Norm
Norm
Norm types.
Definition: utils.h:34
dolfinx::la::PETScVector::get_options_prefix
std::string get_options_prefix() const
Returns the prefix used by PETSc when searching the options database.
Definition: PETScVector.cpp:185
dolfinx::common::IndexMap
This class represents the distribution index arrays across processes. An index array is a contiguous ...
Definition: IndexMap.h:27
dolfinx::la::PETScVector::set_options_prefix
void set_options_prefix(std::string options_prefix)
Sets the prefix used by PETSc when searching the options database.
Definition: PETScVector.cpp:178
dolfinx::la::PETScVector::size
std::int64_t size() const
Return global size of vector.
Definition: PETScVector.cpp:75
dolfinx::la::PETScVector::PETScVector
PETScVector(const common::IndexMap &map)
Create vector.
Definition: PETScVector.cpp:26
dolfinx::la::PETScVector::set_from_options
void set_from_options()
Call PETSc function VecSetFromOptions on the underlying Vec object.
Definition: PETScVector.cpp:194
dolfinx::la::PETScVector::copy
PETScVector copy() const
Copy vector.
Definition: PETScVector.cpp:65
dolfinx::la::PETScVector
It is a simple wrapper for a PETSc vector pointer (Vec). Its main purpose is to assist memory managem...
Definition: PETScVector.h:31
dolfinx::la::PETScVector::local_size
std::int32_t local_size() const
Return local size of vector (belonging to this process)
Definition: PETScVector.cpp:84
dolfinx::la::PETScVector::norm
PetscReal norm(la::Norm norm_type) const
Return norm of vector.
Definition: PETScVector.cpp:152
dolfinx::la::PETScVector::mpi_comm
MPI_Comm mpi_comm() const
Return MPI communicator.
Definition: PETScVector.cpp:143
dolfinx::la::PETScVector::update_ghosts
void update_ghosts()
Update ghost values (gathers ghost values from the owning processes)
Definition: PETScVector.cpp:123
dolfinx::la::PETScVector::local_range
std::array< std::int64_t, 2 > local_range() const
Return ownership range for process.
Definition: PETScVector.cpp:93
dolfinx::la::PETScVector::~PETScVector
virtual ~PETScVector()
Destructor.
Definition: PETScVector.cpp:50
dolfinx::la::PETScVector::apply_ghosts
void apply_ghosts()
Update owned entries owned by this process and which are ghosts on other processes,...
Definition: PETScVector.cpp:103
dolfinx::la::PETScVector::vec
Vec vec() const
Return pointer to PETSc Vec object.
Definition: PETScVector.cpp:201