adding scalarIOList
[OpenFOAM-1.5.x.git] / applications / test / router / router.H
blob832585aaefd498cb2c0bcc06dc768c05e9190422
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::router
28 Description
29     Lee's PCB routing algorithm. Construct with list of connections between
30     nodes (i.e. topology) and list of coordinates of nodes (can be vector::zero)
32     Use e.g.
34         // Enter topology/geometry
35         router cellRouter
36         (
37             mesh().cellCells(),
38             mesh().cellCentres()
39         );
41         // Try to route connections one by one. Specify unique value (<0) to
42         // mark path with.
43         forAll(wantedConnections, i)
44         {
45             bool success = cellRouter.route(wantedConnections[i], -(i+1));
46         }
49     The coordinates are only used at the moment for diagonal preference of
50     routing:
52     So not:
54     +A
55     |
56     |
57     |
58     |
59     ------+B
60         
61     But:
63     + A
64     |_
65       |_
66         |_
67           |_
68             |
69             + B
72     Lee algo: take array with same dimensions as grid of nodes. Initialize to
73     large number. Put 0 at starting point. Now recursively assign neighbours
74     as current value plus one. Stop if you hit node which has smaller number.
75     Phase two is where you search path with lowest value. These are assigned
76     negative number so they for next route are not overwritten.
78 SourceFiles
79     router.C
81 \*---------------------------------------------------------------------------*/
83 #ifndef router_H
84 #define router_H
86 #include "labelList.H"
87 #include "pointField.H"
88 #include "DynamicList.H"
90 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
92 namespace Foam
95 // Forward declaration of classes
97 /*---------------------------------------------------------------------------*\
98                            Class router Declaration
99 \*---------------------------------------------------------------------------*/
101 class router
103     // Private data
105         //- Connections
106         const labelListList connections_;
108         //- Coordinates of nodes
109         const pointField coords_;
111         //- Routing table
112         labelList weights_;
114     // Private Member Functions
116         //- Return number of weights. Utility function
117         label count(const label weight) const;
119         //- Set distance from nodeI
120         void setWeights
121         (
122             const label weight,
123             const label nodeI
124         );
126         //- Finds path from nodeI to startNodeI by travelling in direction
127         //  of lowest weight
128         void fixWeights
129         (
130             const label startNodeI,
131             const label endNodeI,
132             const label nodeI,
133             const label prevNodeI
134         );
136         //- Routes single path
137         bool shortestPath
138         (
139             const labelList& path,
140             const label pathValue
141         );
143         //- Linear search for element with weight
144         label getValue(const label) const;
146         //- Find node which has no neighbours with pathValue
147         label findEndNode
148         (
149             const label startNodeI,
150             const label prevNodeI,
151             const label pathValue
152         ) const;
154         //- Append all pathValue weights to route.
155         void storeRoute
156         (
157             const label startNodeI,
158             const label prevNodeI,
159             const label pathValue,
160             DynamicList<label>& route
161         ) const;
163         //- Disallow default bitwise copy construct
164         router(const router&);
166         //- Disallow default bitwise assignment
167         void operator=(const router&);
170 public:
172     // Constructors
174         //- Construct from connections, route later.
175         router
176         (
177             const labelListList& connections,
178             const List<point>& coords
179         );
182     // Member Functions
184         // Access
186             const labelList& weights() const
187             {
188                 return weights_;
189             }
191         // Edit
193             //- Find path from first element in path to all other elements
194             //  Mark resulting path in weights with (negative) pathValue.
195             //  Returns false and does not mark any elements if cannot route.
196             bool route(const labelList& path, const label pathValue);
198             //- Extract labels of route with given value.
199             labelList getRoute(const label pathValue) const;
204 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
206 } // End namespace Foam
208 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
210 #endif
212 // ************************************************************************* //