MonteCarloTransport.h 2.27 KB
Newer Older
1
2
3
4
5
#ifndef MLMC_MONTECARLOTRANSPORT_HPP
#define MLMC_MONTECARLOTRANSPORT_HPP

#include "MonteCarlo.h"
#include "assemble/DGTransportAssemble.h"
6
#include "timestepping/TimeIntegrator.h"
7
//#include "timestepping/TimeIntegrator2.h"
8

9

10
class MonteCarloTransport : public MonteCarlo {
11
private:
niklas.baumgarten's avatar
niklas.baumgarten committed
12
13
    Plot plot;

14
15
16
17
18
19
20
    void solveTransport(int l,
                        bool fineLevel,
                        double &valueQ,
                        double &cost,
                        Vector &solution);

    TimeSeries getTimeSeries(bool fineLevel);
21

22
23
public:
    DGTransportAssemble *assemble;
24
25
    double startTime = 0.0;
    double endTime = 0.0;
26

niklas.baumgarten's avatar
niklas.baumgarten committed
27
    MatrixGraphs fluxMatrixGraphs;
28
    MatrixGraphs faceMatrixGraphs;
29
30
    CellMatrixGraphs solMatrixGraphs;

31
32
33
    Transfer *transfer;

    MonteCarloTransport(int l, int dM, bool baseLevel, Meshes *meshes,
34
35
36
                        StochasticField *stochFields, DGTransportAssemble *assemble) :
        MonteCarlo(l, dM, baseLevel, meshes, stochFields),
        assemble(assemble),
niklas.baumgarten's avatar
niklas.baumgarten committed
37
        fluxMatrixGraphs(MatrixGraphs(*meshes, dof("cell", 3))),
38
        faceMatrixGraphs(MatrixGraphs(*meshes, dof("face", 3))),
niklas.baumgarten's avatar
niklas.baumgarten committed
39
40
        solMatrixGraphs(*meshes, *assemble->disc),
        plot(Plot((*meshes)[l], meshes->dim())) {
41

42
43
        config.get("startTime", startTime);
        config.get("endTime", endTime);
niklas.baumgarten's avatar
niklas.baumgarten committed
44
45

        transfer = new MatrixTransfer(*assemble);
niklas.baumgarten's avatar
niklas.baumgarten committed
46
47
        if (meshes->dim() != 1)
            transfer->Construct((solMatrixGraphs)[l - pLevel], (solMatrixGraphs)[l - pLevel - 1]);
48
49
    }

50
    ~MonteCarloTransport() {
51
52
53
54
        transfer->Destruct();
        delete transfer;
    }

niklas.baumgarten's avatar
niklas.baumgarten committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
    void UpscaleSolution(const Vector &coarseSol, Vector &coarseSolUp) {
        coarseSolUp = (*transfer) * coarseSol;
    }

    static void UpscaleFlux(const Vector &coarseFlux, Vector &coarseFluxUp) {
        coarseFluxUp = 0;
        for (cell c = coarseFlux.cells(); c != coarseFlux.cells_end(); c++) {
            row coarseRow = coarseFlux.find_row(c());
            for (int k = 0; k < c.Children(); ++k) {
                row fineRow = coarseFluxUp.find_row(c.Child(k));
                for (int i = 0; i < fineRow.n(); ++i)
                    coarseFluxUp(fineRow, i) += coarseFlux(coarseRow, i);
            }
        }
    }

71
    void Method() override;
72
73
74
};

#endif //MLMC_MONTECARLOTRANSPORT_HPP