DOLFIN
DOLFIN C++ interface
Loading...
Searching...
No Matches
GenericTensor.h
1// Copyright (C) 2007-2012 Anders Logg
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// Modified by Garth N. Wells 2007-2011
19// Modified by Ola Skavhaug 2007
20// Modified by Martin Alnæs 2008
21//
22// First added: 2007-01-17
23// Last changed: 2012-08-22
24
25#ifndef __GENERIC_TENSOR_H
26#define __GENERIC_TENSOR_H
27
28#include <cstdint>
29#include <exception>
30#include <memory>
31#include <typeinfo>
32#include <utility>
33
34#include <dolfin/common/ArrayView.h>
35#include <dolfin/common/MPI.h>
36#include <dolfin/common/types.h>
37#include <dolfin/log/log.h>
38#include "LinearAlgebraObject.h"
39
40namespace dolfin
41{
42
43 class TensorLayout;
44 class GenericLinearAlgebraFactory;
45
47
48 class GenericTensor : public virtual LinearAlgebraObject
49 {
50 public:
51
53 virtual ~GenericTensor() {}
54
55 //--- Basic GenericTensor interface ---
56
58 virtual void init(const TensorLayout& tensor_layout) = 0;
59
61 virtual bool empty() const = 0;
62
64 virtual std::size_t rank() const = 0;
65
67 virtual std::size_t size(std::size_t dim) const = 0;
68
70 virtual std::pair<std::int64_t, std::int64_t>
71 local_range(std::size_t dim) const = 0;
72
74 virtual void get(double* block, const dolfin::la_index* num_rows,
75 const dolfin::la_index * const * rows) const = 0;
76
78 virtual void set(const double* block, const dolfin::la_index* num_rows,
79 const dolfin::la_index * const * rows) = 0;
80
82 virtual void set_local(const double* block,
83 const dolfin::la_index* num_rows,
84 const dolfin::la_index * const * rows) = 0;
85
87 virtual
88 void add(const double* block,
89 const std::vector<ArrayView<const dolfin::la_index>>& rows) = 0;
90
92 virtual void add_local(
93 const double* block,
94 const std::vector<ArrayView<const dolfin::la_index>>& rows) = 0;
95
96
98 virtual void add(const double* block, const dolfin::la_index* num_rows,
99 const dolfin::la_index * const * rows) = 0;
100
102 virtual void add_local(const double* block,
103 const dolfin::la_index* num_rows,
104 const dolfin::la_index * const * rows) = 0;
105
107 virtual void zero() = 0;
108
110 virtual void apply(std::string mode) = 0;
111
113 //virtual MPI_Comm mpi_comm() const = 0;
114
116 virtual std::string str(bool verbose) const = 0;
117
120
121 };
122
123}
124
125#endif
Definition SystemAssembler.h:44
Base class for LinearAlgebra factories.
Definition GenericLinearAlgebraFactory.h:47
A common interface for arbitrary rank tensors.
Definition GenericTensor.h:49
virtual void add_local(const double *block, const dolfin::la_index *num_rows, const dolfin::la_index *const *rows)=0
Add block of values using local indices.
virtual void add(const double *block, const std::vector< ArrayView< const dolfin::la_index > > &rows)=0
Add block of values using global indices.
virtual void add(const double *block, const dolfin::la_index *num_rows, const dolfin::la_index *const *rows)=0
Add block of values using global indices.
virtual std::size_t rank() const =0
Return tensor rank (number of dimensions)
virtual void zero()=0
Set all entries to zero and keep any sparse structure.
virtual GenericLinearAlgebraFactory & factory() const =0
Return linear algebra backend factory.
virtual std::pair< std::int64_t, std::int64_t > local_range(std::size_t dim) const =0
Return local ownership range.
virtual void init(const TensorLayout &tensor_layout)=0
Initialize zero tensor using tensor layout.
virtual bool empty() const =0
Return true if empty.
virtual void apply(std::string mode)=0
Finalize assembly of tensor.
virtual std::string str(bool verbose) const =0
Return MPI communicator.
virtual void set(const double *block, const dolfin::la_index *num_rows, const dolfin::la_index *const *rows)=0
Set block of values using global indices.
virtual ~GenericTensor()
Destructor.
Definition GenericTensor.h:53
virtual void add_local(const double *block, const std::vector< ArrayView< const dolfin::la_index > > &rows)=0
Add block of values using local indices.
virtual void set_local(const double *block, const dolfin::la_index *num_rows, const dolfin::la_index *const *rows)=0
Set block of values using local indices.
virtual void get(double *block, const dolfin::la_index *num_rows, const dolfin::la_index *const *rows) const =0
Get block of values.
virtual std::size_t size(std::size_t dim) const =0
Return size of given dimension.
Definition LinearAlgebraObject.h:37
Definition TensorLayout.h:42
Definition adapt.h:30
PetscInt la_index
Index type for compatibility with linear algebra backend(s)
Definition types.h:32