meshSubsetI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | cfMesh: A library for mesh generation
4  \\ / O peration |
5  \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6  \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of cfMesh.
10 
11  cfMesh is free software; you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by the
13  Free Software Foundation; either version 3 of the License, or (at your
14  option) any later version.
15 
16  cfMesh is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with cfMesh. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "meshSubset.H"
29 #include "labelList.H"
30 #include "IOstreams.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38 
40 :
41  name_(),
42  type_(UNKNOWN),
43  data_()
44 {}
45 
47 (
48  const word& name,
50 )
51 :
52  name_(name),
53  type_(t),
54  data_()
55 {}
56 
57 template<class ListType>
59 (
60  const word& name,
62  const ListType& elements
63 )
64 :
65  name_(name),
66  type_(type),
67  data_()
68 {
69  forAll(elements, i)
70  data_.insert(elements[i]);
71 }
72 
74 :
75  name_(ms.name_),
76  type_(ms.type_),
77  data_()
78 {
79  data_ = ms.data_;
80 }
81 
83 :
84  name_(),
85  type_(UNKNOWN),
86  data_()
87 {
88  is >> *this;
89 }
90 
92 {}
93 
94 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
95 
96 inline const word& meshSubset::name() const
97 {
98  return name_;
99 }
100 
101 inline label meshSubset::type() const
102 {
103  return type_;
104 }
105 
106 template<class ListType>
107 inline void meshSubset::containedElements(ListType& l) const
108 {
109  l.setSize(data_.size());
110 
111  label counter(0);
112  forAllConstIter(std::set<label>, data_, it)
113  l[counter++] = *it;
114 }
115 
116 inline void meshSubset::addElement(const label elmt)
117 {
118  data_.insert(elmt);
119 }
120 
121 inline void meshSubset::removeElement(const label elmt)
122 {
123  data_.erase(elmt);
124 }
125 
126 template<class ListType>
127 inline void meshSubset::updateSubset(const ListType& newLabels)
128 {
129  std::set<label> newData;
130 
131  forAllConstIter(std::set<label>, data_, it)
132  {
133  if( newLabels[*it] < 0 )
134  continue;
135 
136  newData.insert(newLabels[*it]);
137  }
138 
139  data_ = newData;
140 }
141 
142 inline void meshSubset::updateSubset(const VRWGraph& newLabels)
143 {
144  std::set<label> newData;
145 
146  forAllConstIter(std::set<label>, data_, it)
147  {
148  forAllRow(newLabels, *it, i)
149  newData.insert(newLabels(*it, i));
150  }
151 
152  data_ = newData;
153 }
154 
155 inline bool meshSubset::contains(const label elmt) const
156 {
157  return (data_.find(elmt) != data_.end());
158 }
159 
160 inline void meshSubset::operator=(const meshSubset& ms)
161 {
162  name_ = ms.name_;
163  type_ = ms.type_;
164 
165  data_.clear();
166  data_ = ms.data_;
167 }
168 
169 inline bool meshSubset::operator==(const meshSubset& ms) const
170 {
171  if( ms.name_ != name_ )
172  return false;
173  if( ms.type_ != ms.type_ )
174  return false;
175 
176  forAllConstIter(std::set<label>, data_, it)
177  if( ms.data_.find(*it) == ms.data_.end() )
178  return false;
179 
180  return true;
181 }
182 
183 inline bool meshSubset::operator!=(const meshSubset& ms) const
184 {
185  return !operator==(ms);
186 }
187 
188 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
189 
190 inline Ostream& operator<<(Ostream& os, const meshSubset& sel)
191 {
192  os.check("inline Ostream& operator<<(Ostream&, const meshSubset&)");
193 
194  os << sel.name_ << nl << sel.type_;
195 
196  labelList data(sel.data_.size());
197  label counter(0);
198  forAllConstIter(std::set<label>, sel.data_, it)
199  data[counter++] = *it;
200 
201  os << nl << data;
202 
203  return os;
204 }
205 
207 {
208  is.check("friend Istream& operator>>(Istream&, meshSubset&)");
209 
210  labelList data;
211  is >> sel.name_ >> sel.type_ >> data;
212 
213  sel.data_.clear();
214  forAll(data, i)
215  sel.data_.insert(data[i]);
216 
217  is.check("friend Istream& operator>>(Istream&, meshSubset&)");
218 
219  return is;
220 }
221 
222 
223 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
224 
225 } // End namespace Foam
226 
227 // ************************************************************************* //
meshSubset.H
Foam::meshSubset::operator!=
bool operator!=(const meshSubset &) const
Definition: meshSubsetI.H:183
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::meshSubset::subsetType_
subsetType_
Definition: meshSubset.H:72
Foam::meshSubset::data_
std::set< label > data_
labels of elements
Definition: meshSubset.H:66
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::meshSubset::name_
word name_
name of the given subset
Definition: meshSubset.H:59
Foam::meshSubset::name
const word & name() const
Return name.
Definition: meshSubsetI.H:96
Foam::meshSubset::updateSubset
void updateSubset(const ListType &)
Definition: meshSubsetI.H:127
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
Foam::meshSubset::contains
bool contains(const label) const
find if the element exists in the subset
Definition: meshSubsetI.H:155
Foam::meshSubset::~meshSubset
~meshSubset()
Definition: meshSubsetI.H:91
Foam::meshSubset
Definition: meshSubset.H:55
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:59
labelList.H
Foam::meshSubset::addElement
void addElement(const label)
add element label to subset
Definition: meshSubsetI.H:116
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::meshSubset::removeElement
void removeElement(const label)
remove element from subset
Definition: meshSubsetI.H:121
forAllRow
#define forAllRow(graph, rowI, index)
Definition: VRWGraph.H:277
Foam::operator<<
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:130
Foam::meshSubset::type_
label type_
type of subset
Definition: meshSubset.H:62
Foam::meshSubset::containedElements
void containedElements(ListType &) const
elements contained in the subset
Definition: meshSubsetI.H:107
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::meshSubset::operator==
bool operator==(const meshSubset &) const
Definition: meshSubsetI.H:169
Foam::meshSubset::meshSubset
meshSubset()
Null constructor.
Definition: meshSubsetI.H:39
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::operator>>
Istream & operator>>(Istream &, edgeMesh &)
Definition: edgeMeshIO.C:141
Foam::meshSubset::type
label type() const
Type of subset.
Definition: meshSubsetI.H:101
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::meshSubset::operator=
void operator=(const meshSubset &)
Definition: meshSubsetI.H:160
Foam::VRWGraph
Definition: VRWGraph.H:101
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:52
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47