SpM Handbook 1.2.4
Loading...
Searching...
No Matches
p_spm_laplacian.c File Reference
#include "common.h"
#include "drivers/laplacian.h"

Go to the source code of this file.

Macros

#define laplacian_add_one_edge(_colptr_, _rowptr_, _valptr_, _dest_, _value_)
 Add an edge to the spm matrix.
 
#define laplacian_add_three_edges(_colptr_, _rowptr_, _valptr_, _dest_, _fcond_, _lcond_, _valone_, _valtwo_)
 Add three edges of the 27 pts stencil. the direct one, and its two diagonal neighboor ones.
 

Functions

static spm_int_t p_spmLaplacian_getnnz (spm_int_t M, spm_int_t N, spm_int_t K, int level, int connexion)
 Return the number of edges in a laplacian of size MxNxK.
 
void p_spmLaplacian_7points (spmatrix_t *spm, spm_int_t dim1, spm_int_t dim2, spm_int_t dim3, spm_fixdbl_t alpha, spm_fixdbl_t beta)
 Generate a laplacian matrix for a 3D 7-points stencil.
 
void p_spmLaplacian_27points (spmatrix_t *spm, spm_int_t dim1, spm_int_t dim2, spm_int_t dim3, spm_fixdbl_t alpha, spm_fixdbl_t beta)
 Generate an extended laplacian matrix for a 3D 27-points stencil.
 

Detailed Description

SParse Matrix package laplacian generator routines.

Version
1.2.4
Author
Mathieu Faverge
Tony Delarue
Gregoire Pichon
Alycia Lisito
Date
2024-06-25
Generated arithmetic file from /builds/2mk6rsew/0/fpruvost/spm/src/z_spm_laplacian.c, normal z -> p, Fri Nov 29 11:34:30 2024

Definition in file p_spm_laplacian.c.

Macro Definition Documentation

◆ laplacian_add_one_edge

#define laplacian_add_one_edge (   _colptr_,
  _rowptr_,
  _valptr_,
  _dest_,
  _value_ 
)
Value:
{ \
*(_rowptr_) = _dest_; \
*(_valptr_) = _value_; \
(_rowptr_)++; \
(_valptr_)++; \
(_colptr_)[1]++; \
}

Add an edge to the spm matrix.

Parameters
[in,out]_colptr_Increment the colptr by 1.
[in,out]_rowptr_Store the edge value and shift to the next array element
[in,out]_valptr_Store the edge value and shift to the next array element
[in]_dest_The destination of the edge
[in]_value_The value of the edge

Definition at line 55 of file p_spm_laplacian.c.

◆ laplacian_add_three_edges

#define laplacian_add_three_edges (   _colptr_,
  _rowptr_,
  _valptr_,
  _dest_,
  _fcond_,
  _lcond_,
  _valone_,
  _valtwo_ 
)
Value:
{ \
if ( _fcond_ ) \
{ \
laplacian_add_one_edge( (_colptr_), (_rowptr_), (_valptr_), (_dest_) - 1, (_valtwo_) ); \
} \
laplacian_add_one_edge( (_colptr_), (_rowptr_), (_valptr_), (_dest_), (_valone_) ); \
if ( _lcond_ ) \
{ \
laplacian_add_one_edge( (_colptr_), (_rowptr_), (_valptr_), (_dest_) + 1, (_valtwo_) ); \
} \
}

Add three edges of the 27 pts stencil. the direct one, and its two diagonal neighboor ones.

Parameters
[in,out]_colptr_Increment the colptr by 1.
[in,out]_rowptr_Store the edge value and shift to the next array element
[in,out]_valptr_Store the edge value and shift to the next array element
[in]_dest_The center destination of the three edges
[in]_fcond_The condition to add the first diagonal
[in]_lcond_The condition to add the last diagonal
[in]_valone_The value on the central edge
[in]_valtwo_The value on the diagonal edges

Definition at line 100 of file p_spm_laplacian.c.

Function Documentation

◆ p_spmLaplacian_getnnz()

static spm_int_t p_spmLaplacian_getnnz ( spm_int_t  M,
spm_int_t  N,
spm_int_t  K,
int  level,
int  connexion 
)
static

Return the number of edges in a laplacian of size MxNxK.

Parameters
[in]MThe main dimension (the one split among the processes if any)
[in]NThe second dimension (Not split)
[in]KThe third dimension (Not split)
[in]levelThe level of the edges to add
  • 0: No edges but the diagonal elements
  • 1: 0 + The edges along the squares if the stencil
  • 2: 1 + The edges on the diagonals of the squares
  • 3: 2 + The edges on the diagonals of the cubes
[in]connexionIf connexion is true, the edges to connect to another domain along the first dimension (M) are added to the computation. If false, nothing is added.
Returns
The number of edges in the final symmetric graph

Definition at line 150 of file p_spm_laplacian.c.

Referenced by p_spmLaplacian_27points(), and p_spmLaplacian_7points().

◆ p_spmLaplacian_7points()

