-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMCgrid.hpp
105 lines (87 loc) · 2.62 KB
/
MCgrid.hpp
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
// MCgrid.hpp
// Class definitions for rectilinear Monte Carlo grids
// Questions/comments to [email protected] (Jason Gruber)
#ifndef MCGRID
#define MCGRID
#include"MMSP.grid.hpp"
namespace MMSP{
class MCgrid1D : public grid1D<scalar,int> {
public:
// constructors
MCgrid1D(int x)
: grid1D<scalar,int>(x) {}
MCgrid1D(const char* filename)
: grid1D<scalar,int>(filename) {}
MCgrid1D(const char* filename, int id, int np, int ng = 1)
: grid1D<scalar,int>(filename,id,np,ng) {}
// the update function
void update(int steps = 1);
void update(int steps, int id, int np, int ng = 1);
// utility functions
std::vector<int> nonzero(int x) const;
};
std::vector<int> MCgrid1D::nonzero(int x) const
{
std::vector<int> nonzero;
for (int i=-1; i<=1; i++)
//if (abs(i)<=1)
nonzero.push_back(neighbor(x,i));
sort(nonzero.begin(),nonzero.end());
nonzero.erase(unique(nonzero.begin(),nonzero.end()),nonzero.end());
return nonzero;
}
class MCgrid2D : public grid2D<scalar,int> {
public:
// constructors
MCgrid2D(int x, int y)
: grid2D<scalar,int>(x,y) {}
MCgrid2D(const char* filename)
: grid2D<scalar,int>(filename) {}
MCgrid2D(const char* filename, int id, int np, int ng = 1)
: grid2D<scalar,int>(filename,id,np,ng) {}
// the update function
void update(int steps = 1);
void update(int steps, int id, int np, int ng = 1);
// utility functions
std::vector<int> nonzero(int x, int y) const;
};
std::vector<int> MCgrid2D::nonzero(int x, int y) const
{
std::vector<int> nonzero;
for (int i=-1; i<=1; i++)
for (int j=-1; j<=1; j++)
//if (abs(i)+abs(j)<=1)
nonzero.push_back(neighbor(x,y,i,j));
sort(nonzero.begin(),nonzero.end());
nonzero.erase(unique(nonzero.begin(),nonzero.end()),nonzero.end());
return nonzero;
}
class MCgrid3D : public grid3D<scalar,int> {
public:
// constructors
MCgrid3D(int x, int y, int z)
: grid3D<scalar,int>(x,y,z) {}
MCgrid3D(const char* filename)
: grid3D<scalar,int>(filename) {}
MCgrid3D(const char* filename, int id, int np, int ng = 1)
: grid3D<scalar,int>(filename,id,np,ng) {}
// the update function
void update(int steps = 1);
void update(int steps, int id, int np, int ng = 1);
// utility functions
std::vector<int> nonzero(int x, int y, int z) const;
};
std::vector<int> MCgrid3D::nonzero(int x, int y, int z) const
{
std::vector<int> nonzero;
for (int i=-1; i<=1; i++)
for (int j=-1; j<=1; j++)
for (int k=-1; k<=1; k++)
//if (abs(i)+abs(j)+abs(k)<=1)
nonzero.push_back(neighbor(x,y,z,i,j,k));
sort(nonzero.begin(),nonzero.end());
nonzero.erase(unique(nonzero.begin(),nonzero.end()),nonzero.end());
return nonzero;
}
} // namespace MMSP
#endif