00001
00002
00003
00004
00005
00006 #ifndef AMROC_GFM_GEOM_H
00007 #define AMROC_GFM_GEOM_H
00008
00015 #include "Geom.h"
00016
00023 template <class DataType, int dim>
00024 class GFMGeomBase {
00025 public:
00026 typedef GridData<DataType,dim> grid_data_type;
00027 typedef Vector<DataType,dim> point_type;
00028
00029 virtual ~GFMGeomBase() {}
00030
00031
00032
00033
00034 virtual void CellNormals(GridHierarchy& GH, grid_data_type& gdphi, const int& nc,
00035 const int* idx, point_type* normals) = 0;
00036 virtual void CellDistances(GridHierarchy& GH, grid_data_type& gdphi, const int& nc,
00037 const int* idx, DataType* distance) = 0;
00038
00039 };
00040
00041 template <class DataType, int dim> class GFMGeom;
00042
00049 template <class DataType>
00050 class GFMGeom<DataType,2> : public GFMGeomBase<DataType,2> {
00051 typedef GFMGeomBase<DataType,2> base;
00052
00053 public:
00054 typedef typename base::grid_data_type grid_data_type;
00055 typedef typename base::point_type point_type;
00056
00057 GFMGeom() : base() {}
00058
00059 virtual ~GFMGeom() {}
00060
00061 virtual void CellNormals(GridHierarchy& GH, grid_data_type& gdphi, const int& nc,
00062 const int* idx, point_type* normals) {
00063 Coords ss(gdphi.stepsize());
00064 DCoords dx2(GH.worldStep(ss));
00065 dx2 *= static_cast<DataType>(2.0);
00066
00067 BeginFastIndex2(phi, gdphi.bbox(), gdphi.data(), DataType);
00068 for (register int i = 0; i<nc; i++) {
00069 const int& n = idx[2*i]; const int& m = idx[2*i+1];
00070 normals[i](0) = -(FastIndex2(phi,n+ss(0),m)-FastIndex2(phi,n-ss(0),m))/dx2(0);
00071 normals[i](1) = -(FastIndex2(phi,n,m+ss(1))-FastIndex2(phi,n,m-ss(1)))/dx2(1);
00072 normals[i] /= normals[i].abs();
00073 }
00074 EndFastIndex2(phi);
00075 }
00076
00077 virtual void CellDistances(GridHierarchy& GH, grid_data_type& gdphi, const int& nc,
00078 const int* idx, DataType* distance) {
00079 BeginFastIndex2(phi, gdphi.bbox(), gdphi.data(), DataType);
00080 for (register int n = 0; n<nc; n++)
00081 distance[n] = FastIndex2(phi,idx[2*n],idx[2*n+1]);
00082 EndFastIndex2(phi);
00083 }
00084 };
00085
00086
00093 template <class DataType>
00094 class GFMGeom<DataType,3> : public GFMGeomBase<DataType,3> {
00095 typedef GFMGeomBase<DataType,3> base;
00096
00097 public:
00098 typedef typename base::grid_data_type grid_data_type;
00099 typedef typename base::point_type point_type;
00100
00101 GFMGeom() : base() {}
00102
00103 virtual ~GFMGeom() {}
00104
00105 virtual void CellNormals(GridHierarchy& GH, grid_data_type& gdphi, const int& nc,
00106 const int* idx, point_type* normals) {
00107 Coords ss(gdphi.stepsize());
00108 DCoords dx2(GH.worldStep(ss));
00109 dx2 *= static_cast<DataType>(2.0);
00110
00111 BeginFastIndex3(phi, gdphi.bbox(), gdphi.data(), DataType);
00112 for (register int i = 0; i<nc; i++) {
00113 const int& n = idx[3*i]; const int& m = idx[3*i+1]; const int& l = idx[3*i+2];
00114 normals[i](0) = -(FastIndex3(phi,n+ss(0),m,l)-FastIndex3(phi,n-ss(0),m,l))/dx2(0);
00115 normals[i](1) = -(FastIndex3(phi,n,m+ss(1),l)-FastIndex3(phi,n,m-ss(1),l))/dx2(1);
00116 normals[i](2) = -(FastIndex3(phi,n,m,l+ss(2))-FastIndex3(phi,n,m,l-ss(2)))/dx2(2);
00117 normals[i] /= normals[i].abs();
00118 }
00119 EndFastIndex3(phi);
00120 }
00121
00122 virtual void CellDistances(GridHierarchy& GH, grid_data_type& gdphi, const int& nc,
00123 const int* idx, DataType* distance) {
00124 BeginFastIndex3(phi, gdphi.bbox(), gdphi.data(), DataType);
00125 for (register int n = 0; n<nc; n++)
00126 distance[n] = FastIndex3(phi,idx[3*n],idx[3*n+1],idx[3*n+2]);
00127 EndFastIndex3(phi);
00128 }
00129 };
00130
00131 #endif