Loading...
Searching...
No Matches
TensorLayout.h
// Copyright (C) 2012 Garth N. Wells
//
// This file is part of DOLFIN.
//
// DOLFIN is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// DOLFIN is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
//
// First added: 2012-02-24
// Last changed:
#ifndef __TENSOR_LAYOUT_H
#define __TENSOR_LAYOUT_H
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "dolfin/common/types.h"
#include "dolfin/common/MPI.h"
namespace dolfin
{
class IndexMap;
class SparsityPattern;
class TensorLayout : public Variable
{
public:
enum class Sparsity : bool { SPARSE = true, DENSE = false };
enum class Ghosts : bool { GHOSTED = true, UNGHOSTED = false };
TensorLayout(MPI_Comm comm, std::size_t primary_dim,
Sparsity sparsity_pattern);
TensorLayout(MPI_Comm mpi_comm,
std::vector<std::shared_ptr<const IndexMap>> index_maps,
std::size_t primary_dim,
Sparsity sparsity_pattern,
Ghosts ghosted);
void init(std::vector<std::shared_ptr<const IndexMap>> index_maps,
Ghosts ghosted);
std::size_t rank() const;
std::size_t size(std::size_t i) const;
std::pair<std::size_t, std::size_t> local_range(std::size_t dim) const;
std::shared_ptr<SparsityPattern> sparsity_pattern()
{ return _sparsity_pattern; }
std::shared_ptr<const SparsityPattern> sparsity_pattern() const
{ return _sparsity_pattern; }
std::string str(bool verbose) const;
const std::size_t primary_dim;
MPI_Comm mpi_comm() const
{ return _mpi_comm.comm(); }
std::shared_ptr<const IndexMap> index_map(std::size_t i) const
{
dolfin_assert(i < _index_maps.size());
return _index_maps[i];
}
Ghosts is_ghosted() const
{
return _ghosted;
}
private:
// MPI communicator
dolfin::MPI::Comm _mpi_comm;
// Index maps
std::vector<std::shared_ptr<const IndexMap>> _index_maps;
// Sparsity pattern
std::shared_ptr<SparsityPattern> _sparsity_pattern;
// Ghosted tensor (typically vector) required
Ghosts _ghosted = Ghosts::UNGHOSTED;
};
}
#endif
dolfin::IndexMap
Definition IndexMap.h:36
dolfin::MPI::Comm
Definition MPI.h:77
dolfin::SparsityPattern
Definition SparsityPattern.h:46
dolfin::TensorLayout::init
void init(std::vector< std::shared_ptr< const IndexMap > > index_maps, Ghosts ghosted)
Initialize tensor layout.
Definition TensorLayout.cpp:53
dolfin::TensorLayout::sparsity_pattern
std::shared_ptr< const SparsityPattern > sparsity_pattern() const
Return sparsity pattern (possibly null), const version.
Definition TensorLayout.h:82
dolfin::TensorLayout::index_map
std::shared_ptr< const IndexMap > index_map(std::size_t i) const
Return IndexMap for dimension.
Definition TensorLayout.h:96
dolfin::TensorLayout::TensorLayout
TensorLayout(MPI_Comm comm, std::size_t primary_dim, Sparsity sparsity_pattern)
Create empty tensor layout.
Definition TensorLayout.cpp:29
dolfin::TensorLayout::rank
std::size_t rank() const
Return rank.
Definition TensorLayout.cpp:64
dolfin::TensorLayout::size
std::size_t size(std::size_t i) const
Definition TensorLayout.cpp:69
dolfin::TensorLayout::str
std::string str(bool verbose) const
Return informal string representation (pretty-print).
Definition TensorLayout.cpp:83
dolfin::TensorLayout::primary_dim
const std::size_t primary_dim
Primary storage dim (e.g., 0=row major, 1=column major).
Definition TensorLayout.h:89
dolfin::TensorLayout::Ghosts
Ghosts
Ghosted or unghosted layout.
Definition TensorLayout.h:50
dolfin::TensorLayout::local_range
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
dolfin::TensorLayout::Sparsity
Sparsity
Sparse or dense layout.
Definition TensorLayout.h:47
dolfin::TensorLayout::is_ghosted
Ghosts is_ghosted() const
Require ghosts.
Definition TensorLayout.h:103
dolfin::TensorLayout::sparsity_pattern
std::shared_ptr< SparsityPattern > sparsity_pattern()
Return sparsity pattern (possibly null).
Definition TensorLayout.h:78
dolfin::TensorLayout::mpi_comm
MPI_Comm mpi_comm() const
Return MPI communicator.
Definition TensorLayout.h:92
dolfin::Variable::Variable
Variable()
Create unnamed variable.
Definition Variable.cpp:31
dolfin
Definition adapt.h:30