polyMeshGenPoints.C
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 "polyMeshGenPoints.H"
29 #include "pointIOField.H"
30 #include "IOobjectList.H"
31 #include "pointSet.H"
32 
33 namespace Foam
34 {
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 // Constructors
38 //- Null constructor
40 :
41  runTime_(runTime),
42  points_
43  (
44  IOobject
45  (
46  "points",
47  runTime.constant(),
48  "polyMesh",
49  runTime
50  ),
51  0
52  ),
53  pointSubsets_()
54 {
55 }
56 
57 //- Construct from time and points
59 (
60  const Time& runTime,
61  const pointField& points
62 )
63 :
64  runTime_(runTime),
65  points_
66  (
67  IOobject
68  (
69  "points",
70  runTime.constant(),
71  "polyMesh",
72  runTime
73  ),
74  points
75  ),
76  pointSubsets_()
77 {
78 }
79 
80 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
81 // Destructor
83 {
84 }
85 
86 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
87 
89 {
90  label id = pointSubsetIndex(subsetName);
91  if( id >= 0 )
92  {
93  Warning << "Point subset " << subsetName << " already exists!" << endl;
94  return id;
95  }
96 
97  id = 0;
98  std::map<label, meshSubset>::const_iterator it;
99  for(it=pointSubsets_.begin();it!=pointSubsets_.end();++it)
100  id = Foam::max(id, it->first+1);
101 
102  pointSubsets_.insert
103  (
104  std::make_pair
105  (
106  id,
108  )
109  );
110 
111  return id;
112 }
113 
115 {
116  if( pointSubsets_.find(subsetID) == pointSubsets_.end() )
117  return;
118 
119  pointSubsets_.erase(subsetID);
120 }
121 
123 {
124  std::map<label, meshSubset>::const_iterator it =
125  pointSubsets_.find(subsetID);
126  if( it == pointSubsets_.end() )
127  {
128  Warning << "Subset " << subsetID << " is not a point subset" << endl;
129  return word();
130  }
131 
132  return it->second.name();
133 }
134 
136 {
137  std::map<label, meshSubset>::const_iterator it;
138  for(it=pointSubsets_.begin();it!=pointSubsets_.end();++it)
139  {
140  if( it->second.name() == subsetName )
141  return it->first;
142  }
143 
144  return -1;
145 }
146 
148 {
149  pointIOField pts
150  (
151  IOobject
152  (
153  "points",
154  runTime_.constant(),
155  "polyMesh",
156  runTime_,
158  )
159  );
160  points_ = pts;
161 
162  //- read point subsets
163  IOobjectList allSets
164  (
165  runTime_,
166  runTime_.constant(),
167  "polyMesh/sets"
168  );
169 
170  wordList setNames = allSets.names("pointSet");
171  forAll(setNames, setI)
172  {
173  IOobject* obj = allSets.lookup(setNames[setI]);
174 
175  pointSet pSet(*obj);
176 
177  const labelList content = pSet.toc();
178  const label id = addPointSubset(setNames[setI]);
179 
180  pointSubsets_[id].updateSubset(content);
181  }
182 }
183 
185 {
186  points_.write();
187 
188  std::map<label, meshSubset>::const_iterator setIt;
189  labelLongList containedElements;
190 
191  //- write point selections
192  for(setIt=pointSubsets_.begin();setIt!=pointSubsets_.end();++setIt)
193  {
194  pointSet set
195  (
196  IOobject
197  (
198  setIt->second.name(),
199  runTime_.constant(),
200  "polyMesh/sets",
201  runTime_,
204  )
205  );
206 
207  setIt->second.containedElements(containedElements);
208 
209  forAll(containedElements, i)
210  set.insert(containedElements[i]);
211  set.write();
212  }
213 }
214 
215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216 
217 } // End namespace Foam
218 
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::polyMeshGenPoints::polyMeshGenPoints
polyMeshGenPoints(const polyMeshGenPoints &)
Foam::polyMeshGenPoints::~polyMeshGenPoints
~polyMeshGenPoints()
Definition: polyMeshGenPoints.C:82
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::IOField< vector >
Foam::IOobject::AUTO_WRITE
@ AUTO_WRITE
Definition: IOobject.H:117
Foam::HashTable::toc
List< Key > toc() const
Return the table of contents.
Definition: HashTable.C:201
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::Warning
messageStream Warning
Foam::polyMeshGenPoints::removePointSubset
void removePointSubset(const label)
Definition: polyMeshGenPoints.C:114
Foam::regIOobject::write
virtual bool write() const
Write using setting from DB.
Definition: regIOobjectWrite.C:126
pointIOField.H
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:108
IOobjectList.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::IOobjectList::names
wordList names() const
Return the list of names of the IOobjects.
Definition: IOobjectList.C:221
Foam::polyMeshGenPoints::pointSubsetIndex
label pointSubsetIndex(const word &) const
Definition: polyMeshGenPoints.C:135
Foam::polyMeshGenPoints::write
void write() const
Definition: polyMeshGenPoints.C:184
Foam::polyMeshGenPoints::read
void read()
Definition: polyMeshGenPoints.C:147
constant
Constant dispersed-phase particle diameter model.
Foam::LongList< label >
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
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::IOobject::NO_READ
@ NO_READ
Definition: IOobject.H:111
Foam::polyMeshGenPoints::pointSubsets_
std::map< label, meshSubset > pointSubsets_
map of point subsets
Definition: polyMeshGenPoints.H:67
Foam::IOobjectList::lookup
IOobject * lookup(const word &name) const
Lookup a given name and return IOobject ptr if found else NULL.
Definition: IOobjectList.C:128
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:50
Foam::meshSubset::POINTSUBSET
@ POINTSUBSET
Definition: meshSubset.H:77
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::pointSet
A set of point labels.
Definition: pointSet.H:48
Foam::polyMeshGenPoints::pointSubsetName
word pointSubsetName(const label) const
Definition: polyMeshGenPoints.C:122
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::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePaths.H:130
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::HashSet::insert
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:116
Foam::polyMeshGenPoints::runTime_
const Time & runTime_
reference to the Time registry
Definition: polyMeshGenPoints.H:61
Foam::polyMeshGenPoints::points_
pointFieldPMG points_
list of vertices
Definition: polyMeshGenPoints.H:64
polyMeshGenPoints.H
Foam::polyMeshGenPoints::addPointSubset
label addPointSubset(const word &)
point subsets
Definition: polyMeshGenPoints.C:88
pointSet.H