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

Scalar.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 \*---------------------------------------------------------------------------*/
00026 
00027 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00028 
00029 namespace Foam
00030 {
00031 
00032 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00033 
00034 const char* const pTraits<Scalar>::typeName = "scalar";
00035 const Scalar pTraits<Scalar>::zero = 0.0;
00036 const Scalar pTraits<Scalar>::one = 1.0;
00037 const Scalar pTraits<Scalar>::min = -ScalarVGREAT;
00038 const Scalar pTraits<Scalar>::max = ScalarVGREAT;
00039 
00040 const char* pTraits<Scalar>::componentNames[] = { "x" };
00041 
00042 pTraits<Scalar>::pTraits(Istream& is)
00043 {
00044     is >> p_;
00045 }
00046 
00047 
00048 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00049 
00050 word name(const Scalar val)
00051 {
00052     std::ostringstream buf;
00053     buf << val;
00054     return buf.str();
00055 }
00056 
00057 
00058 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
00059 
00060 Scalar readScalar(Istream& is)
00061 {
00062     Scalar rs;
00063     is >> rs;
00064 
00065     return rs;
00066 }
00067 
00068 
00069 Istream& operator>>(Istream& is, Scalar& s)
00070 {
00071     token t(is);
00072 
00073     if (!t.good())
00074     {
00075         is.setBad();
00076         return is;
00077     }
00078 
00079     if (t.isNumber())
00080     {
00081         s = t.number();
00082     }
00083     else
00084     {
00085         is.setBad();
00086         FatalIOErrorIn("operator>>(Istream&, Scalar&)", is)
00087             << "wrong token type - expected Scalar found " << t.info()
00088             << exit(FatalIOError);
00089 
00090         return is;
00091     }
00092 
00093     // Check state of Istream
00094     is.check("Istream& operator>>(Istream&, Scalar&)");
00095 
00096     return is;
00097 }
00098 
00099 
00100 Ostream& operator<<(Ostream& os, const Scalar s)
00101 {
00102     os.write(s);
00103     os.check("Ostream& operator<<(Ostream&, const Scalar&)");
00104     return os;
00105 }
00106 
00107 
00108 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00109 
00110 } // End namespace Foam
00111 
00112 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd