GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
n_les_assemble.c File Reference
#include <math.h>
#include <grass/N_pde.h>
Include dependency graph for n_les_assemble.c:

Go to the source code of this file.

Functions

N_data_starN_alloc_5star (void)
 allocate a 5 point star data structure More...
 
N_data_starN_alloc_7star (void)
 allocate a 7 point star data structure More...
 
N_data_starN_alloc_9star (void)
 allocate a 9 point star data structure More...
 
N_data_starN_alloc_27star (void)
 allocate a 27 point star data structure More...
 
N_data_starN_create_5star (double C, double W, double E, double N, double S, double V)
 allocate and initialize a 5 point star data structure More...
 
N_data_starN_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 More...
 
N_data_starN_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 More...
 
N_data_starN_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 More...
 
void N_set_les_callback_3d_func (N_les_callback_3d *data, N_data_star *(*callback_func_3d)())
 Set the callback function which is called while assembling the les in 3d. More...
 
void N_set_les_callback_2d_func (N_les_callback_2d *data, N_data_star *(*callback_func_2d)())
 Set the callback function which is called while assembling the les in 2d. More...
 
N_les_callback_3dN_alloc_les_callback_3d (void)
 Allocate the structure holding the callback function. More...
 
N_les_callback_2dN_alloc_les_callback_2d (void)
 Allocate the structure holding the callback function. More...
 
N_data_starN_callback_template_3d (void *data, N_geom_data *geom, int col, int row, int depth)
 A callback template creates a 7 point star structure. More...
 
N_data_starN_callback_template_2d (void *data, N_geom_data *geom, int col, int row)
 A callback template creates a 9 point star structure. More...
 
N_lesN_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. More...
 
N_lesN_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. More...
 
N_lesN_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 cells. More...
 
N_lesN_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) More...
 
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) More...
 
N_lesN_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. More...
 
N_lesN_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. More...
 
N_lesN_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. More...
 
N_lesN_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) More...
 
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) More...
 

Function Documentation

◆ N_alloc_27star()

N_data_star* N_alloc_27star ( void  )

allocate a 27 point star data structure

Returns
N_data_star *
Attention
The 27 point start is not yet implemented in the matrix assembling function

Definition at line 103 of file n_les_assemble.c.

References N_data_star::count, G_calloc, N_27_POINT_STAR, and N_data_star::type.

Referenced by N_create_27star().

◆ N_alloc_5star()

N_data_star* N_alloc_5star ( void  )

allocate a 5 point star data structure

Returns
N_data_star *

Definition at line 46 of file n_les_assemble.c.

References N_data_star::count, G_calloc, N_5_POINT_STAR, and N_data_star::type.

Referenced by N_create_5star().

◆ N_alloc_7star()

N_data_star* N_alloc_7star ( void  )

allocate a 7 point star data structure

Returns
N_data_star *

Definition at line 63 of file n_les_assemble.c.

References N_data_star::count, G_calloc, N_7_POINT_STAR, and N_data_star::type.

Referenced by N_create_7star().

◆ N_alloc_9star()

N_data_star* N_alloc_9star ( void  )

allocate a 9 point star data structure

Returns
N_data_star *
Attention
The 9 point start is not yet implemented in the matrix assembling function

Definition at line 83 of file n_les_assemble.c.

References N_data_star::count, G_calloc, N_9_POINT_STAR, and N_data_star::type.

Referenced by N_callback_template_2d(), and N_create_9star().

◆ N_alloc_les_callback_2d()

N_les_callback_2d* N_alloc_les_callback_2d ( void  )

Allocate the structure holding the callback function.

A template callback is set. Use N_set_les_callback_2d_func to set up a specific function.

Returns
N_les_callback_2d *

Definition at line 397 of file n_les_assemble.c.

References N_les_callback_2d::callback, G_calloc, and N_callback_template_2d().

◆ N_alloc_les_callback_3d()

N_les_callback_3d* N_alloc_les_callback_3d ( void  )

Allocate the structure holding the callback function.

A template callback is set. Use N_set_les_callback_3d_func to set up a specific function.

Returns
N_les_callback_3d *

Definition at line 376 of file n_les_assemble.c.

References N_les_callback_3d::callback, G_calloc, and N_callback_template_3d().

◆ N_assemble_les_2d()

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.

This function calls N_assemble_les_2d_param

Definition at line 493 of file n_les_assemble.c.

References N_assemble_les_2d_param(), and N_CELL_ACTIVE.

◆ N_assemble_les_2d_active()

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.

This function calls N_assemble_les_2d_param

Definition at line 507 of file n_les_assemble.c.

References N_assemble_les_2d_param(), and N_CELL_ACTIVE.

◆ N_assemble_les_2d_dirichlet()

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 cells.

This function calls N_assemble_les_2d_param

Definition at line 521 of file n_les_assemble.c.

References N_assemble_les_2d_param(), and N_CELL_DIRICHLET.

◆ N_assemble_les_2d_param()

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)

The linear equation system type can be set to N_NORMAL_LES to create a regular matrix, or to N_SPARSE_LES to create a sparse matrix. This function returns a new created linear equation system which can be solved with linear equation solvers. An 2d array with start values and an 2d status array must be provided as well as the location geometry and a void pointer to data passed to the callback which creates the les row entries. This callback must be defined in the N_les_callback_2d strcuture.

The creation of the les is parallelized with OpenMP. If you implement new callbacks, please make sure that the function calls are thread safe.

the les can be created in two ways, with dirichlet and similar cells and without them, to spare some memory. If the les is created with dirichlet cell, the dirichlet boundary condition must be added.

Parameters
les_typeint
geomN_geom_data*
statusN_array_2d *
start_valN_array_2d *
datavoid *
cell_typeint – les assemble based on N_CELL_ACTIVE or N_CELL_DIRICHLET
callN_les_callback_2d *
Returns
N_les *

Definition at line 560 of file n_les_assemble.c.

References N_les::A, N_les::b, N_data_star::C, N_les_callback_2d::callback, CELL_TYPE, N_geom_data::cols, count, N_data_star::count, G_calloc, G_debug(), G_fatal_error(), G_math_alloc_spvector(), G_math_spvector::index, N_alloc_array_2d(), N_alloc_les_Ax_b(), N_CELL_ACTIVE, N_CELL_DIRICHLET, N_CELL_INACTIVE, N_get_array_2d_c_value(), N_get_array_2d_d_value(), N_MAX_CELL_STATE, N_put_array_2d_c_value(), N_SPARSE_LES, NULL, N_geom_data::rows, N_data_star::V, G_math_spvector::values, and N_les::x.

Referenced by N_assemble_les_2d(), N_assemble_les_2d_active(), and N_assemble_les_2d_dirichlet().

◆ N_assemble_les_3d()

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.

This function calls N_assemble_les_3d_param

Definition at line 949 of file n_les_assemble.c.

References N_assemble_les_3d_param(), and N_CELL_ACTIVE.

◆ N_assemble_les_3d_active()

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.

This function calls N_assemble_les_3d_param

Definition at line 962 of file n_les_assemble.c.

References N_assemble_les_3d_param(), and N_CELL_ACTIVE.

◆ N_assemble_les_3d_dirichlet()

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.

This function calls N_assemble_les_3d_param

Definition at line 975 of file n_les_assemble.c.

References N_assemble_les_3d_param(), and N_CELL_DIRICHLET.

◆ N_assemble_les_3d_param()

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 linear equation system type can be set to N_NORMAL_LES to create a regular matrix, or to N_SPARSE_LES to create a sparse matrix. This function returns a new created linear equation system which can be solved with linear equation solvers. An 3d array with start values and an 3d status array must be provided as well as the location geometry and a void pointer to data passed to the callback which creates the les row entries. This callback must be defined in the N_les_callback_3d structure.

The creation of the les is parallelized with OpenMP. If you implement new callbacks, please make sure that the function calls are thread safe.

the les can be created in two ways, with dirichlet and similar cells and without them, to spare some memory. If the les is created with dirichlet cell, the dirichlet boundary condition must be added.

Parameters
les_typeint
geomN_geom_data*
statusN_array_3d *
start_valN_array_3d *
datavoid *
callN_les_callback_3d *
cell_typeint – les assemble based on N_CELL_ACTIVE or N_CELL_DIRICHLET
Returns
N_les *

Definition at line 1012 of file n_les_assemble.c.

References N_les::A, N_les::b, N_data_star::C, N_les_callback_3d::callback, N_geom_data::cols, count, N_data_star::count, DCELL_TYPE, N_geom_data::depths, G_calloc, G_debug(), G_fatal_error(), G_math_alloc_spvector(), G_math_spvector::index, N_alloc_array_3d(), N_alloc_les_Ax_b(), N_CELL_ACTIVE, N_CELL_DIRICHLET, N_CELL_INACTIVE, N_get_array_3d_d_value(), N_MAX_CELL_STATE, N_put_array_3d_d_value(), N_SPARSE_LES, NULL, N_geom_data::rows, N_data_star::V, G_math_spvector::values, and N_les::x.

Referenced by N_assemble_les_3d(), N_assemble_les_3d_active(), and N_assemble_les_3d_dirichlet().

◆ N_callback_template_2d()

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.

This is a template callback for mass balance calculation with 9 point stars based on 2d data (raster).

Parameters
datavoid *
geomN_geom_data *
rowint
colint
Returns
N_data_star *

Definition at line 463 of file n_les_assemble.c.

References N_data_star::C, N_geom_data::dx, N_geom_data::dy, N_data_star::E, N_data_star::N, N_alloc_9star(), N_data_star::NE, N_data_star::NW, N_data_star::S, N_data_star::SE, N_data_star::SW, N_data_star::V, and N_data_star::W.

Referenced by N_alloc_les_callback_2d().

◆ N_callback_template_3d()

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.

This is a template callback for mass balance calculation with 7 point stars based on 3d data (g3d).

Parameters
datavoid *
geomN_geom_data *
depthint
rowint
colint
Returns
N_data_star *

Definition at line 424 of file n_les_assemble.c.

Referenced by N_alloc_les_callback_3d().

◆ N_create_27star()

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

Parameters
Cdouble
Wdouble
Edouble
Ndouble
Sdouble
NWdouble
SWdouble
NEdouble
SEdouble
Tdouble
W_Tdouble
E_Tdouble
N_Tdouble
S_Tdouble
NW_Tdouble
SW_Tdouble
NE_Tdouble
SE_Tdouble
Bdouble
W_Bdouble
E_Bdouble
N_Bdouble
S_Bdouble
NW_Bdouble
SW_Bdouble
NE_Bdouble
SE_Bdouble
Vdouble
Returns
N_data_star *

Definition at line 265 of file n_les_assemble.c.

References N_data_star::B, N_data_star::C, N_data_star::E, N_data_star::E_B, N_data_star::E_T, G_debug(), N_data_star::N, N, N_alloc_27star(), N_data_star::N_B, N_data_star::N_T, NE, N_data_star::NE, N_data_star::NE_B, N_data_star::NE_T, NW, N_data_star::NW, N_data_star::NW_B, N_data_star::NW_T, N_data_star::S, N_data_star::S_B, N_data_star::S_T, SE, N_data_star::SE, N_data_star::SE_B, N_data_star::SE_T, SW, N_data_star::SW, N_data_star::SW_B, N_data_star::SW_T, N_data_star::T, N_data_star::V, W, N_data_star::W, N_data_star::W_B, and N_data_star::W_T.

◆ N_create_5star()

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

Parameters
Cdouble
Wdouble
Edouble
Ndouble
Sdouble
Vdouble
Returns
N_data_star *

Definition at line 126 of file n_les_assemble.c.

References N_data_star::C, N_data_star::E, G_debug(), N_data_star::N, N, N_alloc_5star(), N_data_star::S, N_data_star::V, W, and N_data_star::W.

◆ N_create_7star()

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

Parameters
Cdouble
Wdouble
Edouble
Ndouble
Sdouble
Tdouble
Bdouble
Vdouble
Returns
N_data_star *

Definition at line 161 of file n_les_assemble.c.

References N_data_star::B, N_data_star::C, N_data_star::E, G_debug(), N_data_star::N, N, N_alloc_7star(), N_data_star::S, N_data_star::T, N_data_star::V, W, and N_data_star::W.

