/// Solve the linear system Ax = b, with A being the
    /// combined derivative matrix of the residual and b
    /// being the residual itself.
    /// \param[in] residual   residual object containing A and b.
    /// \return               the solution x
    NewtonIterationBlackoilSimple::SolutionVector
    NewtonIterationBlackoilSimple::computeNewtonIncrement(const LinearisedBlackoilResidual& residual) const
    {
        typedef LinearisedBlackoilResidual::ADB ADB;
        const int np = residual.material_balance_eq.size();
        ADB mass_res = residual.material_balance_eq[0];
        for (int phase = 1; phase < np; ++phase) {
            mass_res = vertcat(mass_res, residual.material_balance_eq[phase]);
        }
        const ADB well_res = vertcat(residual.well_flux_eq, residual.well_eq);
        const ADB total_residual = collapseJacs(vertcat(mass_res, well_res));

        Eigen::SparseMatrix<double, Eigen::RowMajor> matr;
        total_residual.derivative()[0].toSparse(matr);

        SolutionVector dx(SolutionVector::Zero(total_residual.size()));
        Opm::LinearSolverInterface::LinearSolverReport rep
            = linsolver_->solve(matr.rows(), matr.nonZeros(),
                                matr.outerIndexPtr(), matr.innerIndexPtr(), matr.valuePtr(),
                                total_residual.value().data(), dx.data(), parallelInformation_);

        // store iterations
        iterations_ = rep.iterations;

        if (!rep.converged) {
            OPM_THROW(LinearSolverProblem,
                      "FullyImplicitBlackoilSolver::solveJacobianSystem(): "
                      "Linear solver convergence failure.");
        }
        return dx;
    }
Exemplo n.º 2
0
void MakeDeposits::fillDepositList()
{
    QApplication::setOverrideCursor(waitCursor);
    ADB     DB;
    char    tmpStr[1024];
    float   totalFunds = 0.00;
    
    strcpy(tmpStr, cfgVal("UndepositedFundsAccount"));
    
    emit(setStatus("Creating undeposited funds list..."));
    DB.query("select GL.InternalID, GL.TransDate, GL.Amount, AcctsRecv.RefNo, AcctsRecv.CustomerID, Customers.FullName from GL, AcctsRecv, Customers where GL.IntAccountNo = %d and GL.TransType = 2 and AcctsRecv.InternalID = GL.TransTypeLink and AcctsRecv.RefNo > 0 and Customers.CustomerID = AcctsRecv.CustomerID and GL.Cleared = 0", atoi(cfgVal("UndepositedFundsAcct")));
    //DB.query("select * from GL where AccountNo = %d and LinkedTrans = 0", atoi(tmpStr));
    
    if (DB.rowCount) while (DB.getrow()) {
        (void) new Q3ListViewItem(paymentList, 
          DB.curRow["TransDate"],
          DB.curRow["CustomerID"], 
          DB.curRow["FullName"],
          DB.curRow["RefNo"],
          DB.curRow["Amount"],
          DB.curRow["InternalID"]
        );
        totalFunds += atof(DB.curRow["Amount"]);
    }

    sprintf(tmpStr, "$%.2f", totalFunds);
    undepositedAmount->setText(tmpStr);
    
    emit(setStatus(""));
    QApplication::restoreOverrideCursor();
    
    
}
Exemplo n.º 3
0
void LogCall::setLoginID(const char * newLoginID)
{
    QApplication::setOverrideCursor(waitCursor);
    if (strlen(newLoginID) < 32) {
        strcpy(myLoginID, newLoginID);
        loginID->setText(myLoginID);
        
        if (strlen(myLoginID)) {
            // Now, get the customer ID for this login ID
            char        *query = new char[32768];
            ADB         DB;
        
            DB.query("select CustomerID from Logins where LoginID = '%s'", myLoginID);
            if (DB.rowCount == 1) {
                DB.getrow();
                myCustID = atol(DB.curRow["CustomerID"]);
                // Load the customer's name so we can verify who we're talking
                // to.
                CustomersDB CDB;
                CDB.get(myCustID);
                strcpy(custName, (const char *) CDB.getStr("FullName"));
                sprintf(query, "Customer ID %ld selected (%s)", myCustID, custName);
                statusLabel->setText(query);
            } else {
                myCustID = 0;
                statusLabel->setText("No customer selected");
            }
        } else {
            myCustID = 0;
            statusLabel->setText("No customer selected");
        }
    }
    QApplication::restoreOverrideCursor();
}
Exemplo n.º 4
0
BOOST_FIXTURE_TEST_CASE(ViscosityAD, TestFixture<SetupSimple>)
{
    const Opm::BlackoilPropsAdFromDeck::Cells cells(5, 0);

    typedef Opm::BlackoilPropsAdFromDeck::V V;
    typedef Opm::BlackoilPropsAdFromDeck::ADB ADB;

    V Vpw;
    Vpw.resize(cells.size());
    Vpw[0] =  1*Opm::unit::barsa;
    Vpw[1] =  2*Opm::unit::barsa;
    Vpw[2] =  4*Opm::unit::barsa;
    Vpw[3] =  8*Opm::unit::barsa;
    Vpw[4] = 16*Opm::unit::barsa;

    // standard temperature
    V T = V::Constant(cells.size(), 273.15+20);

    typedef Opm::BlackoilPropsAdFromDeck::ADB ADB;

    const V VmuWat = boprops_ad.muWat(ADB::constant(Vpw), ADB::constant(T), cells).value();
    for (V::Index i = 0, n = Vpw.size(); i < n; ++i) {
        const std::vector<int> bp(1, grid.c_grid()->number_of_cells);

        const Opm::BlackoilPropsAdFromDeck::Cells c(1, 0);
        const V   pw     = V(1, 1) * Vpw[i];
        const ADB Apw    = ADB::variable(0, pw, bp);
        const ADB AT     = ADB::constant(T);
        const ADB AmuWat = boprops_ad.muWat(Apw, AT, c);

        BOOST_CHECK_EQUAL(AmuWat.value()[0], VmuWat[i]);
    }
}
Exemplo n.º 5
0
 /// Gas formation volume factor.
 /// \param[in]  pg     Array of n gas pressure values.
 /// \param[in]  rv     Array of n vapor oil/gas ratio
 /// \param[in]  cond   Array of n objects, each specifying which phases are present with non-zero saturation in a cell.
 /// \param[in]  cells  Array of n cell indices to be associated with the pressure values.
 /// \return            Array of n formation volume factor values.
 ADB BlackoilPropsAd::bGas(const ADB& pg,
                           const ADB& rv,
                           const std::vector<PhasePresence>& /*cond*/,
                           const Cells& cells) const
 {
     if (!pu_.phase_used[Gas]) {
         OPM_THROW(std::runtime_error, "Cannot call muGas(): gas phase not present.");
     }
     const int n = cells.size();
     assert(pg.value().size() == n);
     const int np = props_.numPhases();
     Block z = Block::Zero(n, np);
     if (pu_.phase_used[Oil]) {
         // Faking a z with the right ratio:
         //   rv = zo/zg
         z.col(pu_.phase_pos[Oil]) = rv.value();
         z.col(pu_.phase_pos[Gas]) = V::Ones(n, 1);
     }
     Block matrix(n, np*np);
     Block dmatrix(n, np*np);
     props_.matrix(n, pg.value().data(), z.data(), cells.data(), matrix.data(), dmatrix.data());
     const int phase_ind = pu_.phase_pos[Gas];
     const int column = phase_ind*np + phase_ind; // Index of our sought diagonal column.
     ADB::M db_diag = spdiag(dmatrix.col(column));
     const int num_blocks = pg.numBlocks();
     std::vector<ADB::M> jacs(num_blocks);
     for (int block = 0; block < num_blocks; ++block) {
         jacs[block] = db_diag * pg.derivative()[block];
     }
     return ADB::function(matrix.col(column), jacs);
 }
Exemplo n.º 6
0
    ADB PolymerPropsAd::polymerWaterVelocityRatio(const ADB& c) const
    {

        const int nc = c.size();
        V mc(nc);
        V dmc(nc);

        for (int i = 0; i < nc; ++i) {
            double m = 0;
            double dm = 0;
            polymer_props_.computeMcWithDer(c.value()(i), m, dm);

            mc(i) = m;
            dmc(i) = dm;
        }

        ADB::M dmc_diag(dmc.matrix().asDiagonal());
        const int num_blocks = c.numBlocks();
        std::vector<ADB::M> jacs(num_blocks);
        for (int block = 0; block < num_blocks; ++block) {
            jacs[block] = dmc_diag * c.derivative()[block];
        }

        return ADB::function(std::move(mc), std::move(jacs));
    }
Exemplo n.º 7
0
    /// Gas formation volume factor.
    /// \param[in]  pg     Array of n gas pressure values.
    /// \param[in]  cells  Array of n cell indices to be associated with the pressure values.
    /// \return            Array of n formation volume factor values.
    ADB BlackoilPropsAdFromDeck::bGas(const ADB& pg,
                                      const Cells& cells) const
    {
        if (!phase_usage_.phase_used[Gas]) {
            OPM_THROW(std::runtime_error, "Cannot call muGas(): gas phase not present.");
        }
        const int n = cells.size();
        assert(pg.size() == n);

        V b(n);
        V dbdp(n);
        V dbdr(n);
        const double* rs = 0;

        props_[phase_usage_.phase_pos[Gas]]->b(n, pg.value().data(), rs,
                                               b.data(), dbdp.data(), dbdr.data());

        ADB::M dbdp_diag = spdiag(dbdp);
        const int num_blocks = pg.numBlocks();
        std::vector<ADB::M> jacs(num_blocks);
        for (int block = 0; block < num_blocks; ++block) {
            jacs[block] = dbdp_diag * pg.derivative()[block];
        }
        return ADB::function(b, jacs);
    }
