MPI_jacsolve
 All Files Functions
Functions
getmatrix.cpp File Reference
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <cassert>
#include "getmatrix.h"
#include "userset.h"

Functions

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

Function Documentation

void AddElem ( const int  ial[3],
const double  ske[3][3],
const double  fe[3],
const int  id[],
const int  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 last entry in a CSR row
[in]ikcolumn index vector of CSR matrix
[out]fdistributed local vector storing the right hand side
void ApplyDirichletBC ( const int  nx,
const int  ny,
const int  neigh[],
const double  u[],
const int  id[],
const int  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 last 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
void CalcElem ( const int  ial[3],
const double  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
void CrsMult ( double  w[],
const double  u[],
const int  nnode,
const int  id[],
const int  ik[],
const double  sk[] 
)

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

Parameters
[in,out]wdistributed local vector.
[in]uaccumulated local vector.
[in]nnodenumber of rows
[in]idindex vector containing the last entry in a CSR row
[in]ikcolumn index vector of CSR matrix
[in]skvector non-zero entries of CSR matrix
void DebugMatrix ( const int  nnode,
const int  id[],
const int  ik[],
const double  sk[] 
)

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

Parameters
[in]nnodenumber of rows
[in]idindex vector containing the last entry in a CSR row
[in]ikcolumn index vector of CSR matrix
[in]skvector non-zero entries of CSR matrix
void DebugVector ( const int  nnode,
const double  v[] 
)

Print entries of a vector.

Parameters
[in]nnodenumber of entries
[in]vvector values
void Defect ( double  w[],
const double  f[],
const double  u[],
const int  nnode,
const int  id[],
const int  ik[],
const double  sk[] 
)

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

Parameters
[in,out]wdistributed local vector.
[in]fdistributed local vector.
[in]uaccumulated local vector.
[in]nnodenumber of rows
[in]idindex vector containing the last entry in a CSR row
[in]ikcolumn index vector of CSR matrix
[in]skvector non-zero entries of CSR matrix
int fetch ( const int  row,
const int  col,
const int  id[],
const int  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.
void Get_Matrix_Pattern ( const int  nelem,
const int  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
[out]ik[nnz]array storing column indices of non-zero entries
[out]sk[nnz]array storing values of non-zero entries
void GetDiag ( const int  nnode,
const int  id[],
const int  ik[],
const double  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 last 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
void GetMatrix ( const int  nelem,
const int  ndof_e,
const int  ia[],
const int  nnode,
const double  xc[],
const int  nnz,
const int  id[],
const int  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 last 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