DOLFIN-X
DOLFIN-X C++ interface
Vector.h
1 // Copyright (C) 2020 Garth N. Wells
2 //
3 // This file is part of DOLFINX (https://www.fenicsproject.org)
4 //
5 // SPDX-License-Identifier: LGPL-3.0-or-later
6 
7 #pragma once
8 
9 #include <Eigen/Dense>
10 #include <dolfinx/common/IndexMap.h>
11 #include <memory>
12 
13 namespace dolfinx::la
14 {
15 
17 
18 template <typename T>
19 class Vector
20 {
21 public:
23  Vector(const std::shared_ptr<const common::IndexMap>& map) : _map(map)
24  {
25  assert(map);
26  const std::int32_t local_size
27  = map->block_size() * (map->size_local() + map->num_ghosts());
28  _x.resize(local_size);
29  }
30 
32  Vector(const Vector& x) = default;
33 
35  Vector(Vector&& x) noexcept = default;
36 
38  ~Vector() = default;
39 
40  // Assignment operator (disabled)
41  Vector& operator=(const Vector& x) = delete;
42 
44  Vector& operator=(Vector&& x) = default;
45 
47  std::shared_ptr<const common::IndexMap> map() const { return _map; }
48 
50  const Eigen::Matrix<T, Eigen::Dynamic, 1>& array() const { return _x; }
51 
53  Eigen::Matrix<T, Eigen::Dynamic, 1>& array() { return _x; }
54 
55 private:
56  // Map describing the data layout
57  std::shared_ptr<const common::IndexMap> _map;
58 
59  // Data
60  Eigen::Matrix<T, Eigen::Dynamic, 1> _x;
61 };
62 } // namespace dolfinx::la
Distributed vector.
Definition: Vector.h:20
Vector(Vector &&x) noexcept=default
Move constructor.
Vector(const std::shared_ptr< const common::IndexMap > &map)
Create vector.
Definition: Vector.h:23
std::shared_ptr< const common::IndexMap > map() const
Get local part of the vector (const version)
Definition: Vector.h:47
Vector(const Vector &x)=default
Copy constructor.
~Vector()=default
Destructor.
const Eigen::Matrix< T, Eigen::Dynamic, 1 > & array() const
Get local part of the vector (const version)
Definition: Vector.h:50
Vector & operator=(Vector &&x)=default
Move Assignment operator.
Eigen::Matrix< T, Eigen::Dynamic, 1 > & array()
Get local part of the vector.
Definition: Vector.h:53
Linear algebra interface.
Definition: DiscreteOperators.h:20