/* ---------------------------------------------------------------------- */ struct Wells * create_wells(int nphases, int nwells, int nperf) /* ---------------------------------------------------------------------- */ { int ok; struct Wells *W; W = malloc(1 * sizeof *W); if (W != NULL) { W->number_of_wells = 0; W->number_of_phases = nphases; W->type = NULL; W->depth_ref = NULL; W->comp_frac = NULL; W->well_connpos = malloc(1 * sizeof *W->well_connpos); W->well_cells = NULL; W->WI = NULL; W->ctrls = NULL; W->name = NULL; W->allow_cf = NULL; W->data = create_well_mgmt(); ok = (W->well_connpos != NULL) && (W->data != NULL); if (ok) { W->well_connpos[0] = 0; if ((nwells > 0) || (nperf > 0)) { ok = wells_reserve(nwells, nperf, W); } } if (! ok) { destroy_wells(W); W = NULL; } } return W; }
/* ---------------------------------------------------------------------- */ int add_well(enum WellType type , double depth_ref, int nperf , const double *comp_frac, /* Injection fraction or NULL */ const int *cells , const double *WI , /* Well index per perf (or NULL) */ const char *name , /* Well name (or NULL) */ struct Wells *W ) /* ---------------------------------------------------------------------- */ { int ok, nw, np, nperf_tot, off; int nwalloc, nperfalloc; struct WellMgmt *m; assert (W != NULL); nw = W->number_of_wells; nperf_tot = W->well_connpos[nw]; m = W->data; ok = (nw < m->well_cpty) && (nperf_tot + nperf <= m->perf_cpty); if (! ok) { nwalloc = alloc_size(nw , 1 , m->well_cpty); nperfalloc = alloc_size(nperf_tot, nperf, m->perf_cpty); ok = wells_reserve(nwalloc, nperfalloc, W); } off = W->well_connpos[nw]; if (ok && (nperf > 0)) { assert (cells != NULL); memcpy(W->well_cells + off, cells, nperf * sizeof *W->well_cells); if (WI != NULL) { memcpy(W->WI + off, WI, nperf * sizeof *W->WI); } } if (ok) { W->type [nw] = type ; W->depth_ref[nw] = depth_ref; if (name != NULL) { /* May return NULL, but that's fine for the current * purpose. */ W->name [nw] = dup_string(name); } np = W->number_of_phases; if (comp_frac != NULL) { memcpy(W->comp_frac + np*nw, comp_frac, np * sizeof *W->comp_frac); } W->well_connpos[nw + 1] = off + nperf; W->number_of_wells += 1; } return ok; }