Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / conversion / ensight / part / ensightPart.C
blob99a110ef727a1c75b7ccb06b78762e780240d405
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*----------------------------------------------------------------------------*/
26 #include "ensightPart.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "dictionary.H"
29 #include "ListOps.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 namespace Foam
34    defineTypeNameAndDebug(ensightPart, 0);
35    defineTemplateTypeNameAndDebug(IOPtrList<ensightPart>, 0);
36    defineRunTimeSelectionTable(ensightPart, istream);
39 Foam::List<Foam::word> Foam::ensightPart::elemTypes_(0);
41 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
43 bool Foam::ensightPart::isFieldDefined(const List<scalar>& field) const
45     forAll(elemLists_, elemI)
46     {
47         const labelList& idList = elemLists_[elemI];
49         forAll(idList, i)
50         {
51             label id = idList[i];
53 #           ifndef Intel
54             if (id >= field.size() || std::isnan(field[id]))
55 #           else
56             if (id >= field.size())
57 #           endif
58             {
59                 return false;
60             }
61         }
62     }
63     return true;
67 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
69 Foam::ensightPart::ensightPart
72     number_(0),
73     name_(""),
74     elemLists_(0),
75     offset_(0),
76     size_(0),
77     isCellData_(true),
78     matId_(0),
79     meshPtr_(0)
83 Foam::ensightPart::ensightPart
85     label partNumber,
86     const string& partDescription
89     number_(partNumber),
90     name_(partDescription),
91     elemLists_(0),
92     offset_(0),
93     size_(0),
94     isCellData_(true),
95     matId_(0),
96     meshPtr_(0)
100 Foam::ensightPart::ensightPart
102     label partNumber,
103     const string& partDescription,
104     const polyMesh& pMesh
107     number_(partNumber),
108     name_(partDescription),
109     elemLists_(0),
110     offset_(0),
111     size_(0),
112     isCellData_(true),
113     matId_(0),
114     meshPtr_(&pMesh)
118 Foam::ensightPart::ensightPart(const ensightPart& part)
120     number_(part.number_),
121     name_(part.name_),
122     elemLists_(part.elemLists_),
123     offset_(part.offset_),
124     size_(part.size_),
125     isCellData_(part.isCellData_),
126     matId_(part.matId_),
127     meshPtr_(part.meshPtr_)
131 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
133 Foam::autoPtr<Foam::ensightPart> Foam::ensightPart::New(Istream& is)
135     word partType(is);
137     istreamConstructorTable::iterator cstrIter =
138         istreamConstructorTablePtr_->find(partType);
140     if (cstrIter == istreamConstructorTablePtr_->end())
141     {
142         FatalIOErrorIn
143         (
144             "ensightPart::New(Istream&)",
145             is
146         )   << "unknown ensightPart type " << partType << endl << endl
147             << "Valid ensightPart types are :" << endl
148             << istreamConstructorTablePtr_->sortedToc()
149             << exit(FatalIOError);
150     }
152     return autoPtr<ensightPart>(cstrIter()(is));
156 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
158 Foam::ensightPart::~ensightPart()
162 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
164 void Foam::ensightPart::reconstruct(Istream& is)
166     dictionary dict(is);
167     dict.lookup("id") >> number_;
168     dict.lookup("name") >> name_;
169     dict.readIfPresent("offset", offset_);
171     // populate elemLists_
172     elemLists_.setSize(elementTypes().size());
174     forAll(elementTypes(), elemI)
175     {
176         word key(elementTypes()[elemI]);
178         elemLists_[elemI].clear();
179         dict.readIfPresent(key, elemLists_[elemI]);
181         size_ += elemLists_[elemI].size();
182     }
184     is.check("ensightPart::reconstruct(Istream&)");
188 void Foam::ensightPart::renumber(labelList const& origId)
190     // transform to global values first
191     if (offset_)
192     {
193         forAll(elemLists_, elemI)
194         {
195             labelList& idList = elemLists_[elemI];
196             forAll(idList, i)
197             {
198                 idList[i] += offset_;
199             }
200         }
202         offset_ = 0;
203     }
205     if (origId.size())
206     {
207         forAll(elemLists_, elemI)
208         {
209             inplaceRenumber(origId, elemLists_[elemI]);
210         }
211     }
215 // ************************************************************************* //