23 #include "grass/gis.h"
24 #include "grass/glocale.h"
25 #include "grass/gmath.h"
28 #define COMP_PIVOT 100
45 G_message(_(
"Starting direct gauss elimination solver"));
73 G_message(_(
"Starting direct lu decomposition solver"));
83 #pragma omp for schedule (static) private(i)
84 for (i = 0; i < rows; i++) {
94 #pragma omp for schedule (static) private(i)
95 for (i = 0; i < rows; i++) {
130 G_message(_(
"Starting cholesky decomposition solver"));
133 G_warning(_(
"Unable to solve the linear equation system"));
165 for (k = 0; k < rows - 1; k++) {
166 #pragma omp parallel for schedule (static) private(i, j, tmpval) shared(k, A, b, rows)
167 for (i = k + 1; i < rows; i++) {
168 tmpval = A[i][k] / A[k][k];
169 b[i] = b[i] - tmpval * b[k];
170 for (j = k + 1; j < rows; j++) {
171 A[i][j] = A[i][j] - tmpval * A[k][j];
201 for (k = 0; k < rows - 1; k++) {
202 #pragma omp parallel for schedule (static) private(i, j) shared(k, A, rows)
203 for (i = k + 1; i < rows; i++) {
204 A[i][k] = A[i][k] / A[k][k];
205 for (j = k + 1; j < rows; j++) {
206 A[i][j] = A[i][j] - A[i][k] * A[k][j];
230 int i = 0, j = 0, k = 0;
243 for (k = 0; k < rows; k++) {
244 #pragma omp parallel for schedule (static) private(i, j, sum_2) shared(A, k) reduction(+:sum_1)
245 for (j = 0; j < k; j++) {
246 sum_1 += A[k][j] * A[k][j];
249 if (0 > (A[k][k] - sum_1)) {
250 G_warning(
"Matrix is not positive definite. break.");
253 A[k][k] = sqrt(A[k][k] - sum_1);
256 if ((k + bandwith) > rows) {
260 colsize = k + bandwith;
263 #pragma omp parallel for schedule (static) private(i, j, sum_2) shared(A, k, sum_1, colsize)
265 for (i = k + 1; i < colsize; i++) {
267 for (j = 0; j < k; j++) {
268 sum_2 += A[i][j] * A[k][j];
270 A[i][k] = (A[i][k] - sum_2) / A[k][k];
275 #pragma omp parallel for schedule (static) private(i, k) shared(A, rows)
276 for (k = 0; k < rows; k++) {
277 for (i = k + 1; i < rows; i++) {
300 for (i = rows - 1; i >= 0; i--) {
301 for (j = i + 1; j < rows; j++) {
302 b[i] = b[i] - A[i][j] * x[j];
304 x[i] = (b[i]) / A[i][i];
326 for (i = 0; i < rows; i++) {
328 for (j = 0; j < i; j++) {
329 tmpval += A[i][j] * x[j];
331 x[i] = (b[i] - tmpval) / A[i][i];
367 double tmpval = 0.0,
s = 0.0;
373 G_debug(2,
"G_math_pivot_create: swap rows if needed");
374 for (i = start; i < rows; i++) {
376 for (k = i + 1; k < rows; k++) {
379 max = fabs(A[i][i]) /
s;
381 for (j = i + 1; j < rows; j++) {
383 for (k = j; k < rows; k++) {
387 if (max < fabs(A[j][i]) /
s) {
388 max = fabs(A[j][i] /
s);
399 G_debug(4,
"swap row %i with row %i", i, number);
int G_math_solver_lu(double **A, double *x, double *b, int rows)
The LU solver for quardatic matrices.
void G_free(void *buf)
Free allocated memory.
void G_math_forward_solving(double **A, double *x, double *b, int rows)
forward solving
int G_math_solver_cholesky(double **A, double *x, double *b, int bandwith, int rows)
The choleksy decomposition solver for quardatic, symmetric positiv definite matrices.
int G_math_cholesky_decomposition(double **A, int rows, int bandwith)
cholesky decomposition for symmetric, positiv definite matrices with bandwith optimization ...
int G_math_pivot_create(double **A, double *b, int rows, int start)
Optimize the structure of the linear equation system with a common pivoting strategy.
int G_math_solver_gauss(double **A, double *x, double *b, int rows)
The gauss elimination solver for quardatic matrices.
void G_math_lu_decomposition(double **A, double *b, int rows)
lu decomposition
void G_free_vector(double *v)
Vector memory deallocation.
void G_message(const char *msg,...)
Print a message to stderr.
void G_math_d_copy(double *x, double *y, int rows)
Copy the vector x to y.
void G_math_backward_solving(double **A, double *x, double *b, int rows)
backward solving
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int G_debug(int level, const char *msg,...)
Print debugging message.
void G_math_gauss_elimination(double **A, double *b, int rows)
Gauss elimination.
double * G_alloc_vector(size_t n)
Vector matrix memory allocation.