patchIdentifier.C
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) 2011-2013 OpenFOAM Foundation
9  Copyright (C) 2020-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "patchIdentifier.H"
30 #include "dictionary.H"
31 
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 
35 :
36  name_(),
37  index_(0)
38 {}
39 
40 
42 (
43  const word& name,
44  const label index
45 )
46 :
47  name_(name),
48  index_(index)
49 {}
50 
51 
53 (
54  const word& name,
55  const label index,
56  const word& physicalType,
57  const wordList& inGroups
58 )
59 :
60  name_(name),
61  index_(index),
62  physicalType_(physicalType),
63  inGroups_(inGroups)
64 {}
65 
66 
68 (
69  const word& name,
70  const dictionary& dict,
71  const label index
72 )
73 :
74  patchIdentifier(name, index)
75 {
76  dict.readIfPresent("physicalType", physicalType_);
77  dict.readIfPresent("inGroups", inGroups_);
78 }
79 
80 
82 (
83  const patchIdentifier& ident,
84  const label newIndex
85 )
86 :
87  patchIdentifier(ident)
88 {
89  if (newIndex >= 0)
90  {
91  index_ = newIndex;
92  }
93 }
94 
95 
97 (
98  patchIdentifier&& ident,
99  const label newIndex
100 )
101 :
102  patchIdentifier(std::move(ident))
103 {
104  if (newIndex >= 0)
105  {
106  index_ = newIndex;
107  }
108 }
109 
110 
111 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
112 
114 {
115  label idx = name.empty() ? -1 : inGroups_.find(name);
116 
117  if (idx >= 0)
118  {
119  for (label i = idx + 1; i < inGroups_.size(); ++i)
120  {
121  if (inGroups_[i] != name)
122  {
123  inGroups_[idx] = std::move(inGroups_[i]);
124  ++idx;
125  }
126  }
127  inGroups_.resize(idx);
128  }
129 }
130 
131 
132 void Foam::patchIdentifier::write(Ostream& os) const
133 {
134  if (!physicalType_.empty())
135  {
136  os.writeEntry("physicalType", physicalType_);
137  }
138 
139  if (!inGroups_.empty())
140  {
141  os.writeKeyword("inGroups");
142  inGroups_.writeList(os, 0); // Flat output
144  }
145 }
146 
147 
148 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
149 
150 Foam::Ostream& Foam::operator<<(Ostream& os, const patchIdentifier& ident)
151 {
152  ident.write(os);
154  return os;
155 }
156 
157 
158 // ************************************************************************* //
dictionary dict
void removeGroup(const word &name)
Remove group for the patch.
void write(Ostream &os) const
Write (physicalType, inGroups) dictionary entries (without surrounding braces)
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:45
Identifies a patch by name and index, with optional physical type and group information.
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:321
patchIdentifier()
Default construct: name="", index=0.
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
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
virtual Ostream & endEntry()
Write end entry (&#39;;&#39;) followed by newline.
Definition: Ostream.C:117
virtual Ostream & writeKeyword(const keyType &kw)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:60