mirror of
https://github.com/OPM/opm-simulators.git
synced 2024-12-26 17:20:59 -06:00
Add a routine for allocating a CSR matrix with known number of rows
and non-zeros. Note that this routine is for allocation only. Caller must create and manage sparsity structure if this is being used in a global assembly process. This routine finds utility in MsMFEM BF construction.
This commit is contained in:
parent
1e2e18bda2
commit
284683b00d
32
sparse_sys.c
32
sparse_sys.c
@ -37,6 +37,38 @@ csrmatrix_new_count_nnz(size_t m)
|
||||
}
|
||||
|
||||
|
||||
/* Allocate CSR matrix, known nnz. Allocation only. Caller must
|
||||
* build sparsity structure before using in global assembly.
|
||||
*
|
||||
* Returns fully allocated structure if successful and NULL otherwise. */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
struct CSRMatrix *
|
||||
csrmatrix_new_known_nnz(size_t m, size_t nnz)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
struct CSRMatrix *new;
|
||||
|
||||
new = malloc(1 * sizeof *new);
|
||||
|
||||
if (new != NULL) {
|
||||
new->ia = malloc((m + 1) * sizeof *new->ia);
|
||||
new->ja = malloc(nnz * sizeof *new->ja);
|
||||
new->sa = malloc(nnz * sizeof *new->sa);
|
||||
|
||||
if ((new->ia == NULL) || (new->ja == NULL) || (new->sa == NULL)) {
|
||||
csrmatrix_delete(new);
|
||||
new = NULL;
|
||||
} else {
|
||||
new->m = m;
|
||||
new->n = 0;
|
||||
new->nnz = nnz;
|
||||
}
|
||||
}
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
size_t
|
||||
csrmatrix_new_elms_pushback(struct CSRMatrix *A)
|
||||
|
@ -35,6 +35,9 @@ struct CSRMatrix
|
||||
struct CSRMatrix *
|
||||
csrmatrix_new_count_nnz(size_t m);
|
||||
|
||||
struct CSRMatrix *
|
||||
csrmatrix_new_known_nnz(size_t m, size_t nnz);
|
||||
|
||||
size_t
|
||||
csrmatrix_new_elms_pushback(struct CSRMatrix *A);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user