complex.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011 OpenFOAM Foundation
9  Copyright (C) 2019-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "complex.H"
30 #include "IOstreams.H"
31 #include <sstream>
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 const char* const Foam::pTraits<Foam::complex>::typeName = "complex";
36 const char* const Foam::pTraits<Foam::complex>::componentNames[] = {"re", "im"};
37 
40 
41 const Foam::complex Foam::pTraits<Foam::complex>::min(-VGREAT, -VGREAT);
43 
45 (
46  -ROOTVGREAT, -ROOTVGREAT
47 );
48 
50 (
51  ROOTVGREAT, ROOTVGREAT
52 );
53 
54 
55 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
56 
58 {
59  is >> p_;
60 }
61 
62 
64 {
65  is >> *this;
66 }
67 
68 
69 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
70 
72 {
73  // Caution std::to_string(double) is locale sensitive!
74  std::ostringstream buf;
75  buf << '(' << c.real() << ',' << c.imag() << ')';
76 
77  return word(buf.str(), false); // Needs no stripping
78 }
79 
80 
81 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
82 
84 {
85  scalar r, i;
86 
87  is.readBegin("complex");
88  is >> r >> i;
89  is.readEnd("complex");
90 
91  c.real(r);
92  c.imag(i);
93 
94  is.check(FUNCTION_NAME);
95  return is;
96 }
97 
98 
99 Foam::Ostream& Foam::operator<<(Ostream& os, const complex& c)
100 {
102  << c.real() << token::SPACE << c.imag()
103  << token::END_LIST;
104 
105  return os;
106 }
107 
108 
109 // ************************************************************************* //
bool readBegin(const char *funcName)
Begin read of data chunk, starts with &#39;(&#39;.
Definition: Istream.C:134
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:75
Begin list [isseparator].
Definition: token.H:161
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
pTraits(const Base &obj)
Copy construct from base class.
Definition: pTraits.H:86
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
Istream & operator>>(Istream &, directionInfo &)
Space [isspace].
Definition: token.H:131
End list [isseparator].
Definition: token.H:162
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:26
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
constexpr complex() noexcept
Default construct, as zero-initialized.
Definition: complexI.H:24
const dimensionedScalar c
Speed of light in a vacuum.
A complex number, similar to the C++ complex type.
Definition: complex.H:70