sandbox/b-flood/rain.h
Rain term in saint venant
Rain source term
The rain is simply added to the mass equation of Saint-Venant
// Intensity of the rainfall
scalar rain[];
double maxrain;
event updaterain( i++ ){
foreach(){
[] += dt*rain[];
h}
boundary({h});
}
Read_Lameeau function
This function reads the “lame d’eau” given by Meteo-france. THe arguments of the routine are :
name : the name of the .asc files
start : the starting hour. format hhmm or hh
end : the ending hour : format hhmm or hh
step : the step between two files in minutes
t : the time
mult : a multiplicator of the readen file
linear : (true/false) activating the bilinear interpolation between two points
timelin : (true/flase) activating the linear interpolation between two times
#if TREE //input.h does not work without quadtree, so does read_lameau
#include "input.h"
static void coarsen_maxrain (Point point, scalar s){
[] = max(max(fine(s,0,0),fine(s,1,0)),max(fine(s,0,1),fine(s,1,1)));
s}
event defaults( i = 0 ){
.refine = rain.prolongation = refine_injection;
rain.coarsen = coarsen_maxrain;
rain}
struct InputRain {
char * name;
int start;
int end;
int step;
double t;
double mult;
bool linear;
bool timelin;
};
scalar rain1[], rain2[];
void read_lameeau(struct InputRain p){
// Default value
int time;
if( p.t == 0 )
= (int)t;
time
else= (int)p.t;
time if( p.mult == 0 )
.mult = 1;
pif( p.step == 0 )
.step = 5*60;
p
int hstart = 0 , mstart = 0;
if ( p.start <= 24 ){ // just hour
= p.start;
hstart }
else if ( p.start < 2400 && p.start > 100 ) {
= p.start/100;
hstart = p.start%100;
mstart }
else
fprintf(stderr,"#warning : wrong hour format in read_lameeau routine\n#use hhmm format or hh format only\n");
= time + hstart*3600 + mstart*60 + 5 ;
time int timea = time + hstart*3600 + mstart*60 + 5;
int sec = time%60;
= (time - sec)/60;
time int min = time%60 ;
= (time - min)/60;
time int hour = time%24 ;
if( min%5 != 0 )
= min - min%5;
min
char str[100], str1[100];
(str,p.name);
strcpyif(hour < 10) //add 0 to the right place
(str,"0");
strcatsprintf(str1, "%d", hour);
(str,str1);
strcatif(min < 10) // again
(str,"0");
strcatsprintf(str1, "%d", min); // here we read the next lameeau
(str,str1);
strcat(str,".asc");
strcat
// Reading files
FILE * fpo = fopen(str,"r");
if (fpo == NULL)
fprintf(stderr,"# skiping file that does not exist : %s\n",str);
else{
input_grd(rain1, fp = fpo, linear = p.linear );
foreach()
[] *= p.mult*1e-3/(5*60);
rain1if( p.timelin ) {
(str,p.name);
strcpyif( min + 5 >= 60 )
-= 60, hour++;
min if(hour < 10) //add 0 to the right place
(str,"0");
strcat
sprintf(str1, "%d", hour);
(str,str1);
strcatif(min + 5 < 10) // again
(str,"0");
strcatsprintf(str1, "%d", min + 5);
(str,str1);
strcat(str,".asc");
strcat
= fopen(str,"r");
fpo if (fpo == NULL)
fprintf(stderr,"# skiping file that does not exist : %s\n",str);
else{
input_grd(rain2, fp = fpo, linear = p.linear );
foreach()
[] *= p.mult*1e-3/(5*60);
rain2}
}
}
if( p.timelin ) {
int tt = timea%(5*60);
foreach()
[] = rain1[] + tt*(rain2[]-rain1[])/(5*60); // Linear interpolation in time
rain}
else{
foreach()
[] =rain1[];
rain}
}
#endif