Exemplo n.º 8
0
 /// Oil formation volume factor.
 /// \param[in]  po     Array of n oil pressure values.
 /// \param[in]  rs     Array of n gas solution factor values.
 /// \param[in]  cond   Array of n taxonomies classifying fluid condition.
 /// \param[in]  cells  Array of n cell indices to be associated with the pressure values.
 /// \return            Array of n formation volume factor values.
 ADB BlackoilPropsAd::bOil(const ADB& po,
                           const ADB& rs,
                           const std::vector<PhasePresence>& /*cond*/,
                           const Cells& cells) const
 {
     if (!pu_.phase_used[Oil]) {
         OPM_THROW(std::runtime_error, "Cannot call muOil(): oil phase not present.");
     }
     const int n = cells.size();
     assert(po.value().size() == n);
     const int np = props_.numPhases();
     Block z = Block::Zero(n, np);
     if (pu_.phase_used[Gas]) {
         // Faking a z with the right ratio:
         //   rs = zg/zo
         z.col(pu_.phase_pos[Oil]) = V::Ones(n, 1);
         z.col(pu_.phase_pos[Gas]) = rs.value();
     }
     Block matrix(n, np*np);
     Block dmatrix(n, np*np);
     props_.matrix(n, po.value().data(), z.data(), cells.data(), matrix.data(), dmatrix.data());
     const int phase_ind = pu_.phase_pos[Oil];
     const int column = phase_ind*np + phase_ind; // Index of our sought diagonal column.
     ADB::M db_diag = spdiag(dmatrix.col(column));
     const int num_blocks = po.numBlocks();
     std::vector<ADB::M> jacs(num_blocks);
     for (int block = 0; block < num_blocks; ++block) {
         // For now, we deliberately ignore the derivative with respect to rs,
         // since the BlackoilPropertiesInterface class does not evaluate it.
         // We would add to the next line: + db_drs_diag * rs.derivative()[block]
         jacs[block] = db_diag * po.derivative()[block];
     }
     return ADB::function(matrix.col(column), jacs);
 }
Exemplo n.º 9
0
ADB SolventPropsAdFromDeck::muSolvent(const ADB& pg,
                                 const Cells& cells) const
{
    const int n = cells.size();
    assert(pg.value().size() == n);
    V mu(n);
    V dmudp(n);
    for (int i = 0; i < n; ++i) {
        const double& pg_i = pg.value()[i];
        int regionIdx = cellPvtRegionIdx_[cells[i]];
        double tempInvB = b_[regionIdx](pg_i);
        double tempInvBmu = inverseBmu_[regionIdx](pg_i);
        mu[i] = tempInvB / tempInvBmu;
        dmudp[i] = (tempInvBmu * b_[regionIdx].derivative(pg_i)
                         - tempInvB * inverseBmu_[regionIdx].derivative(pg_i)) / (tempInvBmu * tempInvBmu);
    }

    ADB::M dmudp_diag(dmudp.matrix().asDiagonal());
    const int num_blocks = pg.numBlocks();
    std::vector<ADB::M> jacs(num_blocks);
    for (int block = 0; block < num_blocks; ++block) {
        jacs[block] = dmudp_diag * pg.derivative()[block];
    }
    return ADB::function(std::move(mu), std::move(jacs));
}
Exemplo n.º 10
0
void UnreleasedDomainsReport::refreshReport()
{
    repBody->clear();
    ADB     DB;
    DB.query("select Domains.CustomerID, Domains.LoginID, DomainTypes.DomainType, Domains.DomainName from Domains, DomainTypes where Domains.Active <> 0 and Domains.Released = '' and DomainTypes.InternalID = Domains.DomainType");
    if (DB.rowCount) while (DB.getrow()) {
        (void) new Q3ListViewItem(repBody, DB.curRow["CustomerID"], DB.curRow["LoginID"], DB.curRow["DomainType"], DB.curRow["DomainName"]);
    }
    
}
Exemplo n.º 11
0
void UserPrivs::refreshList()
{
    ADB             DB;
    char            levelStr[1024];
    AccessLevels    level;
    Q3ListViewItem   *curItem;
    bool            foundSel = false;

    userList->clear();
    DB.query("select * from Staff");
    if (DB.rowCount) {
        while(DB.getrow()) {
            level = (AccessLevels) atoi(DB.curRow["AccessLevel"]);
            switch(level) {
                case Admin:
                    strcpy(levelStr, "Administrator");
                    break;

                case Manager:
                    strcpy(levelStr, "Manager");
                    break;

                case Staff:
                    strcpy(levelStr, "Support Staff");
                    break;

                default:
                    strcpy(levelStr, "Unknown");
                    break;
            }

            curItem = new Q3ListViewItem(userList, DB.curRow["LoginID"], levelStr, DB.curRow["InternalID"]);

            // Is this the user we previously had hilighted?  If so,
            // hilight it now.
            if (myCurrentID == atol(DB.curRow["InternalID"])) {
                foundSel = true;
                userList->setCurrentItem(curItem);
                userList->setSelected(curItem, true);
                userList->ensureItemVisible(curItem);
            }
        }
    }

    // If we didn't find our previously hilighted entry, hilight the
    // first entry in the list.
    if (!foundSel) {
        // None selected, hilight the first one in the list.
        if (userList->firstChild()) {
            userList->setCurrentItem(userList->firstChild());
            userList->setSelected(userList->firstChild(), true);
            userList->ensureItemVisible(userList->firstChild());
        }
    }
}
Exemplo n.º 12
0
/**
 * setGLAccount()
 *
 * Overrides the GL Account that we post to - not the AcctsRecv side
 * but the billable side of the transaction.
 *
 * Returns 1 if successful, 0 if not.
 */
int AcctsRecv::setGLAccount(int intAcctNo)
{
    int     retVal = 0;
    ADB     DB;
    DB.query("select IntAccountNo from Accounts where IntAccountNo = '%d'", intAcctNo);
    if (DB.rowCount) { 
        myIntAcctNo = intAcctNo;
        retVal = 1;
    }
    return retVal;
}
Exemplo n.º 13
0
/**
 * setGLAccount()
 *
 * Overrides the GL Account that we post to - not the AcctsRecv side
 * but the billable side of the transaction.
 *
 * Returns 1 if successful, 0 if not.
 */
int AcctsRecv::setGLAccount(const char *acctNo)
{
    int     retVal = 0;
    ADB     DB;
    DB.query("select IntAccountNo from Accounts where AccountNo = '%s'", acctNo);
    if (DB.rowCount) { 
        DB.getrow();
        myIntAcctNo = atoi(DB.curRow["IntAccountNo"]);
        retVal = 1;
    }
    return retVal;
}
Exemplo n.º 14
0
void TE_Cities::loadCities()
{
    QApplication::setOverrideCursor(Qt::waitCursor);
    
    ADB     DB;
    
    DB.query("select distinct City, State from Addresses where RefFrom = %d", REF_CUSTOMER);
    if (DB.rowCount) while (DB.getrow()) {
        (void) new Q3ListViewItem(cityList, DB.curRow["City"], DB.curRow["State"]);
    }
    
    QApplication::restoreOverrideCursor();
}
Exemplo n.º 15
0
    /// Oil viscosity.
    /// \param[in]  po     Array of n oil pressure values.
    /// \param[in]  rs     Array of n gas solution factor values.
    /// \param[in]  cells  Array of n cell indices to be associated with the pressure values.
    /// \return            Array of n viscosity values.
    ADB BlackoilPropsAd::muOil(const ADB& po,
                               const ADB& rs,
                               const Cells& cells) const
    {
#if 1
        return ADB::constant(muOil(po.value(), rs.value(), cells), po.blockPattern());
#else
        if (!pu_.phase_used[Oil]) {
            THROW("Cannot call muOil(): oil phase not present.");
        }
        const int n = cells.size();
        ASSERT(po.value().size() == n);
        const int np = props_.numPhases();
        Block z = Block::Zero(n, np);
        if (pu_.phase_used[Gas]) {
            // Faking a z with the right ratio:
            //   rs = zg/zo
            z.col(pu_.phase_pos[Oil]) = V::Ones(n, 1);
            z.col(pu_.phase_pos[Gas]) = rs.value();
        }
        Block mu(n, np);
        Block dmu(n, np);
        props_.viscosity(n, po.value().data(), z.data(), cells.data(), mu.data(), dmu.data());
        ADB::M dmu_diag = spdiag(dmu.col(pu_.phase_pos[Oil]));
        const int num_blocks = po.numBlocks();
        std::vector<ADB::M> jacs(num_blocks);
        for (int block = 0; block < num_blocks; ++block) {
            // For now, we deliberately ignore the derivative with respect to rs,
            // since the BlackoilPropertiesInterface class does not evaluate it.
            // We would add to the next line: + dmu_drs_diag * rs.derivative()[block]
            jacs[block] = dmu_diag * po.derivative()[block];
        }
        return ADB::function(mu.col(pu_.phase_pos[Oil]), jacs);
#endif
    }
Exemplo n.º 16
0
void BillingCycles::refreshList(int)
{
    ADB             DB;
    Q3ListViewItem   *curItem = NULL;
    
    // Save the state of the list.
    list->clear();

    DB.query("select CycleID, CycleType, Description from BillingCycles order by CycleID");
    if (DB.rowCount) while(DB.getrow()) {
        curItem = new Q3ListViewItem(list, DB.curRow["CycleID"], DB.curRow["CycleType"], DB.curRow["Description"]);
    }
    list->repaint();
}
Exemplo n.º 17
0
    ADB
    PolymerPropsAd::effectiveRelPerm(const ADB& c,
                                     const ADB& cmax_cells,
                                     const ADB& krw) const
    {
        const int nc = c.value().size();
        V one = V::Ones(nc);
        ADB ads = adsorption(c, cmax_cells);
        V krw_eff = effectiveRelPerm(c.value(), cmax_cells.value(), krw.value());

        double max_ads = polymer_props_.cMaxAds();
        double res_factor = polymer_props_.resFactor();
        double factor = (res_factor - 1.) / max_ads;
        ADB rk = one + ads * factor;

        return krw / rk;
    }
Exemplo n.º 18
0
ADB SolventPropsAdFromDeck::miscibleResidualOilSaturationFunction (const ADB& Sw,
                                                                   const Cells& cells) const {
    if (sorwmis_.size()>0) {
        return SolventPropsAdFromDeck::makeADBfromTables(Sw, cells, cellMiscRegionIdx_, sorwmis_);
    }
    // return zeros if not specified
    return ADB::constant(V::Zero(Sw.size()));
}
Exemplo n.º 19
0
    /// Gas viscosity.
    /// \param[in]  pg     Array of n gas pressure values.
    /// \param[in]  rv     Array of n vapor oil/gas ratio
    /// \param[in]  cond   Array of n objects, each specifying which phases are present with non-zero saturation in a cell.
    /// \param[in]  cells  Array of n cell indices to be associated with the pressure values.
    /// \return            Array of n viscosity values.
    ADB BlackoilPropsAd::muGas(const ADB& pg,
                               const ADB& rv,
                               const std::vector<PhasePresence>& cond,
                               const Cells& cells) const
    {
#if 1
        return ADB::constant(muGas(pg.value(), rv.value(),cond,cells), pg.blockPattern());
#else
        if (!pu_.phase_used[Gas]) {
            OPM_THROW(std::runtime_error, "Cannot call muGas(): gas phase not present.");
        }
        const int n = cells.size();
        assert(pg.value().size() == n);
        const int np = props_.numPhases();
        Block z = Block::Zero(n, np);
        if (pu_.phase_used[Oil]) {
            // Faking a z with the right ratio:
            //   rv = zo/zg
            z.col(pu_.phase_pos[Oil]) = rv;
            z.col(pu_.phase_pos[Gas]) = V::Ones(n, 1);
        }
        Block mu(n, np);
        Block dmu(n, np);
        props_.viscosity(n, pg.value().data(), z.data(), cells.data(), mu.data(), dmu.data());
        ADB::M dmu_diag = spdiag(dmu.col(pu_.phase_pos[Gas]));
        const int num_blocks = pg.numBlocks();
        std::vector<ADB::M> jacs(num_blocks);
        for (int block = 0; block < num_blocks; ++block) {
            jacs[block] = dmu_diag * pg.derivative()[block];
        }
        return ADB::function(mu.col(pu_.phase_pos[Gas]), jacs);
#endif
    }
        inline
        double infinityNormWell( const ADB& a, const boost::any& pinfo )
        {
            static_cast<void>(pinfo); // Suppress warning in non-MPI case.
            double result=0;
            if( a.value().size() > 0 ) {
                result = a.value().matrix().template lpNorm<Eigen::Infinity> ();
            }
#if HAVE_MPI
            if ( pinfo.type() == typeid(ParallelISTLInformation) )
            {
                const ParallelISTLInformation& real_info =
                    boost::any_cast<const ParallelISTLInformation&>(pinfo);
                result = real_info.communicator().max(result);
            }
#endif
            return result;
        }
