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-2019 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 Functions * * * * * * * * * * * * //
66 
68 {
69  Scalar rs;
70  is >> rs;
71 
72  return rs;
73 }
74 
75 
76 void writeEntry(Ostream& os, const Scalar value)
77 {
78  os << value;
79 }
80 
81 
82 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
83 
85 {
86  token t(is);
87 
88  if (!t.good())
89  {
90  is.setBad();
91  return is;
92  }
93 
94  if (t.isNumber())
95  {
96  s = t.number();
97  }
98  else
99  {
100  is.setBad();
102  << "wrong token type - expected Scalar, found " << t.info()
103  << exit(FatalIOError);
104 
105  return is;
106  }
107 
108  // Check state of Istream
109  is.check("Istream& operator>>(Istream&, Scalar&)");
110 
111  return is;
112 }
113 
114 
116 {
117  os.write(s);
118  os.check("Ostream& operator<<(Ostream&, const Scalar&)");
119  return os;
120 }
121 
122 
123 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
124 
125 } // End namespace Foam
126 
127 // ************************************************************************* //
#define ScalarVGreat
Definition: doubleScalar.C:34
static const Scalar zero
Definition: Scalar.H:73
virtual Ostream & write(const char)=0
Write character.
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:503
InfoProxy< token > info() const
Return info proxy.
Definition: token.H:391
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:72
static const Scalar max
Definition: Scalar.H:75
bool isNumber() const
Definition: tokenI.H:498
void setBad()
Set stream to be bad.
Definition: IOstream.H:484
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:228
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
Definition: doubleScalar.H:75
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
#define Scalar
Definition: doubleScalar.C:33
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
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:318
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
volScalarField & p
static const Scalar one
Definition: Scalar.H:74
Namespace for OpenFOAM.
IOerror FatalIOError