WSL/SLF GitLab Repository

Commit 8e3e7afe authored by Mathias Bavay's avatar Mathias Bavay
Browse files

Adding the Grid3DObjects to the tests

parent 91a372c2
......@@ -4,6 +4,55 @@
using namespace std;
using namespace mio;
bool grid3d(const unsigned int& n) {
cout << "Testing Grid3DObject\n";
bool status = true;
srand((unsigned)time(0));
const double range = 10.;
Coords llcorner("CH1903","");
llcorner.setXY(785425. , 191124., 1400.);
Grid3DObject grid1(n, n, n, 100, llcorner);
for(unsigned int kk=0; kk<grid1.getNz(); kk++) {
for(unsigned int jj=0; jj<grid1.getNy(); jj++) {
for(unsigned int ii=0; ii<grid1.getNx(); ii++) {
grid1.grid3D(ii,jj,kk) = (double)rand()/(double)RAND_MAX*range;
}
}
}
Grid3DObject grid2(n, n, n, 100, llcorner, grid1.grid3D);
grid2.grid3D -= 8.;
grid2.grid3D /= 2.;
grid2.grid3D += 4.;
grid2.grid3D *= 2.;
if(!grid2.grid3D.checkEpsilonEquality(grid1.grid3D, 1e-6)) {
cout << "\terror: basic operations with constants fail!\n";
status=false;
}
grid2.set(n, n, n, 100, llcorner, 0.);
grid2.grid3D += grid1.grid3D;
grid2.grid3D /= grid1.grid3D;
if(!IOUtils::checkEpsilonEquality(grid2.grid3D.getMean(), 1., 1e-6)) {
cout << "\terror: grids addition or division fails!\n";
status=false;
}
grid2.grid3D *= grid1.grid3D;
if(!grid2.grid3D.checkEpsilonEquality(grid1.grid3D, 1e-6)) {
cout << "\terror: grids multiplication fails!\n";
status=false;
}
grid2.grid3D -= grid1.grid3D;
if(!IOUtils::checkEpsilonEquality(grid2.grid3D.getMean(), 0., 1e-6)) {
cout << "\terror: grids substraction fails!\n";
status=false;
}
return status;
}
bool grid2d(const unsigned int& n) {
cout << "Testing Grid2DObject\n";
bool status = true;
......@@ -94,7 +143,7 @@ bool matrix(const unsigned int& n) {
cout << "\terror when solving A*X=B\n";
status=false;
}
Matrix L,U;
if(m1.LU(L,U)==false) {
cout << "\terror: LU decomposition could NOT be computed\n";
......@@ -109,7 +158,8 @@ int main() {
const unsigned int n=50;
const bool grid2d_status = grid2d(n);
const bool grid3d_status = grid3d(n);
const bool matrix_status = matrix(n);
if(grid2d_status!=true || matrix_status!=true) throw IOException("Grid/Matrix error", AT);
if(grid2d_status!=true || grid3d_status!=true || matrix_status!=true) throw IOException("Grid/Matrix error", AT);
return 0;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment