Example #1
0
    double MiscibilityLiveOil::miscible_oil(double press, const surfvol_t& surfvol,
					    int item, bool deriv) const
    {
	int section;
	double R = linearInterpolation(saturated_oil_table_[0],
					     saturated_oil_table_[3],
					     press, section);
	double maxR = (surfvol[Liquid] == 0.0) ? 0.0 : surfvol[Vapour]/surfvol[Liquid];
	if (deriv) {
	    if (R < maxR ) {  // Saturated case
		return linearInterpolationDerivative(saturated_oil_table_[0],
						saturated_oil_table_[item],
						press);
	    } else {  // Undersaturated case
		int is = tableIndex(saturated_oil_table_[3], maxR);
		double w = (maxR - saturated_oil_table_[3][is]) /
		    (saturated_oil_table_[3][is+1] - saturated_oil_table_[3][is]);
                ASSERT(undersat_oil_tables_[is][0].size() >= 2);
                ASSERT(undersat_oil_tables_[is+1][0].size() >= 2);
		double val1 =
		    linearInterpolationDerivative(undersat_oil_tables_[is][0],
					     undersat_oil_tables_[is][item],
					     press);
		double val2 = 
		    linearInterpolationDerivative(undersat_oil_tables_[is+1][0],
					     undersat_oil_tables_[is+1][item],
					     press);
		double val = val1 + w*(val2 - val1);
		return val;
	    }
	} else {
	    if (R < maxR ) {  // Saturated case
		return linearInterpolation(saturated_oil_table_[0],
						 saturated_oil_table_[item],
						 press);
	    } else {  // Undersaturated case
		// Interpolate between table sections
                int is = tableIndex(saturated_oil_table_[3], maxR);
		double w = (maxR - saturated_oil_table_[3][is]) /
		    (saturated_oil_table_[3][is+1] - saturated_oil_table_[3][is]);
                ASSERT(undersat_oil_tables_[is][0].size() >= 2);
                ASSERT(undersat_oil_tables_[is+1][0].size() >= 2);
		double val1 =
		    linearInterpolation(undersat_oil_tables_[is][0],
					      undersat_oil_tables_[is][item],
					      press);
		double val2 = 
		    linearInterpolation(undersat_oil_tables_[is+1][0],
					      undersat_oil_tables_[is+1][item],
					      press);
		double val = val1 + w*(val2 - val1);
		return val;
	    }
	}
    }
Example #2
0
    inline double linearInterpolDerivative(const std::vector<double>& xv,
                                           const std::vector<double>& yv, double x)
    {
	int ix1 = tableIndex(xv, x);
	int ix2 = ix1 + 1;
	return  (yv[ix2] - yv[ix1])/(xv[ix2] - xv[ix1]);
    }
Example #3
0
void
TableModel::setItem(int row,
                    int column,
                    TableItem *item)
{
    int i = tableIndex(row, column);

    if ( (i < 0) || ( i >= _imp->tableItems.count() ) ) {
        return;
    }
    TableItem *oldItem = _imp->tableItems.at(i);
    if (item == oldItem) {
        return;
    }

    // remove old
    if (oldItem) {
        oldItem->view = 0;
    }
    delete _imp->tableItems.at(i);

    // set new
    if (item) {
        item->id = i;
    }
    _imp->tableItems[i] = item;

    QModelIndex idx = QAbstractTableModel::index(row, column);
    emit dataChanged(idx, idx);
}
Example #4
0
void
TableModel::setItem(int row,
                    int column,
                    TableItem *item)
{
    int i = tableIndex(row, column);

    if ( (i < 0) || ( i >= (int)_imp->tableItems.size() ) ) {
        throw std::domain_error("TableModel::setItem: index out of range");
    }
    TableItem *oldItem = _imp->tableItems.at(i);
    if (item == oldItem) {
        throw std::domain_error("TableModel::setItem: item already in table");
    }

    // remove old
    if (oldItem) {
        oldItem->view = 0;
    }
    delete _imp->tableItems.at(i);

    // set new
    if (item) {
        item->id = i;
    }
    _imp->tableItems[i] = item;

    QModelIndex idx = QAbstractTableModel::index(row, column);
    Q_EMIT dataChanged(idx, idx);
}
Example #5
0
bool
TableModel::insertRows(int row,
                       int count,
                       const QModelIndex &)
{
    if ( (count < 1) || (row < 0) || (row > _imp->rowCount) ) {
        return false;
    }
    beginInsertRows(QModelIndex(), row, row + count - 1);
    _imp->rowCount += count;
    int cc = _imp->horizontalHeaderItems.size();
    if (_imp->rowCount == 0) {
        _imp->tableItems.resize(cc * count);
    } else {
        std::vector<TableItem*>::iterator pos = _imp->tableItems.begin();
        int idx = tableIndex(row, 0);
        if ( idx < (int)_imp->tableItems.size() ) {
            std::advance(pos, idx);
            _imp->tableItems.insert(pos, cc * count, (TableItem*)0);
        } else {
            _imp->tableItems.insert(_imp->tableItems.end(), cc * count, (TableItem*)0);
        }
    }
    endInsertRows();

    return true;
}
Example #6
0
bool
TableModel::removeColumns(int column,
                          int count,
                          const QModelIndex &)
{
    if ( (count < 1) || (column < 0) || ( column + count >  _imp->horizontalHeaderItems.count() ) ) {
        return false;
    }

    beginRemoveColumns(QModelIndex(), column, column + count - 1);
    TableItem* oldItem = 0;
    for (int row = rowCount() - 1; row >= 0; --row) {
        int i = tableIndex(row, column);
        for (int j = i; j < i + count; ++j) {
            oldItem = _imp->tableItems.at(j);
            if (oldItem) {
                oldItem->view = 0;
            }
            delete oldItem;
        }
        _imp->tableItems.remove(i, count);
    }
    for (int h = column; h < column + count; ++h) {
        oldItem = _imp->horizontalHeaderItems.at(h);
        if (oldItem) {
            oldItem->view = 0;
        }
        delete oldItem;
    }
    _imp->horizontalHeaderItems.remove(column, count);
    endRemoveColumns();

    return true;
}
Example #7
0
bool
TableModel::removeRows(int row,
                       int count,
                       const QModelIndex &)
{
    if ( (count < 1) || (row < 0) || (row + count > _imp->rowCount) ) {
        return false;
    }

    beginRemoveRows(QModelIndex(), row, row + count - 1);
    int i = tableIndex(row, 0);
    int n = count * columnCount();
    TableItem *oldItem = 0;
    for (int j = i; j < n + i; ++j) {
        oldItem = _imp->tableItems.at(j);
        if (oldItem) {
            oldItem->view = 0;
        }
        delete oldItem;
    }
    _imp->rowCount -= count;
    _imp->tableItems.remove(std::max(i, 0), n);
    endRemoveRows();

    return true;
}
Example #8
0
    inline double linearInterpolationExtrap(const std::vector<double>& xv,
                                            const std::vector<double>& yv, double x)
    {
	// Extrapolates if x is outside xv
	int ix1 = tableIndex(xv, x);
	int ix2 = ix1 + 1;
	return  (yv[ix2] - yv[ix1])/(xv[ix2] - xv[ix1])*(x - xv[ix1]) + yv[ix1];
    }