void p_spmLaplacian_7points ( spmatrix_t spm,
spm_int_t  dim1,
spm_int_t  dim2,
spm_int_t  dim3,
spm_fixdbl_t  alpha,
spm_fixdbl_t  beta 
)

Generate a laplacian matrix for a 3D 7-points stencil.

The generated laplacian matrix is

\[ M = \alpha * D - \beta * A \]

with D the doagonal matrix of the degrees and A the adjacency matrix with coefficients of 1. for each connexion.

 *-------*-------*
/|      /|      /|

----—B----— | /| | /| | /| | ----—-|--—* | | | | —|-|-B—|-|- | |/| | |/ | |/| | B--—|-A--—|-B | |/| | |/| |/| | ----—B----— | | | | —|-|-—|-|-* | |/ | |/ | |/ | --—|-B--—|- |/ |/ |/ ----—----—*

Each element A is only connected to its neigbours B in the stencil.

Example:

‍ 3 -1 -1 0 -1 0 0 0 -1 3 0 -1 0 -1 0 0 -1 0 3 -1 0 0 -1 0 0 -1 -1 3 0 0 0 -1 -1 0 0 0 3 -1 -1 0 0 -1 0 0 -1 3 0 -1 0 0 -1 0 -1 0 3 -1 0 0 0 -1 0 -1 -1 3

Remarks
: In int, the Laplacian is set to symmetric. See p_spmLaplacian_27points() to get a symmetric Laplacian, or change the mtxtype field by hand.
Parameters
[in,out]spmAt start, an allocated spm structure. Contains the size of the laplacian in spm->n. At exit, contains the matrix in csc format.
[in]dim1contains the first dimension of the grid of the laplacian.
[in]dim2contains the second dimension of the grid of the laplacian.
[in]dim3contains the third dimension of the grid of the laplacian.
[in]alphaThe alpha coefficient for the degree matrix
[in]betaThe beta coefficient for the adjacency matrix

Definition at line 275 of file p_spm_laplacian.c.

References spmatrix_s::baseval, spmatrix_s::clustnbr, spmatrix_s::clustnum, spmatrix_s::colptr, spmatrix_s::dof, spmatrix_s::flttype, spmatrix_s::fmttype, spmatrix_s::gN, spmatrix_s::gnnz, laplacian_add_one_edge, spmatrix_s::loc2glob, spmatrix_s::mtxtype, spmatrix_s::n, spmatrix_s::nnz, p_spmLaplacian_getnnz(), spmatrix_s::replicated, spmatrix_s::rowptr, spm_imin(), SpmCSC, SpmPattern, SpmSymmetric, and spmatrix_s::values.

◆ p_spmLaplacian_27points()

void p_spmLaplacian_27points ( spmatrix_t spm,
spm_int_t  dim1,
spm_int_t  dim2,
spm_int_t  dim3,
spm_fixdbl_t  alpha,
spm_fixdbl_t  beta 
)

Generate an extended laplacian matrix for a 3D 27-points stencil.

The generated laplacian is a the matrix

\[ M = \alpha * D - \beta * A \]

, where D is the matrix of degrees, and A the matrix of adjacency. In the exemple below for each vertex A, the value of the connexions in the adjacency matrix are:

  • 1 for the connexions with the B vertices
  • 1 / (2) for the connexions with the X vertices (face diagonal)
  • 1 / (3) for the connexions with the D vertices (cube diagonal)

    D----—X----—D /| /| /| X----—B----—X | /| | /| | /| | D----—X-|--—D | | | | X—|-|-B—|-|-X | |/| | |/ | |/| | B--—|-A--—|-B | |/| | |/| |/| | X----—B----—X | | | | D—|-|-X—|-|-D | |/ | |/ | |/ | X--—|-B--—|-X |/ |/ |/ D----—X----—D

Remarks
: In int, the Laplacian is set to symmetric. See p_spmLaplacian_7points() to get an symmetric Laplacian, or change the mtxtype field by hand.
Parameters
[in,out]spmAt start, an allocated spm structure. Contains the size of the laplacian in spm->n. At exit, contains the matrix in csc format.
[in]dim1contains the first dimension of the grid of the laplacian.
[in]dim2contains the second dimension of the grid of the laplacian.
[in]dim3contains the third dimension of the grid of the laplacian.
[in]alphaThe alpha coefficient for the degree matrix
[in]betaThe beta coefficient for the adjacency matrix

Definition at line 498 of file p_spm_laplacian.c.

References spmatrix_s::baseval, spmatrix_s::clustnbr, spmatrix_s::clustnum, spmatrix_s::colptr, spmatrix_s::dof, spmatrix_s::flttype, spmatrix_s::fmttype, spmatrix_s::gN, spmatrix_s::gnnz, laplacian_add_one_edge, laplacian_add_three_edges, spmatrix_s::loc2glob, spmatrix_s::mtxtype, spmatrix_s::n, spmatrix_s::nnz, p_spmLaplacian_getnnz(), spmatrix_s::replicated, spmatrix_s::rowptr, spm_imin(), SpmCSC, SpmPattern, SpmSymmetric, and spmatrix_s::values.