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

#include "Plot.h"
5
#include <memory>
niklas.baumgarten's avatar
niklas.baumgarten committed
6
#include <sys/stat.h>
niklas.baumgarten's avatar
niklas.baumgarten committed
7
//#include "plot/VtuPlot.h"
8
9
10


class MultilevelPlotter {
11
private:
niklas.baumgarten's avatar
niklas.baumgarten committed
12
13
14
15
    const string defaultDir = "data/vtk/";
    string currentDir = defaultDir;
    string currentDirShort = "";

niklas.baumgarten's avatar
niklas.baumgarten committed
16
17
18
19
20
21
    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]);
        }
    }
22

niklas.baumgarten's avatar
niklas.baumgarten committed
23
public:
24
25
26
27
28
29
30
    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
31
32
33
34
35
36
37
    void SetDirectory(const string &dir) {
        currentDirShort = dir;
        currentDir = defaultDir + dir;
        char *currentDirAsCharArr = const_cast<char *> (currentDir.c_str());
        mkdir(currentDirAsCharArr, 0777);
    }

niklas.baumgarten's avatar
niklas.baumgarten committed
38
39
//    map<int, unique_ptr<SerialVtuPlot>> PlotMap;
    map<int, Plot *> PlotMap;
40
41

    void PlotVector(const string &name, const Vector &data,
niklas.baumgarten's avatar
niklas.baumgarten committed
42
                    int dataDim, int l, const string &dataType) {
niklas.baumgarten's avatar
niklas.baumgarten committed
43
        if (dataType == "VertexData") {
niklas.baumgarten's avatar
niklas.baumgarten committed
44
45
46
            PlotMap[l]->vertexdata(data, dataDim);
            if (dataDim > 1)
                PlotMap[l]->vtk_vertexvector(currentDirShort + "/" + name);
niklas.baumgarten's avatar
niklas.baumgarten committed
47
            else
niklas.baumgarten's avatar
niklas.baumgarten committed
48
                PlotMap[l]->vtk_vertexdata(currentDirShort + "/" + name);
niklas.baumgarten's avatar
niklas.baumgarten committed
49
50
51
            return;
//            PlotMap[l]->AddPointData(name, data, dim);
//            PlotMap[l]->PlotFile(name);
52
53
54
        }

        if (dataType == "CellData") {
niklas.baumgarten's avatar
niklas.baumgarten committed
55
56
57
            PlotMap[l]->celldata(data, dataDim);
            if (dataDim > 1)
                PlotMap[l]->vtk_cellvector(currentDirShort + "/" + name);
niklas.baumgarten's avatar
niklas.baumgarten committed
58
            else
niklas.baumgarten's avatar
niklas.baumgarten committed
59
                PlotMap[l]->vtk_celldata(currentDirShort + "/" + name);
niklas.baumgarten's avatar
niklas.baumgarten committed
60
61
62
            return;
//            PlotMap[l]->AddCellData(name, data, dim);
//            PlotMap[l]->PlotFile(name);
63
        }
64
65
66
    }

    ~MultilevelPlotter() {
niklas.baumgarten's avatar
niklas.baumgarten committed
67
68
        for (auto &plot: PlotMap)
            delete plot.second;
69
        PlotMap.clear();
niklas.baumgarten's avatar
niklas.baumgarten committed
70
//        instance = nullptr;
71
72
73
    }
};

74
75
extern std::shared_ptr<MultilevelPlotter> plotter;

76
#endif //MULTILEVELPLOTTER_HPP