Example #9
0
bool
TableModel::removeColumns(int column,
                          int count,
                          const QModelIndex &)
{
    if ( (count < 1) || (column < 0) || ( column + count >  (int)_imp->horizontalHeaderItems.size() ) ) {
        return false;
    }

    beginRemoveColumns(QModelIndex(), column, column + count - 1);
    TableItem* oldItem = 0;
    for (int row = rowCount() - 1; row >= 0; --row) {
        int i = tableIndex(row, column);
        for (int j = i; j < i + count; ++j) {
            oldItem = _imp->tableItems.at(j);
            if (oldItem) {
                oldItem->view = 0;
            }
            delete oldItem;
        }


        std::vector<TableItem*>::iterator pos = _imp->tableItems.begin();
        if ( i < (int)_imp->tableItems.size() ) {
            std::advance(pos, i);
            std::vector<TableItem*>::iterator last = pos;
            if ( (i + count) < (int)_imp->tableItems.size() ) {
                std::advance(last, count);
            } else {
                last = _imp->tableItems.end();
            }
            _imp->tableItems.erase(pos, last);
        }
    }
    for (int h = column; h < column + count; ++h) {
        oldItem = _imp->horizontalHeaderItems.at(h);
        if (oldItem) {
            oldItem->view = 0;
        }
        delete oldItem;
    }

    std::vector<TableItem*>::iterator pos = _imp->horizontalHeaderItems.begin();
    if ( column < (int)_imp->horizontalHeaderItems.size() ) {
        std::advance(pos, column);
        std::vector<TableItem*>::iterator last = pos;
        if ( (column + count) < (int)_imp->horizontalHeaderItems.size() ) {
            std::advance(last, count);
        } else {
            last = _imp->horizontalHeaderItems.end();
        }
        _imp->horizontalHeaderItems.erase(pos, last);
    }

    endRemoveColumns();

    return true;
} // TableModel::removeColumns
Example #10
0
TableItem *
TableModel::item(const QModelIndex &index) const
{
    if ( !isValid(index) ) {
        return 0;
    }

    return _imp->tableItems.at( tableIndex( index.row(), index.column() ) );
}
Example #11
0
TableItem *
TableModel::item(const QModelIndex &index) const
{
    if ( !isValid(index) ) {
        return 0;
    }

    int idx = tableIndex( index.row(), index.column() );

    return idx < (int)_imp->tableItems.size() ? _imp->tableItems[idx] : 0;
}
Example #12
0
TableItem *
TableModel::takeItem(int row,
                     int column)
{
    long i = tableIndex(row, column);
    TableItem *itm = _imp->tableItems[i];

    if (itm) {
        itm->view = 0;
        itm->id = -1;
        _imp->tableItems[i] = 0;
        QModelIndex ind = index(itm);
        Q_EMIT dataChanged(ind, ind);
    }

    return itm;
}
Example #13
0
bool
TableModel::insertRows(int row,
                       int count,
                       const QModelIndex &)
{
    if ( (count < 1) || (row < 0) || (row > _imp->rowCount) ) {
        return false;
    }
    beginInsertRows(QModelIndex(), row, row + count - 1);
    _imp->rowCount += count;
    int cc = _imp->horizontalHeaderItems.size();
    if (_imp->rowCount == 0) {
        _imp->tableItems.resize(cc * count);
    } else {
        _imp->tableItems.insert(tableIndex(row, 0), cc * count,0);
    }
    endInsertRows();

    return true;
}
Example #14
0
bool
TableModel::removeRows(int row,
                       int count,
                       const QModelIndex &)
{
    if ( (count < 1) || (row < 0) || (row + count > _imp->rowCount) ) {
        return false;
    }

    beginRemoveRows(QModelIndex(), row, row + count - 1);
    int i = tableIndex(row, 0);
    int n = count * columnCount();
    TableItem *oldItem = 0;
    for (int j = i; j < n + i; ++j) {
        oldItem = _imp->tableItems.at(j);
        if (oldItem) {
            oldItem->view = 0;
        }
        delete oldItem;
    }
    _imp->rowCount -= count;

    std::vector<TableItem*>::iterator pos = _imp->tableItems.begin();
    int idx = std::max(i, 0);
    if ( idx < (int)_imp->tableItems.size() ) {
        std::advance(pos, idx);
        std::vector<TableItem*>::iterator last = pos;
        if ( (idx + n) < (int)_imp->tableItems.size() ) {
            std::advance(last, n);
        } else {
            last = _imp->tableItems.end();
        }
        _imp->tableItems.erase(pos, last);
    }

    endRemoveRows();

    return true;
}
Example #15
0
bool
TableModel::insertColumns(int column,
                          int count,
                          const QModelIndex &)
{
    if ( (count < 1) || (column < 0) || ( column > (int)_imp->horizontalHeaderItems.size() ) ) {
        return false;
    }
    beginInsertColumns(QModelIndex(), column, column +  count - 1);
    int cc = _imp->horizontalHeaderItems.size();


    {
        std::vector<TableItem*>::iterator pos = _imp->horizontalHeaderItems.begin();
        if ( column < (int)_imp->horizontalHeaderItems.size() ) {
            std::advance(pos, column);
            _imp->horizontalHeaderItems.insert(pos, count, (TableItem*)0);
        } else {
            _imp->horizontalHeaderItems.insert(_imp->horizontalHeaderItems.end(), count, (TableItem*)0);
        }
    }
    if (cc == 0) {
        _imp->tableItems.resize(_imp->rowCount * count);
    } else {
        for (int row = 0; row < _imp->rowCount; ++row) {
            std::vector<TableItem*>::iterator pos = _imp->tableItems.begin();
            int idx = tableIndex(row, column);
            if ( idx < (int)_imp->tableItems.size() ) {
                std::advance(pos, idx);
                _imp->tableItems.insert(pos, count, (TableItem*)0);
            } else {
                _imp->tableItems.insert(_imp->tableItems.end(), count, (TableItem*)0);
            }
        }
    }
    endInsertColumns();

    return true;
}
Example #16
0
bool
TableModel::insertColumns(int column,
                          int count,
                          const QModelIndex &)
{
    if ( (count < 1) || (column < 0) || ( column > _imp->horizontalHeaderItems.size() ) ) {
        return false;
    }
    beginInsertColumns(QModelIndex(), column, column +  count - 1);
    int cc = _imp->horizontalHeaderItems.count();
    _imp->horizontalHeaderItems.insert(column, count, 0);
    if (cc == 0) {
        _imp->tableItems.resize(_imp->rowCount * count);
    } else {
        for (int row = 0; row < _imp->rowCount; ++row) {
            _imp->tableItems.insert(tableIndex(row, column), count, 0);
        }
    }
    endInsertColumns();

    return true;
}