Page MenuHomec4science

surface_generator.cpp
No OneTemporary

File Metadata

Created
Mon, Jul 1, 18:45

surface_generator.cpp

/* -------------------------------------------------------------------------- */
#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