📄 lbio_03082005.c
字号:
break; } /* switch(*(bmih.biBitCount)) */ if( !(n%(bytes_per_row+pad))) { m++; i=0; j++;} n+=( k = fread( &b, 1, 1, in )); } /* while( !feof(in)) */ if( (bytes_per_row+pad)*m!=n) { printf("WARNING: Num bytes read = %d versus num bytes predicted = %d .\n", n, (bytes_per_row+pad)*m); } if( m != *height_ptr) { printf("WARNING: m (%d) != bmih.biHeight (%d).\n", m, *height_ptr); } fclose(in); ei = lattice->param.LX-1; ej = lattice->param.LY-1; for( n=0; n<lattice->NumNodes; n++) { i = n%lattice->param.LX; j = n/lattice->param.LX; if( bcs[ j][ i] != 0) {//printf("read_bcs() -- n = %d, ( %d, %d) of ( %d, %d).\n", n, i, j, ei, ej);#if 0 if( ( i==0 && j==0 ) || ( i==ei && j==0 ) || ( i==ei && j==ej) || ( i==0 && j==ej) ) { // Skip corners for now. printf("read_bcs() -- WARNING: Skipping corner ( %d, %d).", i, j); } else {#endif#if 0 if( i==0) { // West if( bcs[ j][ i] == 1) { // Inflow lattice->bc[n].bc_type |= BC_PRESSURE_W_IN; //lattice->periodic_x = 0; } else if( bcs[ j][ i] == 2) { // Outflow lattice->bc[n].bc_type |= BC_PRESSURE_W_OUT; //lattice->periodic_x = 0; } else { // Unhandled case. printf("read_bcs() -- Unhandled case: " "bcs[ %d][ %d] = %d . Exiting!\n", i, j, bcs[j][i]); exit(1); } } else if( i==ei) { // East if( bcs[ j][ i] == 1) { // Inflow lattice->bc[n].bc_type |= BC_PRESSURE_E_IN; //lattice->periodic_x = 0; } else if( bcs[ j][ i] == 2) { // Outflow lattice->bc[n].bc_type |= BC_PRESSURE_E_OUT; //lattice->periodic_x = 0; } else { // Unhandled case. printf("read_bcs() -- Unhandled case: " "bcs[ %d][ %d] = %d . Exiting!\n", i, j, bcs[j][i]); exit(1); } } else #endif if( j==0) {//printf("read_bcs() -- South at i=%d\n", i); // South if( bcs[ j][ i] == 1) { // Inflow lattice->bc[subs][n].bc_type |= BC_PRESSURE_S_IN; //lattice->periodic_y = 0; } else if( bcs[ j][ i] == 2) { // Outflow lattice->bc[subs][n].bc_type |= BC_PRESSURE_S_OUT; //lattice->periodic_y = 0; } else { // Unhandled case. printf("read_bcs() -- Unhandled case: " "bcs[ %d][ %d] = %d . Exiting!\n", i, j, bcs[j][i]); exit(1); } } else if( j==ej) {//printf("read_bcs() -- North at i=%d\n", i); // North if( bcs[ j][ i] == 1) { // Inflow lattice->bc[subs][n].bc_type |= BC_PRESSURE_N_IN; //lattice->periodic_y = 0; } else if( bcs[ j][ i] == 2) { // Outflow lattice->bc[subs][n].bc_type |= BC_PRESSURE_N_OUT; //lattice->periodic_y = 0; } else { // Unhandled case. printf("read_bcs() -- Unhandled case: " "bcs[ %d][ %d] = %d . Exiting!\n", i, j, bcs[j][i]); exit(1); } } else { // Unhandled case. printf("read_bcs() -- WARNING: " "Support for interior flow bcs is pending! " "Skipping ( i, j) = ( %d, %d).\n", i, j); }#if 0 }#endif } } } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */ printf("read_bcs() -- Bye!\n"); printf("\n");} /* read_bcs( char *filename, int ***bcs, int *height, int *width) */// void rho2bmp( char *filename, int time)//##############################################################################//// R H O 2 B M P //#if 1void rho2bmp( lattice_ptr lattice, int time){ FILE *in, *o; 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]; char red_val, green_val, blue_val, val; double fval; double min_rho, max_rho; int subs; double **colormap; int num_colors;#if SAY_HI printf("rho2bmp() -- Hi!\n");#endif /* SAY_HI */ if( lattice->param.use_colormap) { count_colormap( &num_colors); allocate_colormap( &colormap, num_colors); read_colormap( colormap, num_colors); } for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) { frame = time/lattice->param.FrameRate; sprintf( filename, "./in/%dx%d.bmp", lattice->param.LX, lattice->param.LY); if( !( in = fopen( filename, "r"))) { printf("rho2bmp() -- 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 = (int)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; compute_min_rho( lattice, &min_rho, subs); compute_max_rho( lattice, &max_rho, subs); sprintf( filename, "./out/rho%dx%d_frame%04d_subs%02d.bmp", lattice->param.LX, lattice->param.LY, frame, subs); if( !( o = fopen( filename, "w+"))) { printf("ERROR: fopen( \"%s\", \"w+\") = NULL. Bye, bye!\n", filename); exit(1); } fwrite( &bmfh, sizeof(struct bitmap_file_header), 1, o ); fwrite( &bmih, sizeof(struct bitmap_info_header), 1, o ); for( j=0; j<lattice->param.LY; j++) { n = j*lattice->param.LX; for( i=0; i<lattice->param.LX; i++, n++) { if( lattice->bc[subs][ n].bc_type == /*FLUID_NODE*/0) { if( lattice->param.use_colormap) { if( lattice->param.plot_scale_dynamic) { if( max_rho!=min_rho) { get_color( colormap, num_colors, (lattice->macro_vars[subs][ n].rho - min_rho)/(max_rho-min_rho), &red_val, &green_val, &blue_val ); } else { get_color( colormap, num_colors, 1., &red_val, &green_val, &blue_val ); } } else { get_color( colormap, num_colors, (lattice->macro_vars[subs][ n].rho /( (lattice->param.rho_A[subs]>lattice->param.rho_B[subs]) ?(lattice->param.rho_A[subs]) :(lattice->param.rho_B[subs]) )), &red_val, &green_val, &blue_val ); } } else { if( subs==0) { if( lattice->param.plot_scale_dynamic) { if( max_rho!=min_rho) { fval = ROUND( 255.*( lattice->macro_vars[subs][ n].rho - min_rho) /( max_rho-min_rho)); } else { fval = 255.; } } else { fval = ROUND( 255.*(lattice->macro_vars[subs][ n].rho /( (lattice->param.rho_A[subs]>lattice->param.rho_B[subs]) ?(lattice->param.rho_A[subs]) :(lattice->param.rho_B[subs]) ) )); } if( fval >= 0.) { if( fval <= 255.) { red_val = (char)((int)(255. - fval)%256); green_val = (char)((int)(255. - fval)%256); blue_val = (char)255; } else { red_val = (char)0; green_val = (char)0; blue_val = (char)255; } } else { red_val = (char)((int)(255. + fval)%256); green_val = (char)((int)(255. + fval)%256); blue_val = (char)((int)(255. + fval)%256); // TODO: Issue warning or something? Potential instability? } } /* if( subs==0) */ else // subs == 1 { if( lattice->param.plot_scale_dynamic) { if( max_rho!=min_rho) { fval = ROUND( 255.*( lattice->macro_vars[subs][ n].rho - min_rho) /( max_rho-min_rho)); } else { fval = 0.; } } else {//printf("%s (%d) >> fval = %f -> ", __FILE__, __LINE__, fval);#if INAMURO_SIGMA_COMPONENT fval = ROUND( 255.*(lattice->macro_vars[subs][ n].rho) /(lattice->param.rho_sigma));#else /* !( INAMURO_SIGMA_COMPONENT) */ fval = ROUND( 255.*(lattice->macro_vars[subs][ n].rho /(lattice->param.rho_A[subs])));#endif /* INAMURO_SIGMA_COMPONENT *///printf("%f\n", fval); } if( fval >= 0.) { if( fval <= 255.) { red_val = (char)255; green_val = (char)((int)(255. - fval)%256); blue_val = (char)((int)(255. - fval)%256); } else { red_val = (char)255;//((int)(255. - (fval - 255.))%256); green_val = (char) 0;//((int)(255. - (fval - 255.))%256); blue_val = (char) 0;//((int)(255. - (fval - 255.))%256); } } else { red_val = (char)((int)(255. + fval)%256); green_val = (char)((int)(255. + fval)%256); blue_val = (char)((int)(255. + fval)%256); // TODO: Issue a warning or something? Potential instability? } } /* if( subs==0) else */ } } /* if( lattice->bc[subs][ n].bc_type == 0) */ else // lattice->bc[subs][ n].bc_type != 0 {#if SOLID_COLOR_IS_CHECKERBOARD // Checkerboard pattern over the solids and boundary conditions. if( (i+j)%2) { red_val = (char)200;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -