ug4
Loading...
Searching...
No Matches
bidirectional.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022: G-CSC, Goethe University Frankfurt
3 * Author: Felix Salfelder, 2022
4 *
5 * This file is part of UG4.
6 *
7 * UG4 is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License version 3 (as published by the
9 * Free Software Foundation) with the following additional attribution
10 * requirements (according to LGPL/GPL v3 §7):
11 *
12 * (1) The following notice must be displayed in the Appropriate Legal Notices
13 * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 *
15 * (2) The following notice must be displayed at a prominent place in the
16 * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 *
18 * (3) The following bibliography is recommended for citation and must be
19 * preserved in all covered files:
20 * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 * parallel geometric multigrid solver on hierarchically distributed grids.
22 * Computing and visualization in science 16, 4 (2013), 151-164"
23 * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 * flexible software system for simulating pde based models on high performance
25 * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU Lesser General Public License for more details.
31 */
32
33#ifndef UG_GRAPH_INTERFACE_BIDIR_H
34#define UG_GRAPH_INTERFACE_BIDIR_H
35
36#include "sparsematrix_boost.h"
37
38#ifndef NDEBUG
39#include "common/stopwatch.h"
40#endif
41
42namespace ug{
43
44// give access to edges both ways.
45// keep a transpose matrix to cache iterators.
46template<class T>
48public: // types
49 typedef typename T::const_row_iterator const_row_iterator;
50public:
51 explicit BidirectionalMatrix(T const* m=nullptr)
52 : _matrix(m) {
53 if(m){
54 refresh();
55 }else{
56 }
57 }
59 : _matrix(o._matrix) {
60 _matrix_transpose = o._matrix_transpose; // BUG: missing copy constructor.
61 }
67
68public: // interface
69 void refresh(){
70#ifndef NDEBUG
71 double t = -get_clock_s();
72#endif
73 assert(_matrix);
74 _matrix_transpose.set_as_transpose_of2(*_matrix);
75 assert(_matrix->num_rows() == _matrix_transpose.num_cols());
76 assert(_matrix->num_cols() == _matrix_transpose.num_rows());
77#ifndef NDEBUG
78 t += get_clock_s();
79 UG_LOG("Transpose in bidirectional refresh " << t << "\n");
80#endif
81 }
82
83 int num_rows() const {
84 return std::max(_matrix->num_rows(), _matrix->num_cols());
85 }
86 int num_cols() const { untested();
87 return num_rows();
88 }
89 int num_connections(int v) const {
90 if(v<_matrix->num_rows()){
91 return _matrix->num_connections(v);
92 }else{
93 assert(v<_matrix_transpose.num_rows());
94 return _matrix_transpose.num_connections(v);
95 }
96 }
97 int out_degree(int v) const {
98 assert(_matrix);
99 if(size_t(v)<_matrix->num_rows()){
100 assert(size_t(v)<_matrix->num_rows());
101 return boost::out_degree(v, *_matrix);
102 }else{
103 return 0;
104 }
105 }
106 int in_degree(int v) const {
107 // could use difference, requires zero-pruning in _matrix_transpose.
108 if(size_t(v)<_matrix_transpose.num_rows()){
110 }else{
111 return 0;
112 }
113 }
114 int degree(int v) const { untested();
115 return 2*out_degree(v);
116 }
117
119 assert(_matrix);
120 if(size_t(row)<_matrix->num_rows()){
121 }else{
122 row = 0;
123 }
124 return _matrix->begin_row(row);
125 }
127 assert(_matrix);
128 if(size_t(row)<_matrix->num_rows()){
129 return _matrix->end_row(row);
130 }else{
131 return _matrix->begin_row(0);
132 }
133 }
134
136 if(size_t(col)<_matrix_transpose.num_rows()){
137 }else{
138 col = 0;
139 }
140 return _matrix_transpose.begin_row(col);
141 }
143 if(size_t(col)<_matrix_transpose.num_rows()){
144 return _matrix_transpose.end_row(col);
145 }else{
146 return _matrix_transpose.begin_row(0);
147 }
148 }
149
150private:
151 T const* _matrix;
153};
154
155} // ug
156
157#endif // guard
Definition bidirectional.h:47
BidirectionalMatrix & operator=(BidirectionalMatrix const &o)
Definition bidirectional.h:62
int in_degree(int v) const
Definition bidirectional.h:106
int num_cols() const
Definition bidirectional.h:86
const_row_iterator end_row(int row) const
Definition bidirectional.h:126
const_row_iterator begin_col(int col) const
Definition bidirectional.h:135
void refresh()
Definition bidirectional.h:69
T const * _matrix
Definition bidirectional.h:151
T _matrix_transpose
Definition bidirectional.h:152
int num_connections(int v) const
Definition bidirectional.h:89
const_row_iterator begin_row(int row) const
Definition bidirectional.h:118
int out_degree(int v) const
Definition bidirectional.h:97
BidirectionalMatrix(BidirectionalMatrix const &o)
Definition bidirectional.h:58
T::const_row_iterator const_row_iterator
Definition bidirectional.h:49
BidirectionalMatrix(T const *m=nullptr)
Definition bidirectional.h:51
const_row_iterator end_col(int col) const
Definition bidirectional.h:142
int num_rows() const
Definition bidirectional.h:83
int degree(int v) const
Definition bidirectional.h:114
#define UG_LOG(msg)
Definition log.h:367
#define untested()
Definition lua_table_handle.cpp:15
int out_degree(int v, ug::BidirectionalMatrix< T > const &M)
Definition bidirectional_boost.h:76
the ug namespace
double get_clock_s()
Definition stopwatch.h:103
stopwatch class for quickly taking times