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 #ifndef ccmInterfaceDefinitions_H
31 #define ccmInterfaceDefinitions_H
32 
33 #include "Map.H"
34 #include "Ostream.H"
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40 namespace ccm
41 {
42 
43 class interfaceEntry;
44 class interfaceDefinitions;
45 
46 Ostream& operator<<(Ostream& os, const interfaceEntry& entry);
47 Ostream& operator<<(Ostream& os, const interfaceDefinitions& defs);
48 
49 /*---------------------------------------------------------------------------*\
50  Class Foam::ccm::interfaceEntry Declaration
51 \*---------------------------------------------------------------------------*/
52 
53 //- A STARCCM interface definition is a pair of boundary ids
55 {
56 public:
57  // Public Data
58 
59  //- The internal interface id
61 
62  //- The first boundary
64 
65  //- The second boundary
67 
68 
69  // Constructors
70 
71  //- Construct null
73  :
74  id(-1),
75  bnd0(-1),
76  bnd1(-1)
77  {}
78 
79 
80  //- Construct empty interface definition
81  interfaceEntry(const label index)
82  :
83  id(index),
84  bnd0(-1),
85  bnd1(-1)
86  {}
87 
88 
89  //- Construct from components
91  (
92  const label index,
93  const label boundary0,
94  const label boundary1
95  )
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
114  {
115  return bndId == bnd0 || bndId == bnd1;
116  }
117 
118  //- True if all internal ids are non-negative
119  bool valid() const
120  {
121  return (id >= 0 && bnd0 >= 0 && bnd1 >= 0 && bnd0 != bnd1);
122  }
123 
124 
125  //- Canonical name for boundary 0
127  {
128  return "Interface" + ::Foam::name(id) + "_0";
129  }
130 
131  //- Canonical name for boundary 1
133  {
134  return "Interface" + ::Foam::name(id) + "_1";
135  }
136 
137  //- Canonical name for boundary
138  word canonicalName(label bndId) const
139  {
140  if (bndId == bnd0)
141  {
142  return canonicalName0();
143  }
144  else if (bndId == bnd1)
145  {
146  return canonicalName1();
147  }
148  else
149  {
150  return word::null;
151  }
152  }
153 
154 
155  // IOstream Operators
156 
157  friend Ostream& operator<<
158  (
159  Ostream& os,
160  const interfaceEntry& entry
161  )
162  {
163  os << "(" << entry.bnd0 << " " << entry.bnd1 << ")";
164  return os;
165  }
166 
167 };
168 
169 
170 /*---------------------------------------------------------------------------*\
171  Class ccm::interfaceDefinitions Declaration
172 \*---------------------------------------------------------------------------*/
173 
174 //- A list of available interface definitions
176 :
177  public Map<interfaceEntry>
178 {
179 
180  inline Map<interfaceEntry>& map()
181  {
182  return *this;
183  }
184 
185  inline const Map<interfaceEntry>& map() const
186  {
187  return *this;
188  }
189 
190 
191 public:
192  // Constructor
193 
194  //- Null construct
196  {}
197 
198  //- Size
199  label size() const
200  {
201  return map().size();
202  }
203 
204  //- Size
205  bool empty() const
206  {
207  return map().empty();
208  }
209 
210  //- Clear
211  void clear()
212  {
213  map().clear();
214  }
215 
216 
217  //- Add (valid) interface entry
218  bool add(const interfaceEntry& entry)
219  {
220  return (entry.valid() && map().set(entry.id, entry));
221  }
222 
223 
224  //- Scan available interface entries for one matching this boundary id
225  bool isInterface(label bndId)
226  {
227  forAllConstIters(map(), iter)
228  {
229  if (iter.val().inInterface(bndId))
230  {
231  return true;
232  }
233  }
234  return false;
235  }
236 
237 
238  //- Scan interface entries for one matching this boundary id
239  // return the canonical name
241  {
242  word ifname;
243  forAllConstIters(map(), iter)
244  {
245  ifname = iter.val().canonicalName(bndId);
246  if (!ifname.empty())
247  {
248  break;
249  }
250  }
251 
252  return ifname;
253  }
254 
255 
256  // IOstream Operators
257 
258  friend Ostream& operator<<
259  (
260  Ostream& os,
261  const interfaceDefinitions& defs
262  )
263  {
264  os << defs.map() << nl;
265  return os;
266  }
267 
268 };
269 
270 
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 
273 } // End namespace ccm
274 } // End namespace Foam
275 
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
277 
278 #endif
279 
280 // ************************************************************************* //
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:67
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::ccm::interfaceDefinitions::interfaceDefinitions
interfaceDefinitions()
Null construct.
Definition: ccmInterfaceDefinitions.H:195
Foam::ccm::interfaceDefinitions::size
label size() const
Size.
Definition: ccmInterfaceDefinitions.H:199
Foam::ccm::interfaceEntry::id
label id
The internal interface id.
Definition: ccmInterfaceDefinitions.H:60
Foam::ccm::interfaceDefinitions::isInterface
bool isInterface(label bndId)
Scan available interface entries for one matching this boundary id.
Definition: ccmInterfaceDefinitions.H:225
Foam::ccm::interfaceDefinitions::clear
void clear()
Clear.
Definition: ccmInterfaceDefinitions.H:211
Foam::ccm::interfaceEntry::canonicalName0
word canonicalName0() const
Canonical name for boundary 0.
Definition: ccmInterfaceDefinitions.H:126
Foam::ccm::interfaceEntry::interfaceEntry
interfaceEntry()
Construct null.
Definition: ccmInterfaceDefinitions.H:72
Foam::Map
A HashTable to objects of type <T> with a label key.
Definition: HashTableFwd.H:46
Foam::ccm::operator<<
Ostream & operator<<(Ostream &os, const interfaceEntry &entry)
Definition: ccmInterfaceDefinitions.H:158
Foam::ccm::interfaceEntry::bnd0
label bnd0
The first boundary.
Definition: ccmInterfaceDefinitions.H:63
Foam::ccm::interfaceEntry::valid
bool valid() const
True if all internal ids are non-negative.
Definition: ccmInterfaceDefinitions.H:119
Foam::ccm::interfaceEntry::canonicalName
word canonicalName(label bndId) const
Canonical name for boundary.
Definition: ccmInterfaceDefinitions.H:138
Map.H
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::ccm::interfaceEntry
A STARCCM interface definition is a pair of boundary ids.
Definition: ccmInterfaceDefinitions.H:54
Foam::ccm::interfaceDefinitions::interfaceName
word interfaceName(label bndId)
Scan interface entries for one matching this boundary id.
Definition: ccmInterfaceDefinitions.H:240
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::ccm::interfaceDefinitions::empty
bool empty() const
Size.
Definition: ccmInterfaceDefinitions.H:205
Foam::ccm::interfaceEntry::interfaceEntry
interfaceEntry(const label index)
Construct empty interface definition.
Definition: ccmInterfaceDefinitions.H:81
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::ccm::interfaceEntry::canonicalName1
word canonicalName1() const
Canonical name for boundary 1.
Definition: ccmInterfaceDefinitions.H:132
Ostream.H
Foam::nl
constexpr char nl
Definition: Ostream.H:372
forAllConstIters
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
Foam::ccm::interfaceDefinitions::add
bool add(const interfaceEntry &entry)
Add (valid) interface entry.
Definition: ccmInterfaceDefinitions.H:218
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
Foam::ccm::interfaceEntry::isInPlace
static bool isInPlace(const std::string &configurationType)
Check for in-place interfaces.
Definition: ccmInterfaceDefinitions.H:106
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::ccm::interfaceDefinitions
A list of available interface definitions.
Definition: ccmInterfaceDefinitions.H:175
Foam::ccm::interfaceEntry::bnd1
label bnd1
The second boundary.
Definition: ccmInterfaceDefinitions.H:66
Foam::ccm::interfaceEntry::inInterface
bool inInterface(label bndId) const
True if the boundary id is in this interface.
Definition: ccmInterfaceDefinitions.H:113