BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / applications / test / router / router.H
blob7b675ac22317e699cd66cc1207a22517accc65ce
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software: you can redistribute it and/or modify it
12     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.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
24 Class
25     Foam::router
27 Description
28     Lee's PCB routing algorithm. Construct with list of connections between
29     nodes (i.e. topology) and list of coordinates of nodes (can be vector::zero)
31     Use e.g.
33         // Enter topology/geometry
34         router cellRouter
35         (
36             mesh().cellCells(),
37             mesh().cellCentres()
38         );
40         // Try to route connections one by one. Specify unique value (<0) to
41         // mark path with.
42         forAll(wantedConnections, i)
43         {
44             bool success = cellRouter.route(wantedConnections[i], -(i+1));
45         }
48     The coordinates are only used at the moment for diagonal preference of
49     routing:
51     So not:
53     +A
54     |
55     |
56     |
57     |
58     ------+B
59         
60     But:
62     + A
63     |_
64       |_
65         |_
66           |_
67             |
68             + B
71     Lee algo: take array with same dimensions as grid of nodes. Initialize to
72     large number. Put 0 at starting point. Now recursively assign neighbours
73     as current value plus one. Stop if you hit node which has smaller number.
74     Phase two is where you search path with lowest value. These are assigned
75     negative number so they for next route are not overwritten.
77 SourceFiles
78     router.C
80 \*---------------------------------------------------------------------------*/
82 #ifndef router_H
83 #define router_H
85 #include "labelList.H"
86 #include "pointField.H"
87 #include "DynamicList.H"
89 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
91 namespace Foam
94 // Forward declaration of classes
96 /*---------------------------------------------------------------------------*\
97                            Class router Declaration
98 \*---------------------------------------------------------------------------*/
100 class router
102     // Private data
104         //- Connections
105         const labelListList connections_;
107         //- Coordinates of nodes
108         const pointField coords_;
110         //- Routing table
111         labelList weights_;
113     // Private Member Functions
115         //- Return number of weights. Utility function
116         label count(const label weight) const;
118         //- Set distance from nodeI
119         void setWeights
120         (
121             const label weight,
122             const label nodeI
123         );
125         //- Finds path from nodeI to startNodeI by travelling in direction
126         //  of lowest weight
127         void fixWeights
128         (
129             const label startNodeI,
130             const label endNodeI,
131             const label nodeI,
132             const label prevNodeI
133         );
135         //- Routes single path
136         bool shortestPath
137         (
138             const labelList& path,
139             const label pathValue
140         );
142         //- Linear search for element with weight
143         label getValue(const label) const;
145         //- Find node which has no neighbours with pathValue
146         label findEndNode
147         (
148             const label startNodeI,
149             const label prevNodeI,
150             const label pathValue
151         ) const;
153         //- Append all pathValue weights to route.
154         void storeRoute
155         (
156             const label startNodeI,
157             const label prevNodeI,
158             const label pathValue,
159             DynamicList<label>& route
160         ) const;
162         //- Disallow default bitwise copy construct
163         router(const router&);
165         //- Disallow default bitwise assignment
166         void operator=(const router&);
169 public:
171     // Constructors
173         //- Construct from connections, route later.
174         router
175         (
176             const labelListList& connections,
177             const List<point>& coords
178         );
181     // Member Functions
183         // Access
185             const labelList& weights() const
186             {
187                 return weights_;
188             }
190         // Edit
192             //- Find path from first element in path to all other elements
193             //  Mark resulting path in weights with (negative) pathValue.
194             //  Returns false and does not mark any elements if cannot route.
195             bool route(const labelList& path, const label pathValue);
197             //- Extract labels of route with given value.
198             labelList getRoute(const label pathValue) const;
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205 } // End namespace Foam
207 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
209 #endif
211 // ************************************************************************* //