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

📄 depth.c

📁 波浪数值模拟
💻 C
字号:
/* * Copyright (c) 2001-2005 Falk Feddersen * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * *//* depth.c   Falk Feddersen */       /* TODO!  make a depth_info_t which contains the depth file name and ascii/binary stuff etc.   Load up the depth file in here */     #include <stdio.h>#include <math.h>#include "depth.h"field2D_depth_var *Depth_Vars;void make_depth_var_ZA(field2D *ZA, const field2D *H){  const double beta = -0.531;  field2D_copy(ZA, H);   /* First make ZA = H */  field2D_mult_const(ZA, beta);   /* ZA *= beta */  }void  init_depth_variables(depthinfo *D, int nx, int ny){   /* Now do the depth variables */  //   H = allocate_field2D_grid(nx-1,ny, ETAGRID);  // (double *) g_malloc(sizeof(double)*(nx-1));   Depth_Vars = (field2D_depth_var * ) g_malloc(sizeof(field2D_depth_var));   Depth_Vars->H  =  allocate_field2D_grid(nx+1,ny, ETAGRID);      Depth_Vars->HBX = allocate_field2D_grid(nx,ny, UGRID);   Depth_Vars->HBY = allocate_field2D_grid(nx+1,ny, VGRID);   Depth_Vars->HBXY = allocate_field2D_grid(nx,ny, VORTGRID);   Depth_Vars->ZA =  allocate_field2D_grid(nx+1,ny, ETAGRID);   H = Depth_Vars->H;   // BROKEN: needed because H is a global variable in bdefs.h    Depth_Vars->DEPTH  =  allocate_field2D_grid(nx-1,ny, ETAGRID);      Depth_Vars->DEPTHBX = allocate_field2D_grid(nx,ny, UGRID);   Depth_Vars->DEPTHBY = allocate_field2D_grid(nx-1,ny, VGRID);   Depth_Vars->DEPTHBXY = allocate_field2D_grid(nx,ny, VORTGRID);   /* now load up or setup the depth H */   switch (D->dtype) {   case FLAT:  set_constant_depth(D->h0,H);               break;   case PLANAR: set_planar_depth(D->h0,D->slope,dx,H);                break;   case HFILE1D:  load_line_bathymetry(D->depth_file->str,H);                break;   case HFILE2D: load_full_bathymetry(D->depth_file->str,H);                break;   default: funwaveC_error_message("Shouldn't reach default in process_init_file: switch(){}!\n");  }   /* Now that H is good, do ZA, HBX, HBY etc. */   make_depth_var_ZA(Depth_Vars->ZA, Depth_Vars->H);   field2D_bary_eta_to_v(Depth_Vars->HBY, Depth_Vars->H);   field2D_barx(Depth_Vars->HBX, Depth_Vars->H);   field2D_apply_nogradient_bc(Depth_Vars->HBX);   field2D_bary_u_to_vort(Depth_Vars->HBXY, Depth_Vars->HBX);}void  deallocate_depth_variables(){  /* deallocate the depth var information */  deallocate_field2D(H);  deallocate_field2D(Depth_Vars->HBX);  deallocate_field2D(Depth_Vars->HBY);  deallocate_field2D(Depth_Vars->ZA);  g_free(Depth_Vars);}/* checks to make sure that  h+eta > 0, returns the minimum total water depth  */double check_depth(const field2D *ETA){  int i;  int num = ETA->num;  int M = ETA->M;  const field2D *H = Depth_Vars->H;  const double *etad = ETA->data;  const double *hd = &(H->data[M]);  double depth;  double min_depth = 100;      /* a big number */  for (i=0;i<num;i++) {    depth = *hd++ + *etad++;    if (depth < min_depth) {      min_depth = depth;    }    if (isnan(depth)) {      funwaveC_error_message("** depth.c: check_depth() - error, NAN in eta: ABORT");    }  }  if (min_depth <= 0.0)    funwaveC_error_message("** depth.c: check_depth() - error, total water depth (eta+h) <= 0.0");  return min_depth;}  /* checks to make sure that  h+eta > 0, returns the minimum total water depth  */void report_mass_conservation(const field2D *ETA){  int i;  int num = ETA->num;  const double *etad = ETA->data;  double integral_eta = 0.0;  for (i=0;i<num;i++) {    integral_eta += *etad++;  }  integral_eta *= (dx * dy);  fprintf(stderr," Mass conservation: \\int \\eta dx dy = %g (m^3)\n", integral_eta);}  void set_constant_depth(gdouble depth, field2D  *H){   int i;   int num = H->num;   double *hd = H->data;   for (i=0;i<num;i++) {     *hd++ = depth;   }#ifdef NOSLIP   HEXT0 = depth;   HEXTN = depth;#endif}void set_planar_depth(gdouble slope, gdouble h0, gdouble dx, field2D *H){  int N = H->N;  int M = H->M;  int i,j;  double h;  for (i=0;i<N;i++) {    h = h0+slope*(dx*i+dx/2);    for (j=0;j<M;j++) {      DR2(H,i,j) = h;    }  }  /* Get rid of this stuff */#ifdef NOSLIP   HEXT0 = 1.5*H[0]-0.5*H[1];   HEXTN = 1.5*H[NX-2]-0.5*H[NX-3];   if ((HEXT0<=0)||(HEXTN<=0))       funwaveC_error_message("Warning extrapolated boundary depths <=0 for no-slip BCs.");#endif}void load_line_bathymetry(char *fname, field2D *H){  int N = H->N;  int M = H->M;  FILE *fp;  int i,j;  gdouble a;  char msg[80];   if ((fp=fopen(fname,"r"))==NULL) {       sprintf(msg,"Error loading line bathymetry file: %s\n",fname);       funwaveC_error_message(msg);   }   for (i=1;i<N-1;i++) {      fscanf(fp,"%lf",&a);      for (j=0;j<M;j++) {        DR2(H,i,j) = a;      }   }   fclose(fp);   /* now do the interior boundary depths */   for (j=0;j<M;j++) {     DR2(H,0,j) = DR2(H,1,j);     DR2(H,N-1,j) = DR2(H,N-2,j);   }}void load_full_bathymetry(char *fname, field2D *H){  int N = H->N;  int M = H->M;  FILE *fp;  int i,j;  gdouble a;  char msg[80];    if ((fp=fopen(fname,"r"))==NULL) {       sprintf(msg,"Error loading line bathymetry file: %s\n",fname);       funwaveC_error_message(msg);   }   for (i=0;i<N;i++) {      for (j=0;j<M;j++) {        fscanf(fp,"%lf",&a);        DR2(H,i,j) = a;      }   }   fclose(fp);#ifdef NOSLIP   HEXT0 = 1.5*H[0]-0.5*H[1];   HEXTN = 1.5*H[NX-2]-0.5*H[NX-3];   if ((HEXT0<=0)||(HEXTN<=0))       funwaveC_error_message("Warning extrapolated boundary depths <=0 for no-slip BCs.");#endif}

⌨️ 快捷键说明

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