#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[]) |
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
)
[in] | ial | node indices of the three element vertices |
[in] | ske | element stiffness matrix |
[in] | fe | element load vector |
[out] | sk | vector non-zero entries of CSR matrix |
[in] | id | index vector containing the last entry in a CSR row |
[in] | ik | column index vector of CSR matrix |
[out] | f | distributed 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
[in] | nx | number of discretization intervals in x-direction |
[in] | ny | number of discretization intervals in y-direction |
[in] | neigh | vector of 4 elements containing the ranks of neighbouring processes, -1 indicates a boundary in this direction |
[in] | u | local vector with appropriately initialized b.c. |
[in] | id | index vector containing the last entry in a CSR row |
[in] | ik | column index vector of CSR matrix |
[in,out] | sk | vector non-zero entries of CSR matrix |
[in,out] | f | right 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.
[in] | ial | node indices of the three element vertices |
[in] | xc | vector of node coordinates with x(2*k,2*k+1) as coodinates of node k |
[out] | ske | element stiffness matrix |
[out] | fe | element 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
[in,out] | w | distributed local vector. |
[in] | u | accumulated local vector. |
[in] | nnode | number of rows |
[in] | id | index vector containing the last entry in a CSR row |
[in] | ik | column index vector of CSR matrix |
[in] | sk | vector 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(sk
,id
, ik
).
[in] | nnode | number of rows |
[in] | id | index vector containing the last entry in a CSR row |
[in] | ik | column index vector of CSR matrix |
[in] | sk | vector non-zero entries of CSR matrix |
void DebugVector | ( | const int | nnode, |
const double | v[] | ||
) |
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
).
[in,out] | w | distributed local vector. |
[in] | f | distributed local vector. |
[in] | u | accumulated local vector. |
[in] | nnode | number of rows |
[in] | id | index vector containing the last entry in a CSR row |
[in] | ik | column index vector of CSR matrix |
[in] | sk | vector 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
.
[in] | row | row index |
[in] | col | column index |
[in] | id | index vector containing the first entry in a CSR row |
[in] | ik | column index vector of CSR matrix |
row
, col
). If no appropriate entry exists then -1 will be returned.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.
[in] | nelem | number of triangular elements |
[in] | ndof_e | number of f.e. nodes per element |
[in] | ia | element connectivity array[nelem][ndof_e] for linear triangular elements |
[out] | nnz | number of non-zero elements in matrix |
[out] | id | array[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
.
[in] | nnode | number of rows |
[in] | id | index vector containing the last entry in a CSR row |
[in] | ik | column index vector of CSR matrix |
[in] | sk | vector non-zero entries of CSR matrix |
[out] | d | accumulated 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 memery has to be allocated.
[in] | nelem | number of finite elements |
[in] | ndof_e | degrees of freedom per element |
[in] | ia | element connectivity array[nelem][ndof_e] |
[in] | nnode | number of coordinates (== number of unknowns) |
[in] | xc | coordinates[nnode][2] |
[in] | nnz | number of non-zero entries in CRS matrix |
[in] | id | index vector containing the last entry in a CSR row |
[in] | ik | column index vector of CSR matrix |
[out] | sk | vector of non-zero entries of CSR matrix |
[out] | f | distributed local vector storing the right hand side |