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

cellShapeIO.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     Reads a cellShape
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "cellShape.H"
00030 #include <OpenFOAM/token.H>
00031 #include <OpenFOAM/cellModeller.H>
00032 
00033 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00034 
00035 namespace Foam
00036 {
00037 
00038 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00039 
00040 Istream& operator>>(Istream& is, cellShape& s)
00041 {
00042     bool readEndBracket = false;
00043 
00044     // Read the 'name' token for the symbol
00045     token t(is);
00046 
00047     if (t.isPunctuation())
00048     {
00049         if (t.pToken() == token::BEGIN_LIST)
00050         {
00051             readEndBracket = true;
00052 
00053             is >> t;
00054         }
00055         else
00056         {
00057             FatalIOErrorIn("operator>>(Istream&, cellShape& s)", is)
00058                 << "incorrect first token, expected '(', found "
00059                 << t.info()
00060                 << exit(FatalIOError);
00061         }
00062     }
00063 
00064     // it is allowed to have either a word or a number describing the model
00065     if (t.isLabel())
00066     {
00067         s.m = cellModeller::lookup(int(t.labelToken()));
00068     }
00069     else if (t.isWord())
00070     {
00071         s.m = cellModeller::lookup(t.wordToken());
00072     }
00073     else
00074     {
00075         FatalIOErrorIn("operator>>(Istream& is, cellShape& s)", is)
00076             << "Bad type of token for cellShape symbol " << t.info()
00077             << exit(FatalIOError);
00078         return is;
00079     }
00080 
00081     // Check that a model was found
00082     if (!s.m)
00083     {
00084         FatalIOErrorIn("operator>>(Istream& is, cellShape& s)", is)
00085             << "CellShape has unknown model " << t.info()
00086             << exit(FatalIOError);
00087         return is;
00088     }
00089 
00090     // Read the geometry labels
00091     is >> static_cast<labelList&>(s);
00092 
00093     if (readEndBracket)
00094     {
00095         // Read end)
00096         is.readEnd("cellShape");
00097     }
00098 
00099     return is;
00100 }
00101 
00102 
00103 Ostream& operator<<(Ostream& os, const cellShape & s)
00104 {
00105     // Write beginning of record
00106     os << token::BEGIN_LIST;
00107 
00108     // Write the list label for the symbol (ONE OR THE OTHER !!!)
00109     os << (s.m)->index() << token::SPACE;
00110 
00111     // Write the model name instead of the label (ONE OR THE OTHER !!!)
00112     // os << (s.m)->name() << token::SPACE;
00113 
00114     // Write the geometry
00115     os << static_cast<const labelList&>(s);
00116 
00117     // End of record
00118     os << token::END_LIST;
00119 
00120     return os;
00121 }
00122 
00123 
00124 #if defined (__GNUC__)
00125 template<>
00126 #endif
00127 Ostream& operator<<(Ostream& os, const InfoProxy<cellShape>& ip)
00128 {
00129     const cellShape& cs = ip.t_;
00130 
00131     if (!(&cs.model()))
00132     {
00133         os  << "    cellShape has no model!\n";
00134     }
00135     else
00136     {
00137         os  << cs.model().info() << endl;
00138     }
00139 
00140     os  << "\tGeom:\tpoint\tlabel\txyz\n";
00141 
00142     forAll(cs, i)
00143     {
00144         os  << "\t\t" << i << "\t" << cs[i] << endl;
00145     }
00146 
00147     return os;
00148 }
00149 
00150 
00151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00152 
00153 } // End namespace Foam
00154 
00155 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines