DOLFIN
DOLFIN C++ interface
CoordinateMatrix.h
1 // Copyright (C) 2011 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: 2011-10-16
19 // Last changed:
20 
21 #ifndef __DOLFIN_COORDINATE_MATRIX_H
22 #define __DOLFIN_COORDINATE_MATRIX_H
23 
24 #include <string>
25 #include <vector>
26 #include <dolfin/common/types.h>
27 #include <dolfin/common/MPI.h>
28 
29 namespace dolfin
30 {
31 
32  // Forward declarations
33  class GenericMatrix;
34 
36 
38  {
39  public:
40 
42  CoordinateMatrix(const GenericMatrix& A, bool symmetric, bool base_one);
43 
45  virtual ~CoordinateMatrix() {}
46 
50  std::size_t size(std::size_t dim) const
51  { return _size[dim]; }
52 
54  const std::vector<std::size_t>& rows() const
55  { return _rows; }
56 
58  const std::vector<std::size_t>& columns() const
59  { return _cols; }
60 
62  const std::vector<double>& values() const
63  { return _vals; }
64 
66  double norm(std::string norm_type) const;
67 
69  MPI_Comm mpi_comm() const
70  { return _mpi_comm.comm(); }
71 
73  bool base_one() const
74  { return _base_one; }
75 
76  private:
77 
78  // MPI communicator
79  dolfin::MPI::Comm _mpi_comm;
80 
81  // Row and column indices
82  std::vector<std::size_t> _rows;
83  std::vector<std::size_t> _cols;
84 
85  // Storage of values
86  std::vector<double> _vals;
87 
88  // Global size
89  std::size_t _size[2];
90 
91  // Symmetric storage
92  const bool _symmetric;
93 
94  // Array base (C/Fortran)
95  const bool _base_one;
96  };
97 
98 }
99 
100 #endif
virtual ~CoordinateMatrix()
Destructor.
Definition: CoordinateMatrix.h:45
Definition: adapt.h:29
CoordinateMatrix(const GenericMatrix &A, bool symmetric, bool base_one)
Constructor.
Definition: CoordinateMatrix.cpp:30
MPI_Comm comm() const
Return the underlying MPI_Comm object.
Definition: MPI.cpp:117
std::size_t size(std::size_t dim) const
Definition: CoordinateMatrix.h:50
This class defines a common interface for matrices.
Definition: GenericMatrix.h:46
const std::vector< std::size_t > & rows() const
Get row indices.
Definition: CoordinateMatrix.h:54
double norm(std::string norm_type) const
Return norm of matrix.
Definition: CoordinateMatrix.cpp:89
bool base_one() const
Whether indices start from 0 (C-style) or 1 (FORTRAN-style)
Definition: CoordinateMatrix.h:73
Coordinate sparse matrix.
Definition: CoordinateMatrix.h:37
const std::vector< std::size_t > & columns() const
Get column indices.
Definition: CoordinateMatrix.h:58
MPI_Comm mpi_comm() const
Get MPI_Comm.
Definition: CoordinateMatrix.h:69
Definition: MPI.h:76
const std::vector< double > & values() const
Get values.
Definition: CoordinateMatrix.h:62