Flatten loops and prefer memcpy() to manual copying.
This commit is contained in:
parent
7cd1a9ed05
commit
7ca9f6525d
@ -151,9 +151,9 @@ well_controls_reserve(int nctrl, int nphases, struct WellControls *ctrl)
|
|||||||
|
|
||||||
struct WellControlMgmt *m;
|
struct WellControlMgmt *m;
|
||||||
|
|
||||||
type = realloc(ctrl->type , nctrl * sizeof *ctrl->type );
|
type = realloc(ctrl->type , nctrl * 1 * sizeof *ctrl->type );
|
||||||
target = realloc(ctrl->target, nctrl * sizeof *ctrl->target);
|
target = realloc(ctrl->target, nctrl * 1 * sizeof *ctrl->target);
|
||||||
distr = realloc(ctrl->distr , nphases * nctrl * sizeof *ctrl->distr );
|
distr = realloc(ctrl->distr , nctrl * nphases * sizeof *ctrl->distr );
|
||||||
|
|
||||||
ok = 0;
|
ok = 0;
|
||||||
if (type != NULL) { ctrl->type = type ; ok++; }
|
if (type != NULL) { ctrl->type = type ; ok++; }
|
||||||
@ -165,9 +165,10 @@ well_controls_reserve(int nctrl, int nphases, struct WellControls *ctrl)
|
|||||||
for (c = m->cpty; c < nctrl; c++) {
|
for (c = m->cpty; c < nctrl; c++) {
|
||||||
ctrl->type [c] = BHP;
|
ctrl->type [c] = BHP;
|
||||||
ctrl->target[c] = -1.0;
|
ctrl->target[c] = -1.0;
|
||||||
for (p = 0; p < nphases; ++p) {
|
|
||||||
ctrl->distr [nphases*c + p] = 0.0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (p = m->cpty * nphases; p < nctrl * nphases; ++p) {
|
||||||
|
ctrl->distr[ p ] = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
m->cpty = nctrl;
|
m->cpty = nctrl;
|
||||||
@ -513,11 +514,12 @@ append_well_controls(enum WellControlType type,
|
|||||||
if (ok) {
|
if (ok) {
|
||||||
ctrl->type [ctrl->num] = type ;
|
ctrl->type [ctrl->num] = type ;
|
||||||
ctrl->target[ctrl->num] = target;
|
ctrl->target[ctrl->num] = target;
|
||||||
|
|
||||||
if (distr != NULL) {
|
if (distr != NULL) {
|
||||||
for (p = 0; p < np; ++p) {
|
memcpy(ctrl->distr + (ctrl->num * np), distr,
|
||||||
ctrl->distr[ctrl->num * np + p] = distr[p];
|
np * sizeof *ctrl->distr);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ctrl->num += 1;
|
ctrl->num += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user