Forward compatibility: flex
[foam-extend-3.2.git] / src / mesh / cfMesh / utilities / meshes / polyMeshGen / polyMeshGenPoints.C
blob35fc9fbee77c3632613da070fe2ee83555760bcc
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.
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.
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.
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/>.
24 Description
26 \*---------------------------------------------------------------------------*/
28 #include "polyMeshGenPoints.H"
29 #include "pointIOField.H"
30 #include "IOobjectList.H"
31 #include "pointSet.H"
33 namespace Foam
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 // Constructors
38 //- Null constructor
39 polyMeshGenPoints::polyMeshGenPoints(const Time& runTime)
41     runTime_(runTime),
42     points_
43     (
44         IOobject
45         (
46             "points",
47             runTime.constant(),
48             "polyMesh",
49             runTime
50         ),
51         0
52     ),
53     pointSubsets_()
57 //- Construct from time and points
58 polyMeshGenPoints::polyMeshGenPoints
60     const Time& runTime,
61     const pointField& points
64     runTime_(runTime),
65     points_
66     (
67         IOobject
68         (
69             "points",
70             runTime.constant(),
71             "polyMesh",
72             runTime
73         ),
74         points
75     ),
76     pointSubsets_()
80 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
81 // Destructor
82 polyMeshGenPoints::~polyMeshGenPoints()
86 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
88 label polyMeshGenPoints::addPointSubset(const word& subsetName)
90     label id = pointSubsetIndex(subsetName);
91     if( id >= 0 )
92     {
93         Warning << "Point subset " << subsetName << " already exists!" << endl;
94         return id;
95     }
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);
102     pointSubsets_.insert
103     (
104         std::make_pair
105         (
106             id,
107             meshSubset(subsetName, meshSubset::POINTSUBSET)
108         )
109     );
111     return id;
114 void polyMeshGenPoints::removePointSubset(const label subsetID)
116     if( pointSubsets_.find(subsetID) == pointSubsets_.end() )
117         return;
119     pointSubsets_.erase(subsetID);
122 word polyMeshGenPoints::pointSubsetName(const label subsetID) const
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     }
132     return it->second.name();
135 label polyMeshGenPoints::pointSubsetIndex(const word& subsetName) const
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     }
144     return -1;
147 void polyMeshGenPoints::read()
149     pointIOField pts
150     (
151         IOobject
152         (
153             "points",
154             runTime_.constant(),
155             "polyMesh",
156             runTime_,
157             IOobject::MUST_READ
158         )
159     );
160     points_ = pts;
162     //- read point subsets
163     IOobjectList allSets
164     (
165         runTime_,
166         runTime_.constant(),
167         "polyMesh/sets"
168     );
170     wordList setNames = allSets.names("pointSet");
171     forAll(setNames, setI)
172     {
173         IOobject* obj = allSets.lookup(setNames[setI]);
175         pointSet pSet(*obj);
177         const labelList content = pSet.toc();
178         const label id = addPointSubset(setNames[setI]);
180         pointSubsets_[id].updateSubset(content);
181     }
184 void polyMeshGenPoints::write() const
186     points_.write();
188     std::map<label, meshSubset>::const_iterator setIt;
189     labelLongList containedElements;
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_,
202                 IOobject::NO_READ,
203                 IOobject::AUTO_WRITE
204             )
205         );
207         setIt->second.containedElements(containedElements);
209         forAll(containedElements, i)
210             set.insert(containedElements[i]);
211         set.write();
212     }
215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
217 } // End namespace Foam
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //