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

📄 lbio.c

📁 基于格子Boltzmann方法开源可视化软件的源代码 具有很高的实用价值。对学习LBM方法及其软件开发非常游泳
💻 C
📖 第 1 页 / 共 5 页
字号:
              {                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;          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( lattice->bc[subs][ n].bc_type == 0) else *///printf("blue_val( %d, %d) = %d\n", i, j, (int)blue_val);      if( fwrite( &blue_val, 1, 1, o) != 1) { printf("BOOM!\n"); exit(1);}      //printf("BING %d %d\n", i, j);      if( fwrite( &green_val, 1, 1, o) != 1) { printf("BOOM!\n"); exit(1);}      //printf("BING %d %d\n", i, j);      if( fwrite( &red_val, 1, 1, o) != 1) { printf("BOOM!\n"); exit(1);}      //printf("BING %d %d\n", i, j);         } /* for( i=0; i<lattice->param.LX; i++) */    // Pad for 4-byte boundaries.    val = (char)0;    for( i=0; i<pad; i++)    {      if( fwrite( &val, 1, 1, o) != 1) { printf("BOOM!\n"); exit(1);}    }  } /* for( j=0; j<lattice->param.LY; j++) */  fclose(o);#if VERBOSITY_LEVEL > 0  printf("rho2bmp() -- Wrote file \"%s\".\n", filename);#endif /* VERBOSITY_LEVEL > 0 */ } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */  if( lattice->param.use_colormap)  {    deallocate_colormap( &colormap, num_colors);  }#if SAY_HI  printf("rho2bmp() -- Bye!\n");  printf("\n");#endif /* SAY_HI */} /* rho2bmp( lattice_ptr lattice, int time) */#elsevoid 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 min_rho, max_rho;  int    subs;#if SAY_HI  printf("rho2bmp() -- Hi!\n");#endif /* SAY_HI */ compute_max_rho( lattice, &min_rho, 0); compute_max_rho( lattice, &max_rho, 1); 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( ENDIAN2(*bitcount_ptr) < 24)  {    n = (int)pow(2.,(double)ENDIAN2(*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)(ENDIAN4(*width_ptr)))*((double)(ENDIAN2(*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;  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)      {        red_val = (char)0;        green_val = (char)0;        red_val = (char)ROUND( 255.*(lattice->macro_vars[subs][ n].rho - min_rho)/(max_rho-min_rho));        blue_val = (char)255-red_val;      } /* 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;          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( lattice->bc[subs][ n].bc_type == 0) else *///printf("blue_val( %d, %d) = %d\n", i, j, (int)blue_val);      if( fwrite( &blue_val, 1, 1, o) != 1) { printf("BOOM!\n"); exit(1);}      //printf("BING %d %d\n", i, j);      if( fwrite( &green_val, 1, 1, o) != 1) { printf("BOOM!\n"); exit(1);}      //printf("BING %d %d\n", i, j);      if( fwrite( &red_val, 1, 1, o) != 1) { printf("BOOM!\n"); exit(1);}      //printf("BING %d %d\n", i, j);         } /* for( i=0; i<lattice->param.LX; i++) */    // Pad for 4-byte boundaries.    val = (char)0;    for( i=0; i<pad; i++)    {      if( fwrite( &val, 1, 1, o) != 1) { printf("BOOM!\n"); exit(1);}    }  } /* for( j=0; j<lattice->param.LY; j++) */  fclose(o);#if VERBOSITY_LEVEL > 0  printf("rho2bmp() -- Wrote file \"%s\".\n", filename);#endif /* VERBOSITY_LEVEL > 0 */ } /* for( subs=0; subs<NUM_FLUID_COMPONENTS; subs++) */#if SAY_HI  printf("rho2bmp() -- Bye!\n");  printf("\n");#endif /* SAY_HI */} /* rho2bmp( lattice_ptr lattice, int time) */#endif// void u2bmp( char *filename, int time)//##############################################################################//// U 2 B M P //void u2bmp( lattice_ptr lattice, int time){  FILE   *in,          *o_u,         *o_ux,         *o_uy;  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 max_u[2], maxu;  double u_x, u_y, u;  int    subs;#if SAY_HI  printf("u2bmp() -- Hi!\n");#endif /* SAY_HI */ 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("u2bmp() -- 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);  }#if 0  *((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)))));#endif  width_ptr    = (int*)bmih.biWidth;  height_ptr   = (int*)bmih.biHeight;  bitcount_ptr = (short int*)bmih.biBitCount;printf("%s %d >> width

⌨️ 快捷键说明

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