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

ensightPartIO.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 Description
00025     Output for ensightPart
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "ensightPart.H"
00030 #include <OpenFOAM/dictionary.H>
00031 #include <OpenFOAM/IOstreams.H>
00032 
00033 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00034 
00035 void Foam::ensightPart::writeHeader
00036 (
00037     ensightFile& os,
00038     bool withDescription
00039 ) const
00040 {
00041     os.write("part");
00042     os.newline();
00043 
00044     os.write(number() + 1);   // Ensight starts with 1
00045     os.newline();
00046 
00047     if (withDescription)
00048     {
00049         os.write(name());
00050         os.newline();
00051     }
00052 }
00053 
00054 
00055 void Foam::ensightPart::writeFieldList
00056 (
00057     ensightFile& os,
00058     const List<scalar>& field,
00059     const List<label>& idList
00060 ) const
00061 {
00062     forAll(idList, i)
00063     {
00064         if (idList[i] >= field.size() || std::isnan(field[idList[i]]))
00065         {
00066             os.writeUndef();
00067         }
00068         else
00069         {
00070             os.write(field[idList[i]]);
00071         }
00072 
00073         os.newline();
00074     }
00075 }
00076 
00077 
00078 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00079 
00080 bool Foam::ensightPart::writeSummary(Ostream& os) const
00081 {
00082     os  << indent << type() << nl
00083         << indent << token::BEGIN_BLOCK << incrIndent << nl;
00084 
00085     // Ensight starts with 1
00086     os.writeKeyword("id") << (number() + 1) << token::END_STATEMENT << nl;
00087     os.writeKeyword("name") << name() << token::END_STATEMENT << nl;
00088     os.writeKeyword("offset") << offset() << token::END_STATEMENT << nl;
00089     os.writeKeyword("size") << size() << token::END_STATEMENT << nl;
00090 
00091     os   << decrIndent << indent << token::END_BLOCK << nl << endl;
00092 
00093     return true;
00094 }
00095 
00096 
00097 bool Foam::ensightPart::writeData(Ostream& os) const
00098 {
00099     os  << indent << type() << nl
00100         << indent << token::BEGIN_BLOCK << incrIndent << nl;
00101 
00102     os.writeKeyword("id") << number() << token::END_STATEMENT << nl;
00103     os.writeKeyword("name") << name() << token::END_STATEMENT << nl;
00104     os.writeKeyword("offset") << offset() << token::END_STATEMENT << nl;
00105 
00106     forAll(elementTypes(), typeI)
00107     {
00108         word key(elementTypes()[typeI]);
00109         if (elemLists_[typeI].size())
00110         {
00111             elemLists_[typeI].writeEntry(key, os);
00112         }
00113     }
00114 
00115     os   << decrIndent << indent << token::END_BLOCK << nl << endl;
00116 
00117     return true;
00118 }
00119 
00120 
00121 void Foam::ensightPart::writeGeometry(ensightGeoFile& os) const
00122 {
00123     if (size() && meshPtr_)
00124     {
00125         const polyMesh& mesh = *meshPtr_;
00126         const pointField& meshPoints = mesh.points();
00127 
00128         localPoints ptList = calcLocalPoints();
00129         labelList& pointMap = ptList.list;
00130 
00131         writeHeader(os, true);
00132 
00133         // write points
00134         os.writeKeyword("coordinates");
00135         os.write(ptList.nPoints);
00136         os.newline();
00137 
00138         for (direction cmpt=0; cmpt < vector::nComponents; cmpt++)
00139         {
00140             forAll(pointMap, ptI)
00141             {
00142                 if (pointMap[ptI] > -1)
00143                 {
00144                     os.write( meshPoints[ptI].component(cmpt) );
00145                     os.newline();
00146                 }
00147             }
00148         }
00149 
00150         // write parts
00151         forAll(elementTypes(), elemI)
00152         {
00153             if (elemLists_[elemI].size())
00154             {
00155                 writeConnectivity
00156                 (
00157                     os,
00158                     elementTypes()[elemI],
00159                     elemLists_[elemI],
00160                     pointMap
00161                 );
00162             }
00163         }
00164     }
00165 }
00166 
00167 
00168 void Foam::ensightPart::writeScalarField
00169 (
00170     ensightFile& os,
00171     const List<scalar>& field
00172 ) const
00173 {
00174     if (size() && field.size() && (os.allowUndef() || isFieldDefined(field)))
00175     {
00176         writeHeader(os);
00177 
00178         forAll(elementTypes(), elemI)
00179         {
00180             const labelList& idList = elemLists_[elemI];
00181 
00182             if (idList.size())
00183             {
00184                 os.writeKeyword( elementTypes()[elemI] );
00185                 writeFieldList(os, field, idList);
00186             }
00187         }
00188     }
00189 }
00190 
00191 
00192 void Foam::ensightPart::writeVectorField
00193 (
00194     ensightFile& os,
00195     const List<scalar>& field0,
00196     const List<scalar>& field1,
00197     const List<scalar>& field2
00198 ) const
00199 {
00200     if (size() && field0.size() && (os.allowUndef() || isFieldDefined(field0)))
00201     {
00202         writeHeader(os);
00203 
00204         forAll(elementTypes(), elemI)
00205         {
00206             const labelList& idList = elemLists_[elemI];
00207 
00208             if (idList.size())
00209             {
00210                 os.writeKeyword( elementTypes()[elemI] );
00211                 writeFieldList(os, field0, idList);
00212                 writeFieldList(os, field1, idList);
00213                 writeFieldList(os, field2, idList);
00214             }
00215         }
00216     }
00217 }
00218 
00219 
00220 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
00221 
00222 Foam::Ostream& Foam::operator<<
00223 (
00224     Ostream& os,
00225     const ensightPart& part
00226 )
00227 {
00228     part.writeData(os);
00229     return os;
00230 }
00231 
00232 
00233 Foam::ensightGeoFile& Foam::operator<<
00234 (
00235     ensightGeoFile& os,
00236     const ensightPart& part
00237 )
00238 {
00239     part.writeGeometry(os);
00240     return os;
00241 }
00242 
00243 
00244 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines