Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test.cpp « preprocessed « mantaflow « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b90c886efe7b9374b628f06607ab6d9713d19f18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133


// DO NOT EDIT !
// This file is generated using the MantaFlow preprocessor (prep generate).

/******************************************************************************
 *
 * MantaFlow fluid solver framework
 * Copyright 2011 Tobias Pfaff, Nils Thuerey
 *
 * This program is free software, distributed under the terms of the
 * Apache License, Version 2.0
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Use this file to test new functionality
 *
 ******************************************************************************/

#include "levelset.h"
#include "commonkernels.h"
#include "particle.h"
#include <cmath>

using namespace std;

namespace Manta {

// two simple example kernels

struct reductionTest : public KernelBase {
  reductionTest(const Grid<Real> &v) : KernelBase(&v, 0), v(v), sum(0)
  {
    runMessage();
    run();
  }
  inline void op(IndexInt idx, const Grid<Real> &v, double &sum)
  {
    sum += v[idx];
  }
  inline operator double()
  {
    return sum;
  }
  inline double &getRet()
  {
    return sum;
  }
  inline const Grid<Real> &getArg0()
  {
    return v;
  }
  typedef Grid<Real> type0;
  void runMessage()
  {
    debMsg("Executing kernel reductionTest ", 3);
    debMsg("Kernel range"
               << " x " << maxX << " y " << maxY << " z " << minZ << " - " << maxZ << " ",
           4);
  };
  void operator()(const tbb::blocked_range<IndexInt> &__r)
  {
    for (IndexInt idx = __r.begin(); idx != (IndexInt)__r.end(); idx++)
      op(idx, v, sum);
  }
  void run()
  {
    tbb::parallel_reduce(tbb::blocked_range<IndexInt>(0, size), *this);
  }
  reductionTest(reductionTest &o, tbb::split) : KernelBase(o), v(o.v), sum(0)
  {
  }
  void join(const reductionTest &o)
  {
    sum += o.sum;
  }
  const Grid<Real> &v;
  double sum;
};

struct minReduction : public KernelBase {
  minReduction(const Grid<Real> &v) : KernelBase(&v, 0), v(v), sum(0)
  {
    runMessage();
    run();
  }
  inline void op(IndexInt idx, const Grid<Real> &v, double &sum)
  {
    if (sum < v[idx])
      sum = v[idx];
  }
  inline operator double()
  {
    return sum;
  }
  inline double &getRet()
  {
    return sum;
  }
  inline const Grid<Real> &getArg0()
  {
    return v;
  }
  typedef Grid<Real> type0;
  void runMessage()
  {
    debMsg("Executing kernel minReduction ", 3);
    debMsg("Kernel range"
               << " x " << maxX << " y " << maxY << " z " << minZ << " - " << maxZ << " ",
           4);
  };
  void operator()(const tbb::blocked_range<IndexInt> &__r)
  {
    for (IndexInt idx = __r.begin(); idx != (IndexInt)__r.end(); idx++)
      op(idx, v, sum);
  }
  void run()
  {
    tbb::parallel_reduce(tbb::blocked_range<IndexInt>(0, size), *this);
  }
  minReduction(minReduction &o, tbb::split) : KernelBase(o), v(o.v), sum(0)
  {
  }
  void join(const minReduction &o)
  {
    sum = min(sum, o.sum);
  }
  const Grid<Real> &v;
  double sum;
};

// ... add more test code here if necessary ...

}  // namespace Manta