GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-d6dec75dd4
n_gradient_calc.c File Reference
#include <grass/N_pde.h>
Include dependency graph for n_gradient_calc.c:

Go to the source code of this file.

Functions

void N_calc_gradient_field_2d_stats (N_gradient_field_2d *field)
 Calculate basic statistics of a gradient field. More...
 
N_gradient_field_2dN_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. More...
 
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 provided N_array_2d structures. More...
 
void N_calc_gradient_field_3d_stats (N_gradient_field_3d *field)
 Calculate basic statistics of a gradient field. More...
 
N_gradient_field_3dN_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), a weighting factor N_array_3d named weight and the distance between two cells saved in the N_geom_data struct. More...
 
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 provided N_array_3d structures. More...
 

Function Documentation

◆ N_calc_gradient_field_2d_stats()

void N_calc_gradient_field_2d_stats ( N_gradient_field_2d field)

Calculate basic statistics of a gradient field.

The statistic is stored in the gradient field struct

Parameters
fieldN_gradient_2d_field *
Returns
void

Definition at line 28 of file n_gradient_calc.c.

References G_debug(), N_gradient_field_2d::max, N_gradient_field_2d::mean, N_gradient_field_2d::min, N_calc_array_2d_stats(), N_gradient_field_2d::nonull, N_gradient_field_2d::sum, N_gradient_field_2d::x_array, and N_gradient_field_2d::y_array.

Referenced by N_compute_gradient_field_2d().

◆ N_calc_gradient_field_3d_stats()

void N_calc_gradient_field_3d_stats ( N_gradient_field_3d field)

Calculate basic statistics of a gradient field.

The statistic is stored in the gradient field struct

Parameters
fieldN_gradient_3d_field *
Returns
void

Definition at line 303 of file n_gradient_calc.c.

References G_debug(), N_gradient_field_3d::max, N_gradient_field_3d::mean, N_gradient_field_3d::min, N_calc_array_3d_stats(), N_gradient_field_3d::nonull, N_gradient_field_3d::sum, N_gradient_field_3d::x_array, N_gradient_field_3d::y_array, and N_gradient_field_3d::z_array.

Referenced by N_compute_gradient_field_3d().

◆ N_compute_gradient_field_2d()

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.

The gradient is calculated between cells for each cell and direction. An existing gradient field can be filled with new data or, if a NULL pointer is given, a new gradient field will be allocated with the appropriate size.

______________
|    |    |    |
|    |    |    |
|----|-NC-|----|
|    |    |    |
|   WC    EC   |
|    |    |    |
|----|-SC-|----|
|    |    |    |
|____|____|____|


x - direction:

r = 2 * weight[row][col]*weight[row][col + 1] /
(weight[row][col]*weight[row][col + 1]) EC = r * (pot[row][col] - pot[row][col
+ 1])/dx

y - direction:

r = 2 * weight[row][col]*weight[row + 1][col] / (weight[row][col]*weight[row +
1][col]) SC = r * (pot[row][col] - pot[row + 1][col])/dy

the values SC and EC are the values of the next row/col
Parameters
potN_array_2d * - the potential N_array_2d
weight_xN_array_2d * - the weighting factor N_array_2d used to modify the gradient in x-direction
weight_yN_array_2d * - the weighting factor N_array_2d used to modify the gradient in y-direction
geomN_geom_data * - geometry data structure
gradfieldN_gradient_field_2d * - a gradient field of the correct size, if a NULL pointer is provided this gradient field will be new allocated
Returns
N_gradient_field_2d * - the pointer to the computed gradient field

Definition at line 109 of file n_gradient_calc.c.

References N_geom_data::cols, N_array_2d::cols, N_gradient_field_2d::cols, N_geom_data::dx, N_geom_data::dy, G_debug(), G_fatal_error(), mean(), N_alloc_gradient_field_2d(), N_calc_gradient_field_2d_stats(), N_calc_harmonic_mean(), N_get_array_2d_d_value(), N_is_array_2d_value_null(), N_put_array_2d_d_value(), NULL, N_geom_data::rows, N_array_2d::rows, N_gradient_field_2d::rows, N_gradient_field_2d::x_array, and N_gradient_field_2d::y_array.

◆ N_compute_gradient_field_3d()

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), a weighting factor N_array_3d named weight and the distance between two cells saved in the N_geom_data struct.

The gradient is calculated between cells for each cell and direction. An existing gradient field can be filled with new data or, if a NULL pointer is given, a new gradient field will be allocated with the appropriate size.

