Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F77942470
surface_generator.cpp
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
Sat, Aug 17, 09:09
Size
3 KB
Mime Type
text/x-c
Expires
Mon, Aug 19, 09:09 (2 d)
Engine
blob
Format
Raw Data
Handle
19953234
Attached To
rTAMAAS tamaas
surface_generator.cpp
View Options
/* -------------------------------------------------------------------------- */
#include <iostream>
#include <map>
#include <fstream>
/* -------------------------------------------------------------------------- */
#include "surface_generator.hh"
#include "surface_generator_voss.hh"
#include "surface_generator_filter.hh"
#include "surface_generator_filter_bessel.hh"
#include "surface_generator_filter_fft.hh"
#include "surface_generator_crenel.hh"
#include "surface_generator_ellipsoid.hh"
#include "surface_statistics.hh"
/* -------------------------------------------------------------------------- */
using
namespace
std
;
/* -------------------------------------------------------------------------- */
/* Sort functions */
int
sortAscend
(
const
void
*
a
,
const
void
*
b
)
{
return
(
*
(
int
*
)
a
-
*
(
int
*
)
b
);
}
/* -------------------------------------------------------------------------- */
int
sortDescend
(
const
void
*
a
,
const
void
*
b
)
{
return
(
*
(
int
*
)
b
-
*
(
int
*
)
a
);
}
/* -------------------------------------------------------------------------- */
/* Check if a number is a power of two */
int
isPowerOfTwo
(
unsigned
int
x
)
{
return
((
x
!=
0
)
&&
((
x
&
(
~
x
+
1
))
==
x
));
}
/* -------------------------------------------------------------------------- */
SurfaceGenerator
::
SurfaceGenerator
(
const
string
&
inputfile
)
:
surface
(
NULL
)
{
configfile
=
inputfile
;
}
/* -------------------------------------------------------------------------- */
SurfaceGenerator
::
SurfaceGenerator
()
:
rms
(
0.
),
random_seed
(
0
),
configfile
(
""
),
surface
(
NULL
),
gridsize
(
0
)
{
}
/* -------------------------------------------------------------------------- */
void
SurfaceGenerator
::
Init
()
{
if
(
configfile
!=
""
){
ifstream
fp
(
configfile
.
c_str
());
//double layerthickness;
if
(
fp
.
is_open
()
==
false
)
{
SURFACE_FATAL
(
"Could not read the file "
<<
configfile
);
}
else
cout
<<
"Reading options from the file "
<<
configfile
<<
std
::
endl
;
/* Parse the input file */
parseInputFile
(
fp
);
/* close the file */
fp
.
close
();
}
/* Post-process grid size */
if
(
!
isPowerOfTwo
(
gridsize
))
{
SURFACE_FATAL
(
"Grid size should be a power of two and is "
<<
gridsize
);
}
surface
=
new
Surface
<
Real
>
(
gridsize
,
1.
);
/* Post-process random seed */
//RandomSeed = makeseed(RandomSeed);
return
;
}
/* -------------------------------------------------------------------------- */
// Real SurfaceGenerator::roughness(Real d) {
// //return d*(2*uniform(&RandomSeed)-1);
// return d*(gaussian(&RandomSeed));
// }
/* -------------------------------------------------------------------------- */
Real
SurfaceGenerator
::
constrainRMS
(){
int
n
=
surface
->
size
();
// Real avg = SurfaceStatistics::computeAverage(*surface);
Real
measured_rms
=
SurfaceStatistics
::
computeStdev
(
*
surface
);
std
::
cerr
<<
"actual rms is "
<<
rms
<<
endl
;
/* shift to center to mean value */
for
(
int
i
=
0
;
i
<
n
;
++
i
)
for
(
int
j
=
0
;
j
<
n
;
++
j
){
surface
->
at
(
i
,
j
)
*=
rms
/
measured_rms
;
}
return
rms
/
measured_rms
;
}
/* -------------------------------------------------------------------------- */
Event Timeline
Log In to Comment