📄 lbio.c
字号:
{ red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; }#else /* !( SOLID_COLOR_IS_CHECKERBOARD) */#if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0;#else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255;#endif /* SOLID_COLOR_IS_BLACK */#endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( map[j][i] != INACTIVE_NODE) else */// Mark the origin for reference.if( ( i == 0 && j == 0)){ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255;} if( fwrite( &blue_val, 1, 1, o_u ) != 1) { printf("BOOM!\n"); exit(1);} if( fwrite( &green_val, 1, 1, o_u ) != 1) { printf("BOOM!\n"); exit(1);} if( fwrite( &red_val, 1, 1, o_u ) != 1) { printf("BOOM!\n"); exit(1);} if( map[j][i] != INACTIVE_NODE //&& !( lattice->bc[ map[j][i]].bc_type & BC_SOLID_NODE) && lattice->bc[ map[j][i]].bc_type == /*FLUID_NODE*/0 ) { blue_val = (char)0; green_val = (char)0; red_val = (char)0; u_x = (lattice->macro_vars[ map[j][i]].u[0]); u_y = (lattice->macro_vars[ map[j][i]].u[1]); val = (char)0; if( lattice->bc[ map[j][i]].bc_type & BC_SOLID_NODE) { if( u_x > 0) { red_val = val; blue_val = (char)round( 128.*fabs(u_x)/max_u[0]); } else { red_val = (char)round( 128.*fabs(u_x)/max_u[0]); blue_val = val; } } /* if( lattice->bc[ map[j][i]].bc_type & BC_SOLID_NODE) */ else // !( lattice->bc[ map[j][i]].bc_type & BC_SOLID_NODE) { if( u_x > 0) { red_val = val; blue_val = (char)round( 255.*fabs(u_x)/max_u[0]); } else { red_val = (char)round( 255.*fabs(u_x)/max_u[0]); blue_val = val; } } /* if( lattice->bc[ map[j][i]].bc_type & BC_SOLID_NODE) else */ } /* if( map[j][i] != INACTIVE_NODE) */ else // map[j][i] == INACTIVE_NODE {#if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; }#else /* !( SOLID_COLOR_IS_CHECKERBOARD) */#if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0;#else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255;#endif /* SOLID_COLOR_IS_BLACK */#endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( map[j][i] != INACTIVE_NODE) else */// Mark the origin for reference.if( ( i == 0 && j == 0)){ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255;} if( fwrite( &blue_val, 1, 1, o_ux) != 1) { printf("BOOM!\n"); exit(1);} if( fwrite( &val, 1, 1, o_ux) != 1) { printf("BOOM!\n"); exit(1);} if( fwrite( &red_val, 1, 1, o_ux) != 1) { printf("BOOM!\n"); exit(1);} if( map[j][i] != INACTIVE_NODE //&& !( lattice->bc[ map[j][i]].bc_type & BC_SOLID_NODE) && lattice->bc[ map[j][i]].bc_type == /*FLUID_NODE*/0 ) { blue_val = (char)0; green_val = (char)0; red_val = (char)0; u_x = (lattice->macro_vars[ map[j][i]].u[0]); u_y = (lattice->macro_vars[ map[j][i]].u[1]); val = (char)0; if( lattice->bc[ map[j][i]].bc_type & BC_SOLID_NODE) { if( u_y > 0) { red_val = val; green_val = (char)round( 128.*fabs(u_y)/max_u[1]); } else { red_val = (char)round( 128.*fabs(u_y)/max_u[1]); green_val = val; } } /* if( lattice->bc[ map[j][i]].bc_type & BC_SOLID_NODE) */ else // !( lattice->bc[ map[j][i]].bc_type & BC_SOLID_NODE) { if( u_y > 0) { blue_val = (char)round( 255.*fabs(u_y)/max_u[1]); green_val = val; } else { blue_val = val; green_val = (char)round( 255.*fabs(u_y)/max_u[1]); } } /* if( lattice->bc[ map[j][i]].bc_type & BC_SOLID_NODE) else */ } /* if( map[j][i] != INACTIVE_NODE) */ else // map[j][i] == INACTIVE_NODE {#if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200; green_val = (char)200; blue_val = (char)200; val = (char)200; } else { red_val = (char)184; green_val = (char)184; blue_val = (char)184; val = (char)184; }#else /* !( SOLID_COLOR_IS_CHECKERBOARD) */#if SOLID_COLOR_IS_BLACK red_val = (char)0; green_val = (char)0; blue_val = (char)0; val = (char)0;#else /* !( SOLID_COLOR_IS_BLACK) */ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255;#endif /* SOLID_COLOR_IS_BLACK */#endif /* SOLID_COLOR_IS_CHECKERBOARD */ } /* if( map[j][i] != INACTIVE_NODE) else */// Mark the origin for reference.if( ( i == 0 && j == 0)){ red_val = (char)255; green_val = (char)255; blue_val = (char)255; val = (char)255;} if( fwrite( &blue_val, 1, 1, o_uy) != 1) { printf("BOOM!\n"); exit(1);} if( fwrite( &green_val, 1, 1, o_uy) != 1) { printf("BOOM!\n"); exit(1);} if( fwrite( &red_val, 1, 1, o_uy) != 1) { printf("BOOM!\n"); exit(1);} } /* for( i=0; i<lattice->param.LY; i++) */ // Pad for 4-byte boundaries. val = (char)0; for( i=0; i<pad; i++) { if( fwrite( &val, 1, 1, o_u ) != 1) { printf("BOOM!\n"); exit(1);} if( fwrite( &val, 1, 1, o_ux) != 1) { printf("BOOM!\n"); exit(1);} if( fwrite( &val, 1, 1, o_uy) != 1) { printf("BOOM!\n"); exit(1);} } } /* for( j=0; j<lattice->param.LY; j++) */ fclose(o_u ); fclose(o_ux); fclose(o_uy);#if VERBOSITY_LEVEL > 0 sprintf( filename, "u%dx%d_frame%04d.bmp", lattice->param.LX, lattice->param.LY, frame); printf("u2bmp() -- Wrote file \"%s\".\n", filename); sprintf( filename, "u_x%dx%d_frame%04d.bmp", lattice->param.LX, lattice->param.LY, frame); printf("u2bmp() -- Wrote file \"%s\".\n", filename); sprintf( filename, "u_y%dx%d_frame%04d.bmp", lattice->param.LX, lattice->param.LY, frame); printf("u2bmp() -- Wrote file \"%s\".\n", filename);#endif /* VERBOSITY_LEVEL > 0 */#if SAY_HI printf("u2bmp() -- Bye!\n"); printf("\n");#endif /* SAY_HI */} /* u2bmp( lattice_ptr lattice, int time) */// void vor2bmp( char *filename, int time)//##############################################################################//// V O R 2 B M P //void vor2bmp( lattice_ptr lattice, int time){ FILE *in, *o_vor; int i, j, n, m; int pad, bytes_per_row; int frame; char k; char b; struct bitmap_file_header bmfh; struct bitmap_info_header bmih; struct rgb_quad rgb; int *int_ptr; short int *short_int_ptr; int *width_ptr; int *height_ptr; short int *bitcount_ptr; char filename[1024]; int **map; char red_val, green_val, blue_val, val; double max_vor_p, max_vor_n; double ave_vor_p, ave_vor_n; double vor;#if SAY_HI printf("vor2bmp() -- Hi!\n");#endif /* SAY_HI */ frame = time/lattice->param.FrameRate; sprintf( filename, "%dx%d.bmp", lattice->param.LX, lattice->param.LY); if( !( in = fopen( filename, "r"))) { printf("vor2bmp() -- Error opening file \"%s\".\n", filename); exit(1); } // n = fread( void *BUF, size_t SIZE, size_t COUNT, FILE *FP); n = fread( &bmfh, sizeof(struct bitmap_file_header), 1, in ); if( strncmp(bmfh.bfType,"BM",2)) { printf("ERROR: Can't process this file type. Exiting!\n"); printf("\n"); exit(1); } n = fread( &bmih, sizeof(struct bitmap_info_header), 1, in ); int_ptr = (int*)bmih.biCompression; if( *int_ptr != 0) { printf("ERROR: Can't handle compression. Exiting!\n"); printf("\n"); exit(1); } width_ptr = (int*)bmih.biWidth; height_ptr = (int*)bmih.biHeight; bitcount_ptr = (short int*)bmih.biBitCount; // Read palette entries, if applicable. if( *bitcount_ptr < 24) { n = (double)pow(2.,(double)*bitcount_ptr); // Num palette entries. for( i=0; i<n; i++) { k = fread( &rgb, sizeof(struct rgb_quad), 1, in ); if( k!=1) { printf("Error reading palette entry %d. Exiting!\n", i); exit(1); } } } fclose(in); // Bytes per row of the bitmap. bytes_per_row = ((int)ceil(( (((double)(*width_ptr))*((double)(*bitcount_ptr)))/8.))); // Bitmaps pad rows to preserve 4-byte boundaries. // The length of a row in the file will be bytes_per_row + pad . pad = ((4) - bytes_per_row%4)%4; // Create a map from (i,j) space onto n index space. This could be a // bad idea in terms of memory usage. But the purpose is to create a // bitmap file. If the domain is small enough to view as a BMP, then // it is small enough to manage in a 2D array like this... map = (int**)malloc( (lattice->param.LY)*sizeof(int*)); for( j=0; j<(lattice->param.LY); j++) { map[j] = (int*)malloc( (lattice->param.LX)*sizeof(int)); }#if 0 //memset( &(map[0][0]), -1, (lattice->param.LX)*(lattice->param.LY)*sizeof(int)); memset( &(map[0][0]), -1, 29*sizeof(int));#else for( j=0; j<lattice->param.LY; j++) { for( i=0; i<lattice->param.LX; i++) { map[j][i] = -1; } }#endif#if 0 for( j=0; j<lattice->param.LY; j++) { for( i=0; i<lattice->param.LX; i++) { printf(" %d", map[j][i]); } printf("\n"); } printf("\n");#endif for( n=0; n<lattice->NumNodes; n++) { map[lattice->node[n].j][lattice->node[n].i] = lattice->node[n].n; }#if 0 for( j=0; j<lattice->param.LY; j++) { for( i=0; i<lattice->param.LX; i++) { printf(" %d", map[j][i]); } printf("\n"); } printf("\n");#endif compute_max_vor( lattice, &max_vor_p, &max_vor_n); printf("vor2bmp() -- max_vor_p = %f\n", max_vor_p); printf("vor2bmp() -- max_vor_n = %f\n", max_vor_n); compute_ave_vor( lattice, &ave_vor_p, &ave_vor_n); printf("vor2bmp() -- ave_vor_p = %f\n", ave_vor_p); printf("vor2bmp() -- ave_vor_n = %f\n", ave_vor_n); sprintf( filename, "vor%dx%d_frame%04d.bmp", lattice->param.LX, lattice->param.LY, frame); o_vor = fopen( filename, "w+"); fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o_vor ); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o_vor ); //for( j=lattice->param.LY-1; j>=0; j--) for( j=0; j<lattice->param.LY; j++) { for( i=0; i<lattice->param.LX; i++) { if( map[j][i] != INACTIVE_NODE //&& !( lattice->bc[ map[j][i]].bc_type & BC_SOLID_NODE) && lattice->bc[ map[j][i]].bc_type == /*FLUID_NODE*/0 ) { blue_val = (char)255; green_val = (char)255; red_val = (char)255; //u_x = (lattice->macro_vars[ map[j][i]].u[0]); //u_y = (lattice->macro_vars[ map[j][i]].u[1]); compute_vorticity( lattice, i, j, map[ j][ i], &vor);//if( fabs(vor)/max_vor_p > .5)//{// printf("vor2bmp() -- vor/max_vor_p = %f/%f = %f\n", vor, max_vor_p, vor/max_vor_p);//} if( vor > 0) { if( 100.*vor/ave_vor_p > 1.) {//printf("vor2bmp() -- vor/ave_vor_p = %f > 1.\n", vor/ave_vor_p); red_val = (char)0; green_val = (char)0; } else {//printf("vor2bmp() -- vor/ave_vor_p = %f <= 1.\n", vor/ave_vor_p); red_val = (char)round( 255.*( 1. - 10000.*(vor/ave_vor_p)*(vo
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -