⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lbio.c

📁 基于格子Boltzmann方法开源可视化软件的源代码 具有很高的实用价值。对学习LBM方法及其软件开发非常游泳
💻 C
📖 第 1 页 / 共 5 页
字号:
//  - 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) */// 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, *o;  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;  char ctemp;  int  itemp;  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")))  {#if 1    printf("spy_bmp() -- Error opening file \"%s\".\n", filename);    exit(1);#else    printf(" %s::spy_bmp() %d >> File \"%s\" cannot be opened for reading.\n",        __FILE__, __LINE__, filename);    if( !( o = fopen( filename, "w+")))    {      // TODO: Write blank bmp file.    }    printf(" %s::spy_bmp() %d >> Wrote a blank \"%s\" file.\n",         __FILE__, __LINE__, filename);    printf(" %s::spy_bmp() %d >> Returning all zeros!\n", __FILE__, __LINE__);    fclose( o);    return;#endif  }  // 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 );#if 0printf("%s %d >> sizeof(int) = %d \n", __FILE__, __LINE__, sizeof(int));printf("%s %d >> biWidth = %d \n", __FILE__, __LINE__, (int)*(int*)bmih.biWidth);printf("%s %d >> biWidth = [ '%c' '%c' '%c' '%c'] \n", __FILE__, __LINE__,     bmih.biWidth[0], bmih.biWidth[1], bmih.biWidth[2], bmih.biWidth[3] );printf("%s %d >> biWidth = [ '%d' '%d' '%d' '%d'] \n", __FILE__, __LINE__,     bmih.biWidth[0], bmih.biWidth[1], bmih.biWidth[2], bmih.biWidth[3] );ctemp = bmih.biWidth[0];bmih.biWidth[0] = bmih.biWidth[3];bmih.biWidth[3] = ctemp;ctemp = bmih.biWidth[1];bmih.biWidth[1] = bmih.biWidth[2];bmih.biWidth[2] = ctemp;   itemp = 0xaabbccdd;//(int)*(int*)bmih.biWidth;printf("%s %d >> itemp = %d\n",__FILE__,__LINE__, itemp);printf("%s %d >> itemp = [ '%d' '%d' '%d' '%d'] \n", __FILE__, __LINE__,    (itemp&0xff000000)>>24,   (itemp&0x00ff0000)>>16,   (itemp&0x0000ff00)>> 8,   (itemp&0x000000ff)>> 0 );  itemp = ENDIAN4(itemp);printf("%s %d >> itemp = %d\n",__FILE__,__LINE__, itemp);printf("%s %d >> itemp = [ '%d' '%d' '%d' '%d'] \n", __FILE__, __LINE__,    (itemp&0xff000000)>>24,   (itemp&0x00ff0000)>>16,   (itemp&0x0000ff00)>> 8,   (itemp&0x000000ff)>> 0 );printf("%s %d >> biWidth = [ '%d' '%d' '%d' '%d'] \n", __FILE__, __LINE__,     bmih.biWidth[0], bmih.biWidth[1], bmih.biWidth[2], bmih.biWidth[3] );printf("%s %d >> biWidth = %d \n", __FILE__, __LINE__, (int)*(int*)bmih.biWidth);printf("%s %d >> sizeof(int) = %d \n", __FILE__, __LINE__, sizeof(int));printf("%s %d >> biHeight = %d \n", __FILE__, __LINE__, (int)*(int*)bmih.biHeight);printf("%s %d >> biHeight = [ '%c' '%c' '%c' '%c'] \n", __FILE__, __LINE__,     bmih.biHeight[0], bmih.biHeight[1], bmih.biHeight[2], bmih.biHeight[3] );printf("%s %d >> biHeight = [ '%d' '%d' '%d' '%d'] \n", __FILE__, __LINE__,     bmih.biHeight[0], bmih.biHeight[1], bmih.biHeight[2], bmih.biHeight[3] );ctemp = bmih.biHeight[0];bmih.biHeight[0] = bmih.biHeight[3];bmih.biHeight[3] = ctemp;ctemp = bmih.biHeight[1];bmih.biHeight[1] = bmih.biHeight[2];bmih.biHeight[2] = ctemp;printf("%s %d >> biHeight = [ '%d' '%d' '%d' '%d'] \n", __FILE__, __LINE__,     bmih.biHeight[0], bmih.biHeight[1], bmih.biHeight[2], bmih.biHeight[3] );printf("%s %d >> biHeight = %d \n", __FILE__, __LINE__, (int)*(int*)bmih.biHeight);ctemp = bmih.biBitCount[0];bmih.biBitCount[0] = bmih.biBitCount[1];bmih.biBitCount[1] = ctemp;#endif  *((int*)(bmih.biWidth)) = ENDIAN4(((int)(*((int*)(bmih.biWidth)))));  *((int*)(bmih.biHeight)) = ENDIAN4(((int)(*((int*)(bmih.biHeight)))));  *((short int*)(bmih.biBitCount)) = ENDIAN2(((short int)(*((short int*)(bmih.biBitCount)))));  int_ptr = (int*)bmih.biCompression;  if( *int_ptr != 0)  {    printf("%s %d >> ERROR: Can't handle compression.  Exiting!\n",__FILE__,__LINE__);    printf("\n");    exit(1);  }  width_ptr = (int*)bmih.biWidth;  height_ptr = (int*)bmih.biHeight;  bitcount_ptr = (short int*)bmih.biBitCount;  if( *width_ptr != lattice->param.LX)  {    printf("%s %d >> ERROR: LX %d does not match the "        "width %d of the BMP file. Exiting!\n",         __FILE__, __LINE__, lattice->param.LX, *width_ptr);    exit(1);  }printf("%s %d >> biWidth = %d \n", __FILE__, __LINE__, (int)*bmih.biWidth);printf("%s %d >> width_ptr = %d \n", __FILE__, __LINE__, (int)*width_ptr);  if( *height_ptr != lattice->param.LY)  {    printf("%s %d >> ERROR: LY %d does not match the "        "height %d of the BMP file. Exiting!\n",         __FILE__, __LINE__, lattice->param.LY, *height_ptr);    exit(1);  }  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("%s %d >> Error reading palette entry %d.  Exiting!\n", __FILE__, __LINE__, 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("%s %d >> spy_bmp() -- "            "Support for Monochrome BMPs is pending.  "            "Exiting!\n", __FILE__, __LINE__);        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("%s %d >> spy_bmp() -- "            "Support for 16 color BMPs is pending.  "            "Exiting!\n", __FILE__, __LINE__);        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("%s %d >> spy_bmp() -- "            "Support for 256 color BMPs is pending.  "            "Exiting!\n", __FILE__, __LINE__);        exit(1);        if( i < *width_ptr) { (spy)[j][i] = ( (b&0xff) != 255); }        i++;        break;      case 24: // 24-bit colors.        if( i < 3*(*width_ptr))         {           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 0          if( ( (b&0xff) == 0) &&( (g&0xff) == 0) &&( (r&0xff) == 255) )          {            // Red ==> Inflow, Pressure boundaries.            if(    (int)floor((double)i/3.) == 0                 || (int)floor((double)i/3.) == lattice->param.LX-1 )            {              if( !( j==0 || j == lattice->param.LY-1))              {                lattice->periodic_x[subs] = 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))              {                lattice->periodic_y[subs] = 0;              }            }          }          if( ( (b&0xff) == 0) &&( (g&0xff) == 255) &&( (r&0xff) == 0) )          {            // Green ==> Outflow, Pressure boundaries.            if(    (int)floor((double)i/3.) == 0                 || (int)floor((double)i/3.) == lattice->param.LX-1 )            {              if( !( j==0 || j == lattice->param.LY-1))              {                lattice->periodic_x[subs] = 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))              {                lattice->periodic_y[subs] = 0;              }            }          }#endif        }        i++;        break;      default: // 32-bit colors?        printf("%s %d >> ERROR: Unhandled color depth, "            "BitCount = %d. Exiting!\n", __FILE__, __LINE__, *bitcount_ptr);        exit(1);        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);  printf("spy_bmp() -- Bye!\n");  printf("\n");} /* spy_bmp( char *filename, int **spy) */// void read_bcs( char *filename, int **bcs)//##############################################################################//// R E A D   B C S////  - Read boundary condition information from file.//void read_bcs( lattice_ptr lattice, int **bcs){  FILE   *in;  char   filename[1024];  int    i, j, n, m;  int    ei, ej;  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;  int    subs;  printf("read_bcs() -- Hi!\n"); for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) {  // Clear the bcs array.  for( j=0; j<lattice->param.LY; j++)  {    for( i=0; i<lattice->param.LX; i++)    {      bcs[j][i] = 0;    }  }  sprintf( filename, "./in/%dx%dbc_subs%02d.bmp",            lattice->param.LX,            lattice->param.LY, subs);  if( !( in = fopen( filename, "r")))  {    printf("read_bcs() -- Error opening file \"%s\".\n", filename);    exit(1);  }  // Read the headers.  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( ENDIAN4(*height_ptr) != lattice->param.LY)  {    printf("ERROR: Lattice height does not match "        "soil matrix data \"%s\".  (%d!=%d)  Exiting!\n",        filename,        lattice->param.LY, ENDIAN4(*height_ptr) );    printf("\n");    exit(1);  }  if( ENDIAN4(*width_ptr) != lattice->param.LX)  {    printf("ERROR: Lattice width does not match "        "soil matrix data \"%s\".  (%d!=%d)  Exiting!\n",         filename,        lattice->param.LX, ENDIAN4(*width_ptr) );    printf("\n");    exit(1);  }  // Read the palette, if necessary.  if( ENDIAN2(*bitcount_ptr) < 24)  {    n = (int)pow(2.,(double)ENDIAN2(*bitcount_ptr)); // Num palette entries.    for( i=0; i<n; i++)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -