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-2024 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 Foam_ccmInterfaceDefinitions_H
32 #define Foam_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 
59  // Public Data
60 
61  //- The internal interface id
62  label id;
63 
64  //- The first boundary
65  label bnd0;
66 
67  //- The second boundary
68  label bnd1;
69 
70 
71  // Constructors
72 
73  //- Default construct
74  constexpr interfaceEntry() noexcept
75  :
76  id(-1),
77  bnd0(-1),
78  bnd1(-1)
79  {}
80 
81  //- Construct empty interface definition
82  constexpr interfaceEntry(const label index) noexcept
83  :
84  id(index),
85  bnd0(-1),
86  bnd1(-1)
87  {}
88 
89  //- Construct from components
90  constexpr interfaceEntry
91  (
92  const label index,
93  const label boundary0,
94  const label boundary1
95  ) noexcept
96  :
97  id(index),
98  bnd0(boundary0),
99  bnd1(boundary1)
100  {}
101 
102 
103  // Access
104 
105  //- Check for in-place interfaces
106  static bool isInPlace(const std::string& configurationType)
107  {
108  return configurationType == "IN_PLACE";
109  }
110 
111 
112  //- True if the boundary id is in this interface
113  bool inInterface(label bndId) const noexcept
114  {
115  return bndId == bnd0 || bndId == bnd1;
116  }
117 
118  //- True if all internal ids are non-negative
119  bool good() const noexcept
120  {
121  return (id >= 0 && bnd0 >= 0 && bnd1 >= 0 && bnd0 != bnd1);
122  }
123 
124  //- Same as good()
125  bool valid() const noexcept { return good(); }
126 
127 
128  //- Canonical name for boundary 0
129  word canonicalName0() const
130  {
131  return "Interface" + ::Foam::name(id) + "_0";
132  }
134  //- Canonical name for boundary 1
135  word canonicalName1() const
136  {
137  return "Interface" + ::Foam::name(id) + "_1";
138  }
139 
140  //- Canonical name for boundary
141  word canonicalName(label bndId) const
142  {
143  if (bndId == bnd0)
144  {
145  return canonicalName0();
146  }
147  else if (bndId == bnd1)
148  {
149  return canonicalName1();
150  }
151  else
152  {
153  return word();
154  }
155  }
156 
157 
158  // IOstream Operators
159 
160  friend Ostream& operator<<
161  (
162  Ostream& os,
164  )
165  {
166  os << '(' << entry.bnd0 << ' ' << entry.bnd1 << ')';
167  return os;
168  }
169 };
170 
171 
172 /*---------------------------------------------------------------------------*\
173  Class ccm::interfaceDefinitions Declaration
174 \*---------------------------------------------------------------------------*/
175 
176 //- A list of available interface definitions
177 class interfaceDefinitions
178 :
179  public Map<interfaceEntry>
180 {
181  typedef Map<interfaceEntry> map_type;
182 
183  const map_type& map() const noexcept { return *this; }
184 
185 
186 public:
187 
188  // Constructor
189 
190  //- Default construct
191  interfaceDefinitions() noexcept = default;
192 
193  //- Map size
194  using map_type::size;
195 
196  //- Map empty?
197  using map_type::empty;
198 
199  //- Map clear
200  using map_type::clear;
202 
203  //- Add (valid) interface entry
204  bool add(const interfaceEntry& entry)
205  {
206  return (entry.good() && map_type::set(entry.id, entry));
207  }
208 
209 
210  //- Scan available interface entries for one matching this boundary id
211  bool isInterface(label bndId)
212  {
213  forAllConstIters(map(), iter)
214  {
215  if (iter.val().inInterface(bndId))
216  {
217  return true;
218  }
219  }
220  return false;
221  }
222 
223 
224  //- Scan interface entries for one matching this boundary id
225  // return the canonical name
226  word interfaceName(label bndId)
227  {
228  word ifname;
229  forAllConstIters(map(), iter)
230  {
231  ifname = iter.val().canonicalName(bndId);
232  if (!ifname.empty())
233  {
234  break;
235  }
236  }
237 
238  return ifname;
239  }
240 
241 
242  // IOstream Operators
243 
244  friend Ostream& operator<<
245  (
246  Ostream& os,
248  )
249  {
250  os << defs.map() << nl;
251  return os;
252  }
253 };
254 
255 
256 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
257 
258 } // End namespace ccm
259 } // End namespace Foam
260 
261 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
262 
263 #endif
264 
265 // ************************************************************************* //
constexpr interfaceEntry() noexcept
Default construct.
label bnd0
The first boundary.
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.
interfaceDefinitions() noexcept=default
Default construct.
label size() const noexcept
The number of elements in table.
Definition: HashTable.H:358
A class for handling words, derived from Foam::string.
Definition: word.H:63
void clear()
Remove all entries from table.
Definition: HashTable.C:742
word canonicalName(label bndId) const
Canonical name for boundary.
bool add(const interfaceEntry &entry)
Add (valid) interface entry.
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: scalarImpl.H:265
bool empty() const noexcept
True if the hash table is empty.
Definition: HashTable.H:353
bool valid() const noexcept
Same as good()
auto & name
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 inInterface(label bndId) const noexcept
True if the boundary id is in this interface.
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.