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

bye bye Level

parent 53b5e489
Pipeline #145651 failed with stages
in 10 minutes and 18 seconds
#include "Level.hpp" #include "Level.hpp"
void Level::Update(int level) {
fine = level;
coarse = level - 1;
if (coarse < 0) coarse = 0;
pLevel = coarse;
}
bool Level::operator==(const Level &level) const {
if (this->fine != level.fine)
return false;
if (this->coarse != level.coarse)
return false;
if (this->pLevel != level.pLevel)
return false;
return true;
}
bool Level::operator==(int level) const {
if (this->fine != level)
return false;
return true;
}
bool Level::operator!=(const Level &level) const {
return !(*this == level);
}
bool Level::operator!=(int level) const {
return !(*this == level);
}
bool Level::operator<=(const Level &level) const {
if (this->fine < level.fine) return true;
else return false;
}
bool Level::operator>=(const Level &level) const {
if (this->fine > level.fine) return true;
else return false;
}
bool Level::operator<(const Level &level) const {
if (this->fine < level.fine) return true;
else return false;
}
bool Level::operator>(const Level &level) const {
if (this->fine > level.fine) return true;
else return false;
}
bool Level::operator<(int level) const {
if (this->fine < level) return true;
else return false;
}
bool Level::operator>(int level) const {
if (this->fine > level) return true;
else return false;
}
bool Level::operator<=(int level) const {
if (this->fine <= level) return true;
else return false;
}
bool Level::operator>=(int level) const {
if (this->fine >= level) return true;
else return false;
}
...@@ -6,62 +6,10 @@ ...@@ -6,62 +6,10 @@
#include <map> #include <map>
/*
* Todo
* Only Fine true: pLevel = fine = coarse
* Only Fine false: plevel = coarse, fine = coarse + 1
*
* Add commSplit to Level
*/
struct Level {
int fine;
int coarse;
int pLevel;
Level() {}
explicit Level(int level) {
Update(level);
}
void Update(int level);
int ActualLevel(bool getCoarse) const {
if (!getCoarse) return fine;
else return coarse;
};
bool operator==(const Level &level) const;
bool operator==(int level) const;
bool operator!=(const Level &level) const;
bool operator!=(int level) const;
bool operator<=(const Level &level) const;
bool operator>=(const Level &level) const;
bool operator<(const Level &level) const;
bool operator>(const Level &level) const;
bool operator<(int level) const;
bool operator>(int level) const;
bool operator<=(int level) const;
bool operator>=(int level) const;
};
/* /*
* Todo: * Todo:
* * make second key template for degree * * idea: make second key template for degree
* to realize MultidegreeMonteCarlo * to realize MultidegreeMonteCarlo
* * also key (thus Level) should include proc information
* && ? * && ?
*/ */
......
...@@ -9,8 +9,6 @@ ...@@ -9,8 +9,6 @@
struct SampleID { struct SampleID {
private:
Level level;
public: public:
int fLevel; int fLevel;
int cLevel; int cLevel;
...@@ -23,25 +21,16 @@ public: ...@@ -23,25 +21,16 @@ public:
SampleID() {} SampleID() {}
SampleID(Level level, int number, bool coarse, const std::string &name = "U") :
level(level), number(number), coarse(coarse), name(name) {
fLevel = level.fine;
cLevel = level.coarse;
}
SampleID(int level, int number, bool coarse, const std::string &name = "U") : SampleID(int level, int number, bool coarse, const std::string &name = "U") :
level(Level(level)), number(number), coarse(coarse), name(name) { fLevel(level), cLevel(level - 1), number(number), coarse(coarse), name(name) {}
fLevel = this->level.fine;
cLevel = this->level.coarse;
}
int l() const { int level() const {
if (coarse) return cLevel; if (coarse) return cLevel;
else return fLevel; else return fLevel;
}; };
std::string IdString(const std::string &name_) const { std::string IdString(const std::string &name_) const {
return name_ + "." + std::to_string(level.fine) return name_ + "." + std::to_string(fLevel)
+ "." + std::to_string((int) coarse) + "." + std::to_string((int) coarse)
+ "." + std::to_string(number); + "." + std::to_string(number);
} }
...@@ -69,7 +58,7 @@ public: ...@@ -69,7 +58,7 @@ public:
SampleSolution(IDiscretization *disc, const SampleID &id, SampleSolution(IDiscretization *disc, const SampleID &id,
const std::string &name = "U") : const std::string &name = "U") :
id(id), U(Vector(*disc, id.l())) { id(id), U(Vector(*disc, id.level())) {
this->id.name = name; this->id.name = name;
Init(); Init();
} }
......
...@@ -91,7 +91,7 @@ Tensor CirculantEmbedding1D::EvalSample(const cell &c) { ...@@ -91,7 +91,7 @@ Tensor CirculantEmbedding1D::EvalSample(const cell &c) {
void CirculantEmbedding1D::initVec(const SampleID &id) { void CirculantEmbedding1D::initVec(const SampleID &id) {
if (sampleVec) delete sampleVec; if (sampleVec) delete sampleVec;
sampleVec = new Vector(disc, id.l()); sampleVec = new Vector(disc, id.level());
*sampleVec = 0.0; *sampleVec = 0.0;
} }
...@@ -187,7 +187,7 @@ Tensor CirculantEmbedding2D::EvalSample(const cell &c) { ...@@ -187,7 +187,7 @@ Tensor CirculantEmbedding2D::EvalSample(const cell &c) {
void CirculantEmbedding2D::initVec(const SampleID &id) { void CirculantEmbedding2D::initVec(const SampleID &id) {
if (sampleVec) delete sampleVec; if (sampleVec) delete sampleVec;
sampleVec = new Vector(disc, id.l()); sampleVec = new Vector(disc, id.level());
*sampleVec = 0.0; *sampleVec = 0.0;
} }
......
...@@ -9,7 +9,6 @@ file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/mlmc/tests/data/vtu) ...@@ -9,7 +9,6 @@ file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/mlmc/tests/data/vtu)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/mlmc/tests/log) file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/mlmc/tests/log)
# ------- Unit Tests ------- # ------- Unit Tests -------
add_mpp_test(basics/TestLevel BASICS)
add_mpp_test(basics/TestPlotting BASICS) add_mpp_test(basics/TestPlotting BASICS)
add_mpp_test(generators/TestNormalDistribution GENERATORS) add_mpp_test(generators/TestNormalDistribution GENERATORS)
......
#include "basics/Level.hpp"
#include "TestEnvironment.hpp"
#include <vector>
class TestLevel : public Test {
protected:
typedef std::vector<Level> TestLevels;
typedef std::vector<int> TestIntegers;
TestLevels testLevels;
TestIntegers testIntegers;
void SetUp() override {
testLevels = {Level(0), Level(1), Level(2), Level(3)};
testIntegers = {int(), 1, 2, 3};
}
};
TEST_F(TestLevel, TestEqualsAndNotEqualsLevelOperators) {
EXPECT_TRUE(testLevels[0] == testLevels[0]);
for (int index = 1; index < testLevels.size(); index++)
EXPECT_TRUE(testLevels[0] != testLevels[index]);
EXPECT_TRUE(testLevels[1] == testLevels[1]);
for (int index = 2; index < testLevels.size(); index++)
EXPECT_TRUE(testLevels[1] != testLevels[index]);
EXPECT_TRUE(testLevels[2] == testLevels[2]);
for (int index = 3; index < testLevels.size(); index++)
EXPECT_TRUE(testLevels[2] != testLevels[index]);
EXPECT_TRUE(testLevels[3] == testLevels[3]);
}
TEST_F(TestLevel, TestEqualsAndNotEqualsIntegerOperators) {
EXPECT_TRUE(testLevels[0] == testIntegers[0]);
EXPECT_TRUE(testLevels[0] != testIntegers[1]);
EXPECT_TRUE(testLevels[0] != testIntegers[2]);
EXPECT_TRUE(testLevels[0] != testIntegers[3]);
EXPECT_TRUE(testLevels[1] != testIntegers[0]);
EXPECT_TRUE(testLevels[1] == testIntegers[1]);
EXPECT_TRUE(testLevels[1] != testIntegers[2]);
EXPECT_TRUE(testLevels[1] != testIntegers[3]);
EXPECT_TRUE(testLevels[2] != testIntegers[0]);
EXPECT_TRUE(testLevels[2] != testIntegers[1]);
EXPECT_TRUE(testLevels[2] == testIntegers[2]);
EXPECT_TRUE(testLevels[2] != testIntegers[3]);
EXPECT_TRUE(testLevels[3] != testIntegers[0]);
EXPECT_TRUE(testLevels[3] != testIntegers[1]);
EXPECT_TRUE(testLevels[3] != testIntegers[2]);
EXPECT_TRUE(testLevels[3] == testIntegers[3]);
}
// Todo finish
int main(int argc, char **argv) {
MppTest mppTest = MppTestBuilder(argc, argv).WithPPM().WithScreenLogging();
return mppTest.RUN_ALL_MPP_TESTS();
}
\ No newline at end of file
...@@ -37,14 +37,14 @@ TEST_F(TestCirculantEmbedding, TestDrawSample) { ...@@ -37,14 +37,14 @@ TEST_F(TestCirculantEmbedding, TestDrawSample) {
CirculantEmbedding2D circEmb(*meshes, covariance); CirculantEmbedding2D circEmb(*meshes, covariance);
for (int sample = 0; sample < samples; sample++) { for (int sample = 0; sample < samples; sample++) {
SampleID idFine(Level(level), sample, 0, "Kappa"); SampleID idFine(level, sample, 0, "Kappa");
circEmb.DrawSample(idFine); circEmb.DrawSample(idFine);
PPM->Barrier(0); PPM->Barrier(0);
std::string file = "data/vtu/" + idFine.IdString() + ".vtu"; std::string file = "data/vtu/" + idFine.IdString() + ".vtu";
EXPECT_TRUE(std::filesystem::exists(file)); EXPECT_TRUE(std::filesystem::exists(file));
SampleID idCoarse(Level(level), sample, 1, "Kappa"); SampleID idCoarse(level, sample, 1, "Kappa");
circEmb.DrawSample(idCoarse); circEmb.DrawSample(idCoarse);
PPM->Barrier(0); PPM->Barrier(0);
......
...@@ -17,7 +17,7 @@ protected: ...@@ -17,7 +17,7 @@ protected:
void SetUp() override { void SetUp() override {
meshes = MeshesCreator("Interval").Create(); meshes = MeshesCreator("Interval").Create();
for (int number = 0; number < numSamples; number++) for (int number = 0; number < numSamples; number++)
sampleIDs.push_back(SampleID(Level(), number, false)); sampleIDs.push_back(SampleID(0, number, false));
} }
void TearDown() override { void TearDown() override {
......
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