ccmInterfaceDefinitions.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) 2016 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Description
27 Containers for holding STARCCM interface definitions
28
29\*---------------------------------------------------------------------------*/
30
31#ifndef ccmInterfaceDefinitions_H
32#define ccmInterfaceDefinitions_H
33
34#include "Map.H"
35#include "Ostream.H"
36
37// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38
39namespace Foam
40{
41namespace ccm
42{
43
44class interfaceEntry;
45class interfaceDefinitions;
46
47Ostream& operator<<(Ostream& os, const interfaceEntry& entry);
48Ostream& operator<<(Ostream& os, const interfaceDefinitions& defs);
49
50/*---------------------------------------------------------------------------*\
51 Class Foam::ccm::interfaceEntry Declaration
52\*---------------------------------------------------------------------------*/
53
54//- A STARCCM interface definition is a pair of boundary ids
56{
57public:
58 // Public Data
59
60 //- The internal interface id
61 label id;
62
63 //- The first boundary
64 label bnd0;
65
66 //- The second boundary
67 label bnd1;
68
69
70 // Constructors
71
72 //- Construct null
74 :
75 id(-1),
76 bnd0(-1),
77 bnd1(-1)
78 {}
79
80
81 //- Construct empty interface definition
82 interfaceEntry(const label index)
83 :
84 id(index),
85 bnd0(-1),
86 bnd1(-1)
87 {}
88
89
90 //- Construct from components
92 (
93 const label index,
94 const label boundary0,
95 const label boundary1
96 )
97 :
98 id(index),
99 bnd0(boundary0),
100 bnd1(boundary1)
101 {}
102
103
104 // Access
105
106 //- Check for in-place interfaces
107 static bool isInPlace(const std::string& configurationType)
108 {
109 return configurationType == "IN_PLACE";
110 }
111
112
113 //- True if the boundary id is in this interface
114 bool inInterface(label bndId) const
115 {
116 return bndId == bnd0 || bndId == bnd1;
117 }
118
119 //- True if all internal ids are non-negative
120 bool valid() const
121 {
122 return (id >= 0 && bnd0 >= 0 && bnd1 >= 0 && bnd0 != bnd1);
123 }
124
125
126 //- Canonical name for boundary 0
128 {
129 return "Interface" + ::Foam::name(id) + "_0";
130 }
131
132 //- Canonical name for boundary 1
134 {
135 return "Interface" + ::Foam::name(id) + "_1";
136 }
137
138 //- Canonical name for boundary
139 word canonicalName(label bndId) const
140 {
141 if (bndId == bnd0)
142 {
143 return canonicalName0();
144 }
145 else if (bndId == bnd1)
146 {
147 return canonicalName1();
148 }
149 else
150 {
151 return word::null;
152 }
153 }
154
155
156 // IOstream Operators
157
158 friend Ostream& operator<<
159 (
160 Ostream& os,
161 const interfaceEntry& entry
162 )
163 {
164 os << "(" << entry.bnd0 << " " << entry.bnd1 << ")";
165 return os;
166 }
167
168};
169
170
171/*---------------------------------------------------------------------------*\
172 Class ccm::interfaceDefinitions Declaration
173\*---------------------------------------------------------------------------*/
174
175//- A list of available interface definitions
177:
178 public Map<interfaceEntry>
179{
180
181 inline Map<interfaceEntry>& map()
182 {
183 return *this;
184 }
185
186 inline const Map<interfaceEntry>& map() const
187 {
188 return *this;
189 }
190
191
192public:
193 // Constructor
194
195 //- Null construct
197 {}
198
199 //- Size
200 label size() const
201 {
202 return map().size();
203 }
204
205 //- Size
206 bool empty() const
207 {
208 return map().empty();
209 }
210
211 //- Clear
212 void clear()
213 {
214 map().clear();
215 }
216
217
218 //- Add (valid) interface entry
220 {
221 return (entry.valid() && map().set(entry.id, entry));
222 }
223
224
225 //- Scan available interface entries for one matching this boundary id
226 bool isInterface(label bndId)
227 {
228 forAllConstIters(map(), iter)
229 {
230 if (iter.val().inInterface(bndId))
231 {
232 return true;
233 }
234 }
235 return false;
236 }
237
238
239 //- Scan interface entries for one matching this boundary id
240 // return the canonical name
241 word interfaceName(label bndId)
242 {
243 word ifname;
244 forAllConstIters(map(), iter)
245 {
246 ifname = iter.val().canonicalName(bndId);
247 if (!ifname.empty())
248 {
249 break;
250 }
251 }
252
253 return ifname;
254 }
255
256
257 // IOstream Operators
258
259 friend Ostream& operator<<
260 (
261 Ostream& os,
262 const interfaceDefinitions& defs
263 )
264 {
265 os << defs.map() << nl;
266 return os;
267 }
268
269};
270
271
272// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
273
274} // End namespace ccm
275} // End namespace Foam
276
277// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
278
279#endif
280
281// ************************************************************************* //
bool set(const Key &key, const T &obj)
Copy assign a new entry, overwriting existing entries.
Definition: HashTableI.H:202
bool empty() const noexcept
True if the hash table is empty.
Definition: HashTableI.H:59
label size() const noexcept
The number of elements in table.
Definition: HashTableI.H:52
void clear()
Clear all entries from table.
Definition: HashTable.C:678
A HashTable to objects of type <T> with a label key.
Definition: Map.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A list of available interface definitions.
bool add(const interfaceEntry &entry)
Add (valid) interface entry.
word interfaceName(label bndId)
Scan interface entries for one matching this boundary id.
bool isInterface(label bndId)
Scan available interface entries for one matching this boundary id.
A STARCCM interface definition is a pair of boundary ids.
interfaceEntry(const label index, const label boundary0, const label boundary1)
Construct from components.
label bnd1
The second boundary.
bool valid() const
True if all internal ids are non-negative.
interfaceEntry(const label index)
Construct empty interface definition.
word canonicalName(label bndId) const
Canonical name for boundary.
label id
The internal interface id.
word canonicalName0() const
Canonical name for boundary 0.
static bool isInPlace(const std::string &configurationType)
Check for in-place interfaces.
label bnd0
The first boundary.
word canonicalName1() const
Canonical name for boundary 1.
bool inInterface(label bndId) const
True if the boundary id is in this interface.
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:70
A class for handling words, derived from Foam::string.
Definition: word.H:68
static const word null
An empty word.
Definition: word.H:80
OBJstream os(runTime.globalPath()/outputName)
Ostream & operator<<(Ostream &os, const interfaceEntry &entry)
Namespace for OpenFOAM.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.
Definition: stdFoam.H:278