From 157d0870f2af3b29ec1715dd438a35c8873227fd Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Sun, 5 Jan 2014 14:54:56 +0100 Subject: [PATCH] Removed struct WellControlManagement and replaced with simple integer field cpty in the WellControls structure. --- opm/core/well_controls.h | 11 ++++----- opm/core/wells/well_controls.c | 42 ++++------------------------------ opm/core/wells/wells.c | 6 ++--- 3 files changed, 11 insertions(+), 48 deletions(-) diff --git a/opm/core/well_controls.h b/opm/core/well_controls.h index 0d5fd388c..1e44f9ebe 100644 --- a/opm/core/well_controls.h +++ b/opm/core/well_controls.h @@ -86,10 +86,10 @@ struct WellControls */ int current; - /** - * Internal management structure. - */ - void *data; + /* + The capacity allocated. + */ + int cpty; }; bool @@ -105,9 +105,6 @@ void well_controls_destroy(struct WellControls *ctrl); -struct WellControlMgmt { - int cpty; -}; diff --git a/opm/core/wells/well_controls.c b/opm/core/wells/well_controls.c index 6ebdbcafe..9ad355941 100644 --- a/opm/core/wells/well_controls.c +++ b/opm/core/wells/well_controls.c @@ -42,26 +42,6 @@ #include -static void -destroy_ctrl_mgmt(struct WellControlMgmt *m) -{ - free(m); -} - - -static struct WellControlMgmt * -create_ctrl_mgmt(void) -{ - struct WellControlMgmt *m; - - m = malloc(1 * sizeof *m); - - if (m != NULL) { - m->cpty = 0; - } - - return m; -} @@ -71,7 +51,6 @@ well_controls_destroy(struct WellControls *ctrl) /* ---------------------------------------------------------------------- */ { if (ctrl != NULL) { - destroy_ctrl_mgmt(ctrl->data); free (ctrl->distr); free (ctrl->target); free (ctrl->type); @@ -99,12 +78,7 @@ well_controls_create(void) ctrl->distr = NULL; ctrl->current = -1; - ctrl->data = create_ctrl_mgmt(); - - if (ctrl->data == NULL) { - well_controls_destroy(ctrl); - ctrl = NULL; - } + ctrl->cpty = 0; } return ctrl; @@ -119,8 +93,6 @@ well_controls_reserve(int nctrl, int nphases, struct WellControls *ctrl) int c, p, ok; void *type, *target, *distr; - struct WellControlMgmt *m; - type = realloc(ctrl->type , nctrl * 1 * sizeof *ctrl->type ); target = realloc(ctrl->target, nctrl * 1 * sizeof *ctrl->target); distr = realloc(ctrl->distr , nctrl * nphases * sizeof *ctrl->distr ); @@ -133,17 +105,16 @@ well_controls_reserve(int nctrl, int nphases, struct WellControls *ctrl) ctrl->number_of_phases = nphases; if (ok == 3) { - m = ctrl->data; - for (c = m->cpty; c < nctrl; c++) { + for (c = ctrl->cpty; c < nctrl; c++) { ctrl->type [c] = BHP; ctrl->target[c] = -1.0; } - for (p = m->cpty * ctrl->number_of_phases; p < nctrl * ctrl->number_of_phases; ++p) { + for (p = ctrl->cpty * ctrl->number_of_phases; p < nctrl * ctrl->number_of_phases; ++p) { ctrl->distr[ p ] = 0.0; } - m->cpty = nctrl; + ctrl->cpty = nctrl; } return ok == 3; @@ -166,10 +137,7 @@ well_controls_equal(const struct WellControls *ctrls1, const struct WellControls are_equal &= (memcmp(ctrls1->type, ctrls2->type, ctrls1->num * sizeof *ctrls1->type ) == 0); are_equal &= (memcmp(ctrls1->target, ctrls2->target, ctrls1->num * sizeof *ctrls1->target ) == 0); are_equal &= (memcmp(ctrls1->distr, ctrls2->distr, ctrls1->num * ctrls1->number_of_phases * sizeof *ctrls1->distr ) == 0); - - struct WellControlMgmt* mgmt1 = (struct WellControlMgmt*)(ctrls1->data); - struct WellControlMgmt* mgmt2 = (struct WellControlMgmt*)(ctrls2->data); - are_equal &= (mgmt1->cpty == mgmt2->cpty); + are_equal &= (ctrls1->cpty == ctrls2->cpty); return are_equal; } diff --git a/opm/core/wells/wells.c b/opm/core/wells/wells.c index 312c5432b..616e05d0b 100644 --- a/opm/core/wells/wells.c +++ b/opm/core/wells/wells.c @@ -430,7 +430,6 @@ append_well_controls(enum WellControlType type, { int ok, alloc, np; struct WellControls *ctrl; - struct WellControlMgmt *m; assert (W != NULL); assert ((0 <= well_index) && (well_index < W->number_of_wells)); @@ -440,11 +439,10 @@ append_well_controls(enum WellControlType type, assert (ctrl != NULL); - m = ctrl->data; - ok = ctrl->num < m->cpty; + ok = ctrl->num < ctrl->cpty; if (! ok) { - alloc = alloc_size(ctrl->num, 1, m->cpty); + alloc = alloc_size(ctrl->num, 1, ctrl->cpty); ok = well_controls_reserve(alloc, np, ctrl); }