Exemplo n.º 21
0
ADB SolventPropsAdFromDeck::pressureMiscibilityFunction(const ADB& po,
                                                        const Cells& cells) const
{
    if (pmisc_.size() > 0) {
        return SolventPropsAdFromDeck::makeADBfromTables(po, cells, cellMiscRegionIdx_, pmisc_);
    }
    // return ones if not specified i.e. no effect.
    return ADB::constant(V::Constant(po.size(), 1.0));
}
Exemplo n.º 22
0
void LoginTypeReport::refreshReport()
{
    emit(setStatus("Generating report..."));
    QApplication::setOverrideCursor(waitCursor);

    ADB         DB;
    char        modDate[128];
    char        isActive[128];
    char        isPrimary[128];
    QDateTime   tmpQDT;
    bool        showIt = false;

    repBody->clear();

    DB.query("select Logins.LoginID, Customers.FullName, Logins.LastModified, Logins.Active, Logins.CustomerID, Customers.PrimaryLogin from Logins, Customers where Logins.LoginType = %d and Customers.CustomerID = Logins.CustomerID", loginType);

    if (DB.rowCount) while (DB.getrow()) {
        if (!strcmp(DB.curRow["LoginID"], DB.curRow["PrimaryLogin"])) strcpy(isPrimary, "Yes");
        else strcpy(isPrimary, "No");
        if (atoi(DB.curRow["Active"])) strcpy(isActive, "Yes");
        else strcpy(isActive, "No");

        tmpQDT = DB.curRow.col("LastModified")->toQDateTime();
        sprintf(modDate, "%04d-%02d-%02d", tmpQDT.date().year(), tmpQDT.date().month(), tmpQDT.date().day());

        showIt = false;
        if ((atoi(DB.curRow["Active"])) && showActive) showIt = true;
        if ((!atoi(DB.curRow["Active"])) && showInactive) showIt = true;

        if (showIt) {
            (void) new Q3ListViewItem(repBody,
                                     DB.curRow["LoginID"],
                                     DB.curRow["FullName"],
                                     modDate,
                                     isActive,
                                     isPrimary,
                                     DB.curRow["CustomerID"]
                                    );
        };
    }

    emit(setStatus(""));
    QApplication::restoreOverrideCursor();
}
Exemplo n.º 23
0
void RatePlanReport::refreshReport()
{
    QApplication::setOverrideCursor(waitCursor);

    repBody->clear();
    
    char    tmpActiveStr[1024];
    char    tmpInactiveStr[1024];
    
    char    *query = new char[65536];
    ADB     DB;
    ADB     DB2;
    

    // Get a list of the rate plans.  Then we'll count the customers that
    // are assigned that rate plan.
    DB.query("select InternalID, PlanTag, Description from RatePlans");
    if (DB.rowCount) {
        while (DB.getrow()) {
            // Now, get the number of active customers associated with this
            // rate plan.
            DB2.query("select CustomerID from Customers where RatePlan = %s and Active <> 0", DB.curRow["InternalID"]);
            sprintf(tmpActiveStr, "%6ld", DB2.rowCount);
            
            // Now, get the number of INactive customers associated with this
            // rate plan.
            DB2.query("select CustomerID from Customers where RatePlan = %s and Active = 0", DB.curRow["InternalID"]);
            sprintf(tmpInactiveStr, "%6ld", DB2.rowCount);

            // Now, add the entry into the list, including the last column,
            // which is not shown, containing the internal ID so we can
            // zoom in on it.
            (void) new Q3ListViewItem(repBody, DB.curRow["PlanTag"], DB.curRow["Description"], tmpActiveStr, tmpInactiveStr, DB.curRow["InternalID"]);
        } 
    } else {
        (void) new Q3ListViewItem(repBody, "No rate plans found!!!");
    }
    
    
    delete query;
    
    QApplication::restoreOverrideCursor();
}
Exemplo n.º 24
0
 /// Bubble point curve for Rs as function of oil pressure.
 /// \param[in]  po     Array of n oil pressure values.
 /// \param[in]  cells  Array of n cell indices to be associated with the pressure values.
 /// \return            Array of n bubble point values for Rs.
 ADB BlackoilPropsAdFromDeck::rsMax(const ADB& po,
                                    const Cells& cells) const
 {
     if (!phase_usage_.phase_used[Oil]) {
         OPM_THROW(std::runtime_error, "Cannot call rsMax(): oil phase not present.");
     }
     const int n = cells.size();
     assert(po.size() == n);
     V rbub(n);
     V drbubdp(n);
     props_[Oil]->rbub(n, po.value().data(), rbub.data(), drbubdp.data());
     ADB::M drbubdp_diag = spdiag(drbubdp);
     const int num_blocks = po.numBlocks();
     std::vector<ADB::M> jacs(num_blocks);
     for (int block = 0; block < num_blocks; ++block) {
         jacs[block] = drbubdp_diag * po.derivative()[block];
     }
     return ADB::function(rbub, jacs);
 }
Exemplo n.º 25
0
    std::vector<ADB> BlackoilPropsAd::capPress(const ADB& sw,
                                               const ADB& so,
                                               const ADB& sg,
                                               const Cells& cells) const

    {
        const int numCells = cells.size();
        const int numActivePhases = numPhases();
        const int numBlocks = so.numBlocks();

        Block activeSat(numCells, numActivePhases);
        if (pu_.phase_used[Water]) {
            assert(sw.value().size() == numCells);
            activeSat.col(pu_.phase_pos[Water]) = sw.value();
        }
        if (pu_.phase_used[Oil]) {
            assert(so.value().size() == numCells);
            activeSat.col(pu_.phase_pos[Oil]) = so.value();
        } else {
            OPM_THROW(std::runtime_error, "BlackoilPropsAdFromDeck::relperm() assumes oil phase is active.");
        }
        if (pu_.phase_used[Gas]) {
            assert(sg.value().size() == numCells);
            activeSat.col(pu_.phase_pos[Gas]) = sg.value();
        }

        Block pc(numCells, numActivePhases);
        Block dpc(numCells, numActivePhases*numActivePhases);
        props_.capPress(numCells, activeSat.data(), cells.data(), pc.data(), dpc.data());

        std::vector<ADB> adbCapPressures;
        adbCapPressures.reserve(3);
        const ADB* s[3] = { &sw, &so, &sg };
        for (int phase1 = 0; phase1 < 3; ++phase1) {
            if (pu_.phase_used[phase1]) {
                const int phase1_pos = pu_.phase_pos[phase1];
                std::vector<ADB::M> jacs(numBlocks);
                for (int block = 0; block < numBlocks; ++block) {
                    jacs[block] = ADB::M(numCells, s[phase1]->derivative()[block].cols());
                }
                for (int phase2 = 0; phase2 < 3; ++phase2) {
                    if (!pu_.phase_used[phase2])
                        continue;
                    const int phase2_pos = pu_.phase_pos[phase2];
                    // Assemble dpc1/ds2.
                    const int column = phase1_pos + numActivePhases*phase2_pos; // Recall: Fortran ordering from props_.relperm()
                    ADB::M dpc1_ds2_diag = spdiag(dpc.col(column));
                    for (int block = 0; block < numBlocks; ++block) {
                        jacs[block] += dpc1_ds2_diag * s[phase2]->derivative()[block];
                    }
                }
                adbCapPressures.emplace_back(ADB::function(pc.col(phase1_pos), jacs));
            } else {
                adbCapPressures.emplace_back(ADB::null());
            }
        }
        return adbCapPressures;
    }
Exemplo n.º 26
0
    ADB PolymerPropsAd::effectiveInvWaterVisc(const ADB& c,
	                    				      const double* visc) const
    {
	    const int nc = c.size();
    	V inv_mu_w_eff(nc);
    	V dinv_mu_w_eff(nc);
    	for (int i = 0; i < nc; ++i) {
    	    double im = 0, dim = 0;
    	    polymer_props_.effectiveInvViscWithDer(c.value()(i), visc, im, dim);
    	    inv_mu_w_eff(i) = im;
    	    dinv_mu_w_eff(i) = dim;
    	}
        ADB::M dim_diag = spdiag(dinv_mu_w_eff);
        const int num_blocks = c.numBlocks();
        std::vector<ADB::M> jacs(num_blocks);
        for (int block = 0; block < num_blocks; ++block) {
            jacs[block] = dim_diag * c.derivative()[block];
        }
        return ADB::function(std::move(inv_mu_w_eff), std::move(jacs));
    }
Exemplo n.º 27
0
 /// Relative permeabilities for all phases.
 /// \param[in]  sw     Array of n water saturation values.
 /// \param[in]  so     Array of n oil saturation values.
 /// \param[in]  sg     Array of n gas saturation values.
 /// \param[in]  cells  Array of n cell indices to be associated with the saturation values.
 /// \return            An std::vector with 3 elements, each an array of n relperm values,
 ///                    containing krw, kro, krg. Use PhaseIndex for indexing into the result.
 std::vector<ADB> BlackoilPropsAd::relperm(const ADB& sw,
                                           const ADB& so,
                                           const ADB& sg,
                                           const Cells& cells) const
 {
     const int n = cells.size();
     const int np = props_.numPhases();
     Block s_all(n, np);
     if (pu_.phase_used[Water]) {
         assert(sw.value().size() == n);
         s_all.col(pu_.phase_pos[Water]) = sw.value();
     }
     if (pu_.phase_used[Oil]) {
         assert(so.value().size() == n);
         s_all.col(pu_.phase_pos[Oil]) = so.value();
     } else {
         OPM_THROW(std::runtime_error, "BlackoilPropsAd::relperm() assumes oil phase is active.");
     }
     if (pu_.phase_used[Gas]) {
         assert(sg.value().size() == n);
         s_all.col(pu_.phase_pos[Gas]) = sg.value();
     }
     Block kr(n, np);
     Block dkr(n, np*np);
     props_.relperm(n, s_all.data(), cells.data(), kr.data(), dkr.data());
     const int num_blocks = so.numBlocks();
     std::vector<ADB> relperms;
     relperms.reserve(3);
     typedef const ADB* ADBPtr;
     ADBPtr s[3] = { &sw, &so, &sg };
     for (int phase1 = 0; phase1 < 3; ++phase1) {
         if (pu_.phase_used[phase1]) {
             const int phase1_pos = pu_.phase_pos[phase1];
             std::vector<ADB::M> jacs(num_blocks);
             for (int block = 0; block < num_blocks; ++block) {
                 jacs[block] = ADB::M(n, s[phase1]->derivative()[block].cols());
             }
             for (int phase2 = 0; phase2 < 3; ++phase2) {
                 if (!pu_.phase_used[phase2]) {
                     continue;
                 }
                 const int phase2_pos = pu_.phase_pos[phase2];
                 // Assemble dkr1/ds2.
                 const int column = phase1_pos + np*phase2_pos; // Recall: Fortran ordering from props_.relperm()
                 ADB::M dkr1_ds2_diag = spdiag(dkr.col(column));
                 for (int block = 0; block < num_blocks; ++block) {
                     jacs[block] += dkr1_ds2_diag * s[phase2]->derivative()[block];
                 }
             }
             relperms.emplace_back(ADB::function(kr.col(phase1_pos), jacs));
         } else {
             relperms.emplace_back(ADB::null());
         }
     }
     return relperms;
 }
