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-2023 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;
41 
42 const char* const pTraits<Scalar>::componentNames[] = { "" };
43 
45 :
46  p_(p)
47 {}
48 
49 
51 {
52  is >> p_;
53 }
54 
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 word name(const Scalar val)
59 {
60  std::ostringstream buf;
61  buf << val;
62  return buf.str();
63 }
64 
65 
66 // * * * * * * * * * * * * * * * IOstream Functions * * * * * * * * * * * * //
67 
68 Scalar readScalar(Istream& is)
69 {
70  Scalar rs;
71  is >> rs;
72 
73  return rs;
74 }
75 
76 
77 void writeEntry(Ostream& os, const Scalar value)
78 {
79  os << value;
80 }
81 
82 
83 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
84 
86 {
87  token t(is);
88 
89  if (!t.good())
90  {
91  is.setBad();
92  return is;
93  }
94 
95  if (t.isNumber())
96  {
97  s = t.number();
98  }
99  else
100  {
101  is.setBad();
103  << "wrong token type - expected Scalar, found " << t.info()
104  << exit(FatalIOError);
105 
106  return is;
107  }
108 
109  // Check state of Istream
110  is.check("Istream& operator>>(Istream&, Scalar&)");
111 
112  return is;
113 }
114 
115 
117 {
118  os.write(s);
119  os.check("Ostream& operator<<(Ostream&, const Scalar&)");
120  return os;
121 }
122 
123 
124 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
125 
126 } // End namespace Foam
127 
128 // ************************************************************************* //
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
void setBad()
Set stream to be bad.
Definition: IOstream.H:484
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
virtual Ostream & write(const char)=0
Write character.
static const char *const componentNames[]
Definition: Scalar.H:72
static const Scalar one
Definition: Scalar.H:74
static const Scalar min
Definition: Scalar.H:76
static const Scalar rootMax
Definition: Scalar.H:77
static const Scalar max
Definition: Scalar.H:75
static const Scalar rootMin
Definition: Scalar.H:78
static const Scalar nan
Definition: Scalar.H:79
static const Scalar zero
Definition: Scalar.H:73
static const char *const typeName
Definition: Scalar.H:71
pTraits(const PrimitiveType &p)
Construct from primitive.
Definition: pTraits.H:60
A token holds items read from Istream.
Definition: token.H:73
bool isNumber() const
Definition: tokenI.H:745
InfoProxy< token > info() const
Return info proxy.
Definition: token.H:422
bool good() const
Definition: tokenI.H:265
scalar number() const
Definition: tokenI.H:755
A class for handling words, derived from string.
Definition: word.H:62
#define ScalarRootVGreat
Definition: doubleScalar.C:36
#define Scalar
Definition: doubleScalar.C:33
#define ScalarVGreat
Definition: doubleScalar.C:34
#define ScalarNaN
Definition: doubleScalar.C:38
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
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.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
Definition: doubleScalar.H:75
Istream & operator>>(Istream &, pistonPointEdgeData &)
IOerror FatalIOError
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
volScalarField & p