Debian Codegraph @

skfmm/base_marcher.h

raw symbols SCIP
1 //base_marcher.h
2 #pragma once
3 const unsigned int MaximumDimension = 12;
4 const char Far = 0;
5 const char Narrow = 1;
6 const char Frozen = 2;
7 const char Mask = 3;
8
9 #include <limits>
10 using namespace std;
11 #define doubleEpsilon numeric_limits<double>::epsilon()
12 #define maxDouble numeric_limits<double>::max()
13
14 class heap;
15
16 extern "C" {
17
18 class baseMarcher
19 {
20 public:
21 baseMarcher(double *phi, double *dx, long long *flag,
22 double *distance, int ndim, int *shape,
23 bool self_test, int order, double narrow,
24 int periodic);
25
26 virtual ~baseMarcher();
27 void march();
28 int getError() const { return error_;}
29
30 private:
31 void initalizeNarrow();
32 void solve();
33 void _setIndex(int current, int coord[MaximumDimension])
34 {
35 int rem = current;
36 for (int i=0; i<dim_; i++)
37 {
38 coord[i] = rem/shift_[i]; // integer assignment is like floor()
39 rem -= coord[i]*shift_[i];
40 }
41 }
42
43 int _getIndex(int coord[MaximumDimension])
44 {
45 int ret = 0;
46 for (int i=0; i<dim_; i++) ret += coord[i]*shift_[i];
47 return ret;
48 }
49
50 double narrow_;
51 int order_;
52 int * heapptr_; // heap back pointers
53 heap * heap_;
54 int shape_[MaximumDimension]; // size of each dimension
55 int shift_[MaximumDimension];
56 int periodic_;
57 bool self_test_;
58
59 protected:
60 // derived classes must implement these functions
61 virtual void initalizeFrozen() = 0;
62 virtual double updatePointOrderTwo(int i) = 0;
63 virtual double updatePointOrderOne(int i) = 0;
64
65 // derived classes may implement these functions
66 virtual void cleanUp() { }
67 virtual void finalizePoint(int i, double phi_i) { }
68
69 int _getN(int current, int dim, int dir, int flag)
70 {
71 // for a given point find the neighbor in the given dimension and
72 // direction.
73 // Return -1 if neighbor point is invalid (out of bounds)
74 // Return -1 if neighbor point has flag_ value equal to the flag input
75 int coord[MaximumDimension];
76 _setIndex(current, coord);
77 int newc = coord[dim]+dir;
78
79 if (periodic_ & 1<<dim) {
80 if (newc==-1) newc = shape_[dim]-1;
81 else if (newc==-2) newc = shape_[dim]-2;
82 else if (newc==shape_[dim]) newc = 0;
83 else if (newc==shape_[dim]+1) newc = 1;
84 coord[dim] = newc;
85 return _getIndex(coord);
86 }
87
88 if (newc >= shape_[dim] || newc < 0) return -1;
89 int newa = current + dir*shift_[dim];
90 if (flag_[newa]==flag) return -1;
91 return newa;
92 }
93
94 double * distance_; // return value modified in place
95 double * phi_;
96 double * dx_;
97 long long * flag_;
98 int error_;
99 int dim_; // number of dimensions
100 int size_; // flat size
101 double idx2_[MaximumDimension];
102 };
103
104 } // extern "C"