Exemplo n.º 28
0
void ChangeBillingCycle::saveBillingCycleChange()
{
    CustomersDB CDB;
    ADB         DB;
    
    QApplication::setOverrideCursor(waitCursor);
    CDB.get(myCustID);

    DB.query("select InternalID from BillingCycles where CycleID = '%s'", (const char *) cycleList->text(cycleList->currentItem()));
    DB.getrow();

    CDB.setValue("BillingCycleDate", effectiveDate->date().toString("yyyy-MM-dd").ascii());
    CDB.setValue("BillingCycle", atol(DB.curRow["InternalID"]));
    CDB.upd();
    QApplication::restoreOverrideCursor();
    emit(customerUpdated(myCustID));
    
    QMessageBox::information(this, "Rerate warning", "Note that billing cycle changes are not\nrerated automatically.  You will need to\nmake any necessary adjustments to the\ncustomers register manually.");
    
    close();
}
Exemplo n.º 29
0
    /// Gas viscosity.
    /// \param[in]  pg     Array of n gas pressure values.
    /// \param[in]  cells  Array of n cell indices to be associated with the pressure values.
    /// \return            Array of n viscosity values.
    ADB BlackoilPropsAd::muGas(const ADB& pg,
                               const Cells& cells) const
    {
#if 1
        return ADB::constant(muGas(pg.value(), cells), pg.blockPattern());
#else
        if (!pu_.phase_used[Gas]) {
            THROW("Cannot call muGas(): gas phase not present.");
        }
        const int n = cells.size();
        ASSERT(pg.value().size() == n);
        const int np = props_.numPhases();
        Block z = Block::Zero(n, np);
        Block mu(n, np);
        Block dmu(n, np);
        props_.viscosity(n, pg.value().data(), z.data(), cells.data(), mu.data(), dmu.data());
        ADB::M dmu_diag = spdiag(dmu.col(pu_.phase_pos[Gas]));
        const int num_blocks = pg.numBlocks();
        std::vector<ADB::M> jacs(num_blocks);
        for (int block = 0; block < num_blocks; ++block) {
            jacs[block] = dmu_diag * pg.derivative()[block];
        }
        return ADB::function(mu.col(pu_.phase_pos[Gas]), jacs);
#endif
    }
Exemplo n.º 30
0
    /// Water viscosity.
    /// \param[in]  pw     Array of n water pressure values.
    /// \param[in]  cells  Array of n cell indices to be associated with the pressure values.
    /// \return            Array of n viscosity values.
    ADB BlackoilPropsAd::muWat(const ADB& pw,
                               const Cells& cells) const
    {
#if 1
        return ADB::constant(muWat(pw.value(), cells), pw.blockPattern());
#else
        if (!pu_.phase_used[Water]) {
            OPM_THROW(std::runtime_error, "Cannot call muWat(): water phase not present.");
        }
        const int n = cells.size();
        assert(pw.value().size() == n);
        const int np = props_.numPhases();
        Block z = Block::Zero(n, np);
        Block mu(n, np);
        Block dmu(n, np);
        props_.viscosity(n, pw.value().data(), z.data(), cells.data(), mu.data(), dmu.data());
        ADB::M dmu_diag = spdiag(dmu.col(pu_.phase_pos[Water]));
        const int num_blocks = pw.numBlocks();
        std::vector<ADB::M> jacs(num_blocks);
        for (int block = 0; block < num_blocks; ++block) {
            jacs[block] = dmu_diag * pw.derivative()[block];
        }
        return ADB::function(mu.col(pu_.phase_pos[Water]), jacs);
#endif
    }