bool isValidSudoku(vector<vector<char>>& board) { int ctr1 = 0, ctr2 = 0; for(int i = 0; i < 9; i ++){ vector<bool> arr1(9, false); vector<bool> arr2(9, false); vector<bool> arr3(9, false); int x = (i/3) * 3; int y = (i * 3) % 9; for(int j = 0; j < 9; j ++){ if(board[i][j] !='.'){ if(arr1[board[i][j]-1 - '0']) return false; else arr1[board[i][j]-1 - '0'] = true; } if(board[j][i] !='.'){ if(arr2[board[j][i]-1- '0']) return false; else arr2[board[j][i]-1- '0'] = true; } if(board[x + j % 3][y + j / 3] !='.'){ if(arr3[board[x + j % 3][y + j / 3] - 1 - '0']) return false; else arr3[board[x + j % 3][y + j / 3] - 1 - '0'] = true; } }//end for j }//end for i return true; }
int main(){ Array<double, int> arr1(10); // start index = 1 Array<double, int> arr2(10,-1); // start index = -1 Array<double, int> arr3(10, 0, 3.14); // start index = 0, all values = 3.14 print(arr1); print(arr2); print(arr3); Matrix<double, int> m1(10, 10); Matrix<double, int> m2(10, 10, -2, 3.14); print(m1); print(m2); return 0; }
void WriteOutputParallel(Grid3DCU *grid, EMfields3D *EMf, CollectiveIO *col, VCtopology3D *vct, int cycle){ #ifdef PHDF5 string grpname; string dtaname; stringstream filenmbr; string filename; /* ------------------- */ /* Setup the file name */ /* ------------------- */ filenmbr << setfill('0') << setw(5) << cycle; filename = col->getSaveDirName() + "/" + col->getSimName() + "_" + filenmbr.str() + ".h5"; /* ---------------------------------------------------------------------------- */ /* Define the number of cells in the globa and local mesh and set the mesh size */ /* ---------------------------------------------------------------------------- */ int nxc = grid->getNXC(); int nyc = grid->getNYC(); int nzc = grid->getNZC(); int dglob[3] = { col ->getNxc() , col ->getNyc() , col ->getNzc() }; int dlocl[3] = { nxc-2, nyc-2, nzc-2 }; double L [3] = { col ->getLx () , col ->getLy () , col ->getLz () }; /* --------------------------------------- */ /* Declare and open the parallel HDF5 file */ /* --------------------------------------- */ PHDF5fileClass outputfile(filename, 3, vct->getCoordinates(), vct->getComm()); outputfile.CreatePHDF5file(L, dglob, dlocl, false); /* ------------------------ */ /* Write the Electric field */ /* ------------------------ */ array3_double arr3(nxc-2,nyc-2,nzc-2); grpname = "Fields"; dtaname = "Ex"; EMf->getExc(arr3,grid); outputfile.WritePHDF5dataset(grpname, dtaname, arr3, nxc-2, nyc-2, nzc-2); grpname = "Fields"; dtaname = "Ey"; EMf->getEyc(arr3,grid); outputfile.WritePHDF5dataset(grpname, dtaname, arr3, nxc-2, nyc-2, nzc-2); grpname = "Fields"; dtaname = "Ez"; EMf->getEzc(arr3,grid); outputfile.WritePHDF5dataset(grpname, dtaname, arr3, nxc-2, nyc-2, nzc-2); /* ------------------------ */ /* Write the Magnetic field */ /* ------------------------ */ grpname = "Fields"; dtaname = "Bx"; EMf->getBxc(arr3); outputfile.WritePHDF5dataset(grpname, dtaname, arr3, nxc-2, nyc-2, nzc-2); grpname = "Fields"; dtaname = "By"; EMf->getByc(arr3); outputfile.WritePHDF5dataset(grpname, dtaname, arr3, nxc-2, nyc-2, nzc-2); grpname = "Fields"; dtaname = "Bz"; EMf->getBzc(arr3); outputfile.WritePHDF5dataset(grpname, dtaname, arr3, nxc-2, nyc-2, nzc-2); /* ----------------------------------------------- */ /* Write the Charge Density field for each species */ /* ----------------------------------------------- */ for (int is = 0; is < col->getNs(); is++) { stringstream snmbr; snmbr << is; grpname = "Fields"; dtaname = "Rho_" + snmbr.str(); EMf->getRHOcs(arr3,grid, is); EMf->getRHOcs(arr3, grid, is); outputfile.WritePHDF5dataset(grpname, dtaname, arr3, nxc-2, nyc-2, nzc-2); } /* ---------------------------------------- */ /* Write the Current field for each species */ /* ---------------------------------------- */ for (int is = 0; is < col->getNs(); is++) { stringstream snmbr; snmbr << is; grpname = "Fields"; dtaname = "Jx_" + snmbr.str(); EMf->getJxsc(arr3, grid, is); outputfile.WritePHDF5dataset(grpname, dtaname, arr3, nxc-2, nyc-2, nzc-2); grpname = "Fields"; dtaname = "Jy_" + snmbr.str(); EMf->getJysc(arr3, grid, is); outputfile.WritePHDF5dataset(grpname, dtaname, arr3, nxc-2, nyc-2, nzc-2); grpname = "Fields"; dtaname = "Jz_" + snmbr.str(); EMf->getJzsc(arr3, grid, is); outputfile.WritePHDF5dataset(grpname, dtaname, arr3, nxc-2, nyc-2, nzc-2); } outputfile.ClosePHDF5file(); #else cout << " ERROR: The input file request the use of the Parallel HDF5 functions, but the code has been compiled using the sequential HDF5 library. " << endl; cout << " Recompile the code using the parallel HDF5 options or change the input file options. " << endl; abort(); #endif }
TEST_P(TestGetSubPatch3D, SubPatch) { Go::SplineVolume vol(GetParam().n, GetParam().n, GetParam().n, GetParam().p+1, GetParam().p+1, GetParam().p+1, GetParam().knots.begin(), GetParam().knots.begin(), GetParam().knots.begin(), GetParam().coefs.begin(), GetParam().dim, GetParam().rational); size_t numcoefs0 = vol.basis(0).numCoefs()/2 + GetParam().p; Go::SplineVolume vol0 = MultiPatchModelGenerator3D::getSubPatch(&vol, 0, numcoefs0, GetParam().p+1, 0, numcoefs0, GetParam().p+1, 0, numcoefs0, GetParam().p+1); size_t numcoefs1 = vol.basis(0).numCoefs() - numcoefs0 + GetParam().p; size_t start1 = numcoefs0 - GetParam().p; Go::SplineVolume vol1 = MultiPatchModelGenerator3D::getSubPatch(&vol, start1, numcoefs1, GetParam().p+1, 0, numcoefs0, GetParam().p+1, 0, numcoefs0, GetParam().p+1); // Check first sub-knot-vector std::vector<double> arr0(GetParam().knots.begin(), GetParam().knots.begin()+GetParam().lknots0); std::vector<double> arr1(vol0.basis(0).begin(), vol0.basis(0).end()); std::cout << "sub-knot-vector 0" << std::endl; check_vector_double_near(arr0, arr1); // Check second sub-knot-vector std::vector<double> arr2(GetParam().knots.end()-GetParam().lknots1, GetParam().knots.end()); std::vector<double> arr3(vol1.basis(0).begin(), vol1.basis(0).end()); std::cout << "sub-knot-vector 1" << std::endl; check_vector_double_near(arr2, arr3); std::vector<double> arrX(vol.coefs_begin(), vol.coefs_end()); // Check first sub-control net std::vector<double>::const_iterator i0 = GetParam().rational ? vol0.rcoefs_begin() : vol0.coefs_begin(); std::vector<double>::const_iterator i1 = GetParam().rational ? vol0.rcoefs_end() : vol0.coefs_end(); std::vector<double> arr4(i0, i1); std::cout << "sub-node-vector 0" << std::endl; check_vector_double_near(GetParam().coefs0, arr4); // Check second sub-control net std::vector<double>::const_iterator i2 = GetParam().rational ? vol1.rcoefs_begin() : vol1.coefs_begin(); std::vector<double>::const_iterator i3 = GetParam().rational ? vol1.rcoefs_end() : vol1.coefs_end(); std::vector<double> arr5(i2, i3); std::cout << "sub-node-vector 1" << std::endl; check_vector_double_near(GetParam().coefs1, arr5); // Evaluate function at points double xiA(0.3333), xiB(2), xiC(4.2); RealFunc* f = utl::parseRealFunc("(1-y*y)*(3.14159-x)*(1-z)", "expression"); Go::SplineVolume* fh = SplineUtils::project(&vol, *f); Go::SplineVolume fh0 = MultiPatchModelGenerator3D::getSubPatch(fh, 0, numcoefs0, GetParam().p+1, 0, numcoefs0, GetParam().p+1, 0, numcoefs0, GetParam().p+1); Go::SplineVolume fh1 = MultiPatchModelGenerator3D::getSubPatch(fh, start1, numcoefs1, GetParam().p+1, 0, numcoefs0, GetParam().p+1, 0, numcoefs0, GetParam().p+1); Go::Point fA, fB, fC, fA0, fB0, fB1, fC1; fh->point(fA, xiA, xiA, xiA); fh->point(fB, xiB, xiA, xiA); fh->point(fC, xiC, xiA, xiA); std::cout << "point evaluation" << std::endl; fh0.point(fA0, xiA, xiA, xiA); check_point_near(fA, fA0); fh0.point(fB0, xiB, xiA, xiA); check_point_near(fB, fB0); fh1.point(fB1, xiB, xiA, xiA); check_point_near(fB, fB1); fh1.point(fC1, xiC, xiA, xiA); check_point_near(fC, fC1); // Check FEM topology std::stringstream str0, str1; str0 << "700 1 0 0\n" << vol0; str1 << "700 1 0 0\n" << vol1; ASMs3D pch0, pch1; pch0.resetNumbering(); pch0.read(str0); pch1.read(str1); std::cout << "element/node numbers" << std::endl; ASSERT_TRUE(pch0.generateFEMTopology()); ASSERT_TRUE(pch1.generateFEMTopology()); std::vector<int> myMLGE = pch1.getMyElementNums(); check_vector_int_equals_range(myMLGE, GetParam().mlge1); std::vector<int> myMLGN = pch1.getMyNodeNums(); check_vector_int_equals_range(myMLGN, GetParam().mlgn1); }
double kshell_tri_interp(vector<double> &x, vector<double> &y, vector<double> &z, vector<double> &data, double x0, double y1, double z1, int KK) { //cout << "Entering kshel" << endl; int NI = 53; int NJ = 60; int NK = 65; double p[NI][NJ]; double q[NI][NJ]; double data1[NI][NJ]; double d = 0.0; double p1,q1; for(int i = 0; i < NI; i++) { for(int j = 0; j < NJ; j++) { p[i][j] = x[shellIndex(i,j,KK)]; q[i][j] = sqrt(pow(y[shellIndex(i,j,KK)],2.0)+pow(z[shellIndex(i,j,KK)],2.0)); p1=x0; q1=sqrt(pow(y1,2.0)+pow(z1,2.0)); data1[i][j] = data[shellIndex(i,j,KK)]; } } //Find out which triangle is (p1.q1) in //search through (i,j) pairs, each cell is divided into two triangles // 1 (i,j) (i+1,j),(i,j+1) // 2 (i+1,j+1) (i+1,j), (i,j+1) double s1[2]; double s2[2]; double s3[2]; double s4[2]; double xx1,yy1,ff1,xx2,yy2,ff2,xx3,yy3,ff3; for(int i = 0; i < NI-1; i++) { for(int j = 0; j < NJ-1; j++) { s1[0] = p[i][j]-p1; s1[1] = q[i][j]-q1; s2[0] = p[i+1][j]-p1; s2[1] = q[i+1][j]-q1; s3[0] = p[i+1][j+1]-p1; s3[1] = q[i+1][j+1]-q1; s4[0] = p[i][j+1]-p1; s4[1] = q[i][j+1]-q1; //Triangle 1, ANG(12)+ANG(24)+ANG(41)=2*pi double theta12, theta24, theta41; theta12=acos((s1[0]*s2[0]+s1[1]*s2[1])/sqrt((pow(s1[0],2)+pow(s1[1],2))*(pow(s2[0],2)+pow(s2[1],2)))); theta24=acos((s2[0]*s4[0]+s2[1]*s4[1])/sqrt((pow(s2[0],2)+pow(s2[1],2))*(pow(s4[0],2)+pow(s4[1],2)))); theta41=acos((s4[0]*s1[0]+s4[1]*s1[1])/sqrt((pow(s4[0],2)+pow(s4[1],2))*(pow(s1[0],2)+pow(s1[1],2)))); if(abs(theta12+theta24+theta41-2.0*PI) < 0.001) { xx1=p[i][j]; yy1=q[i][j]; ff1=data1[i][j]; xx2=p[i+1][j]; yy2=q[i+1][j]; ff2=data1[i+1][j]; xx3=p[i][j+1]; yy3=q[i][j+1]; ff3=data1[i][j+1]; break; } //Triangle 2, ANG(23)+ANG(34)+ANG(42)=2*pi double theta23, theta34, theta42; theta23=acos((s2[0]*s3[0]+s2[1]*s3[1])/sqrt((pow(s2[0],2)+pow(s2[1],2))*(pow(s3[0],2)+pow(s3[1],2)))); theta34=acos((s3[0]*s4[0]+s3[1]*s4[1])/sqrt((pow(s3[0],2)+pow(s3[1],2))*(pow(s4[0],2)+pow(s4[1],2)))); theta42=acos((s4[0]*s2[0]+s4[1]*s2[1])/sqrt((pow(s4[0],2)+pow(s4[1],2))*(pow(s2[0],2)+pow(s2[1],2)))); if(abs(theta23+theta34+theta42-2.0*PI) < 0.001) { xx1=p[i+1][j+1]; yy1=q[i+1][j+1]; ff1=data1[i+1][j+1]; xx2=p[i+1][j]; yy2=q[i+1][j]; ff2=data1[i+1][j]; xx3=p[i][j+1]; yy3=q[i][j+1]; ff3=data1[i][j+1]; break; } } } Array2D< double > arr1(3,3); Array2D< double > arr2(3,3); Array2D< double > arr3(3,3); Array2D< double > arr(3,3); double temp[3][3] = { {xx1, yy1, 1}, {xx2, yy2, 1}, {xx3, yy3, 1}}; for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ arr[i][j] = temp[i][j]; } } double temp1[3][3] = { {p1, q1, 1}, {xx2, yy2, 1}, {xx3, yy3, 1}}; for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ arr1[i][j] = temp1[i][j]; } } double temp2[3][3] = { {p1, q1, 1}, {xx1, yy1, 1}, {xx3, yy3, 1}}; for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ arr2[i][j] = temp2[i][j]; } } double temp3[3][3] = { {p1, q1, 1}, {xx1, yy1, 1}, {xx2, yy2, 1}}; for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ arr3[i][j] = temp3[i][j]; } } JAMA::LU< double > compute(arr); JAMA::LU< double > compute1(arr1); JAMA::LU< double > compute2(arr2); JAMA::LU< double > compute3(arr3); d = (ff1*compute1.det() - ff2*compute2.det() + ff3*compute3.det())/compute.det(); return d; }