mantaflow  0.10
A framework for fluid simulation
kernel.h
Go to the documentation of this file.
1 
2 /******************************************************************************
3  *
4  * MantaFlow fluid solver framework
5  * Copyright 2011-2014 Tobias Pfaff, Nils Thuerey
6  *
7  * This program is free software, distributed under the terms of the
8  * GNU General Public License (GPL)
9  * http://www.gnu.org/licenses
10  *
11  * Function and macros for defining compution kernels over grids
12  *
13  ******************************************************************************/
14 
15 #ifndef _KERNEL_H
16 #define _KERNEL_H
17 
18 #if TBB==1
19 # include <tbb/blocked_range3d.h>
20 # include <tbb/blocked_range.h>
21 # include <tbb/parallel_for.h>
22 # include <tbb/parallel_reduce.h>
23 #endif
24 
25 #if OPENMP==1
26 # include <omp.h>
27 #endif
28 
29 #include "general.h"
30 
31 namespace Manta {
32 
33 // fwd decl
34 class GridBase;
35 class Grid4dBase;
36 class ParticleBase;
37 
38 
39 // simple iteration
40 #define FOR_IJK_BND(grid, bnd) \
41  for(int k=((grid).is3D() ? bnd : 0),__kmax=((grid).is3D() ? ((grid).getSizeZ()-bnd) : 1); k<__kmax; k++) \
42  for(int j=bnd; j<(grid).getSizeY()-bnd; j++) \
43  for(int i=bnd; i<(grid).getSizeX()-bnd; i++)
44 
45 #define FOR_IJK_REVERSE(grid) \
46  for(int k=(grid).getSizeZ()-1; k>=0; k--) \
47  for(int j=(grid).getSizeY()-1; j>=0; j--) \
48  for(int i=(grid).getSizeX()-1; i>=0; i--)
49 
50 #define FOR_IDX(grid) \
51  for(IndexInt idx=0, total=(grid).getSizeX()*(grid).getSizeY()*(grid).getSizeZ(); idx<total; idx++)
52 
53 #define FOR_IJK(grid) FOR_IJK_BND(grid, 0)
54 
55 #define FOR_PARTS(parts) \
56  for(IndexInt idx=0, total=(parts).size(); idx<total; idx++)
57 
58 // simple loop over 4d grids
59 #define FOR_IJKT_BND(grid, bnd) \
60  for(int t=((grid).is4D() ? bnd : 0); t<((grid).is4D() ? ((grid).getSizeT()-bnd) : 1); ++t) \
61  for(int k=((grid).is3D() ? bnd : 0); k<((grid).is3D() ? ((grid).getSizeZ()-bnd) : 1); ++k) \
62  for(int j=bnd; j<(grid).getSizeY()-bnd; ++j) \
63  for(int i=bnd; i<(grid).getSizeX()-bnd; ++i)
64 
66 struct KernelBase {
67  int maxX, maxY, maxZ, minZ, maxT, minT;
68  int X, Y, Z, dimT;
69  IndexInt size;
70 
71  KernelBase(IndexInt num);
72  KernelBase(const GridBase* base, int bnd);
73  KernelBase(const Grid4dBase* base, int bnd);
74 
75  // specify in your derived classes:
76 
77  // kernel operators
78  // ijk mode: void operator() (int i, int j, int k)
79  // idx mode: void operator() (IndexInt idx)
80 
81  // reduce mode:
82  // void join(classname& other)
83  // void setup()
84 };
85 
86 } // namespace
87 
88 // all kernels will automatically be added to the "Kernels" group in doxygen
89 
90 #endif
91 
92 
Definition: commonkernels.h:22
Definition: grid4d.h:29
Basic data structure for kernel data, initialized based on kernel type (e.g. single, idx, etc).
Definition: kernel.h:66
Definition: grid.h:29