📄 lbio.c
字号:
+ (double)(lattice)->NumNodes*sizeof(struct bc_struct) ) / (double)pow(2.,20.) ); printf("Full grid: %d bytes = %f MB\n", sizeof(int) + sizeof(struct param_struct) + (lattice)->param.LX*(lattice)->param.LY*sizeof(struct pdf_struct) + (lattice)->param.LX*(lattice)->param.LY*sizeof(struct macro_vars_struct) + (lattice)->param.LX*(lattice)->param.LY*sizeof(struct bc_struct), ( (double)sizeof(int) + (double)sizeof(struct param_struct) + (double)(lattice)->param.LX*(lattice)->param.LY*sizeof(struct pdf_struct) + (double)(lattice)->param.LX*(lattice)->param.LY*sizeof(struct macro_vars_struct) + (double)(lattice)->param.LX*(lattice)->param.LY*sizeof(struct bc_struct) ) / (double)pow(2.,20.) ); printf("Full / Sparse: %f\n", ( (double)sizeof(int) + (double)sizeof(struct param_struct) + (double)(lattice)->param.LX*(lattice)->param.LY*sizeof(struct pdf_struct) + (double)(lattice)->param.LX*(lattice)->param.LY*sizeof(struct macro_vars_struct) + (double)(lattice)->param.LX*(lattice)->param.LY*sizeof(struct bc_struct) ) / ( (double)sizeof(int) + (double)sizeof(struct param_struct) + (double)(lattice)->NumNodes*sizeof(struct node_struct) + (double)(lattice)->NumNodes*sizeof(struct pdf_struct) + (double)(lattice)->NumNodes*sizeof(struct macro_vars_struct) + (double)(lattice)->NumNodes*sizeof(struct bc_struct) ) ); printf("----------------------------------------"); printf("----------------------------------------\n");#endif /* VERBOSITY_LEVEL >= 1 */ if( !( o = fopen("lattice.info","w+"))) { printf("ERROR: fopen(\"lattice.info\",\"w+\") = NULL. Bye, bye!\n"); exit(1); } fprintf( o, "----------------------------------------"); fprintf( o, "----------------------------------------\n"); fprintf( o, " lattice = %x ", lattice); fprintf( o, "(size = %3d bytes)\n", sizeof( struct lattice_struct)); fprintf( o, "&( lattice->NumNodes) = %x ", &( (lattice)->NumNodes)); fprintf( o, "(size = %3d bytes)\n",sizeof(int)); fprintf( o, "&( lattice->param) = %x ", &( (lattice)->param)); fprintf( o, "(size = %3d bytes)\n",sizeof(struct param_struct)); fprintf( o, "&( lattice->node) = %x ", &( (lattice)->node)); fprintf( o, "(size = %3d B/node * ",sizeof(struct node_struct)); fprintf( o, "%d nodes = %d bytes)\n", (lattice)->NumNodes, (lattice)->NumNodes*sizeof(struct node_struct)); fprintf( o, "&( lattice->pdf) = %x ", &( (lattice)->pdf)); fprintf( o, "(size = %3d B/node * ", sizeof(struct pdf_struct)); fprintf( o, "%d nodes = %d bytes)\n", (lattice)->NumNodes, (lattice)->NumNodes*sizeof(struct pdf_struct)); fprintf( o, "&( lattice->macro_vars) = %x ", &( (lattice)->macro_vars)); fprintf( o, "(size = %3d B/node * ", sizeof(struct macro_vars_struct)); fprintf( o, "%d nodes = %d bytes)\n", (lattice)->NumNodes, (lattice)->NumNodes*sizeof(struct macro_vars_struct)); fprintf( o, "&( lattice->bc) = %x ", &( (lattice)->bc)); fprintf( o, "(size = %3d B/node * ", sizeof(struct bc_struct)); fprintf( o, "%d nodes = %d bytes)\n", (lattice)->NumNodes, (lattice)->NumNodes*sizeof(struct bc_struct)); fprintf( o, "----------------------------------------"); fprintf( o, "----------------------------------------\n"); fprintf( o, "Size of \"sparse\" lattice: %d bytes = %f MB\n", sizeof(int) + sizeof(struct param_struct) + (lattice)->NumNodes*sizeof(struct node_struct) + (lattice)->NumNodes*sizeof(struct pdf_struct) + (lattice)->NumNodes*sizeof(struct macro_vars_struct) + (lattice)->NumNodes*sizeof(struct bc_struct), ( (double)sizeof(int) + (double)sizeof(struct param_struct) + (double)(lattice)->NumNodes*sizeof(struct node_struct) + (double)(lattice)->NumNodes*sizeof(struct pdf_struct) + (double)(lattice)->NumNodes*sizeof(struct macro_vars_struct) + (double)(lattice)->NumNodes*sizeof(struct bc_struct) ) / (double)pow(2.,20.) ); fprintf( o, "Full grid: %d bytes = %f MB\n", sizeof(int) + sizeof(struct param_struct) + (lattice)->param.LX*(lattice)->param.LY*sizeof(struct pdf_struct) + (lattice)->param.LX*(lattice)->param.LY*sizeof(struct macro_vars_struct) + (lattice)->param.LX*(lattice)->param.LY*sizeof(struct bc_struct), ( (double)sizeof(int) + (double)sizeof(struct param_struct) + (double)(lattice)->param.LX*(lattice)->param.LY*sizeof(struct pdf_struct) + (double)(lattice)->param.LX*(lattice)->param.LY*sizeof(struct macro_vars_struct) + (double)(lattice)->param.LX*(lattice)->param.LY*sizeof(struct bc_struct) ) / (double)pow(2.,20.) ); fprintf( o, "Full / Sparse: %f\n", ( (double)sizeof(int) + (double)sizeof(struct param_struct) + (double)(lattice)->param.LX*(lattice)->param.LY*sizeof(struct pdf_struct) + (double)(lattice)->param.LX*(lattice)->param.LY*sizeof(struct macro_vars_struct) + (double)(lattice)->param.LX*(lattice)->param.LY*sizeof(struct bc_struct) ) / ( (double)sizeof(int) + (double)sizeof(struct param_struct) + (double)(lattice)->NumNodes*sizeof(struct node_struct) + (double)(lattice)->NumNodes*sizeof(struct pdf_struct) + (double)(lattice)->NumNodes*sizeof(struct macro_vars_struct) + (double)(lattice)->NumNodes*sizeof(struct bc_struct) ) ); fprintf( o, "----------------------------------------"); fprintf( o, "----------------------------------------\n"); fclose(o);#if VERBOSITY_LEVEL >= 1 printf("lbio.c: dump_lattice_info() -- Wrote file \"lattice.info\".\n");#endif /* VERBOSITY_LEVEL >= 1 */} /* void dump_lattice_info( struct lattice_struct *lattice) */// void dump_node_info( struct lattice_struct *lattice)//##############################################################################//// D U M P N O D E I N F O //// - Output node info to file.//void dump_node_info( struct lattice_struct *lattice){ FILE *o; int n; if( !( o = fopen( "nodes.info", "w+"))) { printf("ERROR: fopen( \"nodes.info\", \"w+\") = NULL. Bye, bye!\n"); exit(1); } for( n=0; n<lattice->NumNodes; n++) { fprintf( o, " %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d (%5d)\n", lattice->node[n].i, lattice->node[n].j, lattice->node[n].n, lattice->node[n].nn[0], lattice->node[n].nn[1], lattice->node[n].nn[2], lattice->node[n].nn[3], lattice->node[n].nn[4], lattice->node[n].nn[5], lattice->node[n].nn[6], lattice->node[n].nn[7], lattice->bc[n].bc_type ); } fclose(o);#if VERBOSITY_LEVEL >= 1 printf("lbio.c: dump_node_info() -- Wrote file \"nodes.info\".\n");#endif /* VERBOSITY_LEVEL >= 1 */} /* void dump_lattice_info( struct lattice_struct *lattice) */// void dump_checkpoint( struct lattice_struct *lattice, int time, char *fn)//##############################################################################//// D U M P C H E C K P O I N T //// - Write lattice to a checkpoint file.//// - Should be binary and store all information necessary to// restart the current run at this point.//void dump_checkpoint( struct lattice_struct *lattice, int time, char *fn){} /* void dump_checkpoint( struct lattice_struct *lattice, ...) */// void read_checkpoint( struct lattice_struct *lattice)//##############################################################################//// R E A D C H E C K P O I N T //// - Read lattice from a checkpoint file (as written by dump_checkpoint).//// - With this information, should be able to restart where// the previous run stopped.//void read_checkpoint( struct lattice_struct *lattice){} /* void read_checkpoint( struct lattice_struct *lattice) */struct bitmap_file_header{ // 1 2 bfType 19778 must always be set to 'BM' to declare that this is // a .bmp-file. char bfType[2]; // 3 4 bfSize ?? specifies the size of the file in bytes. char bfSize[4]; // 7 2 bfReserved1 0 must always be set to zero. char bfReserved1[2]; // 9 2 bfReserved2 0 must always be set to zero. char bfReserved2[2]; // 11 4 bfOffBits 1078 specifies the offset from the beginning of the // file to the bitmap data. char bfOffBits[4];};struct bitmap_info_header{ // 15 4 biSize 40 specifies the size of the BITMAPINFOHEADER structure, // in bytes. char biSize[4]; // 19 4 biWidth 100 specifies the width of the image, in pixels. char biWidth[4]; // 23 4 biHeight 100 specifies the height of the image, in pixels. char biHeight[4]; // 27 2 biPlanes 1 specifies the number of planes of the target device, // must be set to zero. [DT: Should be set to one, right? Not zero.] char biPlanes[2]; // 29 2 biBitCount 8 specifies the number of bits per pixel. char biBitCount[2]; // 31 4 biCompression 0 Specifies the type of compression, usually set // to zero (no compression). char biCompression[4]; // 35 4 biSizeImage 0 specifies the size of the image data, in bytes. // If there is no compression, it is valid to set this member to zero. char biSizeImage[4]; // 39 4 biXPelsPerMeter 0 specifies the the horizontal pixels per meter // on the designated targer device, usually set to zero. char biXPelsPerMeter[4]; // 43 4 biYPelsPerMeter 0 specifies the the vertical pixels per meter // on the designated targer device, usually set to zero. char biYPelsPerMeter[4]; // 47 4 biClrUsed 0 specifies the number of colors used in the bitmap, // if set to zero the number of colors is calculated using the biBitCount // member. char biClrUsed[4]; // 51 4 biClrImportant 0 specifies the number of color that are // 'important' for the bitmap, if set to zero, all colors are important. char biClrImportant[4];};struct rgb_quad{ // 1 1 rgbBlue - specifies the blue part of the color. char Blue; // 2 1 rgbGreen - specifies the green part of the color. char Green; // 3 1 rgbRed - specifies the red part of the color. char Red; // 4 1 rgbReserved - must always be set to zero. char Reserved;};// void spy_bmp( char *filename, int ***spy)//##############################################################################//// S P Y B M P //// - Returns matrix 'spy' of ones and zeros.//// - Zeros for white pixels.//// - Ones for non-white pixels.//void spy_bmp( char *filename, lattice_ptr lattice, int **spy){ FILE *in; int i, j, n, m; int pad, bytes_per_row; char k; char b, g, r; 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; printf("spy_bmp() -- Hi!\n"); // Clear the spy array. for( j=0; j<lattice->param.LY; j++) { for( i=0; i<lattice->param.LX; i++) { spy[j][i] = 0; } } if( !( in = fopen( filename, "r"))) { printf("spy_bmp() -- 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; 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); } } } // 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; n = 0; m = 0; n+=( k = fread( &b, 1, 1, in )); i = 0; j = 0; while( !feof(in)) { switch(*bitcount_ptr) { case 1: // Monochrome. printf("read_bcs() -- " "Support for Monochrome BMPs is pending. " "Exiting!\n"); exit(1); if( i < *width_ptr) { (spy)[j][i] = ( (b & 0x80) == 0); } i++; if( i < *width_ptr) { (spy)[j][i] = ( (b & 0x40) == 0); } i++; if( i < *width_ptr) { (spy)[j][i] = ( (b & 0x20) == 0); } i++; if( i < *width_ptr) { (spy)[j][i] = ( (b & 0x10) == 0); } i++; if( i < *width_ptr) { (spy)[j][i] = ( (b & 0x08) == 0); } i++; if( i < *width_ptr) { (spy)[j][i] = ( (b & 0x04) == 0); } i++; if( i < *width_ptr) { (spy)[j][i] = ( (b & 0x02) == 0); } i++; if( i < *width_ptr) { (spy)[j][i] = ( (b & 0x01) == 0); } i++; break; case 4: // 16 colors. printf("read_bcs() -- " "Support for 16 color BMPs is pending. " "Exiting!\n"); exit(1); if( i < *width_ptr) { (spy)[j][i] = ( (b&0xf0)>>4 != 15); } i++; if( i < *width_ptr) { (spy)[j][i] = ( (b&0x0f) != 15); } i++; break; case 8: // 256 colors. printf("read_bcs() -- " "Support for 256 color BMPs is pending. " "Exiting!\n"); exit(1); if( i < *width_ptr) { (spy)[j][i] = ( (b&0xff) != 255); } i++; break; case 24: // 24-bit colors. if( i < 3*(*width_ptr)) { #if 0 (*spy)[j][(int)floor((double)i/3.)] |= ( (b&0xff) != 255);#else i++; n+=( k = fread( &g, 1, 1, in )); i++; n+=( k = fread( &r, 1, 1, in )); if( ( (b&0xff) == 0) &&( (g&0xff) == 0) &&( (r&0xff) == 0) ) { (spy)[j][(int)floor((double)i/3.)] = 1; } if( ( (b&0xff) == 0) &&( (g&0xff) == 0) &&( (r&0xff) == 255) ) { // Red ==> Inflow, Pressure boundaries. //bcs[j][(int)floor((double)i/3.)] = 11;//printf("spy_bmp() -- Inflow at ( %d, %d).\n",// (int)floor((double)i/3.), j); if( (int)floor((double)i/3.) == 0 || (int)floor((double)i/3.) == lattice->param.LX-1 ) { if( !( j==0 || j == lattice->param.LY-1)) {//printf("spy_bmp() -- Turning periodic_x off at ( %d, %d).\n",// (int)floor((double)i/3.), j); lattice->periodic_x = 0; } } if( j == 0 || j == lattice->param.LY-1 ) { if( !( (int)floor((double)i/3.) == 0 || (int)floor((double)i/3.) == lattice->param.LX-1))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -