Page MenuHomec4science

surface_generator_crenel.cpp
No OneTemporary

File Metadata

Created
Mon, Jul 1, 18:08

surface_generator_crenel.cpp

/* -------------------------------------------------------------------------- */
#include "surface_generator_crenel.hh"
#include <math.h>
#include <iostream>
#include <fstream>
/* -------------------------------------------------------------------------- */
using namespace std;
/* -------------------------------------------------------------------------- */
SurfaceGeneratorCrenel::SurfaceGeneratorCrenel(const string & inputfile):
SurfaceGenerator(inputfile){
}
/* -------------------------------------------------------------------------- */
void SurfaceGeneratorCrenel::Init(){
SurfaceGenerator::Init();
}
/* -------------------------------------------------------------------------- */
void SurfaceGeneratorCrenel::parseInputFile(ifstream & fp){
int gridsize;
string line;
while (! fp.eof() )
{
getline (fp,line);
size_t pos = line.find("#"); //remove the comment
line = line.substr(0, pos);
trim(line); // remove unnecessary spaces
/* Read all options one by one */
readInput(line, "gridsize" , gridsize);
readInput(line, "c" , c);
readInput(line, "div_crenel", div_crenel);
}
return;
}
/* -------------------------------------------------------------------------- */
Surface<Real> & SurfaceGeneratorCrenel::buildSurface(){
UInt n = surface->size();
for (UInt i = 0 ; i < n ; ++i)
for (UInt j = 0 ; j < n ; ++j){
int sub_n = n/div_crenel;
int sub_i = i%sub_n;
int sub_j = j%sub_n;
int sub_c = c/div_crenel;
if (fabs(sub_i-sub_n/2) < sub_c/2 &&
fabs(sub_j-sub_n/2) < sub_c/2){
surface->at(i,j) = 1.;
}
else surface->at(i,j) = 0.;
}
return *surface;
}

Event Timeline