19 #include <grass/N_solute_transport.h>
28 int col,
int row,
int depth)
30 double Df_e = 0, Df_w = 0, Df_n = 0, Df_s = 0, Df_t = 0, Df_b = 0;
31 double dx, dy, dz, Az;
32 double diff_x, diff_y, diff_z;
33 double diff_xw, diff_yn;
34 double diff_xe, diff_ys;
35 double diff_zt, diff_zb;
36 double cin = 0, cg_start;
38 double C,
W, E,
N, S, T, B, V;
39 double vw = 0, ve = 0, vn = 0, vs = 0, vt = 0, vb = 0;
40 double Ds_w = 0, Ds_e = 0, Ds_n = 0, Ds_s = 0, Ds_t = 0, Ds_b = 0;
41 double Dw = 0, De = 0, Dn = 0, Ds = 0, Dt = 0, Db = 0;
42 double rw = 0.5, re = 0.5, rn = 0.5, rs = 0.5, rt = 0.5, rb = 0.5;
93 Dw = ((Df_w + Ds_w)) / dx;
94 De = ((Df_e + Ds_e)) / dx;
95 Dn = ((Df_n + Ds_n)) / dy;
96 Ds = ((Df_s + Ds_s)) / dy;
97 Dt = ((Df_t + Ds_t)) / dz;
98 Db = ((Df_b + Ds_b)) / dz;
108 W = -1 * (Dw)*dy * dz - vw * (1 - rw) * dy * dz;
110 E = -1 * (De)*dy * dz + ve * (1 - re) * dy * dz;
112 S = -1 * (Ds)*dx * dz - vs * (1 - rs) * dx * dz;
114 N = -1 * (Dn)*dx * dz + vn * (1 - rn) * dx * dz;
116 B = -1 * (Db)*Az - vb * (1 - rb) * Az;
118 T = -1 * (Dt)*Az + vt * (1 - rt) * Az;
132 C = ((Dw - vw) * dy * dz + (De + ve) * dy * dz + (Ds - vs) * dx * dz +
133 (Dn + vn) * dx * dz + (Db - vb) * Az + (Dt + vt) * Az +
134 Az * dz * R / data->
dt - q / nf);
137 V = (cs + cg_start * Az * dz * R / data->
dt - q / nf * cin);
151 G_debug(6,
"N_callback_solute_transport_3d: called [%i][%i][%i]", row, col,
183 double Df_e = 0, Df_w = 0, Df_n = 0, Df_s = 0;
184 double z_e = 0, z_w = 0, z_n = 0, z_s = 0;
186 double diff_x, diff_y;
187 double disp_x, disp_y;
189 double diff_xw, diff_yn;
190 double disp_xw, disp_yn;
192 double diff_xe, diff_ys;
193 double disp_xe, disp_ys;
195 double cin = 0, cg_start;
198 double vw = 0, ve = 0, vn = 0, vs = 0;
199 double Ds_w = 0, Ds_e = 0, Ds_n = 0, Ds_s = 0;
200 double Dw = 0, De = 0, Dn = 0, Ds = 0;
201 double rw = 0.5, re = 0.5, rn = 0.5, rs = 0.5;
292 Dw = ((Df_w + Ds_w)) / dx;
293 De = ((Df_e + Ds_e)) / dx;
294 Ds = ((Df_s + Ds_s)) / dy;
295 Dn = ((Df_n + Ds_n)) / dy;
316 W = -1 * (Dw)*dy * z_w + vw * (1 - rw) * dy * z_w;
318 E = -1 * (De)*dy * z_e + ve * (1 - re) * dy * z_e;
320 S = -1 * (Ds)*dx * z_s + vs * (1 - rs) * dx * z_s;
322 N = -1 * (Dn)*dx * z_n + vn * (1 - rn) * dx * z_n;
341 C = (Dw + vw * rw) * dy * z_w + (De + ve * re) * dy * z_e +
342 (Ds + vs * rs) * dx * z_s + (Dn + vn * rn) * dx * z_n +
343 Az * z * R / data->
dt - q / nf;
346 V = (cs + cg_start * Az * z * R / data->
dt + q / nf * cin);
361 G_debug(6,
"N_callback_solute_transport_2d: called [%i][%i]", row, col);
573 G_debug(2,
"N_calc_solute_transport_transmission_2d: calculating "
574 "transmission boundary");
576 for (j = 0; j < rows; j++) {
577 for (i = 0; i < cols; i++) {
611 c = c / (double)
count;
613 if (c > 0 || c == 0 || c < 0)
642 double disp_xx, disp_yy, disp_xy;
648 G_debug(2,
"N_calc_solute_transport_disptensor_2d: calculating the "
649 "dispersivity tensor");
651 for (j = 0; j < rows; j++) {
652 for (i = 0; i < cols; i++) {
660 vx = (grad.
WC + grad.
EC) / 2;
661 vy = (grad.
NC + grad.
SC) / 2;
662 vv = sqrt(vx * vx + vy * vy);
665 disp_xx = data->
al * vx * vx / vv + data->
at * vy * vy / vv;
666 disp_yy = data->
at * vx * vx / vv + data->
al * vy * vy / vv;
667 disp_xy = (data->
al - data->
at) * vx * vy / vv;
671 "N_calc_solute_transport_disptensor_2d: [%i][%i] disp_xx "
672 "%g disp_yy %g disp_xy %g",
673 i, j, disp_xx, disp_yy, disp_xy);
701 int cols, rows, depths;
702 double vx, vy, vz, vv;
703 double disp_xx, disp_yy, disp_zz, disp_xy, disp_xz, disp_yz;
710 G_debug(2,
"N_calc_solute_transport_disptensor_3d: calculating the "
711 "dispersivity tensor");
713 for (k = 0; k < depths; k++) {
714 for (j = 0; j < rows; j++) {
715 for (i = 0; i < cols; i++) {
725 vx = (grad.
WC + grad.
EC) / 2;
726 vy = (grad.
NC + grad.
SC) / 2;
727 vz = (grad.
BC + grad.
TC) / 2;
728 vv = sqrt(vx * vx + vy * vy + vz * vz);
731 disp_xx = data->
al * vx * vx / vv +
732 data->
at * vy * vy / vv + data->
at * vz * vz / vv;
733 disp_yy = data->
at * vx * vx / vv +
734 data->
al * vy * vy / vv + data->
at * vz * vz / vv;
735 disp_zz = data->
at * vx * vx / vv +
736 data->
at * vy * vy / vv + data->
al * vz * vz / vv;
737 disp_xy = (data->
al - data->
at) * vx * vy / vv;
738 disp_xz = (data->
al - data->
at) * vx * vz / vv;
739 disp_yz = (data->
al - data->
at) * vy * vz / vv;
743 "N_calc_solute_transport_disptensor_3d: [%i][%i][%i] "
744 "disp_xx %g disp_yy %g disp_zz %g disp_xy %g disp_xz "
746 i, j, k, disp_xx, disp_yy, disp_zz, disp_xy, disp_xz,
#define N_CELL_TRANSMISSION
double N_exp_upwinding(double sprod, double distance, double D)
exponential upwinding stabilization algorithm
double N_calc_geom_mean(double a, double b)
Calculate the geometrical mean of values a and b.
double N_full_upwinding(double sprod, double distance, double D)
full upwinding stabilization algorithm
double N_calc_harmonic_mean(double a, double b)
Calculate the harmonical mean of values a and b.
void G_free(void *)
Free allocated memory.
int G_debug(int, const char *,...) __attribute__((format(printf
void N_free_array_3d(N_array_3d *data)
Release the memory of a N_array_3d.
DCELL N_get_array_2d_d_value(N_array_2d *data, int col, int row)
Returns the value of type DCELL at position col, row.
N_array_3d * N_alloc_array_3d(int cols, int rows, int depths, int offset, int type)
Allocate memory for a N_array_3d data structure.
int N_is_array_2d_value_null(N_array_2d *data, int col, int row)
Returns 1 if the value of N_array_2d struct at position col, row is of type null, otherwise 0.
N_array_2d * N_alloc_array_2d(int cols, int rows, int offset, int type)
Allocate memory for a N_array_2d data structure.
void N_free_array_2d(N_array_2d *data)
Release the memory of a N_array_2d structure.
void N_put_array_3d_d_value(N_array_3d *data, int col, int row, int depth, double value)
Writes a double value to the N_array_3d struct at position col, row, depth.
double N_get_array_3d_d_value(N_array_3d *data, int col, int row, int depth)
This function returns the value of type float at position col, row, depth.
void N_put_array_2d_d_value(N_array_2d *data, int col, int row, DCELL value)
Writes a DCELL value to the N_array_2d struct at position col, row.
double N_get_geom_data_area_of_cell(N_geom_data *geom, int row)
Get the areay size in square meter of one cell (x*y) at row.
N_gradient_3d * N_get_gradient_3d(N_gradient_field_3d *field, N_gradient_3d *gradient, int col, int row, int depth)
Return a N_gradient_3d structure calculated from the input gradient field at position [depth][row][co...
N_gradient_field_2d * N_alloc_gradient_field_2d(int cols, int rows)
Allocate a N_gradient_field_2d.
N_gradient_2d * N_get_gradient_2d(N_gradient_field_2d *field, N_gradient_2d *gradient, int col, int row)
Return a N_gradient_2d structure calculated from the input gradient field at position [row][col].
N_gradient_field_3d * N_alloc_gradient_field_3d(int cols, int rows, int depths)
Allocate a N_gradient_field_3d.
N_data_star * N_create_9star(double C, double W, double E, double N, double S, double NW, double SW, double NE, double SE, double V)
allocate and initialize a 9 point star data structure
N_data_star * N_create_7star(double C, double W, double E, double N, double S, double T, double B, double V)
allocate and initialize a 7 point star data structure
N_data_star * N_callback_solute_transport_2d(void *solutedata, N_geom_data *geom, int col, int row)
This callback function creates the mass balance of a 5 point star.
void N_calc_solute_transport_disptensor_2d(N_solute_transport_data2d *data)
Compute the dispersivity tensor based on the solute transport data in 2d.
void N_free_solute_transport_data2d(N_solute_transport_data2d *data)
Release the memory of the solute transport data structure in two dimensions.
N_solute_transport_data3d * N_alloc_solute_transport_data3d(int cols, int rows, int depths)
Allocate memory for the solute transport data structure in three dimensions.
N_solute_transport_data2d * N_alloc_solute_transport_data2d(int cols, int rows)
Allocate memory for the solute transport data structure in two dimensions.
void N_free_solute_transport_data3d(N_solute_transport_data3d *data)
Release the memory of the solute transport data structure in three dimensions.
N_data_star * N_callback_solute_transport_3d(void *solutedata, N_geom_data *geom, int col, int row, int depth)
This is just a placeholder.
void N_calc_solute_transport_transmission_2d(N_solute_transport_data2d *data)
Compute the transmission boundary condition in 2d.
void N_calc_solute_transport_disptensor_3d(N_solute_transport_data3d *data)
Compute the dispersivity tensor based on the solute transport data in 3d.
Matrix entries for a mass balance 5/7/9 star system.
Geometric information about the structured grid.
Gradient between the cells in X and Y direction.
Gradient between the cells in X, Y and Z direction.
N_gradient_field_2d * grad
N_gradient_field_3d * grad