|  /
TC NC
|/
--WC-----EC--
/|
SC BC
/  |

x - direction:

r = 2 * weight_x[depth][row][col]*weight_x[depth][row][col + 1] /
(weight_X[depth][row][col]*weight_x[depth][row][col + 1]) EC = r *
(pot[depth][row][col] - pot[depth][row][col + 1])/dx

y - direction:

r = 2 * weight_y[depth][row][col]*weight_y[depth][row + 1][col] /
(weight_y[depth][row][col]*weight_y[depth][row + 1][col]) SC = r *
(pot[depth][row][col] - pot[depth][row + 1][col])/dy

z - direction:

r = 2 * weight_z[depth][row][col]*weight_z[depth + 1][row][col] /
(weight_z[depth][row][col]*weight_z[depth + 1][row][col]) TC = r *
(pot[depth][row][col] - pot[depth + 1][row][col])/dy

the values BC, NC, WC are the values of the next depth/row/col
Parameters
potN_array_3d * - the potential N_array_2d
weight_xN_array_3d * - the weighting factor N_array_3d used to modify the gradient in x-direction
weight_yN_array_3d * - the weighting factor N_array_3d used to modify the gradient in y-direction
weight_zN_array_3d * - the weighting factor N_array_3d used to modify the gradient in z-direction
geomN_geom_data * - geometry data structure
gradfieldN_gradient_field_3d * - a gradient field of the correct size, if a NULL pointer is provided this gradient field will be new allocated
Returns
N_gradient_field_3d * - the pointer to the computed gradient field

Definition at line 400 of file n_gradient_calc.c.

References N_geom_data::cols, N_array_3d::cols, N_gradient_field_3d::cols, N_geom_data::depths, N_array_3d::depths, N_gradient_field_3d::depths, N_geom_data::dx, N_geom_data::dy, N_geom_data::dz, G_debug(), G_fatal_error(), mean(), N_alloc_gradient_field_3d(), N_calc_gradient_field_3d_stats(), N_calc_harmonic_mean(), N_get_array_3d_d_value(), N_is_array_3d_value_null(), N_put_array_3d_d_value(), NULL, N_geom_data::rows, N_array_3d::rows, N_gradient_field_3d::rows, N_gradient_field_3d::x_array, N_gradient_field_3d::y_array, and N_gradient_field_3d::z_array.

◆ N_compute_gradient_field_components_2d()

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 provided N_array_2d structures.

The arrays must have the same size as the gradient field.

Based on this storages scheme the gradient vector for each cell is
calculated and stored in the provided  N_array_2d structures

______________
|    |    |    |
|    |    |    |
|----|-NC-|----|
|    |    |    |
|   WC    EC   |
|    |    |    |
|----|-SC-|----|
|    |    |    |
|____|____|____|

x vector component:

x = (WC + EC) / 2

y vector component:

y = (NC + SC) / 2
Parameters
fieldN_gradient_field_2d *
x_compN_array_2d * - the array in which the x component will be written
y_compN_array_2d * - the array in which the y component will be written
Returns
void

Definition at line 242 of file n_gradient_calc.c.

References N_array_2d::cols, N_gradient_2d::EC, G_fatal_error(), N_get_gradient_2d(), N_put_array_2d_d_value(), N_gradient_2d::NC, N_array_2d::rows, N_gradient_2d::SC, N_gradient_2d::WC, x, and N_gradient_field_2d::x_array.

◆ N_compute_gradient_field_components_3d()

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 provided N_array_3d structures.

The arrays must have the same size as the gradient field.

Based on this storages scheme the gradient vector for each cell is
calculated and stored in the provided  N_array_3d structures


|  /
TC NC
|/
--WC-----EC--
/|
SC BC
/  |


x vector component:

x = (WC + EC) / 2

y vector component:

y = (NC + SC) / 2

z vector component:

z = (TC + BC) / 2
Parameters
fieldN_gradient_field_3d *
x_compN_array_3d * - the array in which the x component will be written
y_compN_array_3d * - the array in which the y component will be written
z_compN_array_3d * - the array in which the z component will be written
Returns
void

Definition at line 595 of file n_gradient_calc.c.

References N_gradient_3d::BC, N_array_3d::cols, N_array_3d::depths, N_gradient_3d::EC, G_fatal_error(), N_get_gradient_3d(), N_put_array_3d_d_value(), N_gradient_3d::NC, N_array_3d::rows, N_gradient_3d::SC, N_gradient_3d::TC, N_gradient_3d::WC, x, and N_gradient_field_3d::x_array.