OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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