Note: this is documentation for an old release. View the latest documentation at docs.fenicsproject.org/v0.1.0/v0.9.0/cpp
DOLFINx  0.1.0
DOLFINx 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  constexpr 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
dolfinx::la::Vector::array
const std::vector< T > & array() const
Get local part of the vector (const version)
Definition: Vector.h:53
dolfinx::la
Linear algebra interface.
Definition: sparsitybuild.h:14
dolfinx::la::Vector::Vector
Vector(const std::shared_ptr< const common::IndexMap > &map, int bs)
Create vector.
Definition: Vector.h:22
dolfinx::la::Vector
Distributed vector.
Definition: Vector.h:18
dolfinx::la::Vector::mutable_array
std::vector< T > & mutable_array()
Get local part of the vector.
Definition: Vector.h:56
dolfinx::la::Vector::bs
constexpr int bs() const
Get block size.
Definition: Vector.h:50
dolfinx::la::Vector::~Vector
~Vector()=default
Destructor.
dolfinx::la::Vector::map
std::shared_ptr< const common::IndexMap > map() const
Get IndexMap.
Definition: Vector.h:47