//#include //#include #include #include #include #include #include #include //using namespace std; /*Private functions */ void waveVectorCompute1D(int n,double *vec); void waveVectorCompute3D(int nX,int nY, int nZ, /*double dX, double dY, double dZ,*/ double nDir[3], double *waveVect) { int nTot; double *vecX,*vecY,*vecZ; double *waveVect3DX, *waveVect3DY, *waveVect3DZ; int i, j, k, maille; nTot = nX*nY*nZ; // printf("nX = %d, nY = %d, nZ = %d, nTot = %d\n",nX,nY,nZ,nTot); // printf("Entering waveVectorCompute3D\n"); /*Memory allocation */ waveVect3DX = (double *)malloc(nTot * sizeof(double)); if (waveVect3DX == NULL) { printf("waveVectCompute.cpp : No memory available for waveVect3DX\n"); return; } waveVect3DY = (double *)malloc(nTot * sizeof(double)); if (waveVect3DY == NULL) { printf("waveVectCompute.cpp : No memory available for waveVect3DY\n"); return; } waveVect3DZ = (double *)malloc(nTot * sizeof(double)); if (waveVect3DZ == NULL) { printf("waveVectCompute.cpp : No memory available for waveVect3DZ\n"); return; } vecX = (double *)malloc(nX * sizeof(double)); if (vecX == NULL) { printf("waveVectCompute.cpp : No memory available for vecX\n"); return; } vecY = (double *)malloc(nY * sizeof(double)); if (vecY == NULL) { printf("waveVectCompute.cpp : No memory available for vecY\n"); return; } vecZ = (double *)malloc(nZ * sizeof(double)); if (vecZ == NULL) { printf("waveVectCompute.cpp : No memory available for vecZ\n"); return; } // printf("memory allocation done.\n"); waveVectorCompute1D(nX,vecX); waveVectorCompute1D(nY,vecY); waveVectorCompute1D(nZ,vecZ); // printf("waveVectorCompute1D: done!\n"); for(k = 0; k < nZ; k++) { // printf("k=%d\n",k); for(j = 0; j < nY; j++) { // printf("j=%d: ",j); for(i = 0; i < nX; i++) { maille = i + (j + (k)*nY)*nX; // waveVect3DX[maille] = vecX[i]/(nX*dX); // waveVect3DY[maille] = vecY[j]/(nY*dY); // waveVect3DZ[maille] = vecZ[k]/(nZ*dZ); waveVect3DX[maille] = vecX[i]; waveVect3DY[maille] = vecY[j]; waveVect3DZ[maille] = vecZ[k]; // printf("i=%d: %f ",i,vecZ[k]); } // printf("\n"); } } // printf("waveVector3DX, Y and Z rearanged\n"); free(vecX); free(vecY); free(vecZ); if (waveVect == NULL) { printf("allocate memory for waveVect\n"); waveVect = (double *) malloc((nTot+1)*sizeof(double)); if (waveVect == NULL) { printf("waveVectCompute.cpp : No memory available for waveVect\n"); return; } printf("after allocate memory for waveVect\n"); } for (i=1;i<=nTot;i++) { waveVect[i] = nDir[0]*waveVect3DX[i-1] + nDir[1]*waveVect3DY[i-1] + nDir[2]*waveVect3DZ[i-1]; // printf("waveVect[%d] = %f\n",i,waveVect[i]); } // printf("waveVector rearanged\n"); free(waveVect3DX); free(waveVect3DY); free(waveVect3DZ); } void waveVectorCompute1D(int n,double *vec){ int midPoint,k; if(ceil(n/2) - floor(n/2) < 1.) { // printf("coucou\n"); /*n is even */ midPoint = (int) floor(n/2); vec[midPoint] = (double) midPoint; } else { /*n is odd */ midPoint = (int) floor(n/2)-1; vec[midPoint] = (double) midPoint+1; } for (k=1;k