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
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 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 
192 public:
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
219  bool add(const interfaceEntry& 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 // ************************************************************************* //
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:65
Foam::ccm::interfaceDefinitions::interfaceDefinitions
interfaceDefinitions()
Null construct.
Definition: ccmInterfaceDefinitions.H:196
Foam::ccm::interfaceDefinitions::size
label size() const
Size.
Definition: ccmInterfaceDefinitions.H:200
Foam::ccm::interfaceEntry::id
label id
The internal interface id.
Definition: ccmInterfaceDefinitions.H:61
Foam::ccm::interfaceDefinitions::isInterface
bool isInterface(label bndId)
Scan available interface entries for one matching this boundary id.
Definition: ccmInterfaceDefinitions.H:226
Foam::ccm::interfaceDefinitions::clear
void clear()
Clear.
Definition: ccmInterfaceDefinitions.H:212
Foam::ccm::interfaceEntry::canonicalName0
word canonicalName0() const
Canonical name for boundary 0.
Definition: ccmInterfaceDefinitions.H:127
Foam::ccm::interfaceEntry::interfaceEntry
interfaceEntry()
Construct null.
Definition: ccmInterfaceDefinitions.H:73
Foam::Map
A HashTable to objects of type <T> with a label key.
Definition: lumpedPointController.H:69
Foam::ccm::operator<<
Ostream & operator<<(Ostream &os, const interfaceEntry &entry)
Definition: ccmInterfaceDefinitions.H:159
Foam::ccm::interfaceEntry::bnd0
label bnd0
The first boundary.
Definition: ccmInterfaceDefinitions.H:64
Foam::ccm::interfaceEntry::valid
bool valid() const
True if all internal ids are non-negative.
Definition: ccmInterfaceDefinitions.H:120
Foam::ccm::interfaceEntry::canonicalName
word canonicalName(label bndId) const
Canonical name for boundary.
Definition: ccmInterfaceDefinitions.H:139
Map.H
Foam::ccm::interfaceEntry
A STARCCM interface definition is a pair of boundary ids.
Definition: ccmInterfaceDefinitions.H:55
Foam::ccm::interfaceDefinitions::interfaceName
word interfaceName(label bndId)
Scan interface entries for one matching this boundary id.
Definition: ccmInterfaceDefinitions.H:241
Foam::ccm::interfaceDefinitions::empty
bool empty() const
Size.
Definition: ccmInterfaceDefinitions.H:206
Foam::ccm::interfaceEntry::interfaceEntry
interfaceEntry(const label index)
Construct empty interface definition.
Definition: ccmInterfaceDefinitions.H:82
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::ccm::interfaceEntry::canonicalName1
word canonicalName1() const
Canonical name for boundary 1.
Definition: ccmInterfaceDefinitions.H:133
Ostream.H
Foam::nl
constexpr char nl
Definition: Ostream.H:404
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:219
Foam::word::null
static const word null
An empty word.
Definition: word.H:80
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::ccm::interfaceEntry::isInPlace
static bool isInPlace(const std::string &configurationType)
Check for in-place interfaces.
Definition: ccmInterfaceDefinitions.H:107
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:176
Foam::ccm::interfaceEntry::bnd1
label bnd1
The second boundary.
Definition: ccmInterfaceDefinitions.H:67
Foam::ccm::interfaceEntry::inInterface
bool inInterface(label bndId) const
True if the boundary id is in this interface.
Definition: ccmInterfaceDefinitions.H:114