Exemplo n.º 1
0
/* ---------------------------------------------------------------------- */
struct Wells *
clone_wells(const struct Wells *W)
/* ---------------------------------------------------------------------- */
{
    int                  np, nperf, ok, pos, w;
    const int           *cells;
    const double        *WI, *comp_frac;

    struct WellControls *ctrl;
    struct Wells        *newWells;

    if (W == NULL) {
        newWells = NULL;
    }
    else {
        np  = W->number_of_phases;
        newWells = create_wells(W->number_of_phases, W->number_of_wells,
                                W->well_connpos[ W->number_of_wells ]);

        if (newWells != NULL) {
            pos = W->well_connpos[ 0 ];
            ok  = 1;

            for (w = 0; ok && (w < W->number_of_wells); w++) {
                nperf = W->well_connpos[w + 1] - pos;
                cells = W->well_cells + pos;

                WI        = W->WI        != NULL ? W->WI        + pos  : NULL;
                comp_frac = W->comp_frac != NULL ? W->comp_frac + w*np : NULL;

                ok = add_well(W->type[ w ], W->depth_ref[ w ], nperf,
                              comp_frac, cells, WI, W->name[ w ], newWells);

                if (ok) {
                    ok = (ctrl = well_controls_clone(W->ctrls[w])) != NULL;
                }

                if (ok) {
                    /* Destroy control set implied by add_well() */
                    well_controls_destroy(newWells->ctrls[w]);

                    /* Assign complete clone of w's control set */
                    newWells->ctrls[w] = ctrl;
                }

                pos = W->well_connpos[w + 1];
            }

            if (! ok) {
                destroy_wells(newWells);
                newWells = NULL;
            }
        }
    }

    assert (wells_equal(newWells, W, false));

    return newWells;
}
Exemplo n.º 2
0
/* ---------------------------------------------------------------------- */
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;
}
Exemplo n.º 3
0
 void operator()( Wells* w ) { destroy_wells( w ); }