Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F80576946
dumper_series.hh
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Sep 1, 11:46
Size
1 KB
Mime Type
text/x-c++
Expires
Tue, Sep 3, 11:46 (2 d)
Engine
blob
Format
Raw Data
Handle
20400336
Attached To
R9484 sp4e-homework-lars-bertil
dumper_series.hh
View Options
/* HEADER FILE */
#include <cmath>
#include <iostream>
#include <iomanip>
#include "series.hh"
#include <string>
#include <fstream>
// TODO: Split into hh and cc file
// Create ifdef for header files
class
DumperSeries
{
public
:
DumperSeries
(
Series
&
series
)
:
series
(
series
)
{};
virtual
void
dump
(
std
::
ostream
&
os
)
=
0
;
virtual
~
DumperSeries
()
{};
virtual
void
setPrecision
(
unsigned
int
precision
)
=
0
;
protected
:
Series
&
series
;
};
class
PrintSeries
:
public
DumperSeries
{
public
:
PrintSeries
(
Series
&
series
,
int
maxiter
,
int
freq
)
:
DumperSeries
(
series
),
maxiter
(
maxiter
),
freq
(
freq
)
{}
virtual
~
PrintSeries
()
{};
void
setSeparator
(
std
::
string
in_sep
){
if
(
in_sep
==
","
){
sep
=
","
;
}
else
if
(
in_sep
==
"|"
){
sep
=
"|"
;
}
else
{
// default is txt file with space separated values
sep
=
" "
;
}
}
void
setPrecision
(
unsigned
int
precision
){
prec
=
precision
;
}
void
dump
(
std
::
ostream
&
os
=
std
::
cout
)
{
double
exact
=
series
.
getAnalyticPrediction
();
if
(
std
::
isnan
(
exact
)
){
os
<<
"Step"
<<
sep
<<
"Result
\n
"
;
for
(
int
i
=
1
;
i
<
int
(
maxiter
/
freq
);
i
++
){
double
result
=
series
.
compute
(
i
*
freq
);
os
<<
i
<<
std
::
scientific
<<
std
::
setprecision
(
prec
)
<<
sep
<<
result
<<
sep
<<
"
\n
"
;
}
// end for loop
}
else
{
os
<<
"Step"
<<
sep
<<
"Result"
<<
sep
<<
"Abs-diff
\n
"
;
for
(
int
i
=
1
;
i
<
int
(
maxiter
/
freq
);
i
++
){
double
result
=
series
.
compute
(
i
*
freq
);
double
dist
=
std
::
abs
(
result
-
exact
);
os
<<
i
<<
std
::
scientific
<<
std
::
setprecision
(
prec
)
<<
sep
<<
result
<<
sep
<<
dist
<<
"
\n
"
;
}
// end for loop
}
// end if...else
}
// end member function dump
protected
:
int
freq
;
int
maxiter
;
std
::
string
sep
=
" "
;
// default value
unsigned
int
prec
=
4
;
// default value
};
// end class PrintSeries
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
stream
,
DumperSeries
&
_this
)
{
_this
.
dump
(
stream
);
return
stream
;
}
Event Timeline
Log In to Comment