FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

ensightPart.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*----------------------------------------------------------------------------*/
00025 
00026 #include "ensightPart.H"
00027 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00028 #include <OpenFOAM/dictionary.H>
00029 #include <OpenFOAM/ListOps.H>
00030 
00031 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00032 namespace Foam
00033 {
00034    defineTypeNameAndDebug(ensightPart, 0);
00035    defineTemplateTypeNameAndDebug(IOPtrList<ensightPart>, 0);
00036    defineRunTimeSelectionTable(ensightPart, istream);
00037 }
00038 
00039 Foam::List<Foam::word> Foam::ensightPart::elemTypes_(0);
00040 
00041 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00042 
00043 bool Foam::ensightPart::isFieldDefined(const List<scalar>& field) const
00044 {
00045     forAll(elemLists_, elemI)
00046     {
00047         const labelList& idList = elemLists_[elemI];
00048 
00049         forAll(idList, i)
00050         {
00051             label id = idList[i];
00052 
00053             if (id >= field.size() || std::isnan(field[id]))
00054             {
00055                 return false;
00056             }
00057         }
00058     }
00059     return true;
00060 }
00061 
00062 
00063 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00064 
00065 Foam::ensightPart::ensightPart
00066 ()
00067 :
00068     number_(0),
00069     name_(""),
00070     elemLists_(0),
00071     offset_(0),
00072     size_(0),
00073     isCellData_(true),
00074     matId_(0),
00075     meshPtr_(0)
00076 {}
00077 
00078 
00079 Foam::ensightPart::ensightPart
00080 (
00081     label partNumber,
00082     const string& partDescription
00083 )
00084 :
00085     number_(partNumber),
00086     name_(partDescription),
00087     elemLists_(0),
00088     offset_(0),
00089     size_(0),
00090     isCellData_(true),
00091     matId_(0),
00092     meshPtr_(0)
00093 {}
00094 
00095 
00096 Foam::ensightPart::ensightPart
00097 (
00098     label partNumber,
00099     const string& partDescription,
00100     const polyMesh& pMesh
00101 )
00102 :
00103     number_(partNumber),
00104     name_(partDescription),
00105     elemLists_(0),
00106     offset_(0),
00107     size_(0),
00108     isCellData_(true),
00109     matId_(0),
00110     meshPtr_(&pMesh)
00111 {}
00112 
00113 
00114 Foam::ensightPart::ensightPart(const ensightPart& part)
00115 :
00116     number_(part.number_),
00117     name_(part.name_),
00118     elemLists_(part.elemLists_),
00119     offset_(part.offset_),
00120     size_(part.size_),
00121     isCellData_(part.isCellData_),
00122     matId_(part.matId_),
00123     meshPtr_(part.meshPtr_)
00124 {}
00125 
00126 
00127 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
00128 
00129 Foam::autoPtr<Foam::ensightPart> Foam::ensightPart::New(Istream& is)
00130 {
00131     word partType(is);
00132 
00133     istreamConstructorTable::iterator cstrIter =
00134         istreamConstructorTablePtr_->find(partType);
00135 
00136     if (cstrIter == istreamConstructorTablePtr_->end())
00137     {
00138         FatalIOErrorIn
00139         (
00140             "ensightPart::New(Istream&)",
00141             is
00142         )   << "unknown ensightPart type " << partType << endl << endl
00143             << "Valid ensightPart types are :" << endl
00144             << istreamConstructorTablePtr_->sortedToc()
00145             << exit(FatalIOError);
00146     }
00147 
00148     return autoPtr<ensightPart>(cstrIter()(is));
00149 }
00150 
00151 
00152 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00153 
00154 Foam::ensightPart::~ensightPart()
00155 {}
00156 
00157 
00158 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00159 
00160 void Foam::ensightPart::reconstruct(Istream& is)
00161 {
00162     dictionary dict(is);
00163     dict.lookup("id") >> number_;
00164     dict.lookup("name") >> name_;
00165     dict.readIfPresent("offset", offset_);
00166 
00167     // populate elemLists_
00168     elemLists_.setSize(elementTypes().size());
00169 
00170     forAll(elementTypes(), elemI)
00171     {
00172         word key(elementTypes()[elemI]);
00173 
00174         elemLists_[elemI].clear();
00175         dict.readIfPresent(key, elemLists_[elemI]);
00176 
00177         size_ += elemLists_[elemI].size();
00178     }
00179 
00180     is.check("ensightPart::reconstruct(Istream&)");
00181 }
00182 
00183 
00184 void Foam::ensightPart::renumber(labelList const& origId)
00185 {
00186     // transform to global values first
00187     if (offset_)
00188     {
00189         forAll(elemLists_, elemI)
00190         {
00191             labelList& idList = elemLists_[elemI];
00192             forAll(idList, i)
00193             {
00194                 idList[i] += offset_;
00195             }
00196         }
00197 
00198         offset_ = 0;
00199     }
00200 
00201     if (origId.size())
00202     {
00203         forAll(elemLists_, elemI)
00204         {
00205             inplaceRenumber(origId, elemLists_[elemI]);
00206         }
00207     }
00208 }
00209 
00210 
00211 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines