GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-d6dec75dd4
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)(void *, N_geom_data *, int, int, int))
 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)(void *, N_geom_data *, int, int))
 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 UNUSED, N_geom_data *geom, int col UNUSED, int row UNUSED, int depth UNUSED)
 A callback template creates a 7 point star structure. More...
 
N_data_starN_callback_template_2d (void *data UNUSED, N_geom_data *geom, int col UNUSED, int row UNUSED)
 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 101 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 42 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 59 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 80 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_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 400 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 379 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 495 of file n_les_assemble.c.

◆ 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 510 of file n_les_assemble.c.

◆ 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 525 of file n_les_assemble.c.

◆ 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 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_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 563 of file n_les_assemble.c.

◆ 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 958 of file n_les_assemble.c.

◆ 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 972 of file n_les_assemble.c.

◆ 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 986 of file n_les_assemble.c.

◆ 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 1023 of file n_les_assemble.c.

◆ N_callback_template_2d()

N_data_star* N_callback_template_2d ( void *data  UNUSED,
N_geom_data geom,
int col  UNUSED,
int row  UNUSED 
)

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 * (unused)
geomN_geom_data *
rowint (unused)
colint (unused)
Returns
N_data_star *

Definition at line 465 of file n_les_assemble.c.

Referenced by N_alloc_les_callback_2d().

◆ N_callback_template_3d()

N_data_star* N_callback_template_3d ( void *data  UNUSED,
N_geom_data geom,
int col  UNUSED,
int row  UNUSED,
int depth  UNUSED 
)

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 * (unused)
geomN_geom_data *
depthint (unused)
rowint (unused)
colint (unused)
Returns
N_data_star *

Definition at line 427 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 264 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, N_data_star::NE, NE, N_data_star::NE_B, N_data_star::NE_T, N_data_star::NW, 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, N_data_star::SE, SE, N_data_star::SE_B, N_data_star::SE_T, N_data_star::SW, 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 124 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 159 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 200 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(), N_data_star::NE, NE, N_data_star::NW, NW, N_data_star::S, N_data_star::SE, SE, N_data_star::SW, 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 793 of file n_les_assemble.c.

References N_les::A, N_les::Asp, N_les::b, N_les::cols, N_geom_data::cols, count, G_calloc, G_debug(), G_free(), 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, 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 1252 of file n_les_assemble.c.

References N_les::A, N_les::Asp, N_les::b, N_les::cols, N_geom_data::cols, count, N_geom_data::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, 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 *(*)(void *, N_geom_data *, int, int)  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 360 of file n_les_assemble.c.

◆ N_set_les_callback_3d_func()

void N_set_les_callback_3d_func ( N_les_callback_3d data,
N_data_star *(*)(void *, N_geom_data *, int, int, int)  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 341 of file n_les_assemble.c.