Commit d4a44f80 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

started with uniform distribution

parent be17d77f
#ifndef UNIFORMDISTRIBUTION_HPP
#define UNIFORMDISTRIBUTION_HPP
#include "SampleGenerator.hpp"
//#define USE_MPI
#include "sprng_cpp.h"
#define SEED 985456376
class UniformDistributionReal : public SampleGenerator<Scalar> {
private:
Sprng *randNumberGen;
Scalar firstSample;
Scalar secondSample;
int internalCounter = 0;
double a = 0.0;
double b = 1.0;
void drawSample(const SampleID &id) override {
if (internalCounter) {
updateCounter();
return;
}
firstSample = a + randNumberGen->sprng() * (b - a);
secondSample = a + randNumberGen->sprng() * (b - a);
updateCounter();
};
void updateCounter() {
internalCounter = internalCounter + 1;
internalCounter = internalCounter % 2;
};
public:
UniformDistributionReal(Meshes &meshes,
double a = 0.0,
double b = 1.0,
int streamID = 0,
int numStreams = 1,
int gType = 0,
int seed = SEED) : a(a), b(b),
SampleGenerator(meshes) {
this->randNumberGen = SelectType(gType);
this->randNumberGen->init_sprng(streamID, numStreams,
seed, SPRNG_DEFAULT);
}
~UniformDistributionReal() { randNumberGen->free_sprng(); };
Scalar EvalSample() override {
if (internalCounter)
return firstSample;
else
return secondSample;
};
std::string Name() const override {
return "UniformDistributionReal";
};
};
#endif //UNIFORMDISTRIBUTION_HPP
#ifndef UNIFORMDISTRIBUTION_HPP
#define UNIFORMDISTRIBUTION_HPP
#include "generators/SampleGenerator.hpp"
class UniformDistribution : public SampleGenerator<Scalar> {
public:
std::string Name() const override {
return "UniformDistribution";
};
};
#endif //UNIFORMDISTRIBUTION_HPP
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment