double compute_2corr(const double complex *wi1, const double complex *wi2) { double q0; int i,j,k; q0=0.0; for( i = 0 ; i < NTOTAL_COMPLEX ; i++) { w1[i] = wi1[i]; w2[i] = wi2[i]; } gfft_c2r(w1); gfft_c2r(w2); for( i = 0 ; i < 2*NTOTAL_COMPLEX ; i++) { wr1[i] = wr1[i] / ((double) NTOTAL ); wr2[i] = wr2[i] / ((double) NTOTAL ); } for(i = 0 ; i < 2 * NTOTAL_COMPLEX ; i ++) { q0 += wr1[i] * wr2[i] / ((double) NTOTAL); } return(q0); }
void write_vtk(FILE * ht, double complex wi[], const double t) { // Write the data in the file handler *ht int i,j,k; float q0; DEBUG_START_FUNC; #ifdef MPI_SUPPORT double * chunk = NULL; if(rank==0) { chunk = (double *) malloc( NX * sizeof(double)); if (chunk == NULL) ERROR_HANDLER( ERROR_CRITICAL, "No memory for chunk allocation"); } #endif for( i = 0 ; i < NTOTAL_COMPLEX ; i++) { w1[i] = wi[i]; } gfft_c2r(w1); for( i = 0 ; i < 2 * NTOTAL_COMPLEX ; i++) { wr1[i] = wr1[i] / ((double) NTOTAL ); } #ifdef WITH_SHEAR remap_output(wr1,t); #endif #ifdef BOUNDARY_C for( k = 0 ; k < NZ / 2 ; k++) { #else for( k = 0 ; k < NZ; k++) { #endif for( j = 0; j < NY; j++) { #ifdef MPI_SUPPORT // We have to transpose manually to be Fortran compliant for(i = 0; i < NX/NPROC; i++) { wr2[i] = wr1[k + j * (NZ + 2) + i * NY * (NZ + 2) ]; // Transfer the chunk of data to wr2 } MPI_Gather(wr2, NX/NPROC, MPI_DOUBLE, chunk, NX/NPROC, MPI_DOUBLE, 0, MPI_COMM_WORLD); // Put the full chunk in chunk in the root process #endif for( i = 0; i < NX; i++) { #ifdef MPI_SUPPORT if(rank==0) { q0 = big_endian( (float) chunk[ i ] ); fwrite(&q0, sizeof(float), 1, ht); } #else #ifdef WITH_2D q0 = big_endian( (float) wr1[j + i * (NY + 2)] ); #else q0 = big_endian( (float) wr1[k + j * (NZ + 2) + i * NY * (NZ + 2) ] ); #endif fwrite(&q0, sizeof(float), 1, ht); if(ferror(ht)) ERROR_HANDLER( ERROR_CRITICAL, "Error writing VTK file"); #endif } #ifdef MPI_SUPPORT MPI_Barrier(MPI_COMM_WORLD); #endif } } #ifdef MPI_SUPPORT if(rank==0) free(chunk); #endif DEBUG_END_FUNC; return; } // Geo's personnal VTK writer, using structured data points /***********************************************************/ /** Output a legacy VTK file readable by Paraview. This routine will output all the variables in files data/v****.vtk. @param n Number of the file in which the output will done. @param t Current time of the simulation. */ /***********************************************************/ void output_vtk(struct Field fldi, const int n, double t) { FILE *ht = NULL; char filename[50]; int num_remain_field; int array_size, i; DEBUG_START_FUNC; sprintf(filename,"data/v%04i.vtk",n); #ifdef BOUNDARY_C array_size=NX*NY*NZ/2; // Remove half of the vertical direction for symmetry reason when using walls in z #else array_size=NX*NY*NZ; #endif if(rank==0) { ht=fopen(filename,"w"); fprintf(ht, "# vtk DataFile Version 2.0\n"); fprintf(ht, "t= %015.15e Snoopy Code v5.0\n",t); fprintf(ht, "BINARY\n"); fprintf(ht, "DATASET STRUCTURED_POINTS\n"); #ifdef BOUNDARY_C fprintf(ht, "DIMENSIONS %d %d %d\n", NX, NY, NZ / 2); #else fprintf(ht, "DIMENSIONS %d %d %d\n", NX, NY, NZ); #endif fprintf(ht, "ORIGIN %g %g %g\n", -param.lx/2.0, -param.ly/2.0, -param.lz/2.0); fprintf(ht, "SPACING %g %g %g\n", param.lx/NX, param.ly/NY, param.lz/NZ); // Write the primary scalar (f***ing VTK legacy format...) fprintf(ht, "POINT_DATA %d\n",array_size); fprintf(ht, "SCALARS %s float\n",fldi.fname[0]); fprintf(ht, "LOOKUP_TABLE default\n"); } write_vtk(ht,fldi.farray[0],t); num_remain_field = fldi.nfield - 1; // we have already written the first one if(param.output_vorticity) num_remain_field +=3; #ifndef MPI_SUPPORT #ifdef WITH_PARTICLES num_remain_field++; #endif #endif if(rank==0) fprintf(ht, "FIELD FieldData %d\n",num_remain_field); // Write all the remaining fields for(i = 1 ; i < fldi.nfield ; i++) { if(rank==0) fprintf(ht, "%s 1 %d float\n",fldi.fname[i],array_size); write_vtk(ht,fldi.farray[i],t); } if(param.output_vorticity) { // Compute the vorticity field for( i = 0 ; i < NTOTAL_COMPLEX ; i++) { w4[i] = I * (ky[i] * fldi.vz[i] - kz[i] * fldi.vy[i]); w5[i] = I * (kz[i] * fldi.vx[i] - kxt[i] * fldi.vz[i]); w6[i] = I * (kxt[i] * fldi.vy[i] - ky[i] * fldi.vx[i]); } if(rank==0) fprintf(ht, "wx 1 %d float\n",array_size); write_vtk(ht,w4,t); if(rank==0) fprintf(ht, "wy 1 %d float\n",array_size); write_vtk(ht,w5,t); if(rank==0) fprintf(ht, "wz 1 %d float\n",array_size); write_vtk(ht,w6,t); } #ifndef MPI_SUPPORT #ifdef WITH_PARTICLES if(rank==0) fprintf(ht, "particules 1 %d float\n",array_size); write_vtk_particles(fldi, ht, t); #endif #endif if(rank==0) { if(ferror(ht)) ERROR_HANDLER( ERROR_CRITICAL, "Error writing VTK file"); fclose(ht); } DEBUG_END_FUNC; return; }