zoneIdentifier.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) 2021-2023 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 \*---------------------------------------------------------------------------*/
27 
28 #include "zoneIdentifier.H"
29 #include "dictionary.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
34 :
35  name_(),
36  index_(0)
37 {}
38 
39 
41 (
42  const word& name,
43  const label index
44 )
45 :
46  name_(name),
47  index_(index)
48 {}
49 
50 
52 (
53  const word& name,
54  const label index,
55  const word& physicalType,
56  const wordList& inGroups
57 )
58 :
59  name_(name),
60  index_(index),
61  physicalType_(physicalType),
62  inGroups_(inGroups)
63 {}
64 
65 
67 (
68  const word& name,
69  const dictionary& dict,
70  const label index
71 )
72 :
73  zoneIdentifier(name, index)
74 {
75  dict.readIfPresent("physicalType", physicalType_);
76  dict.readIfPresent("inGroups", inGroups_);
77 }
78 
79 
81 (
82  const zoneIdentifier& ident,
83  const label newIndex
84 )
85 :
86  zoneIdentifier(ident)
87 {
88  if (newIndex >= 0)
89  {
90  index_ = newIndex;
91  }
92 }
93 
94 
96 (
97  zoneIdentifier&& ident,
98  const label newIndex
99 )
100 :
101  zoneIdentifier(std::move(ident))
102 {
103  if (newIndex >= 0)
104  {
105  index_ = newIndex;
106  }
107 }
108 
109 
110 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
111 
112 void Foam::zoneIdentifier::removeGroup(const word& name)
113 {
114  label idx = name.empty() ? -1 : inGroups_.find(name);
115 
116  if (idx >= 0)
117  {
118  for (label i = idx + 1; i < inGroups_.size(); ++i)
119  {
120  if (inGroups_[i] != name)
121  {
122  inGroups_[idx] = std::move(inGroups_[i]);
123  ++idx;
124  }
125  }
126  inGroups_.resize(idx);
127  }
128 }
129 
130 
131 void Foam::zoneIdentifier::write(Ostream& os) const
132 {
133  if (!physicalType_.empty())
134  {
135  os.writeEntry("physicalType", physicalType_);
136  }
137 
138  if (!inGroups_.empty())
139  {
140  os.writeKeyword("inGroups");
141  inGroups_.writeList(os, 0); // Flat output
143  }
144 }
145 
146 
147 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
148 
149 Foam::Ostream& Foam::operator<<(Ostream& os, const zoneIdentifier& ident)
150 {
151  ident.write(os);
153  return os;
154 }
155 
156 
157 // ************************************************************************* //
dictionary dict
zoneIdentifier()
Default construct: name="", index=0.
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
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:321
void removeGroup(const word &name)
Remove group for the zone.
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.
void write(Ostream &os) const
Write (physicalType, inGroups) dictionary entries (without surrounding braces)
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
Identifies a mesh zone by name and index, with optional physical type and group information.
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