-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a wrapping functionality for Kolmogorov phase screen creation to
make it more convenient to use
- Loading branch information
Showing
7 changed files
with
122 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
@@ -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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{ | ||
|
@@ -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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] ); | ||
|
||
} | ||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |