libMesh
metis_csr_graph.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_METIS_CSR_GRAPH_H
21 #define LIBMESH_METIS_CSR_GRAPH_H
22 
23 // Local Includes
24 #include "libmesh/libmesh_common.h"
25 
26 // C++ Includes
27 #include <vector>
28 #include <numeric>
29 
30 namespace libMesh
31 {
32 
42 template <class IndexType>
44 {
45 public:
46  std::vector<IndexType> offsets, vals;
47 
53  const libMesh::dof_id_type n_nonzeros_in)
54  {
55  libmesh_assert_less (row+1, offsets.size());
56  offsets[row+1] = n_nonzeros_in;
57  }
58 
64  {
65  libmesh_assert_less (row+1, offsets.size());
66  return (offsets[row+1] - offsets[row]);
67  }
68 
74  {
75  std::partial_sum (offsets.begin(), offsets.end(), offsets.begin());
76  libmesh_assert (!offsets.empty());
77  vals.resize(offsets.back());
78 
79  if (vals.empty())
80  vals.push_back(0);
81  }
82 
86  IndexType & operator()(const libMesh::dof_id_type row,
87  const libMesh::dof_id_type nonzero)
88  {
89  libmesh_assert_greater (vals.size(), offsets[row]+nonzero);
90 
91  return vals[offsets[row]+nonzero];
92  }
93 
97  const IndexType & operator()(const libMesh::dof_id_type row,
98  const libMesh::dof_id_type nonzero) const
99  {
100  libmesh_assert_greater (vals.size(), offsets[row]+nonzero);
101 
102  return vals[offsets[row]+nonzero];
103  }
104 };
105 
106 } // namespace libMesh
107 
108 #endif // LIBMESH_METIS_CSR_GRAPH_H
IndexType & operator()(const libMesh::dof_id_type row, const libMesh::dof_id_type nonzero)
This utility class provides a convenient implementation for building the compressed-row-storage graph...
The libMesh namespace provides an interface to certain functionality in the library.
libMesh::dof_id_type n_nonzeros(const libMesh::dof_id_type row) const
libmesh_assert(j)
std::vector< IndexType > offsets
std::vector< IndexType > vals
void prepare_for_use()
Replaces the entries in the offsets vector with their partial sums and resizes the val vector accordi...
void prep_n_nonzeros(const libMesh::dof_id_type row, const libMesh::dof_id_type n_nonzeros_in)
Sets the number of non-zero values in the given row.
uint8_t dof_id_type
Definition: id_types.h:64
const IndexType & operator()(const libMesh::dof_id_type row, const libMesh::dof_id_type nonzero) const