MultilevelPlotter.hpp 2.33 KB
Newer Older
1
2
3
4
#ifndef MULTILEVELPLOTTER_HPP
#define MULTILEVELPLOTTER_HPP

#include "Plot.h"
niklas.baumgarten's avatar
niklas.baumgarten committed
5
#include "mesh/Meshes.hpp"
niklas.baumgarten's avatar
moved    
niklas.baumgarten committed
6
#include "utility/SampleID.hpp"
7
#include <memory>
niklas.baumgarten's avatar
niklas.baumgarten committed
8
#include <sys/stat.h>
niklas.baumgarten's avatar
niklas.baumgarten committed
9
//#include "plot/VtuPlot.h"
10
11


niklas.baumgarten's avatar
niklas.baumgarten committed
12
13
14
15
16
/*
 * Todo make singelton
 */


17
class MultilevelPlotter {
18
private:
niklas.baumgarten's avatar
niklas.baumgarten committed
19
20
21
22
    const string defaultDir = "data/vtk/";
    string currentDir = defaultDir;
    string currentDirShort = "";

niklas.baumgarten's avatar
niklas.baumgarten committed
23
24
25
26
27
28
    void initializeMap(const vector<int> &levels, const Meshes &meshes) {
        for (auto &l: levels) {
            PlotMap[l] = new Plot(meshes[l], meshes.dim());
//            PlotMap[l] = make_unique<SerialVtuPlot>(meshes[l]);
        }
    }
29

niklas.baumgarten's avatar
niklas.baumgarten committed
30
public:
31
32
33
34
35
36
37
    explicit MultilevelPlotter(const Meshes &meshes) {
        vector<int> levels;
        for (int l = meshes.pLevel(); l <= meshes.Level(); l++)
            levels.push_back(l);
        initializeMap(levels, meshes);
    }

niklas.baumgarten's avatar
niklas.baumgarten committed
38
39
40
    void SetDirectory(SampleID id) {
        currentDirShort = id.Str();
        currentDir = defaultDir + currentDirShort;
niklas.baumgarten's avatar
niklas.baumgarten committed
41
42
43
44
        char *currentDirAsCharArr = const_cast<char *> (currentDir.c_str());
        mkdir(currentDirAsCharArr, 0777);
    }

niklas.baumgarten's avatar
niklas.baumgarten committed
45
//    map<int, unique_ptr<SerialVtuPlot>> PlotMap;
niklas.baumgarten's avatar
niklas.baumgarten committed
46
    std::map<int, Plot *> PlotMap;
47
48

    void PlotVector(const string &name, const Vector &data,
niklas.baumgarten's avatar
niklas.baumgarten committed
49
                    int dataDim, int l, const string &dataType) {
niklas.baumgarten's avatar
niklas.baumgarten committed
50
        if (dataType == "VertexData") {
niklas.baumgarten's avatar
niklas.baumgarten committed
51
52
53
            PlotMap[l]->vertexdata(data, dataDim);
            if (dataDim > 1)
                PlotMap[l]->vtk_vertexvector(currentDirShort + "/" + name);
niklas.baumgarten's avatar
niklas.baumgarten committed
54
            else
niklas.baumgarten's avatar
niklas.baumgarten committed
55
                PlotMap[l]->vtk_vertexdata(currentDirShort + "/" + name);
niklas.baumgarten's avatar
niklas.baumgarten committed
56
57
58
            return;
//            PlotMap[l]->AddPointData(name, data, dim);
//            PlotMap[l]->PlotFile(name);
59
60
61
        }

        if (dataType == "CellData") {
niklas.baumgarten's avatar
niklas.baumgarten committed
62
63
64
            PlotMap[l]->celldata(data, dataDim);
            if (dataDim > 1)
                PlotMap[l]->vtk_cellvector(currentDirShort + "/" + name);
niklas.baumgarten's avatar
niklas.baumgarten committed
65
            else
niklas.baumgarten's avatar
niklas.baumgarten committed
66
                PlotMap[l]->vtk_celldata(currentDirShort + "/" + name);
niklas.baumgarten's avatar
niklas.baumgarten committed
67
68
69
            return;
//            PlotMap[l]->AddCellData(name, data, dim);
//            PlotMap[l]->PlotFile(name);
70
        }
71
72
73
    }

    ~MultilevelPlotter() {
niklas.baumgarten's avatar
niklas.baumgarten committed
74
75
        for (auto &plot: PlotMap)
            delete plot.second;
76
        PlotMap.clear();
niklas.baumgarten's avatar
niklas.baumgarten committed
77
//        instance = nullptr;
78
79
80
    }
};

niklas.baumgarten's avatar
niklas.baumgarten committed
81
extern MultilevelPlotter *plotter;
82

83
#endif //MULTILEVELPLOTTER_HPP