Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / conversion / ensight / part / ensightPart.C
blob303c417ac753e51caabd0beefd0ee5d23c0d44eb
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2008-2011 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by
13     the Free Software Foundation, either version 3 of the License, or
14     (at your option) any later version.
16     OpenFOAM 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 OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
24 \*----------------------------------------------------------------------------*/
26 #include "ensightPart.H"
27 #include "dictionary.H"
28 #include "ListOps.H"
29 #include "addToRunTimeSelectionTable.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 namespace Foam
34     defineTypeNameAndDebug(ensightPart, 0);
35     defineTemplateTypeNameAndDebug(IOPtrList<ensightPart>, 0);
36     defineRunTimeSelectionTable(ensightPart, istream);
39 const Foam::List<Foam::word> Foam::ensightPart::elemTypes_(0);
42 // * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //
44 bool Foam::ensightPart::isFieldDefined(const List<scalar>& field) const
46     forAll(elemLists_, elemI)
47     {
48         const labelUList& idList = elemLists_[elemI];
50         forAll(idList, i)
51         {
52             const label id = idList[i];
54             if (id >= field.size() || isnan(field[id]))
55             {
56                 return false;
57             }
58         }
59     }
60     return true;
64 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
66 Foam::ensightPart::ensightPart
69     number_(0),
70     name_(""),
71     elemLists_(0),
72     offset_(0),
73     size_(0),
74     isCellData_(true),
75     matId_(0),
76     points_(pointField::null())
80 Foam::ensightPart::ensightPart
82     label partNumber,
83     const string& partDescription
86     number_(partNumber),
87     name_(partDescription),
88     elemLists_(0),
89     offset_(0),
90     size_(0),
91     isCellData_(true),
92     matId_(0),
93     points_(pointField::null())
97 Foam::ensightPart::ensightPart
99     label partNumber,
100     const string& partDescription,
101     const pointField& points
104     number_(partNumber),
105     name_(partDescription),
106     elemLists_(0),
107     offset_(0),
108     size_(0),
109     isCellData_(true),
110     matId_(0),
111     points_(points)
115 Foam::ensightPart::ensightPart(const ensightPart& part)
117     number_(part.number_),
118     name_(part.name_),
119     elemLists_(part.elemLists_),
120     offset_(part.offset_),
121     size_(part.size_),
122     isCellData_(part.isCellData_),
123     matId_(part.matId_),
124     points_(part.points_)
128 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
130 Foam::autoPtr<Foam::ensightPart> Foam::ensightPart::New(Istream& is)
132     const word partType(is);
134     istreamConstructorTable::iterator cstrIter =
135         istreamConstructorTablePtr_->find(partType);
137     if (cstrIter == istreamConstructorTablePtr_->end())
138     {
139         FatalIOErrorIn
140         (
141             "ensightPart::New(Istream&)",
142             is
143         )   << "unknown ensightPart type "
144             << partType << nl << nl
145             << "Valid ensightPart types are :" << endl
146             << istreamConstructorTablePtr_->sortedToc()
147             << exit(FatalIOError);
148     }
150     return autoPtr<ensightPart>(cstrIter()(is));
154 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
156 Foam::ensightPart::~ensightPart()
160 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
162 void Foam::ensightPart::renumber(const labelUList& origId)
164     // transform to global values first
165     if (offset_)
166     {
167         forAll(elemLists_, elemI)
168         {
169             labelList& idList = elemLists_[elemI];
170             forAll(idList, i)
171             {
172                 idList[i] += offset_;
173             }
174         }
176         offset_ = 0;
177     }
179     if (origId.size())
180     {
181         forAll(elemLists_, elemI)
182         {
183             inplaceRenumber(origId, elemLists_[elemI]);
184         }
185     }
189 // ************************************************************************* //