CO2GridGenerator Class Reference

#include <co2gridgenerator.h>

List of all members.

Public Member Functions

 CO2GridGenerator ()
 ~CO2GridGenerator ()

Static Public Member Functions

static void 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)
static void subdivided_hyper_rectangle_with_hole (Triangulation< 3 > &tria, const std::vector< unsigned int > &repetitions, const Point3D &p1, const Point3D &p2, VecWellInfo &wells)

Detailed Description

Definition at line 18 of file co2gridgenerator.h.


Constructor & Destructor Documentation

CO2GridGenerator::CO2GridGenerator (  ) 
CO2GridGenerator::~CO2GridGenerator (  ) 

Member Function Documentation

void CO2GridGenerator::subdivided_hyper_rectangle_with_hole ( Triangulation< 3 > &  tria,
const std::vector< unsigned int > &  repetitions,
const Point3D p1,
const Point3D p2,
VecWellInfo wells 
) [static]

Definition at line 89 of file co2gridgenerator.cpp.

00090 {
00091   assert(repetitions.size() == 3);
00092   assert(p1[0] < p2[0] && p1[1] < p2[1] && p1[2] < p2[2]);
00093 
00094                                    // then check that all repetitions
00095                                    // are >= 1, and calculate deltas
00096                                    // convert repetitions from double
00097                                    // to int by taking the ceiling.
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   // then generate the necessary
00113   // points
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   //Verify which vertices are valid (not inside wells)
00127   //and enumerate all vertices not counting the invalid
00128   //ones. Put the indices in the vector pointsIndex.
00129   //pointsIndex[i] == indice of ith vertice in the vector "points"
00130   //pointsIndex[i] == INVALID_INDEX if the vertice is invalid.
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       //printf("vertice ripped out %d\n",i);
00154     }
00155   }
00156   
00157 
00158   // next create the cells
00159   // Prepare cell data
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         //If cell is in the hole, dont insert it in the array of cells.
00181         //First find the cell's barycenter
00182         Point3D BC  = points[cell.vertices[VERTEX_000]];
00183         BC += points[cell.vertices[VERTEX_111]];
00184         BC/=2.0;
00185 
00186         //Find out if the cell is inside one of the wells
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           //Insert it in the vector cells
00199           //but first map the vertices to the right indices
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   //Now adjust the points vector containning the vertices
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   for (unsigned i=0;i<points.size();i++)
00221   {
00222     printf("%u) %g %g %g\n" ,i,points[i](0),points[i](1),points[i](2));
00223     
00224   }
00225   */
00226   
00227   tria.create_triangulation (points, cells, SubCellData());  
00228 
00229 }

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 
) [static]

Construct a rectangular mesh and adds a hole in it. Important to note that meshes with holes are not structured meshes in the cense that the distribution of its vertices cannot be seen as a matrix of points. So, the creation a general mesh with holes demands data structures and complexities inherent to unstrucured meshes constructions wich is not our objective to develop. Actually if one day we will used complex geometries is better to use third parties meshes generation code lake gmsh. To avoid the complexities of unstructured meshes we restric the hole generation to just one array of contiguos elements along the y axes. In this way we can use the structured mesh generation code of the library deal.II and then add a hole to it deleting cells. Note that if we want to not have dangling vertices the hole must be of the size of one element such that we dont need to delete any vertices. Because to delete vertices we have to do a renumeration of the vertices indices and update all cells that refer to them. This demands much powerfull data structures tipical of unstructured meshes constructrions alghorithms. The hole is specified give the x,z point of the hole than informing the lenght of the well specifying an interval in the y axes direction [y1-y2]. The well is then specified as a line aligned with the y axes. All cells that contain this line are deleted from the mesh.

Parameters:
tria The triangulation to be done
repetitions The vector containing the number of discretizations for each dimension. (repetitions.size() == 3)
p1 The lower point of the rectangular mesh.
p2 The top point of the rectangular mesh.
repetitions Vector os size three containing the discretization in each axis direction
wx The X coordinate of the hole (well).
wz The z coordinate of the hole (well).
wy1 The lower cordinate of well in Y.
wy2 The upper coordinate of well in Y.

Definition at line 16 of file co2gridgenerator.cpp.

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                                    // then check that all repetitions
00023                                    // are >= 1, and calculate deltas
00024                                    // convert repetitions from double
00025                                    // to int by taking the ceiling.
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   // then generate the necessary
00034   // points
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   // next create the cells
00045   // Prepare cell data
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         //If cell is in the hole, dont insert it in the array of cells.
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           //Ok the cell contains at least on point in the line X=wx,y in [wy1,wy2], Z = wz
00075           //So dont add the cell to the array of cells
00076           continue;
00077         }
00078         else 
00079         {
00080           cells.push_back(cell);
00081         }
00082       }
00083 
00084   tria.create_triangulation (points, cells, SubCellData());  
00085 
00086 }


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Sun Apr 8 23:12:58 2012 for CO2INJECTION by  doxygen 1.6.3