TestStochasticCollocation.hpp 1.88 KB
Newer Older
1
2
3
4
5
6
7
#ifndef TESTSTOCHASTICCOLLOCATION_HPP
#define TESTSTOCHASTICCOLLOCATION_HPP

#include "StochasticCollocation.hpp"
#include "TestEnvironment.hpp"


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
struct TestParams {
  std::string problemName;

  std::string quantity;

  std::string model;
};

Logging &operator<<(Logging &s, const TestParams &testParams) {
  return s << "Problem Name: " << testParams.problemName << endl
           << "Quantity: " << testParams.quantity << endl
           << "Model: " << testParams.model << endl;
}

class TestStochasticCollocation : public TestWithParam<TestParams> {
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
protected:
  bool onlyFine = true;

  int level = 3;

  int samples;

  double epsilon;

  MeshesCreator meshesCreator;

  PDESolverCreator pdeSolverCreator;

  std::unique_ptr<Estimator> scSeriell;

  std::unique_ptr<Estimator> scParallel;

  double MeanTolerance() const { return sqrt(1.0 / samples); }

  double SVarTolerance() const { return sqrt(10.0 / samples); }

  TestStochasticCollocation(double epsilon, int samples) :
    samples(samples), epsilon(epsilon),
    meshesCreator(MeshesCreator().
      WithDistribute("RCB").
      WithoutOverlap()),

    pdeSolverCreator(PDESolverCreator().
      WithProblem(GetParam().problemName).
      WithQuantity(GetParam().quantity).
      WithModel(GetParam().model)),

    scSeriell(EstimatorCreator("MonteCarlo").
      WithPDESolverCreator(pdeSolverCreator).
      WithMeshesCreator(meshesCreator).
      WithInitSamples(samples).
      WithOnlyFine(onlyFine).
      WithInitLevel(level).
      WithEpsilon(epsilon).
      WithParallel(false).
      CreateUnique()),

    scParallel(EstimatorCreator("MonteCarlo").
      WithPDESolverCreator(pdeSolverCreator).
      WithMeshesCreator(meshesCreator).
      WithInitSamples(samples).
      WithOnlyFine(onlyFine).
      WithEpsilon(epsilon).
      WithInitLevel(level).
      WithParallel(true).
      CreateUnique()) {}
};

#endif //TESTSTOCHASTICCOLLOCATION_HPP