Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
35const char* const Foam::pTraits<Foam::complex>::typeName = "complex";
36const char* const Foam::pTraits<Foam::complex>::componentNames[] = {"re", "im"};
37
40
43
45(
46 -ROOTVGREAT, -ROOTVGREAT
47);
48
50(
51 ROOTVGREAT, ROOTVGREAT
52);
53
54
55// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
60}
61
62
65 is >> *this;
66}
67
68
69// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
70
71Foam::word Foam::name(const complex& c)
72{
73 // Caution std::to_string(double) is locale sensitive!
74 std::ostringstream buf;
75 buf << '(' << c.real() << ',' << c.imag() << ')';
77 return word(buf.str(), false); // Needs no stripping
78}
79
80
81// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
82
83Foam::Istream& Foam::operator>>(Istream& is, complex& c)
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
99Foam::Ostream& Foam::operator<<(Ostream& os, const complex& c)
100{
102 << c.real() << token::SPACE << c.imag()
104
105 return os;
106}
107
108
109// ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition IOstream.C:45
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
bool readEnd(const char *funcName)
End read of data chunk, ends with ')'.
Definition Istream.C:152
bool readBegin(const char *funcName)
Begin read of data chunk, starts with '('.
Definition Istream.C:134
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A complex number, similar to the C++ complex type.
Definition complex.H:71
constexpr complex() noexcept
Default construct, as zero-initialized.
Definition complexI.H:24
A traits class, which is primarily used for primitives and vector-space.
Definition pTraits.H:64
pTraits(const Base &obj)
Copy construct from base class.
Definition pTraits.H:72
@ BEGIN_LIST
Begin list [isseparator].
Definition token.H:174
@ END_LIST
End list [isseparator].
Definition token.H:175
@ SPACE
Space [isspace].
Definition token.H:144
A class for handling words, derived from Foam::string.
Definition word.H:66
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
Istream & operator>>(Istream &, directionInfo &)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127