Commit 15c3ce52 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

worked on multilevel plotter

parent 523fa928
#include "MultilevelPlotter.hpp"
//MultilevelPlotter *MultilevelPlotter::instance = nullptr;
\ No newline at end of file
MultilevelPlotter *MultilevelPlotter::instance = nullptr;
\ No newline at end of file
......@@ -2,18 +2,13 @@
#define MULTILEVELPLOTTER_HPP
#include "Plot.h"
#include "plot/VtuPlot.h"
class MultilevelPlotter {
map<int, Plot *> mapPlots;
private:
static MultilevelPlotter *instance;
void initializeMap(const vector<int> &levels, const Meshes &meshes) {
for (auto &l: levels) {
mapPlots[l] = new Plot(meshes[l], meshes.dim());
}
}
public:
explicit MultilevelPlotter(const Meshes &meshes) {
vector<int> levels;
for (int l = meshes.pLevel(); l <= meshes.Level(); l++)
......@@ -21,24 +16,36 @@ public:
initializeMap(levels, meshes);
}
MultilevelPlotter(int startLevel, int endLevel, const Meshes &meshes) {
vector<int> levels;
for (int l = startLevel; l <= endLevel; l++)
levels.push_back(l);
initializeMap(levels, meshes);
void initializeMap(const vector<int> &levels, const Meshes &meshes) {
for (auto &l: levels) {
PlotMap[l] = make_unique<SerialVtuPlot>(meshes[l]);
}
}
explicit MultilevelPlotter(const vector<int> &levels, const Meshes &meshes) {
initializeMap(levels, meshes);
public:
map<int, unique_ptr<SerialVtuPlot>> PlotMap;
static MultilevelPlotter *GetInstance(const Meshes &meshes) {
if (!instance)
instance = new MultilevelPlotter(meshes);
return instance;
}
Plot *GetPlot(int l) {
return mapPlots[l];
void PlotVector(const string &name, const Vector &data,
int dim, int l, const string &dataType) {
if (dataType == "PointData") {
PlotMap[l]->AddPointData(name, data, dim);
PlotMap[l]->PlotFile(name);
}
if (dataType == "CellData") {
PlotMap[l]->AddCellData(name, data, dim);
PlotMap[l]->PlotFile(name);
}
}
~MultilevelPlotter() {
for (auto &plot : mapPlots)
delete plot.second;
PlotMap.clear();
}
};
......
#include "gtest/gtest.h"
#include "utils/MultilevelPlotter.hpp"
#include <memory>
#include "m++.h"
using namespace ::testing;
class TestMultilevelPlotter : public ::Test {
protected:
MultilevelPlotter *plotter;
Meshes *meshes;
MatrixGraphs *cellMatrixGraphs;
MatrixGraphs *vertexMatrixGraphs;
void SetUp() override {
meshes = new Meshes("UnitSquare", 0, 4);
cellMatrixGraphs = new MatrixGraphs(*meshes, dof("cell", 1));
vertexMatrixGraphs = new MatrixGraphs(*meshes, dof("vertex", 1));
plotter = MultilevelPlotter::GetInstance(*meshes);
}
};
TEST_F(TestMultilevelPlotter, TestSingelton) {
MultilevelPlotter *secondInstance;
secondInstance = MultilevelPlotter::GetInstance(*meshes);
ASSERT_EQ(plotter, secondInstance);
}
TEST_F(TestMultilevelPlotter, TestVertexData) {
for (int l = meshes->pLevel(); l <= meshes->Level(); l++) {
Vector pointData((*vertexMatrixGraphs)[l]);
Vector cellData((*cellMatrixGraphs)[l]);
string name = "testVec" + to_string(l);
plotter->PlotVector(name, pointData, 1, l, "PointData");
// plotter->PlotVector(name, cellData, 1, l, "CellData");
if (PPM->master())
ASSERT_TRUE(FileExists("data/vtk/" + name + ".vtu"));
}
}
int main(int argc, char **argv) {
InitGoogleTest(&argc, argv);
Config::setSearchPath("../../tests/");
Config::setConfigFileName("m++.conf");
DPO dpo(&argc, argv);
TestEventListeners &listeners = UnitTest::GetInstance()->listeners();
if (!PPM->master()) {
delete listeners.Release(listeners.default_result_printer());
}
return RUN_ALL_TESTS();
}
\ No newline at end of file
Markdown is supported
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