Loading...
Searching...
No Matches
BiIndirectListI.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) 2019-2022 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
27\*---------------------------------------------------------------------------*/
28
29// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30
31template<class T>
33(
34 const UList<T>& posList,
35 const UList<T>& negList,
36 const labelUList& addr
37)
38:
39 posList_(const_cast<UList<T>&>(posList)),
40 negList_(const_cast<UList<T>&>(negList)),
41 addr_(addr)
42{}
43
44
45template<class T>
47(
48 const UList<T>& posList,
49 const UList<T>& negList,
50 labelList&& addr
51)
52:
53 posList_(const_cast<UList<T>&>(posList)),
54 negList_(const_cast<UList<T>&>(negList)),
55 addr_(std::move(addr))
56{}
57
58
59// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
60
61template<class T>
63{
64 addr_ = addr;
65}
66
67
68template<class T>
70{
71 addr_.transfer(addr);
72}
73
74
75template<class T>
77{
78 List<T> result(size());
79
80 forAll(*this, i)
81 {
82 result[i] = operator[](i);
83 }
84
85 return result;
86}
87
88
89// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
90
91template<class T>
92inline T& Foam::BiIndirectList<T>::operator[](const label i)
93{
94 const label index = addr_[i];
95
96 return (index >= 0 ? posList_[index] : negList_[-index-1]);
97}
98
99
100template<class T>
101inline const T& Foam::BiIndirectList<T>::operator[](const label i) const
102{
103 const label index = addr_[i];
104
105 return (index >= 0 ? posList_[index] : negList_[-index-1]);
106}
107
108
109template<class T>
110inline void Foam::BiIndirectList<T>::operator=(const UList<T>& ae)
111{
112 if (addr_.size() != ae.size())
113 {
115 << "Addressing and list of addressed elements "
116 "have different sizes: "
117 << addr_.size() << " " << ae.size()
118 << abort(FatalError);
119 }
120
121 forAll(addr_, i)
123 operator[](i) = ae[i];
124 }
125}
126
127
128template<class T>
129inline void Foam::BiIndirectList<T>::operator=(const T& val)
130{
131 forAll(addr_, i)
132 {
133 operator[](i) = val;
134 }
135}
136
137
138// ************************************************************************* //
BiIndirectList(const UList< T > &posList, const UList< T > &negList, const labelUList &addr)
Construct given the complete lists and the addressing array.
const UList< T > & negList() const noexcept
The list of negative values (without addressing).
List< T > list() const
Return the addressed elements as a List.
void operator=(const UList< T > &ae)
Assignment to UList of addressed elements.
void resetAddressing(const labelUList &addr)
Copy reset addressing.
label size() const noexcept
The number of elements in the list.
const UList< T > & posList() const noexcept
The list of positive values (without addressing).
T & operator[](const label i)
Return non-const access to an element.
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 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 size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
const volScalarField & T
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
List< label > labelList
A List of labels.
Definition List.H:62
errorManip< error > abort(error &err)
Definition errorManip.H:139
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
UList< label > labelUList
A UList of labels.
Definition UList.H:75
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299