DOLFIN
DOLFIN C++ interface
TensorLayout.h
1 // Copyright (C) 2012 Garth N. Wells
2 //
3 // This file is part of DOLFIN.
4 //
5 // DOLFIN is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // DOLFIN is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // First added: 2012-02-24
19 // Last changed:
20 
21 #ifndef __TENSOR_LAYOUT_H
22 #define __TENSOR_LAYOUT_H
23 
24 #include <memory>
25 #include <string>
26 #include <utility>
27 #include <vector>
28 
29 #include "dolfin/common/types.h"
30 #include "dolfin/common/MPI.h"
31 
32 namespace dolfin
33 {
34  class IndexMap;
35  class SparsityPattern;
36 
40 
41  class TensorLayout : public Variable
42  {
43 
44  public:
45 
47  enum class Sparsity : bool { SPARSE = true, DENSE = false };
48 
50  enum class Ghosts : bool { GHOSTED = true, UNGHOSTED = false };
51 
53  TensorLayout(MPI_Comm comm, std::size_t primary_dim,
55 
57  TensorLayout(MPI_Comm mpi_comm,
58  std::vector<std::shared_ptr<const IndexMap>> index_maps,
59  std::size_t primary_dim,
60  Sparsity sparsity_pattern,
61  Ghosts ghosted);
62 
64  void init(std::vector<std::shared_ptr<const IndexMap>> index_maps,
65  Ghosts ghosted);
66 
68  std::size_t rank() const;
69 
72  std::size_t size(std::size_t i) const;
73 
75  std::pair<std::size_t, std::size_t> local_range(std::size_t dim) const;
76 
78  std::shared_ptr<SparsityPattern> sparsity_pattern()
79  { return _sparsity_pattern; }
80 
82  std::shared_ptr<const SparsityPattern> sparsity_pattern() const
83  { return _sparsity_pattern; }
84 
86  std::string str(bool verbose) const;
87 
89  const std::size_t primary_dim;
90 
92  MPI_Comm mpi_comm() const
93  { return _mpi_comm.comm(); }
94 
96  std::shared_ptr<const IndexMap> index_map(std::size_t i) const
97  {
98  dolfin_assert(i < _index_maps.size());
99  return _index_maps[i];
100  }
101 
104  {
105  return _ghosted;
106  }
107 
108  private:
109 
110  // MPI communicator
111  dolfin::MPI::Comm _mpi_comm;
112 
113  // Index maps
114  std::vector<std::shared_ptr<const IndexMap>> _index_maps;
115 
116  // Sparsity pattern
117  std::shared_ptr<SparsityPattern> _sparsity_pattern;
118 
119  // Ghosted tensor (typically vector) required
120  Ghosts _ghosted = Ghosts::UNGHOSTED;
121 
122  };
123 
124 }
125 #endif
Sparsity
Sparse or dense layout.
Definition: TensorLayout.h:47
std::string str(bool verbose) const
Return informal string representation (pretty-print)
Definition: TensorLayout.cpp:83
Common base class for DOLFIN variables.
Definition: Variable.h:35
std::size_t size(std::size_t i) const
Definition: TensorLayout.cpp:69
std::size_t rank() const
Return rank.
Definition: TensorLayout.cpp:64
Definition: adapt.h:29
const std::size_t primary_dim
Primary storage dim (e.g., 0=row major, 1=column major)
Definition: TensorLayout.h:89
Ghosts
Ghosted or unghosted layout.
Definition: TensorLayout.h:50
Ghosts is_ghosted() const
Require ghosts.
Definition: TensorLayout.h:103
Definition: TensorLayout.h:41
MPI_Comm mpi_comm() const
Return MPI communicator.
Definition: TensorLayout.h:92
std::pair< std::size_t, std::size_t > local_range(std::size_t dim) const
Return local range for dimension dim.
Definition: TensorLayout.cpp:76
std::shared_ptr< const IndexMap > index_map(std::size_t i) const
Return IndexMap for dimension.
Definition: TensorLayout.h:96
std::shared_ptr< SparsityPattern > sparsity_pattern()
Return sparsity pattern (possibly null)
Definition: TensorLayout.h:78
TensorLayout(MPI_Comm comm, std::size_t primary_dim, Sparsity sparsity_pattern)
Create empty tensor layout.
Definition: TensorLayout.cpp:29
void init(std::vector< std::shared_ptr< const IndexMap >> index_maps, Ghosts ghosted)
Initialize tensor layout.
Definition: TensorLayout.cpp:53
std::shared_ptr< const SparsityPattern > sparsity_pattern() const
Return sparsity pattern (possibly null), const version.
Definition: TensorLayout.h:82
Definition: MPI.h:76