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 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 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 const char* const Foam::pTraits<Foam::complex>::typeName = "complex";
35 const char* const Foam::pTraits<Foam::complex>::componentNames[] = {"re", "im"};
36 
39 
40 const Foam::complex Foam::pTraits<Foam::complex>::min(-VGREAT, -VGREAT);
42 
44 (
45  -ROOTVGREAT, -ROOTVGREAT
46 );
47 
49 (
50  ROOTVGREAT, ROOTVGREAT
51 );
52 
53 
55 :
56  p_(val)
57 {}
58 
59 
61 {
62  is >> p_;
63 }
64 
65 
66 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
67 
69 {
70  is >> *this;
71 }
72 
73 
74 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
75 
77 {
78  return '(' + std::to_string(c.Re()) + ',' + std::to_string(c.Im()) + ')';
79 }
80 
81 
82 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
83 
85 {
86  scalar r, i;
87 
88  is.readBegin("complex");
89  is >> r >> i;
90  is.readEnd("complex");
91 
92  c.real(r);
93  c.imag(i);
94 
95  is.check(FUNCTION_NAME);
96  return is;
97 }
98 
99 
101 {
102  os << token::BEGIN_LIST
103  << c.real() << token::SPACE << c.imag()
104  << token::END_LIST;
105 
106  return os;
107 }
108 
109 
110 // ************************************************************************* //
Foam::roots::complex
Definition: Roots.H:57
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::Istream::readEnd
bool readEnd(const char *funcName)
End read of data chunk, ends with ')'.
Definition: Istream.C:127
complex.H
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
Foam::Istream::readBegin
bool readBegin(const char *funcName)
Begin read of data chunk, starts with '('.
Definition: Istream.C:109
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::pTraits::pTraits
pTraits(const PrimitiveType &p)
Copy construct from primitive.
Definition: pTraits.H:63
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:51
Foam::complex
A complex number, similar to the C++ complex type.
Definition: complex.H:82
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:54
Foam::token::SPACE
Space [isspace].
Definition: token.H:117
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:270
Foam::token::END_LIST
End list [isseparator].
Definition: token.H:123
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::token::BEGIN_LIST
Begin list [isseparator].
Definition: token.H:122
Foam::complex::complex
constexpr complex() noexcept
Default construct, as zero-initialized.
Definition: complexI.H:31