Scalar.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
27 
28 namespace Foam
29 {
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 const char* const pTraits<Scalar>::typeName = "scalar";
34 const Scalar pTraits<Scalar>::zero = 0.0;
35 const Scalar pTraits<Scalar>::one = 1.0;
40 
41 const char* pTraits<Scalar>::componentNames[] = { "x" };
42 
44 :
45  p_(p)
46 {}
47 
48 
49 pTraits<Scalar>::pTraits(Istream& is)
50 {
51  is >> p_;
52 }
53 
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 word name(const Scalar val)
58 {
59  std::ostringstream buf;
60  buf << val;
61  return buf.str();
62 }
63 
64 
65 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
66 
67 Scalar readScalar(Istream& is)
68 {
69  Scalar rs;
70  is >> rs;
71 
72  return rs;
73 }
74 
75 
77 {
78  token t(is);
79 
80  if (!t.good())
81  {
82  is.setBad();
83  return is;
84  }
85 
86  if (t.isNumber())
87  {
88  s = t.number();
89  }
90  else
91  {
92  is.setBad();
93  FatalIOErrorIn("operator>>(Istream&, Scalar&)", is)
94  << "wrong token type - expected Scalar, found " << t.info()
95  << exit(FatalIOError);
96 
97  return is;
98  }
99 
100  // Check state of Istream
101  is.check("Istream& operator>>(Istream&, Scalar&)");
102 
103  return is;
104 }
105 
106 
108 {
109  os.write(s);
110  os.check("Ostream& operator<<(Ostream&, const Scalar&)");
111  return os;
112 }
113 
114 
115 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
116 
117 } // End namespace Foam
118 
119 // ************************************************************************* //
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:58
#define Scalar
Single floating point number.
Definition: doubleScalar.C:33
Ostream & operator<<(Ostream &, const Scalar)
static const Scalar one
Definition: Scalar.H:62
static const char *const typeName
Definition: Scalar.H:59
pTraits(const PrimitiveType &p)
Construct from primitive.
Definition: pTraits.H:61
#define ScalarVGREAT
Definition: doubleScalar.C:34
#define ScalarROOTVGREAT
Definition: doubleScalar.C:36
static const Scalar min
Definition: Scalar.H:64
volScalarField & p
Definition: createFields.H:51
scalar number() const
Definition: tokenI.H:345
#define FatalIOErrorIn(fn, ios)
Definition: error.H:327
InfoProxy< token > info() const
Return info proxy.
Definition: token.H:373
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
static const Scalar rootMax
Definition: Scalar.H:65
#define readScalar
Definition: doubleScalar.C:38
static const Scalar max
Definition: Scalar.H:63
static const Scalar zero
Definition: Scalar.H:61
static const char * componentNames[]
Definition: Scalar.H:60
word name(const Scalar)
Return a string representation of a Scalar.
Definition: Scalar.C:57
bool good() const
Definition: tokenI.H:188
bool isNumber() const
Definition: tokenI.H:340
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
A token holds items read from Istream.
Definition: token.H:68
Istream & operator>>(Istream &, Scalar &)
pTraits(const Scalar &)
Construct from primitive.
virtual Ostream & write(const token &)=0
Write next token to stream.
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
void setBad()
Set stream to be bad.
Definition: IOstream.H:492
static const Scalar rootMin
Definition: Scalar.H:66