Debian Codegraph @

3rdparty/dissection/src/Splitters/BisectionInterConnection.hpp

raw
1 /*! \file BisectionInterConnetction.hpp
2 \brief Inter connection between off-diag strips
3 \author Xavier Juvigny, ONERA
4 \date Jul. 2nd 2012
5 \date Jul. 12th 2015
6 \date Nov. 30th 2016
7 */
8
9 // This file is part of Dissection
10 //
11 // Dissection is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 3 of the License, or
14 // (at your option) any later version.
15 //
16 // Linking Dissection statically or dynamically with other modules is making
17 // a combined work based on Disssection. Thus, the terms and conditions of
18 // the GNU General Public License cover the whole combination.
19 //
20 // As a special exception, the copyright holders of Dissection give you
21 // permission to combine Dissection program with free software programs or
22 // libraries that are released under the GNU LGPL and with independent modules
23 // that communicate with Dissection solely through the Dissection-fortran
24 // interface. You may copy and distribute such a system following the terms of
25 // the GNU GPL for Dissection and the licenses of the other code concerned,
26 // provided that you include the source code of that other code when and as
27 // the GNU GPL requires distribution of source code and provided that you do
28 // not modify the Dissection-fortran interface.
29 //
30 // Note that people who make modified versions of Dissection are not obligated
31 // to grant this special exception for their modified versions; it is their
32 // choice whether to do so. The GNU General Public License gives permission to
33 // release a modified version without this exception; this exception also makes
34 // it possible to release a modified version which carries forward this
35 // exception. If you modify the Dissection-fortran interface, this exception
36 // does not apply to your modified version of Dissection, and you must remove
37 // this exception when you distribute your modified version.
38 //
39 // This exception is an additional permission under section 7 of the GNU
40 // General Public License, version 3 ("GPLv3")
41 //
42 // Dissection is distributed in the hope that it will be useful,
43 // but WITHOUT ANY WARRANTY; without even the implied warranty of
44 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 // GNU General Public License for more details.
46 //
47 // You should have received a copy of the GNU General Public License
48 // along with Dissection. If not, see <http://www.gnu.org/licenses/>.
49 //
50
51 // ==============================================================
52 // == Bisection interconnection : store the indices of the==
53 // == nodes of an interface connected with nodes of a child ==
54 // == interface (or domain). The indices are stored as local of==
55 // == the interface and global. ==
56 // ==============================================================
57 #ifndef _DISSECTION_SPLITTERS_BISECTIONINTERCONNECTION_HPP_
58 #define _DISSECTION_SPLITTERS_BISECTIONINTERCONNECTION_HPP_
59 # include <list>
60
61 namespace Dissection
62 {
63 struct Strip {
64 unsigned begin_src;// Starting indice in source block
65 unsigned begin_dst;// Starting indice in target block
66 unsigned width;
67
68 ///@name Constructors and destructor
69 ///@{
70 /** Default constructor. Initialize with unvalid indices
71 */
72 Strip() :
73 begin_dst(unsigned(-1)), width(unsigned(-1))
74 {}
75 /** Simple constructor initializing directly members of the instance
76 */
77 Strip(unsigned first, unsigned sz) :
78 begin_src(0), begin_dst(first), width(sz)
79 {}
80 /** Simple constructor which initialize members with starting
81 indices for source block
82 */
83 Strip(unsigned firstSnd, unsigned firstRcv, unsigned sz) :
84 begin_src(firstSnd), begin_dst(firstRcv), width(sz)
85 {}
86 /** Copy constructor (default behaviour) */
87 Strip(const Strip& strp) :
88 begin_src(strp.begin_src), begin_dst(strp.begin_dst),
89 width(strp.width)
90 {}
91 /** From a list of indices, compute the biggest valid strip from
92 the first indices of the list.
93
94 @return The indices include in the strip are removed from the list.
95 */
96 Strip(std::list<unsigned>& indices);
97 /** Return first indice contiguous to the last indice of the strip
98 */
99 unsigned nextIndice() const
100 {
101 return begin_dst + width;
102 }
103 /** Check if a strip S is contained inside another strip T.
104 If true, initialize decal with the difference between
105 the first indice of T and S.
106
107 If false, decal is undefined
108 */
109 bool inside(const Strip& T, unsigned& decal) const;
110 /** Check if a strip S contains another strip T.
111 If true, initialize decal with the difference between
112 the first indice of S and T.
113
114 If false, decal is undefined
115 */
116 bool contains(const Strip& T, unsigned& decal) const
117 {
118 return T.inside(*this,decal);
119 }
120 /** Check if an indice is contained by the strip */
121 bool contains(unsigned ind) const
122 {
123 return ((ind>=begin_dst)&&(ind<nextIndice()));
124 }
125 };
126 // --------------------------------------------------------------
127 class SetOfStrips
128 {
129 public:
130 typedef std::list<Strip>::iterator iterator;
131 typedef std::list<Strip>::const_iterator const_iterator;
132 ///@name Constructors and destructor
133 //@{
134 /** @brief Default constructor
135
136 Build a empty set of strips
137 */
138 SetOfStrips() : _lst_strips() {}
139 /** @brief Build a list of strips from a set of indices
140
141 At the exit of the constructor, indices will be an empty
142 list.
143 */
144 SetOfStrips(std::list<unsigned>& indices);
145 //@}
146
147 ///@name Getters/Setters
148 //@{
149 /// @brief Iterator on the first strip
150 iterator begin() { return _lst_strips.begin(); }
151 /// @brief Const iterator on the first strip
152 const_iterator begin() const { return _lst_strips.begin(); }
153 /// @brief Iterator on the end of the set
154 iterator end() { return _lst_strips.end(); }
155 /// @brief Const iterator on the end of the set
156 const_iterator end() const { return _lst_strips.end(); }
157 /// @brief Number of indices included into the set of strips
158 unsigned numberOfIndices() const;
159 /// @brief Return the number of strips
160 unsigned numberOfStrips() const {
161 return unsigned(_lst_strips.size());
162 }
163 //@}
164
165 ///@name Operations on SetOfStrips
166 //@{
167 /** Check if an indice is contained by the strip */
168 bool contains(unsigned ind) const
169 {
170 bool ok = false;
171 for (const_iterator it = begin(); it != end(); it++)
172 ok |= (*it).contains(ind);
173 return ok;
174 }
175 /** Add a new strip in the SetOfStrips */
176 void push_back(const Strip& strp) {
177 _lst_strips.push_back(strp);
178 }
179 /** Add a new SetOfStrips in the SetOfStrips */
180 void push_back(const SetOfStrips& strps);
181
182 /** Convert set of strips as list of indices */
183 operator std::list<unsigned>();
184 /** Compute the union of current strips indices
185 and strips coming from strips parameter.
186 */
187 SetOfStrips& operator += (const SetOfStrips& strips);
188 /** \brief Compute the union of current strips indices
189 with indices of another strips as union of
190 intersections and differences (for parallel
191 managing).
192
193 The first indice in the source is not computed here,
194 the main reason is than we renumber after this computation.
195 */
196 void para_union(const SetOfStrips& strips,
197 SetOfStrips& paraStrips1,
198 SetOfStrips& paraStrips2,
199 SetOfStrips& seqStrips) const;
200 //@}
201 private:
202 std::list<Strip> _lst_strips;
203 };
204 // --------------------------------------------------------------
205 /** @brief Interconnection between a block B and his ancestors
206 in the bisection tree at the time when the block B
207 must be eliminated by the factorization algorithm.
208
209 During numerical factorization, Schur complements must
210 be computed by the LDU factorization. Schur complements
211 are computed for ancestors of a domain and added
212 on a part of the condensed problem on these ancestors.
213 This class provides some helpers to keep which nodes
214 indices in each ancestor are changed by the Schur
215 complement.
216
217 NB : For the direct father, only one strip is stored
218 --- for the reason that all nodes of the father are connected
219 with the domain.
220 */
221 class FathersStrips
222 {
223 public:
224 /// @name Constructors and destructor
225 //@{
226 /** @brief Initialize interconnection with empty connections
227 */
228 FathersStrips();
229 /** @brief Initialize interconnection with his
230 Schur complement for a node at level lvl (>=1).
231 */
232 FathersStrips(unsigned lvl);
233 /** @brief Copy constructor
234
235 Steal pointer of the copied object which is destroyed !
236 */
237 FathersStrips(FathersStrips& connections);
238 /// @brief Destructor
239 ~FathersStrips();
240 //@}
241
242 void alloc(unsigned lvl);
243
244 /// @name Getters/Setters
245 //@{
246 /** @brief Return the set of strips for the out of
247 diagonal block coming from ancestor at
248 level lvl.
249 */
250 SetOfStrips& operator [] (unsigned lvl);
251 /** @brief Return the set of strips for the out of
252 diagonal block coming from ancestor at
253 level lvl.
254 */
255 const SetOfStrips& operator [] (unsigned lvl) const;
256 /** @brief Return the set of strips for row indices
257 for interaction block between
258 the ancestor at level l1 and ancestor at
259 level l2 (0 <= l1,l2<lvl)
260 */
261 SetOfStrips& getRowSetOfStrips(unsigned l1, unsigned l2);
262 /** @brief Return the set of strips for row indices
263 for interaction block between
264 the ancestor at level l1 and ancestor at
265 level l2 (0 <= l1,l2<lvl)
266 */
267 const SetOfStrips&
268 getRowSetOfStrips(unsigned l1, unsigned l2) const;
269 /** @brief Return the set of strips for column indices
270 for interaction block between
271 the ancestor at level l1 and ancestor at
272 level l2 (0 <= l1,l2<lvl)
273 */
274 SetOfStrips& getColSetOfStrips(unsigned l1, unsigned l2);
275 /** @brief Return the set of strips for column indices
276 for interaction block between
277 the ancestor at level l1 and ancestor at
278 level l2 (0 <= l1,l2<lvl)
279 */
280 const SetOfStrips&
281 getColSetOfStrips(unsigned l1, unsigned l2) const;
282
283 //@}
284 private:
285 unsigned _level; // Level of the node
286 // Local indices (referring to each ancestors) for out
287 // of diagonal block for current domain stored per ancestor
288 SetOfStrips* _outOfDiags;
289 // Set of strips for the out of diagonal blocks coming from direct
290 // father with another ancestor. This strips are splitted
291 // into sequential strips (strips within indices are cared for
292 // both children) and parallel strips (one only child contains
293 // these indices).
294 // NB : For the diagonal block coming from the direct parent,
295 // --- none strip is necessary...
296 SetOfStrips* _seq_strips,* _par_strips;
297
298 // Set of strips for row and columns on upper triangular part
299 // of the Schur complement (swap row and col for lower part)
300 // which not contains a direct parent.
301 SetOfStrips* _row_strips;
302 SetOfStrips* _col_strips;
303 };
304 }
305 // std::ostream& operator << (std::ostream& out,
306 // const Dissection::Strip& strp);
307 //std::ostream& operator << (std::ostream& out,
308 // const Dissection::SetOfStrips& set);
309 #endif