jacobi_C-Style
Functions
getmatrix.cpp File Reference
#include "getmatrix.h"
#include "userset.h"
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <vector>

Go to the source code of this file.

Functions

void Get_Matrix_Pattern (int const nelem, int const ndof_e, int const *const ia, int &nnz, int *&id, int *&ik, double *&sk)
 
void CalcElem (int const ial[3], double const xc[], double ske[3][3], double fe[3])
 
void AddElem (int const ial[3], double const ske[3][3], double const fe[3], int const id[], int const ik[], double sk[], double f[])
 
void DebugMatrix (int const nnode, int const id[], int const ik[], double const sk[])
 
void DebugVector (int const nnode, double const v[])
 
int fetch (int const row, int const col, int const id[], int const ik[])
 
void Defect (double w[], double const f[], double const u[], int const nnode, int const id[], int const ik[], double const sk[])
 
void CrsMult (double w[], double const u[], int const nnode, int const id[], int const ik[], double const sk[])
 
void GetDiag (int const nnode, int const id[], int const ik[], double const sk[], double d[])
 
void GetMatrix (int const nelem, int const ndof_e, int const ia[], int const nnode, double const xc[], int const nnz, int const id[], int const ik[], double sk[], double f[])
 
void ApplyDirichletBC (int const nx, int const ny, int const neigh[], double const u[], int const id[], int const ik[], double sk[], double f[])
 

Function Documentation

◆ AddElem()

void AddElem ( int const  ial[3],
double const  ske[3][3],
double const  fe[3],
int const  id[],
int const  ik[],
double  sk[],
double  f[] 
)

Adds the element stiffness matrix ske and the element load vector fe of one triangular element with linear shape functions to the appropriate positions in the symmetric stiffness matrix, stored as CSR matrix K(sk,id, ik)

Parameters
[in]ialnode indices of the three element vertices
[in]skeelement stiffness matrix
[in]feelement load vector
[out]skvector non-zero entries of CSR matrix
[in]idindex vector containing the first entry in a CSR row
[in]ikcolumn index vector of CSR matrix
[out]fdistributed local vector storing the right hand side

Definition at line 97 of file getmatrix.cpp.

◆ ApplyDirichletBC()

void ApplyDirichletBC ( int const  nx,
int const  ny,
int const  neigh[],
double const  u[],
int const  id[],
int const  ik[],
double  sk[],
double  f[] 
)

Applies Dirichlet boundary conditions to symmetric CSR matrix (sk,id, ik) and right hand side f of a system of equations resulting from a FEM/FDM discretization

Parameters
[in]nxnumber of discretization intervals in x-direction
[in]nynumber of discretization intervals in y-direction
[in]neighvector of 4 elements containing the ranks of neighbouring processes, -1 indicates a boundary in this direction
[in]ulocal vector with appropriately initialized b.c.
[in]idindex vector containing the first entry in a CSR row
[in]ikcolumn index vector of CSR matrix
[in,out]skvector non-zero entries of CSR matrix
[in,out]fright hand side

Definition at line 275 of file getmatrix.cpp.

◆ CalcElem()

void CalcElem ( int const  ial[3],
double const  xc[],
double  ske[3][3],
double  fe[3] 
)

Calculates the element stiffness matrix ske and the element load vector fe of one triangular element with linear shape functions.

Parameters
[in]ialnode indices of the three element vertices
[in]xcvector of node coordinates with x(2*k,2*k+1) as coodinates of node k
[out]skeelement stiffness matrix
[out]feelement load vector

Definition at line 68 of file getmatrix.cpp.

◆ CrsMult()

void CrsMult ( double  w[],
double const  u[],
int  nnode,
int const  id[],
int const  ik[],
double const  sk[] 
)

Multiplies vector u with a CSR matrix K(id, ik, sk). w := K*u

Parameters
[out]wdistributed local vector.
[in]uaccumulated local vector.
[in]nnodenumber of rows
[in]idindex vector containing the first entry in a CSR row
[in]ikcolumn index vector of CSR matrix
[in]skvector non-zero entries of CSR matrix

Definition at line 206 of file getmatrix.cpp.

◆ DebugMatrix()

void DebugMatrix ( int const  nnode,
int const  id[],
int const  ik[],
double const  sk[] 
)

Print entries of the CSR matrix K(id, ik, sk).

Parameters
[in]nnodenumber of rows
[in]idindex vector containing the first entry in a CSR row
[in]ikcolumn index vector of CSR matrix
[in]skvector non-zero entries of CSR matrix

Definition at line 132 of file getmatrix.cpp.

◆ DebugVector()

void DebugVector ( int const  nnode,
double const  v[] 
)

Print entries of a vector.

Parameters
[in]nnodenumber of entries
[in]vvector values

Definition at line 154 of file getmatrix.cpp.

◆ Defect()

void Defect ( double  w[],
double const  f[],
double const  u[],
int  nnode,
int const  id[],
int const  ik[],
double const  sk[] 
)

Calculates the defect w := f - K*u a CSR matrix K(id, ik, sk).

Parameters
[out]wdistributed local vector.
[in]fdistributed local vector.
[in]uaccumulated local vector.
[in]nnodenumber of rows
[in]idindex vector containing the first entry in a CSR row
[in]ikcolumn index vector of CSR matrix
[in]skvector non-zero entries of CSR matrix

Definition at line 191 of file getmatrix.cpp.

◆ fetch()

int fetch ( int const  row,
int const  col,
int const  id[],
int const  ik[] 
)

Finds in a CRS matrix the access index for an entry at row row and column col.

Parameters
[in]rowrow index
[in]colcolumn index
[in]idindex vector containing the first entry in a CSR row
[in]ikcolumn index vector of CSR matrix
Returns
index for element (row, col). If no appropriate entry exists then -1 will be returned.
Warning
assert() stops the function in case that element (row, col) doesn't exist.

Definition at line 170 of file getmatrix.cpp.

◆ Get_Matrix_Pattern()

void Get_Matrix_Pattern ( int const  nelem,
int const  ndof_e,
int const *const  ia,
int &  nnz,
int *&  id,
int *&  ik,
double *&  sk 
)

Determines the matrix graph of an CRS matrix (id, ik, sk) based on the element connectivity ia.

The memory for arrays id, ik, sk is allocated inside the function.

Parameters
[in]nelemnumber of triangular elements
[in]ndof_enumber of f.e. nodes per element
[in]iaelement connectivity array[nelem][ndof_e] for linear triangular elements
[out]nnznumber of non-zero elements in matrix
[out]idarray[nnode+1] storing indices of first entry of a row (is allocated in function)
[out]ikarray[nnz] storing column indices of non-zero entries (is allocated in function)
[out]skarray[nnz] storing values of non-zero entries (is allocated in function)

Definition at line 14 of file getmatrix.cpp.

◆ GetDiag()

void GetDiag ( int  nnode,
int const  id[],
int const  ik[],
double const  sk[],
double  d[] 
)

Copies the diagonal entries of a CSR matrix (sk,id, ik) onto a vector d.

Parameters
[in]nnodenumber of rows
[in]idindex vector containing the first entry in a CSR row
[in]ikcolumn index vector of CSR matrix
[in]skvector non-zero entries of CSR matrix
[out]daccumulated diagonal entries of CSR matrix

Definition at line 223 of file getmatrix.cpp.

◆ GetMatrix()

void GetMatrix ( int const  nelem,
int const  ndof_e,
int const  ia[],
int const  nnode,
double const  xc[],
int const  nnz,
int const  id[],
int const  ik[],
double  sk[],
double  f[] 
)

Computes the stiffness matrix in CRS format(id, ik, sk) and load vector f for the Poisson problem without incorporating the boundary conditions The matrix pattern has to be generated previously and the memory has to be allocated therein.

See also
Get_Matrix_Pattern
Parameters
[in]nelemnumber of finite elements
[in]ndof_edegrees of freedom per element
[in]iaelement connectivity array[nelem][ndof_e]
[in]nnodenumber of coordinates (== number of unknowns)
[in]xccoordinates[nnode][2]
[in]nnznumber of non-zero entries in CRS matrix
[in]idindex vector containing the first entry in a CSR row
[in]ikcolumn index vector of CSR matrix
[out]skvector of non-zero entries of CSR matrix
[out]fdistributed local vector storing the right hand side

Definition at line 243 of file getmatrix.cpp.