19#include <grass/N_pde.h>
137 G_debug(5,
"N_create_5star: w %g e %g n %g s %g c %g v %g\n", star->
W,
138 star->
E, star->
N, star->
S, star->
C, star->
V);
160 double T,
double B,
double V)
175 G_debug(5,
"N_create_7star: w %g e %g n %g s %g t %g b %g c %g v %g\n",
176 star->
W, star->
E, star->
N, star->
S, star->
T, star->
B, star->
C,
201 double NW,
double SW,
double NE,
double SE,
220 "N_create_9star: w %g e %g n %g s %g nw %g sw %g ne %g se %g c %g "
222 star->
W, star->
E, star->
N, star->
S, star->
NW, star->
SW, star->
NE,
223 star->
SE, star->
C, star->
V);
265 double NW,
double SW,
double NE,
double SE,
266 double T,
double W_T,
double E_T,
double N_T,
267 double S_T,
double NW_T,
double SW_T,
double NE_T,
268 double SE_T,
double B,
double W_B,
double E_B,
269 double N_B,
double S_B,
double NW_B,
double SW_B,
270 double NE_B,
double SE_B,
double V)
310 "N_create_27star: w %g e %g n %g s %g nw %g sw %g ne %g se %g c "
312 star->
W, star->
E, star->
N, star->
S, star->
NW, star->
SW, star->
NE,
313 star->
SE, star->
C, star->
V);
316 "N_create_27star: w_t %g e_t %g n_t %g s_t %g nw_t %g sw_t %g "
317 "ne_t %g se_t %g t %g \n",
322 "N_create_27star: w_b %g e_b %g n_b %g s_b %g nw_b %g sw_b %g "
323 "ne_b %g se_B %g b %g\n",
433 star->
E = 1 /
geom->dx;
434 star->
W = 1 /
geom->dx;
435 star->
N = 1 /
geom->dy;
436 star->
S = 1 /
geom->dy;
437 star->
T = 1 /
geom->dz;
438 star->
B = 1 /
geom->dz;
443 5,
"N_callback_template_3d: w %g e %g n %g s %g t %g b %g c %g v %g\n",
444 star->
W, star->
E, star->
N, star->
S, star->
T, star->
B, star->
C, star->
V);
470 star->
E = 1 /
geom->dx;
473 star->
W = 1 /
geom->dx;
476 star->
N = 1 /
geom->dy;
477 star->
S = 1 /
geom->dy;
478 star->
C = -1 * (star->
E + star->
NE + star->
SE + star->
W + star->
NW +
479 star->
SW + star->
N + star->
S);
568 int i,
j,
count = 0, pos = 0;
576 "N_assemble_les_2d: starting to assemble the linear equation system");
587 for (
j = 0;
j <
geom->rows;
j++) {
588 for (i = 0; i <
geom->cols; i++) {
598 for (
j = 0;
j <
geom->rows;
j++) {
599 for (i = 0; i <
geom->cols; i++) {
610 G_fatal_error(
"Not enough cells [%i] to create the linear equation "
611 "system. Check the cell status. Only active cells (value "
612 "= 1) are used to create the equation system.",
628 for (
j = 0;
j <
geom->rows;
j++) {
629 for (i = 0; i <
geom->cols; i++) {
639 "N_assemble_les_2d: non-inactive cells count %i at "
651 "N_assemble_les_2d: active cells count %i at pos x[%i] "
658 G_debug(2,
"N_assemble_les_2d: starting the parallel assemble loop");
661#pragma omp parallel for private(i, j, pos, count) schedule(static)
688 spvect->values[pos] = items->
C;
720 if (i > 0 &&
j > 0) {
802 G_debug(2,
"N_les_integrate_dirichlet_2d: integrating the dirichlet "
803 "boundary condition");
814 for (y = 0; y < rows; y++) {
815 for (
x = 0;
x < cols;
x++) {
828#pragma omp parallel default(shared)
835#pragma omp for schedule(static) private(i)
836 for (i = 0; i <
les->cols; i++)
843 for (y = 0; y < rows; y++) {
844 for (
x = 0;
x < cols;
x++) {
852 for (i = 0; i <
les->rows; i++) {
854 if (
les->Asp[i]->index[
j] == (
unsigned int)
count)
855 les->Asp[i]->values[
j] = 0.0;
864 for (i = 0; i <
les->cols; i++)
867 for (i = 0; i <
les->rows; i++)
908 if ((count +
K) >= 0 && (count +
K) <
les->cols) {
910 " make_les_entry_2d: (N_CELL_ACTIVE) create matrix "
911 "entry at row[%i] col[%i] value %g\n",
929 if ((count +
K) >= 0 && (count +
K) <
les->cols) {
931 " make_les_entry_2d: (N_CELL_DIRICHLET) create matrix "
932 "entry at row[%i] col[%i] value %g\n",
1028 int i,
j, k,
count = 0, pos = 0;
1036 "N_assemble_les_3d: starting to assemble the linear equation system");
1047 for (k = 0; k <
geom->depths; k++) {
1048 for (
j = 0;
j <
geom->rows;
j++) {
1049 for (i = 0; i <
geom->cols; i++) {
1062 for (k = 0; k <
geom->depths; k++) {
1063 for (
j = 0;
j <
geom->rows;
j++) {
1064 for (i = 0; i <
geom->cols; i++) {
1074 G_debug(2,
"N_assemble_les_3d: number of used cells %i\n",
1079 "Not enough active cells [%i] to create the linear equation "
1080 "system. Check the cell status. Only active cells (value = 1) are "
1081 "used to create the equation system.",
1096 for (k = 0; k <
geom->depths; k++) {
1097 for (
j = 0;
j <
geom->rows;
j++) {
1098 for (i = 0; i <
geom->cols; i++) {
1110 "N_assemble_les_3d: non-inactive cells count "
1111 "%i at pos x[%i] y[%i] z[%i]\n",
1123 "N_assemble_les_3d: active cells count %i at pos "
1124 "x[%i] y[%i] z[%i]\n",
1131 G_debug(2,
"N_assemble_les_3d: starting the parallel assemble loop");
1133#pragma omp parallel for private(i, j, k, pos, count) schedule(static)
1160 spvect->values[pos] = items->
C;
1167 pos = make_les_entry_3d(i,
j, k, -1, 0, 0,
count, pos,
les,
spvect,
1173 pos = make_les_entry_3d(i,
j, k, 1, 0, 0,
count, pos,
les,
spvect,
1179 pos = make_les_entry_3d(i,
j, k, 0, -1, 0,
count, pos,
les,
spvect,
1185 pos = make_les_entry_3d(i,
j, k, 0, 1, 0,
count, pos,
les,
spvect,
1193 pos = make_les_entry_3d(i,
j, k, 0, 0, 1,
count, pos,
les,
1199 pos = make_les_entry_3d(i,
j, k, 0, 0, -1,
count, pos,
les,
1255 int rows, cols, depths;
1261 G_debug(2,
"N_les_integrate_dirichlet_3d: integrating the dirichlet "
1262 "boundary condition");
1266 depths =
geom->depths;
1274 for (z = 0; z < depths; z++) {
1275 for (y = 0; y < rows; y++) {
1276 for (
x = 0;
x < cols;
x++) {
1290#pragma omp parallel default(shared)
1297#pragma omp for schedule(static) private(i)
1298 for (i = 0; i <
les->cols; i++)
1305 for (z = 0; z < depths; z++) {
1306 for (y = 0; y < rows; y++) {
1307 for (
x = 0;
x < cols;
x++) {
1316 for (i = 0; i <
les->rows; i++) {
1319 if (
les->Asp[i]->index[
j] ==
1320 (
unsigned int)
count)
1321 les->Asp[i]->values[
j] = 0.0;
1330 for (i = 0; i <
les->cols; i++)
1333 for (i = 0; i <
les->rows; i++)
1376 if ((count +
K) >= 0 && (
count +
K) <
les->cols) {
1378 " make_les_entry_3d: (N_CELL_ACTIVE) create matrix "
1379 "entry at row[%i] col[%i] value %g\n",
1380 count, count +
K,
entry);
1395 if ((count +
K) >= 0 && (count +
K) <
les->cols) {
1397 " make_les_entry_3d: (N_CELL_DIRICHLET) create matrix "
1398 "entry at row[%i] col[%i] value %g\n",
1399 count, count +
K,
entry);
#define N_MAX_CELL_STATE
the maximum number of available cell states (eg: boundary condition, inactiven active)
void G_free(void *)
Free allocated memory.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
int G_debug(int, const char *,...) __attribute__((format(printf
G_math_spvector * G_math_alloc_spvector(int)
Allocate memory for a sparse vector.
void G_math_Ax_sparse(G_math_spvector **, double *, double *, int)
Compute the matrix - vector product of sparse matrix **Asp and vector x.
int G_math_add_spvector(G_math_spvector **, G_math_spvector *, int)
Adds a sparse vector to a sparse matrix at position row.
void G_math_d_Ax(double **, double *, double *, int, int)
Compute the matrix - vector product of matrix A and vector x.
#define UNUSED
A macro for an attribute, if attached to a variable, indicating that the variable is not used.
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.
CELL N_get_array_2d_c_value(N_array_2d *data, int col, int row)
Returns the value of type CELL at position col, row.
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.
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.
N_array_2d * N_alloc_array_2d(int cols, int rows, int offset, int type)
Allocate memory for a N_array_2d data structure.
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_c_value(N_array_2d *data, int col, int row, CELL value)
Writes a CELL value to the N_array_2d struct at position col, row.
N_les * N_alloc_les_Ax_b(int rows, int type)
Allocate memory for a quadratic linear equation system which includes the Matrix A,...
N_data_star * N_alloc_27star(void)
allocate a 27 point star data structure
N_data_star * N_callback_template_3d(void *data, N_geom_data *geom, int col, int row, int depth)
A callback template creates a 7 point star structure.
N_les * N_assemble_les_2d_dirichlet(int les_type, N_geom_data *geom, N_array_2d *status, N_array_2d *start_val, void *data, N_les_callback_2d *call)
Assemble a linear equation system (les) based on 2d location data (raster) and active and dirichlet c...
N_data_star * N_create_5star(double C, double W, double E, double N, double S, double V)
allocate and initialize a 5 point star data structure
N_data_star * N_create_27star(double C, double W, double E, double N, double S, double NW, double SW, double NE, double SE, double T, double W_T, double E_T, double N_T, double S_T, double NW_T, double SW_T, double NE_T, double SE_T, double B, double W_B, double E_B, double N_B, double S_B, double NW_B, double SW_B, double NE_B, double SE_B, double V)
allocate and initialize a 27 point star data structure
N_data_star * N_alloc_7star(void)
allocate a 7 point star data structure
N_les * N_assemble_les_2d(int les_type, N_geom_data *geom, N_array_2d *status, N_array_2d *start_val, void *data, N_les_callback_2d *call)
Assemble a linear equation system (les) based on 2d location data (raster) and active cells.
N_data_star * N_alloc_9star(void)
allocate a 9 point star data structure
int N_les_integrate_dirichlet_3d(N_les *les, N_geom_data *geom, N_array_3d *status, N_array_3d *start_val)
Integrate Dirichlet or Transmission boundary conditions into the les (3d)
N_les * N_assemble_les_3d_dirichlet(int les_type, N_geom_data *geom, N_array_3d *status, N_array_3d *start_val, void *data, N_les_callback_3d *call)
Assemble a linear equation system (les) based on 3d location data (g3d) active and dirichlet cells.
int N_les_integrate_dirichlet_2d(N_les *les, N_geom_data *geom, N_array_2d *status, N_array_2d *start_val)
Integrate Dirichlet or Transmission boundary conditions into the les (2s)
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_les * N_assemble_les_3d_active(int les_type, N_geom_data *geom, N_array_3d *status, N_array_3d *start_val, void *data, N_les_callback_3d *call)
Assemble a linear equation system (les) based on 3d location data (g3d) active cells.
N_data_star * N_callback_template_2d(void *data, N_geom_data *geom, int col, int row)
A callback template creates a 9 point star 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_alloc_5star(void)
allocate a 5 point star data structure
N_les * N_assemble_les_2d_active(int les_type, N_geom_data *geom, N_array_2d *status, N_array_2d *start_val, void *data, N_les_callback_2d *call)
Assemble a linear equation system (les) based on 2d location data (raster) and active cells.
N_les * N_assemble_les_2d_param(int les_type, N_geom_data *geom, N_array_2d *status, N_array_2d *start_val, void *data, N_les_callback_2d *call, int cell_type)
Assemble a linear equation system (les) based on 2d location data (raster)
N_les_callback_2d * N_alloc_les_callback_2d(void)
Allocate the structure holding the callback function.
N_les * N_assemble_les_3d(int les_type, N_geom_data *geom, N_array_3d *status, N_array_3d *start_val, void *data, N_les_callback_3d *call)
Assemble a linear equation system (les) based on 3d location data (g3d) active cells.
N_les_callback_3d * N_alloc_les_callback_3d(void)
Allocate the structure holding the callback function.
void N_set_les_callback_3d_func(N_les_callback_3d *data, N_data_star *(*callback_func_3d)(void *, N_geom_data *, int, int, int))
Set the callback function which is called while assembling the les in 3d.
void N_set_les_callback_2d_func(N_les_callback_2d *data, N_data_star *(*callback_func_2d)(void *, N_geom_data *, int, int))
Set the callback function which is called while assembling the les in 2d.
N_les * N_assemble_les_3d_param(int les_type, N_geom_data *geom, N_array_3d *status, N_array_3d *start_val, void *data, N_les_callback_3d *call, int cell_type)
Assemble a linear equation system (les) based on 3d location data (g3d)
The row vector of the sparse matrix.
Matrix entries for a mass balance 5/7/9 star system.
Geometric information about the structured grid.
callback structure for 2d matrix assembling
N_data_star *(* callback)(void *, N_geom_data *, int, int)
callback structure for 3d matrix assembling
N_data_star *(* callback)(void *, N_geom_data *, int, int, int)
The linear equation system (les) structure.