directFieldMapper.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) 2013 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
27Class
28 Foam::DirectFieldMapper
29
30Description
31 A templated direct mapper for the given FieldMapper type
32
33\*---------------------------------------------------------------------------*/
34
35#ifndef Foam_directFieldMapper_H
36#define Foam_directFieldMapper_H
37
38#include "FieldMapper.H"
39
40// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41
42namespace Foam
43{
44
45// Forward Declarations
46template<class FieldMapperType> class DirectFieldMapper;
47
48// Standard Types
49
50//- A FieldMapper with direct mapping
52
53
54/*---------------------------------------------------------------------------*\
55 Class DirectFieldMapper Declaration
56\*---------------------------------------------------------------------------*/
57
58template<class FieldMapperType>
60:
61 public FieldMapperType
62{
63 // Private Data
64
65 //- Addressing from new back to old
66 const labelUList& directAddressing_;
67
68 //- Does map contain any unmapped values
69 bool hasUnmapped_;
70
71
72 // Private Member Functions
73
74 //- Any negative (unmapped) values in the addressing?
75 static bool hasUnmappedEntry(const labelUList& directAddr)
76 {
77 for (const label val : directAddr)
78 {
79 if (val < 0) return true; // early exit
80 }
81 return false;
82 }
83
84public:
85
86 // Public Types
87
88 //- The base mapper type
89 typedef FieldMapperType mapper_type;
90
91
92 // Constructors
93
94 //- Construct given addressing, check for unmapped (negative) values
95 explicit DirectFieldMapper
96 (
97 const labelUList& directAddr,
98 const bool checkUnmapped = true
99 )
100 :
101 FieldMapperType(),
102 directAddressing_(directAddr),
103 hasUnmapped_(checkUnmapped && hasUnmappedEntry(directAddr))
104 {}
105
106
107 //- Destructor
108 virtual ~DirectFieldMapper() = default;
109
110
111 // Member Functions
112
113 //- True if directAddressing is not the null object (unallocated)
114 virtual bool hasDirectAddressing() const
115 {
116 return notNull(directAddressing_);
117 }
118
119 //- The mapper size is given by the size of the direct addressing
120 virtual label size() const
121 {
122 return directAddressing_.size();
123 }
124
125 //- It is a direct mapper
126 virtual bool direct() const
127 {
128 return true;
129 }
130
131 //- Any unmapped values?
132 virtual bool hasUnmapped() const
133 {
134 return hasUnmapped_;
135 }
136
137 //- Allow modification
138 virtual bool& hasUnmapped()
139 {
140 return hasUnmapped_;
141 }
142
143 //- Return the direct addressing values
144 virtual const labelUList& directAddressing() const
145 {
146 return directAddressing_;
147 }
148};
149
150
151// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152
153} // End namespace Foam
154
155// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156
157#endif
158
159// ************************************************************************* //
A templated direct mapper for the given FieldMapper type.
virtual bool hasDirectAddressing() const
True if directAddressing is not the null object (unallocated)
virtual label size() const
The mapper size is given by the size of the direct addressing.
FieldMapperType mapper_type
The base mapper type.
virtual bool hasUnmapped() const
Any unmapped values?
virtual const labelUList & directAddressing() const
Return the direct addressing values.
virtual ~DirectFieldMapper()=default
Destructor.
virtual bool & hasUnmapped()
Allow modification.
virtual bool direct() const
It is a direct mapper.
DirectFieldMapper(const labelUList &directAddr, const bool checkUnmapped=true)
Construct given addressing, check for unmapped (negative) values.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Namespace for OpenFOAM.
DirectFieldMapper< FieldMapper > directFieldMapper
A FieldMapper with direct mapping.
bool notNull(const T *ptr)
True if ptr is not a pointer (of type T) to the nullObject.
Definition: nullObject.H:207