programmer's documentation
Functions | Variables
cs_sdm.c File Reference
#include "cs_defs.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include <limits.h>
#include <bft_mem.h>
#include "cs_cdo.h"
#include "cs_blas.h"
#include "cs_log.h"
#include "cs_math.h"
#include "cs_parall.h"
#include "cs_sort.h"
#include "cs_sdm.h"
Include dependency graph for cs_sdm.c:

Functions

static cs_sdm_t * _create_sdm (cs_flag_t flag, int n_max_rows, int n_max_cols)
 Generic way to allocate a cs_sdm_t structure. More...
 
cs_sdm_t * cs_sdm_create (cs_flag_t flag, int n_max_rows, int n_max_cols)
 Allocate and initialize a cs_sdm_t structure Most generic function to create a cs_sdm_t structure without block description. More...
 
cs_sdm_t * cs_sdm_square_create (int n_max_rows)
 Allocate and initialize a cs_sdm_t structure Case of a square matrix. More...
 
cs_sdm_t * cs_sdm_create_copy (const cs_sdm_t *m)
 Allocate a cs_sdm_t structure and initialized it with the copy of the matrix m in input. More...
 
cs_sdm_t * cs_sdm_create_transpose (cs_sdm_t *mat)
 Define a new matrix by adding the given matrix with its transpose. Keep the transposed matrix for a future use. More...
 
cs_sdm_t * cs_sdm_block_create (short int n_max_blocks_by_row, short int n_max_blocks_by_col, const short int max_row_block_sizes[], const short int max_col_block_sizes[])
 Allocate and initialize a cs_sdm_t structure. More...
 
cs_sdm_t * cs_sdm_free (cs_sdm_t *mat)
 Free a cs_sdm_t structure. More...
 
void cs_sdm_block_init (cs_sdm_t *m, short int n_blocks_by_row, short int n_blocks_by_col, const short int row_block_sizes[], const short int col_block_sizes[])
 Initialize the pattern of cs_sdm_t structure defined by block The matrix should have been allocated before calling this function. More...
 
void cs_sdm_multiply (const cs_sdm_t *a, const cs_sdm_t *b, cs_sdm_t *c)
 Compute a local dense matrix-product c = a*b c has been previously allocated. More...
 
void cs_sdm_multiply_rowrow (const cs_sdm_t *a, const cs_sdm_t *b, cs_sdm_t *c)
 Compute a row-row matrix product of a and b. It is basically equal to the classical a*b^T. It is a fast (matrices are row-major) way of computing a*b if b is symmetric or if b^T is given. Generic version: all compatible sizes. More...
 
void cs_sdm_multiply_rowrow_sym (const cs_sdm_t *a, const cs_sdm_t *b, cs_sdm_t *c)
 Compute a row-row matrix product of a and b. It is basically equal to the classical a*b^T. It is a fast (matrices are row-major) way of computing a*b if b is symmetric or if b^T is given. Generic version: all compatible sizes Result is known to be symmetric. More...
 
void cs_sdm_block_multiply_rowrow (const cs_sdm_t *a, const cs_sdm_t *b, cs_sdm_t *c)
 Compute a row-row matrix product of a and b. It is basically equal to the classical a*b^T. It is a fast (matrices are row-major) way of computing a*b if b is symmetric or if b^T is given. Case of matrices defined by block. More...
 
void cs_sdm_block_multiply_rowrow_sym (const cs_sdm_t *a, const cs_sdm_t *b, cs_sdm_t *c)
 Compute a row-row matrix product of a and b. It is basically equal to the classical a*b^T. It is a fast (matrices are row-major) way of computing a*b if b is symmetric or if b^T is given. Case of matrices defined by block. Results is known to be symmetric. More...
 
void cs_sdm_square_matvec (const cs_sdm_t *mat, const cs_real_t *vec, cs_real_t *mv)
 Compute a dense matrix-vector product for a small square matrix mv has been previously allocated. More...
 
void cs_sdm_matvec (const cs_sdm_t *mat, const cs_real_t *vec, cs_real_t *mv)
 Compute a dense matrix-vector product for a rectangular matrix mv has been previously allocated. More...
 
void cs_sdm_block_add (cs_sdm_t *mat, const cs_sdm_t *add)
 Add two matrices defined by block: loc += add. More...
 
void cs_sdm_add (cs_sdm_t *mat, const cs_sdm_t *add)
 Add two small dense matrices: loc += add. More...
 
void cs_sdm_add_mult (cs_sdm_t *mat, cs_real_t alpha, const cs_sdm_t *add)
 Add two small dense matrices: loc += alpha*add. More...
 
void cs_sdm_square_add_transpose (cs_sdm_t *mat, cs_sdm_t *tr)
 Define a new matrix by adding the given matrix with its transpose. Keep the transposed matrix for a future use. More...
 
void cs_sdm_square_asymm (cs_sdm_t *mat)
 Set the given matrix into its anti-symmetric part. More...
 
void cs_sdm_33_sym_qr_compute (const cs_real_t m[9], cs_real_t Qt[9], cs_real_t R[6])
 Decompose a matrix into the matrix product Q.R Case of a 3x3 symmetric matrix. More...
 
void cs_sdm_33_ldlt_compute (const cs_sdm_t *m, cs_real_t facto[6])
 LDL^T: Modified Cholesky decomposition of a 3x3 SPD matrix. For more reference, see for instance http://mathforcollege.com/nm/mws/gen/04sle/mws_gen_sle_txt_cholesky.pdf. More...
 
void cs_sdm_44_ldlt_compute (const cs_sdm_t *m, cs_real_t facto[10])
 LDL^T: Modified Cholesky decomposition of a 4x4 SPD matrix. For more reference, see for instance http://mathforcollege.com/nm/mws/gen/04sle/mws_gen_sle_txt_cholesky.pdf. More...
 
void cs_sdm_66_ldlt_compute (const cs_sdm_t *m, cs_real_t facto[21])
 LDL^T: Modified Cholesky decomposition of a 6x6 SPD matrix. For more reference, see for instance http://mathforcollege.com/nm/mws/gen/04sle/mws_gen_sle_txt_cholesky.pdf. More...
 
void cs_sdm_ldlt_compute (const cs_sdm_t *m, cs_real_t *facto, cs_real_t *dkk)
 LDL^T: Modified Cholesky decomposition of a SPD matrix. For more reference, see for instance http://mathforcollege.com/nm/mws/gen/04sle/mws_gen_sle_txt_cholesky.pdf. More...
 
void cs_sdm_33_ldlt_solve (const cs_real_t facto[6], const cs_real_t rhs[3], cs_real_t sol[3])
 Solve a 3x3 matrix with a modified Cholesky decomposition (L.D.L^T) The solution should be already allocated Ref. http://mathforcollege.com/nm/mws/gen/04sle/mws_gen_sle_txt_cholesky.pdf. More...
 
void cs_sdm_44_ldlt_solve (const cs_real_t facto[10], const cs_real_t rhs[4], cs_real_t x[4])
 Solve a 4x4 matrix with a modified Cholesky decomposition (L.D.L^T) The solution should be already allocated Ref. http://mathforcollege.com/nm/mws/gen/04sle/mws_gen_sle_txt_cholesky.pdf. More...
 
void cs_sdm_66_ldlt_solve (const cs_real_t f[21], const cs_real_t b[3], cs_real_t x[3])
 Solve a 6x6 matrix with a modified Cholesky decomposition (L.D.L^T) The solution should be already allocated Ref. http://mathforcollege.com/nm/mws/gen/04sle/mws_gen_sle_txt_cholesky.pdf. More...
 
void cs_sdm_ldlt_solve (int n_rows, const cs_real_t *facto, const cs_real_t *rhs, cs_real_t *sol)
 Solve a SPD matrix with a L.D.L^T (Modified Cholesky decomposition) The solution should be already allocated Reference: http://mathforcollege.com/nm/mws/gen/04sle/mws_gen_sle_txt_cholesky.pdf. More...
 
void cs_sdm_simple_dump (const cs_sdm_t *mat)
 Dump a small dense matrix. More...
 
void cs_sdm_dump (cs_lnum_t parent_id, const cs_lnum_t *row_ids, const cs_lnum_t *col_ids, const cs_sdm_t *mat)
 Dump a small dense matrix. More...
 
void cs_sdm_block_dump (cs_lnum_t parent_id, const cs_sdm_t *mat)
 Dump a small dense matrix defined by blocks. More...
 

Variables

static const char _msg_small_p []
 

Function Documentation

◆ _create_sdm()

static cs_sdm_t* _create_sdm ( cs_flag_t  flag,
int  n_max_rows,
int  n_max_cols 
)
static

Generic way to allocate a cs_sdm_t structure.

Parameters
[in]flagmetadata related to a cs_sdm_t structure
[in]n_max_rowsmax number of rows
[in]n_max_colsmax number of columns
[in]n_max_rowsmax number of rows
[in]n_max_colsmax number of columns
Returns
a new allocated cs_sdm_t structure

◆ cs_sdm_33_ldlt_compute()

void cs_sdm_33_ldlt_compute ( const cs_sdm_t *  m,
cs_real_t  facto[6] 
)

LDL^T: Modified Cholesky decomposition of a 3x3 SPD matrix. For more reference, see for instance http://mathforcollege.com/nm/mws/gen/04sle/mws_gen_sle_txt_cholesky.pdf.

Parameters
[in]mpointer to a cs_sdm_t structure
[in,out]factovector of the coefficient of the decomposition

: facto is a lower triangular matrix. The first value of the j-th (zero-based) row is easily accessed: its index is j*(j+1)/2 (cf sum of the first j natural numbers). Instead of 1 on the diagonal we store the inverse of D mat in the L.D.L^T decomposition

◆ cs_sdm_33_ldlt_solve()

void cs_sdm_33_ldlt_solve ( const cs_real_t  facto[6],
const cs_real_t  rhs[3],
cs_real_t  sol[3] 
)

Solve a 3x3 matrix with a modified Cholesky decomposition (L.D.L^T) The solution should be already allocated Ref. http://mathforcollege.com/nm/mws/gen/04sle/mws_gen_sle_txt_cholesky.pdf.

Parameters
[in]factovector of the coefficients of the decomposition
[in]rhsright-hand side
[in,out]solsolution

◆ cs_sdm_33_sym_qr_compute()

void cs_sdm_33_sym_qr_compute ( const cs_real_t  m[9],
cs_real_t  Qt[9],
cs_real_t  R[6] 
)

Decompose a matrix into the matrix product Q.R Case of a 3x3 symmetric matrix.

Parameters
[in]mmatrix values
[in,out]Qttransposed of matrix Q
[in,out]Rvector of the coefficient of the decomposition

: R is an upper triangular matrix. Stored in a compact way.

j= 0, 1, 2 i=0| 0| 1| 2| i=1 | 4| 5| i=2 6|

◆ cs_sdm_44_ldlt_compute()

void cs_sdm_44_ldlt_compute ( const cs_sdm_t *  m,
cs_real_t  facto[10] 
)

LDL^T: Modified Cholesky decomposition of a 4x4 SPD matrix. For more reference, see for instance http://mathforcollege.com/nm/mws/gen/04sle/mws_gen_sle_txt_cholesky.pdf.

Parameters
[in]mpointer to a cs_sdm_t structure
[in,out]factovector of the coefficient of the decomposition

: facto is a lower triangular matrix. The first value of the j-th (zero-based) row is easily accessed: its index is j*(j+1)/2 (cf sum of the first j natural numbers). Instead of 1 on the diagonal we store the inverse of D mat in the L.D.L^T decomposition

◆ cs_sdm_44_ldlt_solve()

void cs_sdm_44_ldlt_solve ( const cs_real_t  facto[10],
const cs_real_t  rhs[4],
cs_real_t  x[4] 
)

Solve a 4x4 matrix with a modified Cholesky decomposition (L.D.L^T) The solution should be already allocated Ref. http://mathforcollege.com/nm/mws/gen/04sle/mws_gen_sle_txt_cholesky.pdf.

Parameters
[in]factovector of the coefficients of the decomposition
[in]rhsright-hand side
[in,out]xsolution

◆ cs_sdm_66_ldlt_compute()

void cs_sdm_66_ldlt_compute ( const cs_sdm_t *  m,
cs_real_t  facto[21] 
)

LDL^T: Modified Cholesky decomposition of a 6x6 SPD matrix. For more reference, see for instance http://mathforcollege.com/nm/mws/gen/04sle/mws_gen_sle_txt_cholesky.pdf.

Parameters
[in]mpointer to a cs_sdm_t structure
[in,out]factovector of the coefficient of the decomposition

: facto is a lower triangular matrix. The first value of the j-th (zero-based) row is easily accessed: its index is j*(j+1)/2 (cf sum of the first j natural numbers). Instead of 1 on the diagonal we store the inverse of D mat in the L.D.L^T decomposition

◆ cs_sdm_66_ldlt_solve()

void cs_sdm_66_ldlt_solve ( const cs_real_t  f[21],
const cs_real_t  b[3],
cs_real_t  x[3] 
)

Solve a 6x6 matrix with a modified Cholesky decomposition (L.D.L^T) The solution should be already allocated Ref. http://mathforcollege.com/nm/mws/gen/04sle/mws_gen_sle_txt_cholesky.pdf.

Parameters
[in]fvector of the coefficients of the decomposition
[in]bright-hand side
[in,out]xsolution

◆ cs_sdm_add()

void cs_sdm_add ( cs_sdm_t *  mat,
const cs_sdm_t *  add 
)

Add two small dense matrices: loc += add.

Parameters
[in,out]matlocal matrix storing the result
[in]addvalues to add to mat

◆ cs_sdm_add_mult()

void cs_sdm_add_mult ( cs_sdm_t *  mat,
cs_real_t  alpha,
const cs_sdm_t *  add 
)

Add two small dense matrices: loc += alpha*add.

Parameters
[in,out]matlocal matrix storing the result
[in]alphamultiplicative coefficient
[in]addvalues to add to mat

◆ cs_sdm_block_add()

void cs_sdm_block_add ( cs_sdm_t *  mat,
const cs_sdm_t *  add 
)

Add two matrices defined by block: loc += add.

Parameters
[in,out]matlocal matrix storing the result
[in]addvalues to add to mat

◆ cs_sdm_block_create()

cs_sdm_t* cs_sdm_block_create ( short int  n_max_blocks_by_row,
short int  n_max_blocks_by_col,
const short int  max_row_block_sizes[],
const short int  max_col_block_sizes[] 
)

Allocate and initialize a cs_sdm_t structure.

Parameters
[in]n_max_blocks_by_rowmax number of blocks in a row
[in]n_max_blocks_by_colmax number of blocks in a column
[in]max_row_block_sizesmax number of rows by block in a column
[in]max_col_block_sizesmax number of columns by block in a row
Returns
a new allocated cs_sdm_t structure

◆ cs_sdm_block_dump()

void cs_sdm_block_dump ( cs_lnum_t  parent_id,
const cs_sdm_t *  mat 
)

Dump a small dense matrix defined by blocks.

Parameters
[in]parent_idid of the related parent entity
[in]matpointer to the cs_sdm_t structure

◆ cs_sdm_block_init()

void cs_sdm_block_init ( cs_sdm_t *  m,
short int  n_blocks_by_row,
short int  n_blocks_by_col,
const short int  row_block_sizes[],
const short int  col_block_sizes[] 
)

Initialize the pattern of cs_sdm_t structure defined by block The matrix should have been allocated before calling this function.

Parameters
[in,out]m
[in]n_blocks_by_rownumber of blocks in a row
[in]n_blocks_by_colnumber of blocks in a column
[in]row_block_sizesnumber of rows by block in a column
[in]col_block_sizesnumber of columns by block in a row

◆ cs_sdm_block_multiply_rowrow()

void cs_sdm_block_multiply_rowrow ( const cs_sdm_t *  a,
const cs_sdm_t *  b,
cs_sdm_t *  c 
)

Compute a row-row matrix product of a and b. It is basically equal to the classical a*b^T. It is a fast (matrices are row-major) way of computing a*b if b is symmetric or if b^T is given. Case of matrices defined by block.

Compute a row-row matrix product of a and b. It is basically equal to the classical a*b^T. It is a fast (matrices are row-major) way of computing a*b if b is symmetric or if b^T is given. Case of a matrix defined by block.

Parameters
[in]alocal matrix to use
[in]blocal matrix to use
[in,out]cresult of the local matrix-product (already allocated) is updated

◆ cs_sdm_block_multiply_rowrow_sym()

void cs_sdm_block_multiply_rowrow_sym ( const cs_sdm_t *  a,
const cs_sdm_t *  b,
cs_sdm_t *  c 
)

Compute a row-row matrix product of a and b. It is basically equal to the classical a*b^T. It is a fast (matrices are row-major) way of computing a*b if b is symmetric or if b^T is given. Case of matrices defined by block. Results is known to be symmetric.

Parameters
[in]alocal matrix to use
[in]blocal matrix to use
[in,out]cresult of the local matrix-product (already allocated) is updated

◆ cs_sdm_create()

cs_sdm_t* cs_sdm_create ( cs_flag_t  flag,
int  n_max_rows,
int  n_max_cols 
)

Allocate and initialize a cs_sdm_t structure Most generic function to create a cs_sdm_t structure without block description.

Allocate and initialize a cs_sdm_t structure Most generic function to create a cs_sdm_t structure.

Parameters
[in]flagmetadata related to a cs_sdm_t structure
[in]n_max_rowsmax number of rows
[in]n_max_colsmax number of columns
Returns
a new allocated cs_sdm_t structure

◆ cs_sdm_create_copy()

cs_sdm_t* cs_sdm_create_copy ( const cs_sdm_t *  m)

Allocate a cs_sdm_t structure and initialized it with the copy of the matrix m in input.

Parameters
[in]mpointer to a cs_sdm_t structure to copy
Returns
a pointer to a new allocated cs_sdm_t structure

◆ cs_sdm_create_transpose()

cs_sdm_t* cs_sdm_create_transpose ( cs_sdm_t *  mat)

Define a new matrix by adding the given matrix with its transpose. Keep the transposed matrix for a future use.

Parameters
[in]matlocal matrix to transpose
Returns
a pointer to the new allocated transposed matrix

◆ cs_sdm_dump()

void cs_sdm_dump ( cs_lnum_t  parent_id,
const cs_lnum_t row_ids,
const cs_lnum_t col_ids,
const cs_sdm_t *  mat 
)

Dump a small dense matrix.

Parameters
[in]parent_idid of the related parent entity
[in]row_idslist of ids related to associated entities (or NULL)
[in]col_idslist of ids related to associated entities (or NULL)
[in]matpointer to the cs_sdm_t structure

◆ cs_sdm_free()

cs_sdm_t* cs_sdm_free ( cs_sdm_t *  mat)

Free a cs_sdm_t structure.

Parameters
[in]matpointer to a cs_sdm_t struct. to free
Returns
a NULL pointer

◆ cs_sdm_ldlt_compute()

void cs_sdm_ldlt_compute ( const cs_sdm_t *  m,
cs_real_t facto,
cs_real_t dkk 
)

LDL^T: Modified Cholesky decomposition of a SPD matrix. For more reference, see for instance http://mathforcollege.com/nm/mws/gen/04sle/mws_gen_sle_txt_cholesky.pdf.

Parameters
[in]mpointer to a cs_sdm_t structure
[in,out]factovector of the coefficient of the decomposition
[in,out]dkkstore temporary the diagonal (size = n_rows)

: facto is a lower triangular matrix. The first value of the j-th (zero-based) row is easily accessed: its index is j*(j+1)/2 (cf sum of the first j natural numbers). Instead of 1 on the diagonal we store the inverse of D mat in the L.D.L^T decomposition

◆ cs_sdm_ldlt_solve()

void cs_sdm_ldlt_solve ( int  n_rows,
const cs_real_t facto,
const cs_real_t rhs,
cs_real_t sol 
)

Solve a SPD matrix with a L.D.L^T (Modified Cholesky decomposition) The solution should be already allocated Reference: http://mathforcollege.com/nm/mws/gen/04sle/mws_gen_sle_txt_cholesky.pdf.

Parameters
[in]n_rowsdimension of the system to solve
[in]factovector of the coefficients of the decomposition
[in]rhsright-hand side
[in,out]solsolution

◆ cs_sdm_matvec()

void cs_sdm_matvec ( const cs_sdm_t *  mat,
const cs_real_t vec,
cs_real_t mv 
)

Compute a dense matrix-vector product for a rectangular matrix mv has been previously allocated.

Parameters
[in]matlocal matrix to use
[in]veclocal vector to use (size = mat->n_cols)
[in,out]mvresult of the operation (size = mat->n_rows)

◆ cs_sdm_multiply()

void cs_sdm_multiply ( const cs_sdm_t *  a,
const cs_sdm_t *  b,
cs_sdm_t *  c 
)

Compute a local dense matrix-product c = a*b c has been previously allocated.

Parameters
[in]alocal dense matrix to use
[in]blocal dense matrix to use
[in,out]cresult of the local matrix-product is updated

◆ cs_sdm_multiply_rowrow()

void cs_sdm_multiply_rowrow ( const cs_sdm_t *  a,
const cs_sdm_t *  b,
cs_sdm_t *  c 
)

Compute a row-row matrix product of a and b. It is basically equal to the classical a*b^T. It is a fast (matrices are row-major) way of computing a*b if b is symmetric or if b^T is given. Generic version: all compatible sizes.

Parameters
[in]alocal matrix to use
[in]blocal matrix to use
[in,out]cresult of the local matrix-product (already allocated) is updated.

◆ cs_sdm_multiply_rowrow_sym()

void cs_sdm_multiply_rowrow_sym ( const cs_sdm_t *  a,
const cs_sdm_t *  b,
cs_sdm_t *  c 
)

Compute a row-row matrix product of a and b. It is basically equal to the classical a*b^T. It is a fast (matrices are row-major) way of computing a*b if b is symmetric or if b^T is given. Generic version: all compatible sizes Result is known to be symmetric.

Parameters
[in]alocal matrix to use
[in]blocal matrix to use
[in,out]cresult of the local matrix-product (already allocated) is updated.

◆ cs_sdm_simple_dump()

void cs_sdm_simple_dump ( const cs_sdm_t *  mat)

Dump a small dense matrix.

Parameters
[in]matpointer to the cs_sdm_t structure

◆ cs_sdm_square_add_transpose()

void cs_sdm_square_add_transpose ( cs_sdm_t *  mat,
cs_sdm_t *  tr 
)

Define a new matrix by adding the given matrix with its transpose. Keep the transposed matrix for a future use.

Parameters
[in,out]matlocal matrix to transpose and add
[in,out]trtransposed of the local matrix

◆ cs_sdm_square_asymm()

void cs_sdm_square_asymm ( cs_sdm_t *  mat)

Set the given matrix into its anti-symmetric part.

Parameters
[in,out]matsmall dense matrix to transform

◆ cs_sdm_square_create()

cs_sdm_t* cs_sdm_square_create ( int  n_max_rows)

Allocate and initialize a cs_sdm_t structure Case of a square matrix.

Parameters
[in]n_max_rowsmax number of rows
Returns
a new allocated cs_sdm_t structure

◆ cs_sdm_square_matvec()

void cs_sdm_square_matvec ( const cs_sdm_t *  mat,
const cs_real_t vec,
cs_real_t mv 
)

Compute a dense matrix-vector product for a small square matrix mv has been previously allocated.

Parameters
[in]matlocal matrix to use
[in]veclocal vector to use
[in,out]mvresult of the local matrix-vector product

Variable Documentation

◆ _msg_small_p

const char _msg_small_p[]
static
Initial value:
=
" %s: Very small or null pivot.\n Stop inversion."