HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
matops.h File Reference

Contains macros and function definitions for common matrix operations. More...

#include <stdio.h>

Go to the source code of this file.

Macros

#define _MatrixZero_(A, N)
 
#define _MatrixMultiply_(A, B, C, N)
 
#define _MatrixMultiplyNonSquare_(A, B, C, NRowA, NColA, NColB)
 
#define _MatrixMultiplySubtract_(C, A, B, N)
 
#define _MatVecMultiply_(A, x, y, N)
 
#define _MatVecMultiplySubtract_(y, A, x, N)
 
#define _MatrixInvert_(A, B, N)
 

Detailed Description

Contains macros and function definitions for common matrix operations.

Author
Debojyoti Ghosh

Definition in file matops.h.

Macro Definition Documentation

#define _MatrixZero_ (   A,
 
)
Value:
{ \
int arraycounter; \
for (arraycounter=0; arraycounter<(N)*(N); arraycounter++) *((A)+arraycounter) = 0.0; \
}

Set all elements of the square matrix A of size N to 0, stored as a 1D array in row-major format.

Definition at line 15 of file matops.h.

#define _MatrixMultiply_ (   A,
  B,
  C,
 
)
Value:
{ \
int matopsi,matopsj,matopsk; \
for (matopsi=0; matopsi<(N); matopsi++) \
for (matopsj=0; matopsj<(N); matopsj++) { \
*((C)+matopsi*(N)+matopsj) = 0; \
for (matopsk=0; matopsk<(N); matopsk++) *((C)+matopsi*(N)+matopsj) += ((*((A)+matopsi*(N)+matopsk)) * (*((B)+matopsk*(N)+matopsj))); \
} \
}

C = A B, where A, B, C are square matrices of size N, stored as 1D arrays in row major format.

Definition at line 25 of file matops.h.

#define _MatrixMultiplyNonSquare_ (   A,
  B,
  C,
  NRowA,
  NColA,
  NColB 
)
Value:
{ \
int matopsi,matopsj,matopsk; \
for (matopsi=0; matopsi<(NRowA); matopsi++) \
for (matopsj=0; matopsj<(NColB); matopsj++) { \
*((C)+matopsi*(NColB)+matopsj) = 0; \
for (matopsk=0; matopsk<(NColA); matopsk++) *((C)+matopsi*(NColB)+matopsj) += ((*((A)+matopsi*(NColA)+matopsk)) * (*((B)+matopsk*(NColB)+matopsj))); \
} \
}

C = A B where A is a NRowA X NColA matrix, B is a NColA X NColB matrix, and C is a NRowA X NColB matrix. All matrices are stored as 1D arrays in row-major format.

Definition at line 40 of file matops.h.

#define _MatrixMultiplySubtract_ (   C,
  A,
  B,
 
)
Value:
{ \
int matopsi,matopsj,matopsk; \
for (matopsi=0; matopsi<(N); matopsi++) \
for (matopsj=0; matopsj<(N); matopsj++) \
for (matopsk=0; matopsk<(N); matopsk++) *((C)+matopsi*(N)+matopsj) -= ((*((A)+matopsi*(N)+matopsk)) * (*((B)+matopsk*(N)+matopsj))); \
} \

C = C - A B, where A, B, C are square matrices of size N, saved as 1D arrays in row-major format.

Definition at line 54 of file matops.h.

#define _MatVecMultiply_ (   A,
  x,
  y,
 
)
Value:
{ \
int matopsi,matopsj; \
for (matopsi=0; matopsi<(N); matopsi++) { \
*((y)+matopsi) = 0; \
for (matopsj=0; matopsj<(N); matopsj++) *((y)+matopsi) += (*((A)+matopsi*N+matopsj) * *((x)+matopsj)); \
} \
}

y = A x, where x, y are vectors of size N, and A is a square matrix of size N stored as a 1D array in row major format.

Definition at line 67 of file matops.h.

#define _MatVecMultiplySubtract_ (   y,
  A,
  x,
 
)
Value:
{ \
int matopsi,matopsj; \
for (matopsi=0; matopsi<N; matopsi++) \
for (matopsj=0; matopsj<(N); matopsj++) *((y)+matopsi) -= (*((A)+matopsi*N+matopsj) * *((x)+matopsj)); \
}

y = y - A x, where x, y are vectors of size N, and A is a square matrix of size N stored as a 1D array in row major format.

Definition at line 81 of file matops.h.

#define _MatrixInvert_ (   A,
  B,
 
)

B =A^{-1} (Inverse of A), where A, B are square matrices of size N stored as 1D arrays in row-major format. Uses LU decomposition. If A is singular, B will contain NaN or Inf.

Definition at line 93 of file matops.h.