Skip to content

Commit

Permalink
Create a wrapping functionality for Kolmogorov phase screen creation to
Browse files Browse the repository at this point in the history
make it more convenient to use
  • Loading branch information
bnikolic committed May 15, 2007
1 parent fb4ada9 commit 4a34664
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 19 deletions.
2 changes: 2 additions & 0 deletions bnlib/pybind/pybnlib.i
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "../src/phycosmo.hxx"
#include "../src/integrate.hxx"
#include "../src/kolmogorov.hxx"
#include "../src/kolmogorov_wrap.hxx"

%}

Expand All @@ -39,6 +40,7 @@
%include "../src/phyfunc.hxx"
%include "../src/phycosmo.hxx"
%include "../src/kolmogorov.hxx"
%include "../src/kolmogorov_wrap.hxx"

%extend BNLib::ConstUDD {

Expand Down
9 changes: 3 additions & 6 deletions bnlib/pybind/test/kolmogorov.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,14 @@ def MarkEiter( grid,

MarkGIter( grid, o , pybnlib.EdgeIter)

def GenKolmogorov(N):
def GenKolmogorov(N,
seed=0):

grid=pybnlib.doubleArray( N*N)
normv = pybnlib.doubleArray( N*N+2)
anormv=numarray.random_array.normal(0.0, 1.0 , N*N+2)
for i,x in enumerate(anormv):
normv[i]=x

pybnlib.KolmogorovPlatform(N,
grid,
normv)
seed)

res=numarray.zeros( (N,N),
numarray.Float64)
Expand Down
6 changes: 4 additions & 2 deletions bnlib/src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ libbnlib_la_SOURCES= interpolate.hxx interpolate.cxx \
tophat.cxx tophat.hxx \
integrateutils.cxx integrateutils.hxx\
unaryfnutils.cxx unaryfnutils.hxx\
kolmogorov.cxx kolmogorov.hxx
kolmogorov.cxx kolmogorov.hxx \
kolmogorov_wrap.cxx kolmogorov_wrap.hxx

libbnlib_la_CFLAGS = -Wall
libbnlib_la_CPPFLAGS = -Wall
Expand Down Expand Up @@ -51,4 +52,5 @@ include_HEADERS = unaryfn.hxx \
tophat.hxx\
integrateutils.hxx\
unaryfnutils.hxx \
kolmogorov.hxx
kolmogorov.hxx\
kolmogorov_wrap.hxx
24 changes: 19 additions & 5 deletions bnlib/src/bnrandom.cxx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
Copyright:
Bojan Nikolic
/**
\file bnrandom.cxx
Bojan Nikolic <[email protected]>, <[email protected]>
2004-2007
*/

#include "bnrandom.hxx"
Expand All @@ -18,6 +18,20 @@

namespace BNLib {

// ---------------- class RDist section -----------------

double RDist::samplefill(std::vector<double> &res)
{
for (size_t i = 0 ; i < res.size() ; ++ i)
{
res[i] = sample();
}
return sample();
}

// ---------------- Helpers for GSL random number generators ----------------


/*! Implements random number generation using GSL */
class GSLRanGen {
gsl_rng * generator;
Expand Down
25 changes: 19 additions & 6 deletions bnlib/src/bnrandom.hxx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
/*
Copyright:
Bojan Nikolic
/**
\file bnrandom.hxx
Interface to random number generators
Bojan Nikolic <[email protected]>, <[email protected]>,
<[email protected]> 2004-2007
Interface to random number generators
*/
#ifndef __BNLib_RANDOM_HXX__
#define __BNLib_RANDOM_HXX__

#include <memory>
#include <vector>


namespace BNLib{
Expand All @@ -24,14 +26,25 @@ namespace BNLib{

/// Returns a sample from the distribution
virtual double sample(void)=0;
};

/**
Fill out the supplied vector res with random numbers sampled
from this ditribution. Returns one further random sample.
Virtual to allow more efficient implementation if a random
number generator allows it.
*/
virtual double samplefill( std::vector<double> & res );
};


class iNormDist;

/// A zero-mean normal distribution
class NormDistZM : public RDist {
class NormDistZM :
public RDist
{

/// This is the implementation class
std::auto_ptr<iNormDist> ip;
Expand Down
43 changes: 43 additions & 0 deletions bnlib/src/kolmogorov_wrap.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
\file kolmogorov_wrap.cxx
Bojan Nikolic <[email protected]>, <[email protected]>
May 2007
*/

#include "kolmogorov_wrap.hxx"

#include "kolmogorov.hxx"
#include "bnrandom.hxx"


namespace BNLib {

void KolmogorovPlatform( size_t N,
double * grid,
unsigned long seed )
{

if ( seed == 0)
{
seed = TimeSeed();
}

std::vector<double> normvect (N*N +2);

NormDistZM dist(1.0 );
dist.reseed(seed);

dist.samplefill(normvect);

KolmogorovPlatform( N,
grid,
&normvect[0] );

}




}
32 changes: 32 additions & 0 deletions bnlib/src/kolmogorov_wrap.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
\file kolmogorov_wrap.hxx
Bojan Nikolic <[email protected]>, <[email protected]>
May 2007
Package up generation of Kolmogorov screens a little to make it
fit in better with rest of BNLib. Interface in kolmogorov.hxx is
intentionally sparse to make it distributable outside of this
package if necessary.
*/
#ifndef __BNLIB_KOKMOGOROV_WRAP_HX__
#define __BNLIB_KOKMOGOROV_WRAP_HX__

#include <stdlib.h>

namespace BNLib {

/**
Construct a Kolmogorov phase screen, generating the required
random numbers automatically. If seed == 0, then seed is taken
from the current system time.
*/
void KolmogorovPlatform( size_t N,
double * grid,
unsigned long seed = 0 );


}

#endif

0 comments on commit 4a34664

Please sign in to comment.