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 -------------------------------------------------------------------------------
10 License
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 
26 Description
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 
39 namespace Foam
40 {
41 namespace ccm
42 {
43 
44 class interfaceEntry;
45 class interfaceDefinitions;
46 
47 Ostream& operator<<(Ostream& os, const interfaceEntry& entry);
48 Ostream& 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
55 class interfaceEntry
56 {
57 public:
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 good() const noexcept
121  {
122  return (id >= 0 && bnd0 >= 0 && bnd1 >= 0 && bnd0 != bnd1);
123  }
124 
125  //- Same as good()
126  bool valid() const noexcept { return good(); }
127 
128 
129  //- Canonical name for boundary 0
130  word canonicalName0() const
131  {
132  return "Interface" + ::Foam::name(id) + "_0";
133  }
135  //- Canonical name for boundary 1
136  word canonicalName1() const
137  {
138  return "Interface" + ::Foam::name(id) + "_1";
139  }
140 
141  //- Canonical name for boundary
142  word canonicalName(label bndId) const
143  {
144  if (bndId == bnd0)
145  {
146  return canonicalName0();
147  }
148  else if (bndId == bnd1)
149  {
150  return canonicalName1();
151  }
152  else
153  {
154  return word::null;
155  }
156  }
157 
158 
159  // IOstream Operators
160 
161  friend Ostream& operator<<
162  (
163  Ostream& os,
165  )
166  {
167  os << "(" << entry.bnd0 << " " << entry.bnd1 << ")";
168  return os;
169  }
170 
171 };
172 
173 
174 /*---------------------------------------------------------------------------*\
175  Class ccm::interfaceDefinitions Declaration
176 \*---------------------------------------------------------------------------*/
177 
178 //- A list of available interface definitions
179 class interfaceDefinitions
180 :
181  public Map<interfaceEntry>
182 {
183 
184  inline Map<interfaceEntry>& map()
185  {
186  return *this;
187  }
188 
189  inline const Map<interfaceEntry>& map() const
190  {
191  return *this;
192  }
193 
194 
195 public:
196  // Constructor
197 
198  //- Null construct
200  {}
201 
202  //- Size
203  label size() const
204  {
205  return map().size();
206  }
207 
208  //- Size
209  bool empty() const
210  {
211  return map().empty();
212  }
213 
214  //- Clear
215  void clear()
216  {
217  map().clear();
218  }
219 
220 
221  //- Add (valid) interface entry
222  bool add(const interfaceEntry& entry)
223  {
224  return (entry.good() && map().set(entry.id, entry));
225  }
226 
227 
228  //- Scan available interface entries for one matching this boundary id
229  bool isInterface(label bndId)
230  {
231  forAllConstIters(map(), iter)
232  {
233  if (iter.val().inInterface(bndId))
234  {
235  return true;
236  }
237  }
238  return false;
239  }
240 
241 
242  //- Scan interface entries for one matching this boundary id
243  // return the canonical name
244  word interfaceName(label bndId)
245  {
246  word ifname;
247  forAllConstIters(map(), iter)
248  {
249  ifname = iter.val().canonicalName(bndId);
250  if (!ifname.empty())
251  {
252  break;
253  }
254  }
255 
256  return ifname;
257  }
258 
259 
260  // IOstream Operators
261 
262  friend Ostream& operator<<
263  (
264  Ostream& os,
266  )
267  {
268  os << defs.map() << nl;
269  return os;
270  }
271 
272 };
273 
274 
275 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
276 
277 } // End namespace ccm
278 } // End namespace Foam
279 
280 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
281 
282 #endif
284 // ************************************************************************* //
label bnd0
The first boundary.
bool inInterface(label bndId) const
True if the boundary id is in this interface.
static bool isInPlace(const std::string &configurationType)
Check for in-place interfaces.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
word interfaceName(label bndId)
Scan interface entries for one matching this boundary id.
A list of available interface definitions.
label size() const noexcept
The number of elements in table.
Definition: HashTable.H:342
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
void clear()
Remove all entries from table.
Definition: HashTable.C:725
word canonicalName(label bndId) const
Canonical name for boundary.
bool add(const interfaceEntry &entry)
Add (valid) interface entry.
static const word null
An empty word.
Definition: word.H:84
A STARCCM interface definition is a pair of boundary ids.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
bool empty() const noexcept
True if the hash table is empty.
Definition: HashTable.H:337
bool valid() const noexcept
Same as good()
OBJstream os(runTime.globalPath()/outputName)
bool good() const noexcept
True if all internal ids are non-negative.
label bnd1
The second boundary.
word canonicalName1() const
Canonical name for boundary 1.
Ostream & operator<<(Ostream &os, const interfaceEntry &entry)
word canonicalName0() const
Canonical name for boundary 0.
label id
The internal interface id.
bool isInterface(label bndId)
Scan available interface entries for one matching this boundary id.
bool set(const Key &key, const T &obj)
Copy assign a new entry, overwriting existing entries.
Definition: HashTableI.H:174
Namespace for OpenFOAM.
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
A keyword and a list of tokens is an &#39;entry&#39;.
Definition: entry.H:63
A HashTable to objects of type <T> with a label key.