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 
54 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
55 
57 {
58  is >> p_;
59 }
60 
61 
63 {
64  is >> *this;
65 }
66 
67 
68 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
69 
71 {
72  return '(' + std::to_string(c.Re()) + ',' + std::to_string(c.Im()) + ')';
73 }
74 
75 
76 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
77 
79 {
80  scalar r, i;
81 
82  is.readBegin("complex");
83  is >> r >> i;
84  is.readEnd("complex");
85 
86  c.real(r);
87  c.imag(i);
88 
89  is.check(FUNCTION_NAME);
90  return is;
91 }
92 
93 
94 Foam::Ostream& Foam::operator<<(Ostream& os, const complex& c)
95 {
97  << c.real() << token::SPACE << c.imag()
98  << token::END_LIST;
99 
100  return os;
101 }
102 
103 
104 // ************************************************************************* //
bool readBegin(const char *funcName)
Begin read of data chunk, starts with &#39;(&#39;.
Definition: Istream.C:104
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.
Definition: pTraits.H:50
Begin list [isseparator].
Definition: token.H:158
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:61
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:52
A class for handling words, derived from Foam::string.
Definition: word.H:63
Istream & operator>>(Istream &, directionInfo &)
Space [isspace].
Definition: token.H:128
End list [isseparator].
Definition: token.H:159
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:55
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:76
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:78