Call malloc() once, at pimpl construction time, rather than in each *_increment().

It's slightly wasteful, however.  Maybe we can just reuse h->x for the
mult_csr_matrix() output?
This commit is contained in:
Bård Skaflestad 2012-05-09 19:15:41 +02:00
parent 00b1ce27f0
commit 97ed64f438

View File

@ -33,6 +33,7 @@ mult_csr_matrix(const struct CSRMatrix *A,
struct ifs_tpfa_impl {
double *fgrav; /* Accumulated grav contrib/face */
double *work;
/* Linear storage */
double *ddata;
@ -70,6 +71,7 @@ impl_allocate(struct UnstructuredGrid *G,
ddata_sz = 2 * nnu; /* b, x */
ddata_sz += 1 * G->number_of_faces; /* fgrav */
ddata_sz += 1 * nnu; /* work */
new = malloc(1 * sizeof *new);
@ -677,6 +679,7 @@ ifs_tpfa_construct(struct UnstructuredGrid *G,
new->x = new->b + new->A->m;
new->pimpl->fgrav = new->x + new->A->m;
new->pimpl->work = new->pimpl->fgrav + G->number_of_faces;
}
return new;
@ -766,8 +769,7 @@ ifs_tpfa_assemble_comprock_increment(struct UnstructuredGrid *G ,
assemble_incompressible(G, F, trans, gpress, h, &system_singular, &ok);
v = malloc(h->A->m * sizeof *v);
v = h->pimpl->work;
mult_csr_matrix(h->A, prev_pressure, v);
/* We want to solve a Newton step for the residual
@ -783,8 +785,6 @@ ifs_tpfa_assemble_comprock_increment(struct UnstructuredGrid *G ,
}
}
free(v);
return ok;
}