19 #include <grass/N_pde.h>
40 "N_calc_gradient_field_2d_stats: compute gradient field stats");
55 field->
sum = sumx + sumy;
56 field->
nonull = nonullx + nonully;
119 double dx, dy, p1, p2, r1, r2, mean, grad, res;
126 (
"N_compute_gradient_field_2d: the arrays are not of equal size");
130 (
"N_compute_gradient_field_2d: the arrays are not of equal size");
134 (
"N_compute_gradient_field_2d: array sizes and geometry data are different");
137 G_debug(3,
"N_compute_gradient_field_2d: compute gradient field");
150 (
"N_compute_gradient_field_2d: gradient field sizes and geometry data are different");
154 for (j = 0; j < rows; j++)
155 for (i = 0; i < cols - 1; i++) {
164 grad = (p1 - p2) / dx;
179 for (j = 0; j < rows - 1; j++)
180 for (i = 0; i <
cols; i++) {
189 grad = (p1 - p2) / dy;
198 res = -1 * mean * grad;
267 G_fatal_error(
"N_compute_gradient_components_2d: x array is empty");
269 G_fatal_error(
"N_compute_gradient_components_2d: y array is empty");
275 if (x->
cols != cols || x->
rows != rows)
277 (
"N_compute_gradient_components_2d: the size of the x array doesn't fit the gradient field size");
278 if (y->
cols != cols || y->
rows != rows)
280 (
"N_compute_gradient_components_2d: the size of the y array doesn't fit the gradient field size");
282 for (j = 0; j < rows; j++)
283 for (i = 0; i <
cols; i++) {
287 if (grad.
WC == 0.0 || grad.
EC == 0.0)
288 vx = (grad.
WC + grad.
EC);
290 vx = (grad.
WC + grad.
EC) / 2;
291 if (grad.
NC == 0.0 || grad.
SC == 0.0)
292 vy = (grad.
NC + grad.
SC);
294 vy = (grad.
NC + grad.
SC) / 2;
313 double minx, miny, minz;
315 double maxx, maxy, maxz;
317 double sumx, sumy, sumz;
319 int nonullx, nonully, nonullz;
322 "N_calc_gradient_field_3d_stats: compute gradient field stats");
328 if (minx <= minz && minx <= miny)
330 if (miny <= minz && miny <= minx)
332 if (minz <= minx && minz <= miny)
335 if (maxx >= maxz && maxx >= maxy)
337 if (maxy >= maxz && maxy >= maxx)
339 if (maxz >= maxx && maxz >= maxy)
342 field->
sum = sumx + sumy + sumz;
343 field->
nonull = nonullx + nonully + nonullz;
410 int cols, rows, depths;
412 double dx, dy, dz, p1, p2, r1, r2, mean, grad, res;
420 (
"N_compute_gradient_field_3d: the arrays are not of equal size");
425 (
"N_compute_gradient_field_3d: the arrays are not of equal size");
430 (
"N_compute_gradient_field_3d: the arrays are not of equal size");
435 (
"N_compute_gradient_field_3d: array sizes and geometry data are different");
437 G_debug(3,
"N_compute_gradient_field_3d: compute gradient field");
446 if (gradfield ==
NULL) {
453 (
"N_compute_gradient_field_3d: gradient field sizes and geometry data are different");
456 for (k = 0; k < depths; k++)
457 for (j = 0; j < rows; j++)
458 for (i = 0; i < cols - 1; i++) {
467 grad = (p1 - p2) / dx;
479 "N_compute_gradient_field_3d: X-direction insert value %6.5g at %i %i %i ",
486 for (k = 0; k < depths; k++)
487 for (j = 0; j < rows - 1; j++)
488 for (i = 0; i <
cols; i++) {
497 grad = (p1 - p2) / dy;
506 res = -1 * mean * grad;
510 "N_compute_gradient_field_3d: Y-direction insert value %6.5g at %i %i %i ",
517 for (k = 0; k < depths - 1; k++)
518 for (j = 0; j < rows; j++)
519 for (i = 0; i <
cols; i++) {
528 grad = (p1 - p2) / dz;
540 "N_compute_gradient_field_3d: Z-direction insert value %6.5g at %i %i %i ",
603 int rows,
cols, depths;
617 G_fatal_error(
"N_compute_gradient_components_3d: x array is empty");
619 G_fatal_error(
"N_compute_gradient_components_3d: y array is empty");
621 G_fatal_error(
"N_compute_gradient_components_3d: z array is empty");
630 (
"N_compute_gradient_components_3d: the size of the x array doesn't fit the gradient field size");
633 (
"N_compute_gradient_components_3d: the size of the y array doesn't fit the gradient field size");
636 (
"N_compute_gradient_components_3d: the size of the z array doesn't fit the gradient field size");
638 for (k = 0; k < depths; k++)
639 for (j = 0; j < rows; j++)
640 for (i = 0; i <
cols; i++) {
643 if (grad.
WC == 0.0 || grad.
EC == 0.0)
644 vx = (grad.
WC + grad.
EC);
646 vx = (grad.
WC + grad.
EC) / 2;
647 if (grad.
NC == 0.0 || grad.
SC == 0.0)
648 vy = (grad.
NC + grad.
SC);
650 vy = (grad.
NC + grad.
SC) / 2;
651 if (grad.
TC == 0.0 || grad.
BC == 0.0)
652 vz = (grad.
TC + grad.
BC);
654 vz = (grad.
TC + grad.
BC) / 2;
int N_is_array_3d_value_null(N_array_3d *data, int col, int row, int depth)
This function returns 1 if value of N_array_3d data at position col, row, depth is of type null...
N_gradient_field_3d * N_compute_gradient_field_3d(N_array_3d *pot, N_array_3d *weight_x, N_array_3d *weight_y, N_array_3d *weight_z, N_geom_data *geom, N_gradient_field_3d *gradfield)
This function computes the gradient based on the input N_array_3d pot (that means potential)...
void N_compute_gradient_field_components_2d(N_gradient_field_2d *field, N_array_2d *x_comp, N_array_2d *y_comp)
Calculate the x and y vector components from a gradient field for each cell and stores them in the pr...
Gradient between the cells in X and Y direction.
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.
N_gradient_field_2d * N_compute_gradient_field_2d(N_array_2d *pot, N_array_2d *weight_x, N_array_2d *weight_y, N_geom_data *geom, N_gradient_field_2d *gradfield)
This function computes the gradient based on the input N_array_2d pot (potential), a weighting factor N_array_2d named weight and the distance between two cells saved in the N_geom_data struct.
void N_calc_gradient_field_3d_stats(N_gradient_field_3d *field)
Calculate basic statistics of a gradient field.
void N_calc_array_2d_stats(N_array_2d *a, double *min, double *max, double *sum, int *nonull, int withoffset)
Calculate basic statistics of the N_array_2d struct.
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...
Geometric information about the structured grid.
N_gradient_field_2d * N_alloc_gradient_field_2d(int cols, int rows)
Allocate a N_gradient_field_2d.
void N_compute_gradient_field_components_3d(N_gradient_field_3d *field, N_array_3d *x_comp, N_array_3d *y_comp, N_array_3d *z_comp)
Calculate the x, y and z vector components from a gradient field for each cell and store them in the ...
Gradient between the cells in X, Y and Z direction.
void N_calc_array_3d_stats(N_array_3d *a, double *min, double *max, double *sum, int *nonull, int withoffset)
Calculate basic statistics of the N_array_3d struct.
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 postion col, row is of type null, otherwise 0...
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.
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]...
int G_debug(int level, const char *msg,...)
Print debugging message.
N_gradient_field_3d * N_alloc_gradient_field_3d(int cols, int rows, int depths)
Allocate a N_gradient_field_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.
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_calc_harmonic_mean(double a, double b)
Calculate the harmonical mean of values a and b.
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
void N_calc_gradient_field_2d_stats(N_gradient_field_2d *field)
Calculate basic statistics of a gradient field.