/* data preparations, sigma, shear, etc. */ int grad_check(void) { int k, l; double zx, zy, zd2, zd4, sinsl; double cc, cmul2; double sheer; double vsum = 0.; double vmax = 0.; double chsum = 0.; double zmin = 1.e12; double zmax = -1.e12; double zd2min = 1.e12; double zd2max = -1.e12; double smin = 1.e12; double smax = -1.e12; double infmin = 1.e12; double infmax = -1.e12; double sigmax = -1.e12; double cchezmax = -1.e12; double rhow = 1000.; double gacc = 9.81; double hh = 1.; double deltaw = 1.e12; sisum = 0.; infsum = 0.; cmul2 = rhow * gacc; for (k = 0; k < my; k++) { for (l = 0; l < mx; l++) { if (zz[k][l] != UNDEF) { zx = v1[k][l]; zy = v2[k][l]; zd2 = zx * zx + zy * zy; sinsl = sqrt(zd2) / sqrt(zd2 + 1); /* sin(terrain slope) */ /* Computing MIN */ zd2 = sqrt(zd2); zd2min = amin1(zd2min, zd2); /* Computing MAX */ zd2max = amax1(zd2max, zd2); zd4 = sqrt(zd2); /* ^.25 */ if (cchez[k][l] != 0.) { cchez[k][l] = 1. / cchez[k][l]; /* 1/n */ } else { G_fatal_error(_("Zero value in Mannings n")); } if (zd2 == 0.) { v1[k][l] = 0.; v2[k][l] = 0.; slope[k][l] = 0.; } else { if (wdepth) hh = pow(gama[k][l], 2. / 3.); /* hh = 1 if there is no water depth input */ v1[k][l] = (double)hh *cchez[k][l] * zx / zd4; v2[k][l] = (double)hh *cchez[k][l] * zy / zd4; slope[k][l] = sqrt(v1[k][l] * v1[k][l] + v2[k][l] * v2[k][l]); } if (wdepth) { sheer = (double)(cmul2 * gama[k][l] * sinsl); /* shear stress */ /* if critical shear stress >= shear then all zero */ if ((sheer <= tau[k][l]) || (ct[k][l] == 0.)) { si[k][l] = 0.; sigma[k][l] = 0.; } else { si[k][l] = (double)(dc[k][l] * (sheer - tau[k][l])); sigma[k][l] = (double)(dc[k][l] / ct[k][l]) * (sheer - tau[k][l]) / (pow(sheer, 1.5)); /* rill erosion=1.5, sheet = 1.1 */ } } sisum += si[k][l]; smin = amin1(smin, si[k][l]); smax = amax1(smax, si[k][l]); if (inf) { infsum += inf[k][l]; infmin = amin1(infmin, inf[k][l]); infmax = amax1(infmax, inf[k][l]); } vmax = amax1(vmax, slope[k][l]); vsum += slope[k][l]; chsum += cchez[k][l]; zmin = amin1(zmin, (double)zz[k][l]); zmax = amax1(zmax, (double)zz[k][l]); /* not clear were needed */ if (wdepth) sigmax = amax1(sigmax, sigma[k][l]); cchezmax = amax1(cchezmax, cchez[k][l]); /* saved sqrt(sinsl)*cchez to cchez array for output */ cchez[k][l] *= sqrt(sinsl); } /* DEFined area */ } } if (inf != NULL && smax < infmax) G_warning(_("Infiltration exceeds the rainfall rate everywhere! No overland flow.")); cc = (double)mx *my; si0 = sisum / cc; vmean = vsum / cc; chmean = chsum / cc; if (inf) infmean = infsum / cc; if (wdepth) deltaw = 0.8 / (sigmax * vmax); /*time step for sediment */ deltap = 0.25 * sqrt(stepx * stepy) / vmean; /*time step for water */ if (deltaw > deltap) timec = 4.; else timec = 1.25; miter = (int)(timesec / (deltap * timec)); /* number of iterations = number of cells to pass */ iterout = (int)(iterout / (deltap * timec)); /* number of cells to pass for time series output */ fprintf(stderr, "\n"); G_message(_("Min elevation \t= %.2f m\nMax elevation \t= %.2f m\n"), zmin, zmax); G_message(_("Mean Source Rate (rainf. excess or sediment) \t= %f m/s or kg/m2s \n"), si0); G_message(_("Mean flow velocity \t= %f m/s\n"), vmean); G_message(_("Mean Mannings \t= %f\n"), 1.0 / chmean); deltap = amin1(deltap, deltaw); G_message(_("Number of iterations \t= %d cells\n"), miter); G_message(_("Time step \t= %.2f s\n"), deltap); if (wdepth) { G_message(_("Sigmax \t= %f\nMax velocity \t= %f m/s\n"), sigmax, vmax); G_message(_("Time step used \t= %.2f s\n"), deltaw); } /* if (wdepth) deltap = 0.1; * deltap for sediment is ar. average deltap and deltaw */ /* if (wdepth) deltap = (deltaw+deltap)/2.; * deltap for sediment is ar. average deltap and deltaw */ /*! For each cell (k,l) compute the length s=(v1,v2) of the path * that the particle will travel per one time step * \f$ s(k,l)=v(k,l)*dt \f$, [m]=[m/s]*[s] * give warning if there is a cell that will lead to path longer than 2 cells * * if running erosion, compute sediment transport capacity for each cell si(k,l) * \f$ * T({\bf r})=K_t({\bf r}) \bigl[\tau({\bf r})\bigr]^p * =K_t({\bf r}) \bigl[\rho_w\, g h({\bf r}) \sin \beta ({\bf r}) \bigr]^p * \f$ * [kg/ms]=... */ for (k = 0; k < my; k++) { for (l = 0; l < mx; l++) { if (zz[k][l] != UNDEF) { v1[k][l] *= deltap; v2[k][l] *= deltap; /*if(v1[k][l]*v1[k][l]+v2[k][l]*v2[k][l] > cellsize, warning, napocitaj *ak viac ako 10%a*/ /* THIS IS CORRECT SOLUTION currently commented out */ if (inf) inf[k][l] *= timesec; if (wdepth) gama[k][l] = 0.; if (et) { if (sigma[k][l] == 0. || slope[k][l] == 0.) si[k][l] = 0.; else /* temp for transp. cap. erod */ si[k][l] = si[k][l] / (slope[k][l] * sigma[k][l]); } } /* DEFined area */ } } /*! compute transport capacity limted erosion/deposition et * as a divergence of sediment transport capacity * \f$ D_T({\bf r})= \nabla\cdot {\bf T}({\bf r}) * \f$ */ if (et) { erod(si); /* compute divergence of t.capc */ if (output_et() != 1) G_fatal_error(_("Unable to write et file")); } /*! compute the inversion operator and store it in sigma - note that after this * sigma does not store the first order reaction coefficient but the operator * WRITE the equation here */ if (wdepth) { for (k = 0; k < my; k++) { for (l = 0; l < mx; l++) { if (zz[k][l] != UNDEF) { /* get back from temp */ if (et) si[k][l] = si[k][l] * slope[k][l] * sigma[k][l]; if (sigma[k][l] != 0.) /* rate of weight loss - w=w*sigma , * vaha prechadzky po n-krokoch je sigma^n */ /*!!!!! not clear what's here :-\ !!!!!*/ sigma[k][l] = exp(-sigma[k][l] * deltap * slope[k][l]); /* if(sigma[k][l]<0.5) warning, napocitaj, * ak vacsie ako 50% skonci, zmensi deltap)*/ } } /*DEFined area */ } } return 1; }
int main(int argc, char *argv[]) { int ii; int ret_val; double x_orig, y_orig; static int rand1 = 12345; static int rand2 = 67891; G_gisinit(argv[0]); module = G_define_module(); G_add_keyword(_("raster")); G_add_keyword(_("hydrology")); G_add_keyword(_("sediment flow")); G_add_keyword(_("erosion")); G_add_keyword(_("deposition")); module->description = _("Sediment transport and erosion/deposition simulation " "using path sampling method (SIMWE)."); parm.elevin = G_define_standard_option(G_OPT_R_ELEV); parm.wdepth = G_define_standard_option(G_OPT_R_INPUT); parm.wdepth->key = "wdepth"; parm.wdepth->description = _("Name of water depth raster map [m]"); parm.dxin = G_define_standard_option(G_OPT_R_INPUT); parm.dxin->key = "dx"; parm.dxin->description = _("Name of x-derivatives raster map [m/m]"); parm.dyin = G_define_standard_option(G_OPT_R_INPUT); parm.dyin->key = "dy"; parm.dyin->description = _("Name of y-derivatives raster map [m/m]"); parm.detin = G_define_standard_option(G_OPT_R_INPUT); parm.detin->key = "det"; parm.detin->description = _("Name of detachment capacity coefficient raster map [s/m]"); parm.tranin = G_define_standard_option(G_OPT_R_INPUT); parm.tranin->key = "tran"; parm.tranin->description = _("Name of transport capacity coefficient raster map [s]"); parm.tauin = G_define_standard_option(G_OPT_R_INPUT); parm.tauin->key = "tau"; parm.tauin->description = _("Name of critical shear stress raster map [Pa]"); parm.manin = G_define_standard_option(G_OPT_R_INPUT); parm.manin->key = "man"; parm.manin->required = NO; parm.manin->description = _("Name of Manning's n raster map"); parm.manin->guisection = _("Input"); parm.maninval = G_define_option(); parm.maninval->key = "man_value"; parm.maninval->type = TYPE_DOUBLE; parm.maninval->answer = MANINVAL; parm.maninval->required = NO; parm.maninval->description = _("Manning's n unique value"); parm.maninval->guisection = _("Input"); parm.outwalk = G_define_standard_option(G_OPT_V_OUTPUT); parm.outwalk->key = "outwalk"; parm.outwalk->required = NO; parm.outwalk->description = _("Base name of the output walkers vector points map"); parm.outwalk->guisection = _("Output options"); parm.observation = G_define_standard_option(G_OPT_V_INPUT); parm.observation->key = "observation"; parm.observation->required = NO; parm.observation->description = _("Name of sampling locations vector points map"); parm.observation->guisection = _("Input options"); parm.logfile = G_define_standard_option(G_OPT_F_OUTPUT); parm.logfile->key = "logfile"; parm.logfile->required = NO; parm.logfile->description = _("Name for sampling points output text file. For each observation vector point the time series of sediment transport is stored."); parm.logfile->guisection = _("Output"); parm.tc = G_define_standard_option(G_OPT_R_OUTPUT); parm.tc->key = "tc"; parm.tc->required = NO; parm.tc->description = _("Name for output transport capacity raster map [kg/ms]"); parm.tc->guisection = _("Output"); parm.et = G_define_standard_option(G_OPT_R_OUTPUT); parm.et->key = "et"; parm.et->required = NO; parm.et->description = _("Name for output transport limited erosion-deposition raster map [kg/m2s]"); parm.et->guisection = _("Output"); parm.conc = G_define_standard_option(G_OPT_R_OUTPUT); parm.conc->key = "conc"; parm.conc->required = NO; parm.conc->description = _("Name for output sediment concentration raster map [particle/m3]"); parm.conc->guisection = _("Output"); parm.flux = G_define_standard_option(G_OPT_R_OUTPUT); parm.flux->key = "flux"; parm.flux->required = NO; parm.flux->description = _("Name for output sediment flux raster map [kg/ms]"); parm.flux->guisection = _("Output"); parm.erdep = G_define_standard_option(G_OPT_R_OUTPUT); parm.erdep->key = "erdep"; parm.erdep->required = NO; parm.erdep->description = _("Name for output erosion-deposition raster map [kg/m2s]"); parm.erdep->guisection = _("Output"); parm.nwalk = G_define_option(); parm.nwalk->key = "nwalk"; parm.nwalk->type = TYPE_INTEGER; parm.nwalk->required = NO; parm.nwalk->description = _("Number of walkers"); parm.nwalk->guisection = _("Parameters"); parm.niter = G_define_option(); parm.niter->key = "niter"; parm.niter->type = TYPE_INTEGER; parm.niter->answer = NITER; parm.niter->required = NO; parm.niter->description = _("Time used for iterations [minutes]"); parm.niter->guisection = _("Parameters"); parm.outiter = G_define_option(); parm.outiter->key = "outiter"; parm.outiter->type = TYPE_INTEGER; parm.outiter->answer = ITEROUT; parm.outiter->required = NO; parm.outiter->description = _("Time interval for creating output maps [minutes]"); parm.outiter->guisection = _("Parameters"); /* parm.density = G_define_option(); parm.density->key = "density"; parm.density->type = TYPE_INTEGER; parm.density->answer = DENSITY; parm.density->required = NO; parm.density->description = _("Density of output walkers"); parm.density->guisection = _("Parameters"); */ parm.diffc = G_define_option(); parm.diffc->key = "diffc"; parm.diffc->type = TYPE_DOUBLE; parm.diffc->answer = DIFFC; parm.diffc->required = NO; parm.diffc->description = _("Water diffusion constant"); parm.diffc->guisection = _("Parameters"); if (G_parser(argc, argv)) exit(EXIT_FAILURE); G_get_set_window(&cellhd); conv = G_database_units_to_meters_factor(); mixx = cellhd.west * conv; maxx = cellhd.east * conv; miyy = cellhd.south * conv; mayy = cellhd.north * conv; stepx = cellhd.ew_res * conv; stepy = cellhd.ns_res * conv; /* step = amin1(stepx,stepy); */ step = (stepx + stepy) / 2.; mx = cellhd.cols; my = cellhd.rows; x_orig = cellhd.west * conv; y_orig = cellhd.south * conv; /* do we need this? */ xmin = 0.; ymin = 0.; xp0 = xmin + stepx / 2.; yp0 = ymin + stepy / 2.; xmax = xmin + stepx * (float)mx; ymax = ymin + stepy * (float)my; hhc = hhmax = 0.; #if 0 bxmi = 2093113. * conv; bymi = 731331. * conv; bxma = 2093461. * conv; byma = 731529. * conv; bresx = 2. * conv; bresy = 2. * conv; maxwab = 100000; mx2o = (int)((bxma - bxmi) / bresx); my2o = (int)((byma - bymi) / bresy); /* relative small box coordinates: leave 1 grid layer for overlap */ bxmi = bxmi - mixx + stepx; bymi = bymi - miyy + stepy; bxma = bxma - mixx - stepx; byma = byma - miyy - stepy; mx2 = mx2o - 2 * ((int)(stepx / bresx)); my2 = my2o - 2 * ((int)(stepy / bresy)); #endif elevin = parm.elevin->answer; wdepth = parm.wdepth->answer; dxin = parm.dxin->answer; dyin = parm.dyin->answer; detin = parm.detin->answer; tranin = parm.tranin->answer; tauin = parm.tauin->answer; manin = parm.manin->answer; tc = parm.tc->answer; et = parm.et->answer; conc = parm.conc->answer; flux = parm.flux->answer; erdep = parm.erdep->answer; outwalk = parm.outwalk->answer; /* sscanf(parm.nwalk->answer, "%d", &maxwa); */ sscanf(parm.niter->answer, "%d", ×ec); sscanf(parm.outiter->answer, "%d", &iterout); /* sscanf(parm.density->answer, "%d", &ldemo); */ sscanf(parm.diffc->answer, "%lf", &frac); sscanf(parm.maninval->answer, "%lf", &manin_val); /* Recompute timesec from user input in minutes * to real timesec in seconds */ timesec = timesec * 60.0; iterout = iterout * 60.0; if ((timesec / iterout) > 100.0) G_message(_("More than 100 files are going to be created !!!!!")); /* compute how big the raster is and set this to appr 2 walkers per cell */ if (parm.nwalk->answer == NULL) { maxwa = mx * my * 2; rwalk = (double)(mx * my * 2.); G_message(_("default nwalk=%d, rwalk=%f"), maxwa, rwalk); } else { sscanf(parm.nwalk->answer, "%d", &maxwa); rwalk = (double)maxwa; } /*rwalk = (double) maxwa; */ if (conv != 1.0) G_message(_("Using metric conversion factor %f, step=%f"), conv, step); if ((tc == NULL) && (et == NULL) && (conc == NULL) && (flux == NULL) && (erdep == NULL)) G_warning(_("You are not outputting any raster or site files")); ret_val = input_data(); if (ret_val != 1) G_fatal_error(_("Input failed")); /* mandatory for si,sigma */ si = G_alloc_matrix(my, mx); sigma = G_alloc_matrix(my, mx); /* memory allocation for output grids */ dif = G_alloc_fmatrix(my, mx); if (erdep != NULL || et != NULL) er = G_alloc_fmatrix(my, mx); seeds(rand1, rand2); grad_check(); if (et != NULL) erod(si); /* treba dat output pre topoerdep */ main_loop(); if (tserie == NULL) { ii = output_data(0, 1.); if (ii != 1) G_fatal_error(_("Cannot write raster maps")); } /* Exit with Success */ exit(EXIT_SUCCESS); }
void init_grids_sediment() { /* this should be fulfilled for sediment but not water */ if (et != NULL) erod(si); }