2019-01-11 00:42:29 +08:00
|
|
|
#include "taucs.h"
|
|
|
|
#include "placer_math.h"
|
|
|
|
#include <stdio.h>
|
2019-01-11 03:10:47 +08:00
|
|
|
#include <assert.h>
|
2019-01-11 00:42:29 +08:00
|
|
|
|
|
|
|
void taucif_init_solver() {
|
2019-01-25 22:04:19 +08:00
|
|
|
//taucs_logfile("stdout");
|
2019-01-11 00:42:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct taucif_system {
|
|
|
|
taucs_ccs_matrix* mat;
|
|
|
|
int ccs_i, ccs_col;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct taucif_system *taucif_create_system(int rows, int cols, int n_nonzero) {
|
|
|
|
struct taucif_system *sys = taucs_malloc(sizeof(struct taucif_system));
|
2019-01-11 03:10:47 +08:00
|
|
|
sys->mat = taucs_ccs_create(cols, rows, n_nonzero, TAUCS_DOUBLE | TAUCS_SYMMETRIC | TAUCS_LOWER);
|
2019-01-11 00:42:29 +08:00
|
|
|
// Internal pointers
|
|
|
|
sys->ccs_i = 0;
|
|
|
|
sys->ccs_col = -1;
|
|
|
|
return sys;
|
|
|
|
};
|
|
|
|
|
2019-01-11 03:10:47 +08:00
|
|
|
void taucif_add_matrix_value(struct taucif_system *sys, int row, int col, double value) {
|
|
|
|
assert(sys->ccs_col <= col);
|
2019-01-11 00:42:29 +08:00
|
|
|
while(sys->ccs_col < col) {
|
|
|
|
sys->mat->colptr[++sys->ccs_col] = sys->ccs_i;
|
|
|
|
}
|
|
|
|
sys->mat->rowind[sys->ccs_i] = row;
|
|
|
|
sys->mat->values.d[sys->ccs_i++] = value;
|
|
|
|
}
|
|
|
|
|
2019-01-11 03:10:47 +08:00
|
|
|
void taucif_finalise_matrix(struct taucif_system *sys) {
|
|
|
|
sys->mat->colptr[++sys->ccs_col] = sys->ccs_i;
|
|
|
|
#if 0
|
|
|
|
taucs_ccs_write_ijv(sys->mat, "matrix.ijv");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int taucif_solve_system(struct taucif_system *sys, double *x, double *rhs) {
|
2019-01-11 00:42:29 +08:00
|
|
|
// FIXME: preconditioner, droptol??
|
2019-01-25 22:04:19 +08:00
|
|
|
taucs_ccs_matrix* precond_mat = taucs_ccs_factor_llt(sys->mat, 1e-2, 0);
|
2019-01-11 03:10:47 +08:00
|
|
|
if (precond_mat == NULL)
|
|
|
|
return -1;
|
2019-01-11 00:42:29 +08:00
|
|
|
// FIXME: itermax, convergetol
|
|
|
|
int cjres = taucs_conjugate_gradients(sys->mat, taucs_ccs_solve_llt, precond_mat, x, rhs, 1000, 1e-6);
|
|
|
|
taucs_ccs_free(precond_mat);
|
2019-01-11 03:10:47 +08:00
|
|
|
return 0;
|
2019-01-11 00:42:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void taucif_free_system(struct taucif_system *sys) {
|
|
|
|
taucs_ccs_free(sys->mat);
|
2019-01-11 03:10:47 +08:00
|
|
|
taucs_free(sys);
|
2019-01-11 00:42:29 +08:00
|
|
|
}
|
|
|
|
|