Loading...
Searching...
No Matches
lduAddressing.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2016-2024 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::lduAddressing
29
30Description
31 The class contains the addressing required by the lduMatrix: upper, lower
32 and losort.
33
34 The addressing can be created in two ways: either with references to
35 upper and lower in which case it stores references or from labelLists,
36 in which case it stores the addressing itself. Additionally, the losort
37 addressing belongs to the class is as on lazy evaluation.
38
39 The ordering of owner addresses is such that the labels are in
40 increasing order, with groups of identical labels for edges "owned" by
41 the same point. The neighbour labels are also ordered in ascending
42 order but only for groups of edges belonging to each point. An example
43 is given below:
44 \verbatim
45 owner neighbour
46 0 1
47 0 20
48 1 2
49 1 21
50 2 3
51 2 22
52 3 4
53 3 23
54 4 5
55 4 24
56 5 6
57 5 25
58 6 7
59 6 26
60 7 8
61 7 27
62 8 9
63 8 28
64 9 10
65 9 29
66 \endverbatim
67
68 There exists an alternative way of addressing the owner
69 list: instead of repeating the same label in the owner list, it is
70 possible to address the start of each point neighbours in the
71 neighbour list. This reduces the size of owner addressing from a list
72 over all edges to a list over all points + 1:
73
74 \verbatim
75 Owner start list: 0 2 4 6 8 10 12 14 16 18
76 \endverbatim
77
78 We shall use the second form of the addressing for fast lookup
79 of edge label from the known owner and neighbour, using the following
80 algorithm:
81 -# take the owner label and position the start of lookup
82 using the owner start list
83 -# loop through all neighbours of this owner (ending at the start of
84 lookup of owner + 1) until the match with current neighbour is found.
85 The index used on the neighbour list for the match is the edge index.
86
87 While owner start addressing allows us to find the edge owned by the
88 points, it is also necessary to find the edges for which the point is
89 a neighbour. Losort addressing lists the edges neighboured by the
90 point and we shall use the same trick as above to address into this
91 list. Thus, for every point the losort start gives the address of the
92 first face to neighbour this point.
93
94 Instead of using losort to lookup the face and then using the lowerAddr
95 to find the neighbour cell one can also directly lookup the neighbour cell
96 using the lowerCSRAddr (upperAddr is already in CSR order).
97
98SourceFiles
99 lduAddressing.C
100
101\*---------------------------------------------------------------------------*/
102
103#ifndef lduAddressing_H
104#define lduAddressing_H
105
106#include "labelList.H"
107#include "lduSchedule.H"
108#include "Tuple2.H"
109
110// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
111
112namespace Foam
113{
115/*---------------------------------------------------------------------------*\
116 Class lduAddressing Declaration
117\*---------------------------------------------------------------------------*/
118
119class lduAddressing
120{
121 // Private Data
122
123 //- Number of equations
124 label size_;
125
126
127 //- Demand-driven data
128
129 //- Losort addressing
130 mutable std::unique_ptr<labelList> losortPtr_;
131
132 //- Owner start addressing
133 mutable std::unique_ptr<labelList> ownerStartPtr_;
134
135 //- Losort start addressing
136 mutable std::unique_ptr<labelList> losortStartPtr_;
137
138 //- Lower addressing
139 mutable std::unique_ptr<labelList> lowerCSRAddrPtr_;
140
141
142 // Private Member Functions
143
144 //- Calculate losort
145 void calcLosort() const;
146
147 //- Calculate owner start
148 void calcOwnerStart() const;
149
150 //- Calculate losort start
151 void calcLosortStart() const;
152
153 //- Calculate CSR lower addressing
154 void calcLoCSR() const;
155
156
157public:
158
159 // Generated Methods
160
161 //- No copy construct
162 lduAddressing(const lduAddressing&) = delete;
163
164 //- No copy assignment
165 void operator=(const lduAddressing&) = delete;
166
167
168 // Constructors
169
170 //- Construct with size (number of equations)
171 explicit lduAddressing(const label nEqns) noexcept
172 :
173 size_(nEqns)
174 {}
175
176
177 //- Destructor
178 virtual ~lduAddressing() = default;
180
181 // Member Functions
182
183 //- Return number of equations
184 label size() const noexcept
185 {
186 return size_;
187 }
188
189 //- Return lower addressing
190 virtual const labelUList& lowerAddr() const = 0;
191
192 //- Return upper addressing
193 virtual const labelUList& upperAddr() const = 0;
194
195 //- Return patch to internal addressing given patch number
196 virtual const labelUList& patchAddr
197 (
198 const label patchNo
199 ) const = 0;
200
201 //- Return patch field evaluation schedule
202 virtual const lduSchedule& patchSchedule() const = 0;
203
204 //- Clear additional addressing
205 void clearOut();
206
207 //- Return losort addressing
208 const labelUList& losortAddr() const;
210 //- Return owner start addressing
211 const labelUList& ownerStartAddr() const;
212
213 //- Return losort start addressing
214 const labelUList& losortStartAddr() const;
215
216 //- Return CSR addressing
217 const labelUList& lowerCSRAddr() const;
218
219 //- Return off-diagonal index given owner and neighbour label
220 label triIndex(const label a, const label b) const;
221
222 //- Calculate bandwidth and profile of addressing
224
225 //- Helper to convert lower addressing & data into CSR format
226 template<class Type>
227 void map
228 (
229 const UList<Type>& faceVals,
230 List<Type>& vals
231 ) const;
232};
233
234
235// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236
237} // End namespace Foam
238
239// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
240
241#ifdef NoRepository
242 #include "lduAddressingTemplates.C"
243#endif
244
245// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
246
247#endif
248
249// ************************************************************************* //
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition Tuple2.H:51
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
void map(const UList< Type > &faceVals, List< Type > &vals) const
Helper to convert lower addressing & data into CSR format.
const labelUList & ownerStartAddr() const
Return owner start addressing.
virtual const lduSchedule & patchSchedule() const =0
Return patch field evaluation schedule.
lduAddressing(const label nEqns) noexcept
Construct with size (number of equations).
const labelUList & losortStartAddr() const
Return losort start addressing.
void operator=(const lduAddressing &)=delete
No copy assignment.
Tuple2< label, scalar > band() const
Calculate bandwidth and profile of addressing.
virtual const labelUList & upperAddr() const =0
Return upper addressing.
lduAddressing(const lduAddressing &)=delete
No copy construct.
virtual const labelUList & lowerAddr() const =0
Return lower addressing.
const labelUList & lowerCSRAddr() const
Return CSR addressing.
virtual const labelUList & patchAddr(const label patchNo) const =0
Return patch to internal addressing given patch number.
label size() const noexcept
Return number of equations.
virtual ~lduAddressing()=default
Destructor.
const labelUList & losortAddr() const
Return losort addressing.
void clearOut()
Clear additional addressing.
label triIndex(const label a, const label b) const
Return off-diagonal index given owner and neighbour label.
Namespace for OpenFOAM.
List< lduScheduleEntry > lduSchedule
A List of lduSchedule entries.
Definition lduSchedule.H:46
const direction noexcept
Definition scalarImpl.H:265
UList< label > labelUList
A UList of labels.
Definition UList.H:75
volScalarField & b