#include <fchessboard3d.h>
Public Member Functions | |
FChessBoard3D (Point3D p0, Point3D p1, Point3D lp0, Point3D lp1, std::string fileName) | |
FChessBoard3D (Point3D p0, Point3D p1, Point3D lp0, Point3D lp1, double My, double Cy, std::string fileName) | |
FChessBoard3D (Point3D p0, Point3D p1, int dimX, int dimY, int dimZ, std::vector< double > &data) | |
virtual double | operator() (const VecDouble &p, unsigned int component=0) const |
int | getDimX () |
int | getDimY () |
int | getDimZ () |
virtual | ~FChessBoard3D () |
Private Attributes | |
Point3D | m_p0 |
Point3D | m_p1 |
Point3D | m_lp0 |
Point3D | m_lp1 |
unsigned | m_dimX |
unsigned | m_dimY |
unsigned | m_dimZ |
double | m_dX |
double | m_dY |
double | m_dZ |
StackVector< 3, unsigned > | Xi |
StackVector< 3, unsigned > | Xe |
dealii::Table< 3, double > | m_matrix3D |
This class implements a function that has a chess board distribution along the domain of the problem. This distribution is loaded from a file the first line is ignored and the second line contain the dimension of the 3D matrix separated by "x" letters. For example "3x3x3". Next follows an array of numbers describing the matrix running in x,y,z in that order. The reservoir are specified with the upper p1 and bottom p0 points defining a rectangle 3D. In applications with MPI each process has just a subdomain of the reservoir. So its good to have in this class the concept of the subdomain of the original domain specified again with two points lp0 and lp1. When the subdomain is specified the class reads the file and store information of the chessboard belonging only to the subdomain. This can save a lot of memory and its a crucial design for the cases we have a large number of process running in big clusters.
Definition at line 20 of file fchessboard3d.h.
FChessBoard3D::FChessBoard3D | ( | Point3D | p0, | |
Point3D | p1, | |||
Point3D | lp0, | |||
Point3D | lp1, | |||
std::string | fileName | |||
) |
Definition at line 9 of file fchessboard3d.cpp.
00010 :m_p0(p0),m_p1(p1) 00011 { 00012 assert(lp0[0] <= lp1[0]); 00013 assert(lp0[1] <= lp1[1]); 00014 assert(lp0[2] <= lp1[2]); 00015 assert(p0[0] <= p1[0]); 00016 assert(p0[1] <= p1[1]); 00017 assert(p0[2] <= p1[2]); 00018 assert(lp0[0] >= p0[0]); 00019 assert(lp0[1] >= p0[1]); 00020 assert(lp0[2] >= p0[2]); 00021 assert(lp1[0] <= p1[0]); 00022 assert(lp1[1] <= p1[1]); 00023 assert(lp1[2] <= p1[2]); 00024 double ddLixo; 00025 00026 00027 00028 00029 ifstream file(fileName.c_str()); 00030 if (file.fail()) 00031 throw new Exception("FChessBoard3D: File \"%s\" not found",fileName.c_str()); 00032 00033 char str[MAX_LINE_SIZE]; 00034 00035 //Ignore the first line 00036 file.getline(str,MAX_LINE_SIZE); 00037 00038 //Get the second line containing the dimension of the chess board 00039 //in the format "size_X x size_Y x size_Z" 00040 file.getline(str,MAX_LINE_SIZE); 00041 if (file.fail() || sscanf(str,"%d x %d x %d",&m_dimX,&m_dimY,&m_dimZ) != 3) 00042 throw new Exception("FChessBoard3D: File \"%s\", Second line (\"%s\")\n\tnot in format <number> x <number> x <number>",fileName.c_str(),str); 00043 00044 00045 00046 m_dX = (p1[0]-p0[0])/m_dimX; 00047 m_dY = (p1[1]-p0[1])/m_dimY; 00048 m_dZ = (p1[2]-p0[2])/m_dimZ; 00049 00050 Xi[0] = static_cast<unsigned>(floor(lp0[0]/m_dX)); 00051 Xi[1] = static_cast<unsigned>(floor(lp0[1]/m_dY)); 00052 Xi[2] = static_cast<unsigned>(floor(lp0[2]/m_dZ)); 00053 00054 Xe[0] = static_cast<unsigned>(ceil(lp1[0]/m_dX)); 00055 Xe[1] = static_cast<unsigned>(ceil(lp1[1]/m_dY)); 00056 Xe[2] = static_cast<unsigned>(ceil(lp1[2]/m_dZ)); 00057 00058 //Just to garantee that roundoff errors would not occur. 00059 //Actually it never ocurred, but just to make sure. 00060 if (Xe[0] > m_dimX) 00061 Xe[0]=m_dimX; 00062 if (Xe[1] > m_dimY) 00063 Xe[1]=m_dimY; 00064 if (Xe[2] > m_dimZ) 00065 Xe[2]=m_dimZ; 00066 00067 00068 //Allocate the table to store the chess board 00069 TableIndices<3> sizes(Xe[2]-Xi[2],Xe[1]-Xi[1],Xe[0]-Xi[0]); 00070 //TableIndices<3> sizes(Xe[0]-Xi[0]+1,Xe[1]-Xi[1]+1,Xe[2]-Xi[2]+1); 00071 m_matrix3D.reinit(sizes); 00072 00073 00074 m_lp0[0]=Xi[0]*m_dX; 00075 m_lp0[1]=Xi[1]*m_dY; 00076 m_lp0[2]=Xi[2]*m_dZ; 00077 00078 m_lp1[0]=Xe[0]*m_dX; 00079 m_lp1[1]=Xe[1]*m_dY; 00080 m_lp1[2]=Xe[2]*m_dZ; 00081 00082 00083 /*printf("========================\n%d) Points %g,%g,%g - %g,%g,%g => %g %g %g - %g %g %g\n",NetMPI::rank(),p0[0],p0[1],p0[2],p1[0],p1[1],p1[2],lp0[0], 00084 lp0[1],lp0[2],lp1[0],lp1[1],lp1[2]); 00085 printf("========================\n%d) Indices %d,%d,%d - %d,%d,%d\n",NetMPI::rank(),Xi[0],Xi[1],Xi[2],Xe[0],Xe[1],Xe[2]); 00086 printf("========================\n%d) Minimal Geo Mesh %g,%g,%g - %g,%g,%g\n",NetMPI::rank(),m_lp0[0],m_lp0[1],m_lp0[2],m_lp1[0],m_lp1[1],m_lp1[2]); 00087 */ 00088 00089 00090 for (unsigned z=0;z<m_dimZ;z++) 00091 for (unsigned y=0;y<m_dimY;y++) 00092 for (unsigned x=0;x<m_dimX;x++) 00093 { 00094 if (x >= Xi[0] && x < Xe[0] && 00095 y >= Xi[1] && y < Xe[1] && 00096 z >= Xi[2] && z < Xe[2] ) 00097 { 00098 //printf("%d) Reading %d,%d,%d\n",NetMPI::rank(),x,y,z); 00099 file >> m_matrix3D(z-Xi[2],y-Xi[1],x-Xi[0]); 00100 } 00101 else 00102 file >> ddLixo; 00103 00104 if (file.fail()) 00105 throw new Exception("FChessBoard3D: File \"%s\", dimension of the matrix does not match with the numbers supplied in the file\n",fileName.c_str()); 00106 } 00107 }
FChessBoard3D::FChessBoard3D | ( | Point3D | p0, | |
Point3D | p1, | |||
Point3D | lp0, | |||
Point3D | lp1, | |||
double | My, | |||
double | CVy, | |||
std::string | fileName | |||
) |
This constructor read a file containing values beetween [-1,1] and builds a gaussian distribution of this values with media My and covariance CVy. One very important use of this constructor is to read the files produced by the generator of fractal meshes created by Marcio Borges at Labtran Friburgo, (Brazil). In this cases the numbers beetween [-1,1] has a Covariance that dependes of the distance separating the points in the grid.
p0 | Bottom left point of the domain. | |
p1 | Upper right point of the domain. | |
My | Media of the field | |
CVy | Coeficient of Variation of the field | |
fileName | The file containing the numbers. The format of that file is the same as the previous constructor |
Definition at line 179 of file fchessboard3d.cpp.
00180 :m_p0(p0),m_p1(p1),m_lp0(lp0),m_lp1(lp1) 00181 { 00182 00183 assert(lp0[0] <= lp1[0]); 00184 assert(lp0[1] <= lp1[1]); 00185 assert(lp0[2] <= lp1[2]); 00186 assert(p0[0] <= p1[0]); 00187 assert(p0[1] <= p1[1]); 00188 assert(p0[2] <= p1[2]); 00189 assert(lp0[0] >= p0[0]); 00190 assert(lp0[1] >= p0[1]); 00191 assert(lp0[2] >= p0[2]); 00192 assert(lp1[0] <= p1[0]); 00193 assert(lp1[1] <= p1[1]); 00194 assert(lp1[2] <= p1[2]); 00195 00196 00197 00198 00199 ifstream file(fileName.c_str()); 00200 if (file.fail()) 00201 throw new Exception("FChessBoard3D: File \"%s\" not found",fileName.c_str()); 00202 00203 char str[MAX_LINE_SIZE]; 00204 00205 //Ignore the first line 00206 file.getline(str,MAX_LINE_SIZE); 00207 00208 //Get the second line containing the dimension of the chess board 00209 //in the format "size_X x size_Y x size_Z" 00210 file.getline(str,MAX_LINE_SIZE); 00211 if (file.fail() || sscanf(str,"%d x %d x %d",&m_dimX,&m_dimY,&m_dimZ) != 3) 00212 throw new Exception("FChessBoard3D: File \"%s\", Second line (\"%s\")\n\tnot in format <number> x <number> x <number>",fileName.c_str(),str); 00213 00214 00215 00216 m_dX = (p1[0]-p0[0])/m_dimX; 00217 m_dY = (p1[1]-p0[1])/m_dimY; 00218 m_dZ = (p1[2]-p0[2])/m_dimZ; 00219 00220 Xi[0] = static_cast<unsigned>(floor(lp0[0]/m_dX)); 00221 Xi[1] = static_cast<unsigned>(floor(lp0[1]/m_dY)); 00222 Xi[2] = static_cast<unsigned>(floor(lp0[2]/m_dZ)); 00223 00224 Xe[0] = static_cast<unsigned>(ceil(lp1[0]/m_dX)); 00225 Xe[1] = static_cast<unsigned>(ceil(lp1[1]/m_dY)); 00226 Xe[2] = static_cast<unsigned>(ceil(lp1[2]/m_dZ)); 00227 00228 //Just to garantee that roundoff errors would not occur. 00229 //Actually it never ocurred, but just to make sure. 00230 if (Xe[0] > m_dimX) 00231 Xe[0]=m_dimX; 00232 if (Xe[1] > m_dimY) 00233 Xe[1]=m_dimY; 00234 if (Xe[2] > m_dimZ) 00235 Xe[2]=m_dimZ; 00236 00237 00238 //Allocate the table to store the chess board 00239 TableIndices<3> sizes(Xe[2]-Xi[2],Xe[1]-Xi[1],Xe[0]-Xi[0]); 00240 //TableIndices<3> sizes(Xe[0]-Xi[0]+1,Xe[1]-Xi[1]+1,Xe[2]-Xi[2]+1); 00241 m_matrix3D.reinit(sizes); 00242 00243 00244 m_lp0[0]=Xi[0]*m_dX; 00245 m_lp0[1]=Xi[1]*m_dY; 00246 m_lp0[2]=Xi[2]*m_dZ; 00247 00248 m_lp1[0]=Xe[0]*m_dX; 00249 m_lp1[1]=Xe[1]*m_dY; 00250 m_lp1[2]=Xe[2]*m_dZ; 00251 00252 00253 /*printf("========================\n%d) Points %g,%g,%g - %g,%g,%g => %g %g %g - %g %g %g\n",NetMPI::rank(),p0[0],p0[1],p0[2],p1[0],p1[1],p1[2],lp0[0], 00254 lp0[1],lp0[2],lp1[0],lp1[1],lp1[2]); 00255 printf("========================\n%d) Indices %d,%d,%d - %d,%d,%d\n",NetMPI::rank(),Xi[0],Xi[1],Xi[2],Xe[0],Xe[1],Xe[2]); 00256 printf("========================\n%d) Minimal Geo Mesh %g,%g,%g - %g,%g,%g\n",NetMPI::rank(),m_lp0[0],m_lp0[1],m_lp0[2],m_lp1[0],m_lp1[1],m_lp1[2]); 00257 */ 00258 double dd; 00259 double dpGauss = sqrt(log(CVy*CVy + 1)); 00260 double C0 = My/(exp(0.5*dpGauss*dpGauss)); 00261 00262 00263 for (unsigned z=0;z<m_dimZ;z++) 00264 for (unsigned y=0;y<m_dimY;y++) 00265 for (unsigned x=0;x<m_dimX;x++) 00266 { 00267 file >> dd; 00268 if (x >= Xi[0] && x < Xe[0] && 00269 y >= Xi[1] && y < Xe[1] && 00270 z >= Xi[2] && z < Xe[2] ) 00271 { 00272 m_matrix3D(z-Xi[2],y-Xi[1],x-Xi[0]) = C0*exp(dpGauss*dd); 00273 } 00274 if (file.fail()) 00275 throw new Exception("FChessBoard3D: File \"%s\", dimension of the matrix does not match with the numbers supplied in the file\n",fileName.c_str()); 00276 } 00277 }
FChessBoard3D::FChessBoard3D | ( | Point3D | p0, | |
Point3D | p1, | |||
int | dimX, | |||
int | dimY, | |||
int | dimZ, | |||
std::vector< double > & | data | |||
) |
Definition at line 110 of file fchessboard3d.cpp.
00111 :m_p0(p0),m_p1(p1),m_lp0(p0),m_lp1(p1) 00112 { 00113 00114 m_dimZ = dimZ; 00115 m_dimX = dimX; 00116 m_dimY = dimY; 00117 00118 Xi = 0; 00119 Xe[0]=m_dimX; 00120 Xe[1]=m_dimY; 00121 Xe[2]=m_dimZ; 00122 00123 TableIndices<3> sizes(m_dimZ,m_dimY,m_dimX); 00124 std::vector<double>::iterator it = data.begin(); 00125 00126 00127 assert(data.size() == (unsigned) dimX*dimY*dimZ); 00128 m_matrix3D.reinit(sizes); 00129 for (unsigned z=0;z<m_dimZ;z++) 00130 for (unsigned y=0;y<m_dimY;y++) 00131 for (unsigned x=0;x<m_dimX;x++) 00132 { 00133 m_matrix3D(z,y,x) = *(it++); 00134 } 00135 m_dX = (p1[0]-p0[0])/m_dimX; 00136 m_dY = (p1[1]-p0[1])/m_dimY; 00137 m_dZ = (p1[2]-p0[2])/m_dimZ; 00138 00139 }
FChessBoard3D::~FChessBoard3D | ( | ) | [virtual] |
Definition at line 157 of file fchessboard3d.cpp.
int FChessBoard3D::getDimX | ( | ) | [inline] |
Definition at line 43 of file fchessboard3d.h.
00043 {return m_dimX;}
int FChessBoard3D::getDimY | ( | ) | [inline] |
Definition at line 44 of file fchessboard3d.h.
00044 {return m_dimY;}
int FChessBoard3D::getDimZ | ( | ) | [inline] |
Definition at line 45 of file fchessboard3d.h.
00045 {return m_dimZ;}
double FChessBoard3D::operator() | ( | const VecDouble & | p, | |
unsigned int | component = 0 | |||
) | const [virtual] |
Implements GeneralFunctionInterface.
Definition at line 143 of file fchessboard3d.cpp.
00144 { 00145 assert(component == 0); 00146 assert(NumericMethods::isInCube(p,m_lp0,m_lp1)); 00147 00148 unsigned x = (unsigned) floor((p(0)-m_lp0(0))/m_dX); 00149 unsigned y = (unsigned) floor((p(1)-m_lp0(1))/m_dY); 00150 unsigned z = (unsigned) floor((p(2)-m_lp0(2))/m_dZ); 00151 00152 00153 return m_matrix3D(z,y,x); 00154 }
unsigned FChessBoard3D::m_dimX [private] |
Definition at line 27 of file fchessboard3d.h.
unsigned FChessBoard3D::m_dimY [private] |
Definition at line 27 of file fchessboard3d.h.
unsigned FChessBoard3D::m_dimZ [private] |
Definition at line 27 of file fchessboard3d.h.
double FChessBoard3D::m_dX [private] |
Definition at line 28 of file fchessboard3d.h.
double FChessBoard3D::m_dY [private] |
Definition at line 28 of file fchessboard3d.h.
double FChessBoard3D::m_dZ [private] |
Definition at line 28 of file fchessboard3d.h.
Point3D FChessBoard3D::m_lp0 [private] |
Definition at line 25 of file fchessboard3d.h.
Point3D FChessBoard3D::m_lp1 [private] |
Definition at line 26 of file fchessboard3d.h.
dealii::Table<3,double> FChessBoard3D::m_matrix3D [private] |
Definition at line 33 of file fchessboard3d.h.
Point3D FChessBoard3D::m_p0 [private] |
Definition at line 23 of file fchessboard3d.h.
Point3D FChessBoard3D::m_p1 [private] |
Definition at line 24 of file fchessboard3d.h.
StackVector<3,unsigned> FChessBoard3D::Xe [private] |
Definition at line 30 of file fchessboard3d.h.
StackVector<3,unsigned> FChessBoard3D::Xi [private] |
Definition at line 30 of file fchessboard3d.h.