◆ N_create_9star()

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

Parameters
Cdouble
Wdouble
Edouble
Ndouble
Sdouble
NWdouble
SWdouble
NEdouble
SEdouble
Vdouble
Returns
N_data_star *

Definition at line 202 of file n_les_assemble.c.

References N_data_star::C, N_data_star::E, G_debug(), N_data_star::N, N, N_alloc_9star(), NE, N_data_star::NE, NW, N_data_star::NW, N_data_star::S, SE, N_data_star::SE, SW, N_data_star::SW, N_data_star::V, W, and N_data_star::W.

◆ N_les_integrate_dirichlet_2d()

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)

Dirichlet and Transmission boundary conditions will be integrated into the provided linear equation system. This is meaningful if the les was created with N_assemble_les_2d_dirichlet, because in this case Dirichlet boundary conditions are not automatically included.

The provided les will be modified:

Ax = b will be split into Ax_u + Ax_d = b

x_u - the unknowns x_d - the Dirichlet cells

Ax_u = b -Ax_d will be computed. Then the matrix A will be modified to

| A_u 0 | x_u | 0 I | x_d

Parameters
lesN_les* – the linear equation system
geomN_geom_data* – geometrical data information
statusN_array_2d* – the status array containing the cell types
start_valN_array_2d* – an array with start values
Returns
int – 1 = success, 0 = failure

Definition at line 786 of file n_les_assemble.c.

References N_les::A, N_les::Asp, N_les::b, G_math_spvector::cols, N_les::cols, N_geom_data::cols, Cell_head::cols, count, G_calloc, G_debug(), G_math_Ax_sparse(), G_math_d_Ax(), G_math_spvector::index, N_CELL_ACTIVE, N_get_array_2d_c_value(), N_get_array_2d_d_value(), N_MAX_CELL_STATE, N_SPARSE_LES, N_les::rows, N_geom_data::rows, Cell_head::rows, N_les::type, G_math_spvector::values, and x.

◆ N_les_integrate_dirichlet_3d()

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)

Dirichlet and Transmission boundary conditions will be integrated into the provided linear equation system. This is meaningful if the les was created with N_assemble_les_2d_dirichlet, because in this case Dirichlet boundary conditions are not automatically included.

The provided les will be modified:

Ax = b will be split into Ax_u + Ax_d = b

x_u - the unknowns x_d - the Dirichlet cells

Ax_u = b -Ax_d will be computed. Then the matrix A will be modified to

| A_u 0 | x_u | 0 I | x_d

Parameters
lesN_les* – the linear equation system
geomN_geom_data* – geometrical data information
statusN_array_2d* – the status array containing the cell types
start_valN_array_2d* – an array with start values
Returns
int – 1 = success, 0 = failure

Definition at line 1239 of file n_les_assemble.c.

References N_les::A, N_les::Asp, N_les::b, G_math_spvector::cols, N_les::cols, N_geom_data::cols, Cell_head::cols, count, N_geom_data::depths, Cell_head::depths, G_calloc, G_debug(), G_math_Ax_sparse(), G_math_d_Ax(), G_math_spvector::index, N_CELL_ACTIVE, N_get_array_3d_d_value(), N_MAX_CELL_STATE, N_SPARSE_LES, N_les::rows, N_geom_data::rows, Cell_head::rows, N_les::type, G_math_spvector::values, and x.

◆ N_set_les_callback_2d_func()

void N_set_les_callback_2d_func ( N_les_callback_2d data,
N_data_star *(*)()  callback_func_2d 
)

Set the callback function which is called while assembling the les in 2d.

Parameters
dataN_les_callback_2d *
callback_func_2dN_data_star *
Returns
void

Definition at line 359 of file n_les_assemble.c.

References N_les_callback_2d::callback.

◆ N_set_les_callback_3d_func()

void N_set_les_callback_3d_func ( N_les_callback_3d data,
N_data_star *(*)()  callback_func_3d 
)

Set the callback function which is called while assembling the les in 3d.

Parameters
dataN_les_callback_3d *
callback_func_3dN_data_star *
Returns
void

Definition at line 342 of file n_les_assemble.c.