Scalar.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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* const pTraits<Scalar>::componentNames[] = { "" };
42 
44 :
45  p_(p)
46 {}
47 
48 
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 
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();
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 // ************************************************************************* //
#define ScalarVGreat
Definition: doubleScalar.C:34
static const Scalar zero
Definition: Scalar.H:73
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
static const char *const typeName
Definition: Scalar.H:71
scalar number() const
Definition: tokenI.H:382
InfoProxy< token > info() const
Return info proxy.
Definition: token.H:380
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A token holds items read from Istream.
Definition: token.H:69
static const Scalar max
Definition: Scalar.H:75
bool isNumber() const
Definition: tokenI.H:377
void setBad()
Set stream to be bad.
Definition: IOstream.H:487
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))
static const Scalar rootMax
Definition: Scalar.H:77
A class for handling words, derived from string.
Definition: word.H:59
Istream & operator>>(Istream &, directionInfo &)
static const Scalar min
Definition: Scalar.H:76
static const char *const componentNames[]
Definition: Scalar.H:72
bool good() const
Definition: tokenI.H:197
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
Definition: doubleScalar.H:68
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
#define Scalar
Definition: doubleScalar.C:33
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:331
static const Scalar rootMin
Definition: Scalar.H:78
#define ScalarRootVGreat
Definition: doubleScalar.C:36
Ostream & operator<<(Ostream &, const ensightPart &)
pTraits(const PrimitiveType &p)
Construct from primitive.
Definition: pTraits.H:60
virtual Ostream & write(const token &)=0
Write next token to stream.
volScalarField & p
static const Scalar one
Definition: Scalar.H:74
Namespace for OpenFOAM.
IOerror FatalIOError