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 <dolfinx/common/IndexMap.h>
10 #include <memory>
11 
12 namespace dolfinx::la
13 {
14 
16 
17 template <typename T>
18 class Vector
19 {
20 public:
22  Vector(const std::shared_ptr<const common::IndexMap>& map, int bs)
23  : _map(map), _bs(bs)
24  {
25  assert(map);
26  const std::int32_t local_size
27  = bs * (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  int bs() const { return _bs; }
51 
53  const std::vector<T>& array() const { return _x; }
54 
56  std::vector<T>& mutable_array() { return _x; }
57 
58 private:
59  // Map describing the data layout
60  std::shared_ptr<const common::IndexMap> _map;
61 
62  // Block size
63  int _bs;
64 
65  // Data
66  std::vector<T> _x;
67 };
68 } // namespace dolfinx::la
Distributed vector.
Definition: Vector.h:19
Vector(Vector &&x) noexcept=default
Move constructor.
Vector(const std::shared_ptr< const common::IndexMap > &map, int bs)
Create vector.
Definition: Vector.h:22
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.
std::vector< T > & mutable_array()
Get local part of the vector.
Definition: Vector.h:56
~Vector()=default
Destructor.
int bs() const
Get block size.
Definition: Vector.h:50
Vector & operator=(Vector &&x)=default
Move Assignment operator.
const std::vector< T > & array() const
Get local part of the vector (const version)
Definition: Vector.h:53
Linear algebra interface.
Definition: sparsitybuild.h:15