Skip to content

Commit

Permalink
Fix some formatting of comments in SWE.c
Browse files Browse the repository at this point in the history
  • Loading branch information
echoix committed Dec 30, 2023
1 parent ce39449 commit 5102c66
Showing 1 changed file with 63 additions and 41 deletions.
104 changes: 63 additions & 41 deletions src/raster/r.damflood/SWE.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ float velocita_breccia(int i, double h)
{
// double h;
// int i;
// float g=9.81;
// float g = 9.81;
float v;

if (i == 1) {
Expand All @@ -62,7 +62,7 @@ void shallow_water(double **m_h1, double **m_u1, double **m_v1, float **m_z,
int method, int num_cell, int num_break, double t)
{

/*FUNCTION VARIABLES*/
/* FUNCTION VARIABLES */
double h_dx, h_sx, h_up, h_dw, Fup, Fdw, Fdx, Fsx, Gup, Gdw, Gdx, Gsx;
double u_sx, u_dx, v_dx, v_sx, v_up, v_dw, u_up, u_dw;

Expand All @@ -82,23 +82,24 @@ void shallow_water(double **m_h1, double **m_u1, double **m_v1, float **m_z,

// DESCRIPTION OF METHOD
// First cycle: Calculation of new water heights at time t + 1:
// - Downstream of the dam: Apply continuity equation to shallow water
// In practice, the new height is evaluated through a balance
// of the incoming and outgoing flows in the two main directions
// - Upstream of the dam:
// - In methods 1 and 2:
// - The continuity equation is applied to the volume of the lake
// Physically this leads to a less realistic but avoids
// the oscillations that causes numerical instability.
// - In the more general case the equations are applied to the whole lake
// - Downstream of the dam: Apply continuity equation to shallow water.
// In practice, the new height is evaluated through a balance
// of the incoming and outgoing flows in the two main directions
// - Upstream of the dam:
// - In methods 1 and 2:
// - The continuity equation is applied to the volume of the lake.
// Physically this leads to a less realistic but avoids the
// oscillations that causes numerical instability.
// - In the more general case, the equations are applied to the whole
// lake

for (row = 1; row < nrows - 1; row++) {
for (col = 1; col < ncols - 1; col++) {
if (m_lake[row][col] == 0 && m_DAMBREAK[row][col] <= 0) {

//*******************************************/
/* CONTINUITY EQUATION --> h(t+1) */
//*******************************************/
/*******************************************
* CONTINUITY EQUATION --> h(t+1)
*******************************************/
// x direction
// right intercell
if (m_u1[row][col] > 0 && m_u1[row][col + 1] > 0) {
Expand Down Expand Up @@ -168,8 +169,9 @@ void shallow_water(double **m_h1, double **m_u1, double **m_v1, float **m_z,
}
F = Fdx - Fsx;

// dGup =m_v1[row][col] * m_h1[row][col]; y direction
// intercell up
/* dGup = m_v1[row][col] * m_h1[row][col]; */
// y direction
// intercell up
if (m_v1[row][col] > 0 && m_v1[row - 1][col] > 0) {
Gup = m_v1[row][col] * m_h1[row][col];
}
Expand Down Expand Up @@ -242,29 +244,48 @@ void shallow_water(double **m_h1, double **m_u1, double **m_v1, float **m_z,
m_h2[row][col] = m_h1[row][col] - timestep / res_ew * F -
timestep / res_ns * G;

/*if ((row==20||row==21||row==22||row==23)&&(col==18||col==19)){
printf("EQ. CONTINUITY --> row:%d, col:%d\n)",row,
col);
printf("m_h1[row][col]:%f,m_u1[row][col]:%f,m_v1[row][col]:%f",m_h1[row][col],m_u1[row][col],m_v1[row][col]);
printf("m_h1[row][col+1]:%f,m_h1[row][col-1]:%f,m_h1[row+1][col]:%f,
m_h1[row-1][col]:%f\n",m_h1[row][col+1],m_h1[row][col-1],m_h1[row+1][col],
m_h1[row-1][col]); printf("h_dx:%f, h_sx:%f, h_up%f,
h_dw:%f\n",h_dx, h_sx, h_up, h_dw);
printf("m_u1[row][col+1]:%f,m_u1[row][col-1]:%f,m_v1[row+1][col]:%f,
m_v1[row-1][col]:%f\n",m_u1[row][col+1],m_u1[row][col-1],m_v1[row+1][col],
m_v1[row-1][col]); printf("v_up: %f,v_dw:%f,u_dx:%f,u_sx:%f
\n",v_up, v_dw, u_dx, u_sx); printf("Fdx: %f,Fsx: %f, F: %f,
Gup:%f, Gdw:%f, G: %f\n",Fdx, Fsx, F,Gup, Gdw, G);
printf("m_h2(row,col): %f\n \n", m_h2[row][col]);
}*/
/* if ((row == 20 || row == 21 || row == 22 || row == 23) &&
(col == 18 || col == 19)) {
printf("EQ. CONTINUITY --> row:%d, col:%d\n)", row, col);
printf("m_h1[row][col]:%f, "
"m_u1[row][col]:%f, "
"m_v1[row][col]:%f",
m_h1[row][col], m_u1[row][col], m_v1[row][col]);
printf("m_h1[row][col+1]:%f, "
"m_h1[row][col-1]:%f, "
"m_h1[row+1][col]:%f, "
"m_h1[row-1][col]:% f\n",
m_h1[row][col + 1], m_h1[row][col - 1],
m_h1[row + 1][col], m_h1[row - 1][col]);
printf("h_dx:%f, h_sx:%f, h_up%f, h_dw:%f\n", h_dx, h_sx,
h_up, h_dw);
printf("m_u1[row][col+1]:%f, "
"m_u1[row][col-1]:%f, "
"m_v1[row+1][col]:%f, "
"m_v1[row-1][col]:%f\n",
m_u1[row][col + 1], m_u1[row][col - 1],
m_v1[row + 1][col], m_v1[row - 1][col]);
printf("v_up: %f, v_dw:%f, "
"u_dx:%f, u_sx:%f\n",
v_up, v_dw, u_dx, u_sx);
printf("Fdx: %f,Fsx: %f, F: %f, "
"Gup:%f, Gdw:%f, G: %f\n",
Fdx, Fsx, F, Gup, Gdw, G);
printf("m_h2(row,col): %f\n \n", m_h2[row][col]);
} */

/*if( (row==1 || row==(nrows-2) || col==1 || col==(ncols-2)) &&
(m_v2[1][col]>0 || m_v2[nrows-2][col]<0 || m_u1[row][1]<0 ||
m_u1[row][ncols-2]>0 )){ if (warn==0){ G_warning("At the time %.3f the
computational region is smaller than inundation",t); warn=1;
G_message("warn=%d",warn);
}
}*/
/* if (((row == 1 || row == (nrows - 2)) ||
(col == 1 || col == (ncols - 2))) &&
(m_v2[1][col] > 0 || m_v2[nrows - 2][col] < 0 ||
m_u1[row][1] < 0 || m_u1[row][ncols - 2] > 0)) {
if (warn == 0) {
G_warning("At the time %.3f the computational region "
"is smaller than inundation",
t);
warn = 1;
G_message("warn=%d", warn);
}
} */

if (m_h2[row][col] < 0) {
/*G_warning("At the time %f h is lesser than 0
Expand Down Expand Up @@ -301,7 +322,8 @@ void shallow_water(double **m_h1, double **m_u1, double **m_v1, float **m_z,

if (method == 1 || method == 2) {
//*******************************************************************
// Calculation of flow rate Q coming out of the lake only in the case of spillway Hp (hypothesis)
// Calculation of flow rate Q coming out of the lake only in the
// case of spillway Hp (hypothesis)
/* Hypothesis: method 1 or 2 */
if (m_DAMBREAK[row][col] > 0) {
if ((m_z[row][col] + m_h1[row][col]) >
Expand Down Expand Up @@ -670,12 +692,12 @@ void shallow_water(double **m_h1, double **m_u1, double **m_v1, float **m_z,
(m_z[row][col + 1] + m_h2[row][col + 1]))
m_u2[row][col] = velocita_breccia(
method,
m_h2[row][col]); //velocity on the spillway
m_h2[row][col]); // velocity on the spillway
else if ((m_z[row][col] + m_h2[row][col]) >
(m_z[row][col - 1] + m_h2[row][col - 1]))
m_u2[row][col] = -velocita_breccia(
method,
m_h2[row][col]); //velocity on the spillway
m_h2[row][col]); // velocity on the spillway
else
m_u2[row][col] = 0.0;
}
Expand Down

0 comments on commit 5102c66

Please sign in to comment.