00001 #include "co2gridgenerator.h"
00002 #include <limits.h>
00003
00004
00016 void CO2GridGenerator::subdivided_hyper_rectangle_with_hole (Triangulation<3> &tria, const std::vector<unsigned int> & repetitions,const Point3D &p1,const Point3D &p2, const double wx, double wz, double wy1, double wy2)
00017 {
00018 assert(repetitions.size() == 3);
00019 assert(p1[0] < p2[0] && p1[1] < p2[1] && p1[2] < p2[2]);
00020 assert(wy2 > wy1);
00021
00022
00023
00024
00025
00026 double delta[3];
00027 for (unsigned int i=0; i<3; ++i)
00028 {
00029 assert (repetitions[i] >= 1);
00030 delta[i] = (p2[i]-p1[i])/repetitions[i];
00031 }
00032
00033
00034
00035 std::vector<Point3D > points;
00036 for (unsigned int z=0; z<=repetitions[2]; ++z)
00037 for (unsigned int y=0; y<=repetitions[1]; ++y)
00038 for (unsigned int x=0; x<=repetitions[0]; ++x)
00039 {
00040 points.push_back (Point3D (p1[0]+x*delta[0],
00041 p1[1]+y*delta[1],
00042 p1[2]+z*delta[2]));
00043 }
00044
00045
00046 std::vector<CellData<3> > cells;
00047 CellData<3> cell;
00048 const unsigned int n_x = (repetitions[0]+1);
00049 const unsigned int n_xy = (repetitions[0]+1)*(repetitions[1]+1);
00050
00051 cells.reserve (repetitions[2]*repetitions[1]*repetitions[0]);
00052 for (unsigned int z=0; z<repetitions[2]; ++z)
00053 for (unsigned int y=0; y<repetitions[1]; ++y)
00054 for (unsigned int x=0; x<repetitions[0]; ++x)
00055 {
00056 cell.vertices[0] = z*n_xy + y*n_x + x;
00057 cell.vertices[1] = z*n_xy + y*n_x + x+1;
00058 cell.vertices[2] = z*n_xy + (y+1)*n_x + x;
00059 cell.vertices[3] = z*n_xy + (y+1)*n_x + x+1;
00060 cell.vertices[4] = (z+1)*n_xy + y*n_x + x;
00061 cell.vertices[5] = (z+1)*n_xy + y*n_x + x+1;
00062 cell.vertices[6] = (z+1)*n_xy + (y+1)*n_x + x;
00063 cell.vertices[7] = (z+1)*n_xy + (y+1)*n_x + x+1;
00064 cell.material_id = 0;
00065
00066
00067 Point3D vertex_000 = points[cell.vertices[VERTEX_000]];
00068 Point3D vertex_111 = points[cell.vertices[VERTEX_111]];
00069
00070 if ( wx > vertex_000[0] && wx < vertex_111[0] &&
00071 wz > vertex_000[2] && wz < vertex_111[2] &&
00072 !( vertex_000[1] >= wy2 || vertex_111[1] <= wy1))
00073 {
00074
00075
00076 continue;
00077 }
00078 else
00079 {
00080 cells.push_back(cell);
00081 }
00082 }
00083
00084 tria.create_triangulation (points, cells, SubCellData());
00085
00086 }
00087
00088
00089 void CO2GridGenerator::subdivided_hyper_rectangle_with_hole (Triangulation<3> &tria, const std::vector<unsigned int> & repetitions,const Point3D &p1,const Point3D &p2, VecWellInfo &wells)
00090 {
00091 assert(repetitions.size() == 3);
00092 assert(p1[0] < p2[0] && p1[1] < p2[1] && p1[2] < p2[2]);
00093
00094
00095
00096
00097
00098
00099
00100 unsigned nVertices=(repetitions[0]+1)*(repetitions[1]+1)*(repetitions[2]+1);
00101
00102 double delta[3];
00103 unsigned INVALID_INDEX = UINT_MAX;
00104
00105 for (unsigned int i=0; i<3; ++i)
00106 {
00107 assert (repetitions[i] >= 1);
00108 delta[i] = (p2[i]-p1[i])/repetitions[i];
00109 }
00110
00111
00112
00113
00114 std::vector<Point3D > points;
00115 points.reserve(nVertices);
00116 std::vector<unsigned> pointsIndex(nVertices);
00117 for (unsigned int z=0; z<=repetitions[2]; ++z)
00118 for (unsigned int y=0; y<=repetitions[1]; ++y)
00119 for (unsigned int x=0; x<=repetitions[0]; ++x)
00120 {
00121 points.push_back (Point3D (p1[0]+x*delta[0],
00122 p1[1]+y*delta[1],
00123 p1[2]+z*delta[2]));
00124 }
00125
00126
00127
00128
00129
00130
00131 unsigned index=0;
00132 Point3D DX_4(delta[0]/4.0,delta[1]/4.0,delta[2]/4.0);
00133 bool bIsValid;
00134 for(unsigned i=0;i<nVertices;i++)
00135 {
00136 bIsValid=true;
00137 for(unsigned j=0;j<wells.size();j++)
00138 {
00139 WellInfo well = wells[j];
00140 well.P+=DX_4;
00141 well.Q-=DX_4;
00142 if (well.isPointInWell(points[i]))
00143 {
00144 bIsValid=false;
00145 break;
00146 }
00147 }
00148 if (bIsValid)
00149 pointsIndex[i]=index++;
00150 else
00151 {
00152 pointsIndex[i]=INVALID_INDEX;
00153
00154 }
00155 }
00156
00157
00158
00159
00160 std::vector<CellData<3> > cells;
00161 CellData<3> cell;
00162 const unsigned int n_x = (repetitions[0]+1);
00163 const unsigned int n_xy = (repetitions[0]+1)*(repetitions[1]+1);
00164
00165 cells.reserve (repetitions[2]*repetitions[1]*repetitions[0]);
00166 for (unsigned int z=0; z<repetitions[2]; ++z)
00167 for (unsigned int y=0; y<repetitions[1]; ++y)
00168 for (unsigned int x=0; x<repetitions[0]; ++x)
00169 {
00170 cell.vertices[0] = z*n_xy + y*n_x + x;
00171 cell.vertices[1] = z*n_xy + y*n_x + x+1;
00172 cell.vertices[2] = z*n_xy + (y+1)*n_x + x;
00173 cell.vertices[3] = z*n_xy + (y+1)*n_x + x+1;
00174 cell.vertices[4] = (z+1)*n_xy + y*n_x + x;
00175 cell.vertices[5] = (z+1)*n_xy + y*n_x + x+1;
00176 cell.vertices[6] = (z+1)*n_xy + (y+1)*n_x + x;
00177 cell.vertices[7] = (z+1)*n_xy + (y+1)*n_x + x+1;
00178 cell.material_id = 0;
00179
00180
00181
00182 Point3D BC = points[cell.vertices[VERTEX_000]];
00183 BC += points[cell.vertices[VERTEX_111]];
00184 BC/=2.0;
00185
00186
00187 bool isCellInWell=false;
00188 for (unsigned w=0;w<wells.size();w++)
00189 {
00190 if (wells[w].isPointInWell(BC))
00191 {
00192 isCellInWell=true;
00193 break;
00194 }
00195 }
00196 if (!isCellInWell)
00197 {
00198
00199
00200 for (unsigned k=0;k<8;k++)
00201 {
00202 cell.vertices[k]=pointsIndex[cell.vertices[k]];
00203 assert(cell.vertices[k] != INVALID_INDEX);
00204 }
00205 cells.push_back(cell);
00206 }
00207 }
00208
00209 std::vector<Point3D>::iterator it = points.begin();
00210 for (unsigned i=0;i<nVertices;i++)
00211 {
00212 if (pointsIndex[i] != INVALID_INDEX)
00213 *(it++) = points[i];
00214 }
00215 if(it != points.end())
00216 points.erase(it,points.end());
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227 tria.create_triangulation (points, cells, SubCellData());
00228
00229 }