initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / conversion / ensight / part / ensightPart.C
blobc02f6c9896bb1994b898683896e64c61d7bb6402
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*----------------------------------------------------------------------------*/
27 #include "ensightPart.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "dictionary.H"
30 #include "ListOps.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 namespace Foam
35    defineTypeNameAndDebug(ensightPart, 0);
36    defineTemplateTypeNameAndDebug(IOPtrList<ensightPart>, 0);
37    defineRunTimeSelectionTable(ensightPart, istream);
40 Foam::List<Foam::word> Foam::ensightPart::elemTypes_(0);
42 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
44 bool Foam::ensightPart::isFieldDefined(const List<scalar>& field) const
46     forAll(elemLists_, elemI)
47     {
48         const labelList& idList = elemLists_[elemI];
50         forAll(idList, i)
51         {
52             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     meshPtr_(0)
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     meshPtr_(0)
97 Foam::ensightPart::ensightPart
99     label partNumber,
100     const string& partDescription,
101     const polyMesh& pMesh
104     number_(partNumber),
105     name_(partDescription),
106     elemLists_(0),
107     offset_(0),
108     size_(0),
109     isCellData_(true),
110     matId_(0),
111     meshPtr_(&pMesh)
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     meshPtr_(part.meshPtr_)
128 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
130 Foam::autoPtr<Foam::ensightPart> Foam::ensightPart::New(Istream& is)
132     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 " << partType << endl << endl
144             << "Valid ensightPart types are :" << endl
145             << istreamConstructorTablePtr_->toc()
146             << exit(FatalIOError);
147     }
149     return autoPtr<ensightPart>(cstrIter()(is));
153 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
155 Foam::ensightPart::~ensightPart()
159 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
161 void Foam::ensightPart::reconstruct(Istream& is)
163     dictionary dict(is);
164     dict.lookup("id") >> number_;
165     dict.lookup("name") >> name_;
166     dict.readIfPresent("offset", offset_);
168     // populate elemLists_
169     elemLists_.setSize(elementTypes().size());
171     forAll(elementTypes(), elemI)
172     {
173         word key(elementTypes()[elemI]);
175         elemLists_[elemI].clear();
176         dict.readIfPresent(key, elemLists_[elemI]);
178         size_ += elemLists_[elemI].size();
179     }
181     is.check("ensightPart::reconstruct(Istream&)");
185 void Foam::ensightPart::renumber(labelList const& origId)
187     // transform to global values first
188     if (offset_)
189     {
190         forAll(elemLists_, elemI)
191         {
192             labelList& idList = elemLists_[elemI];
193             forAll(idList, i)
194             {
195                 idList[i] += offset_;
196             }
197         }
199         offset_ = 0;
200     }
202     if (origId.size())
203     {
204         forAll(elemLists_, elemI)
205         {
206             inplaceRenumber(origId, elemLists_[elemI]);
207         }
208     }
212 // ************************************************************************* //