1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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 <OpenFOAM/addToRunTimeSelectionTable.H>
29 #include <OpenFOAM/dictionary.H>
30 #include <OpenFOAM/ListOps.H>
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
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)
48 const labelList& idList = elemLists_[elemI];
54 if (id >= field.size() || std::isnan(field[id]))
64 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
66 Foam::ensightPart::ensightPart
80 Foam::ensightPart::ensightPart
83 const string& partDescription
87 name_(partDescription),
97 Foam::ensightPart::ensightPart
100 const string& partDescription,
101 const polyMesh& pMesh
105 name_(partDescription),
115 Foam::ensightPart::ensightPart(const ensightPart& part)
117 number_(part.number_),
119 elemLists_(part.elemLists_),
120 offset_(part.offset_),
122 isCellData_(part.isCellData_),
124 meshPtr_(part.meshPtr_)
128 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
130 Foam::autoPtr<Foam::ensightPart> Foam::ensightPart::New(Istream& is)
134 istreamConstructorTable::iterator cstrIter =
135 istreamConstructorTablePtr_->find(partType);
137 if (cstrIter == istreamConstructorTablePtr_->end())
141 "ensightPart::New(Istream&)",
143 ) << "unknown ensightPart type " << partType << endl << endl
144 << "Valid ensightPart types are :" << endl
145 << istreamConstructorTablePtr_->toc()
146 << exit(FatalIOError);
149 return autoPtr<ensightPart>(cstrIter()(is));
153 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
155 Foam::ensightPart::~ensightPart()
159 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
161 void Foam::ensightPart::reconstruct(Istream& 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)
173 word key(elementTypes()[elemI]);
175 elemLists_[elemI].clear();
176 dict.readIfPresent(key, elemLists_[elemI]);
178 size_ += elemLists_[elemI].size();
181 is.check("ensightPart::reconstruct(Istream&)");
185 void Foam::ensightPart::renumber(labelList const& origId)
187 // transform to global values first
190 forAll(elemLists_, elemI)
192 labelList& idList = elemLists_[elemI];
195 idList[i] += offset_;
204 forAll(elemLists_, elemI)
206 inplaceRenumber(origId, elemLists_[elemI]);
212 // ************************ vim: set sw=4 sts=4 et: ************************ //