Пример #1
0
void ByteBuffer::uncommit(std::size_t n)
{
	throwLengthError(n, readbleSize_, "uncommit length error");
	auto frontBlock = blockList_.begin();
	assertReadableSize(frontBlock, position_, fixBlockSize_, readbleSize_);
	while (n > 0)
	{
		if (position_->writerIndex - position_->readerIndex < n)
		{
			assert(position_->readerIndex == 0);
			n -= position_->writerIndex;
			readbleSize_ -= position_->writerIndex;
			writableSize_ += position_->writerIndex;
			position_->writerIndex = 0;
			--position_;
		}
		else
		{
			position_->writerIndex -= n;
			readbleSize_ -= n;
			writableSize_ += n;
			n = 0;
		}
	}
}
Пример #2
0
void ByteBuffer::commit(std::size_t n)
{
	throwLengthError(n, writableSize_, "commit length error");
	assertWritableSize(position_, blockList_.end(), fixBlockSize_, writableSize_);
	while (n > 0)
	{
		std::size_t blockWriteSize = fixBlockSize_ - position_->writerIndex;
		auto frontWriteBlock = position_;
		if (n >= blockWriteSize && ++frontWriteBlock != blockList_.end())
		{
			position_->writerIndex = fixBlockSize_;
			++position_;
			n -= blockWriteSize;
			readbleSize_ += blockWriteSize;
			writableSize_ -= blockWriteSize;
		}
		else
		{
			position_->writerIndex += n;
			readbleSize_ += n;
			writableSize_ -= n;
			n = 0;
		}
	}
}
Пример #3
0
void ByteBuffer::consume(std::size_t n)
{
	throwLengthError(n, readbleSize_, "consume length error");
	auto frontBlock = blockList_.begin();
	assertReadableSize(frontBlock, position_, fixBlockSize_, readbleSize_);
	while (n > 0)
	{
		std::size_t blockReadableSize = frontBlock->writerIndex - frontBlock->readerIndex;
		if (blockReadableSize <= n)
		{
			frontBlock->readerIndex += blockReadableSize;
			n -= blockReadableSize;
			readbleSize_ -= blockReadableSize;
			if (frontBlock->writerIndex == fixBlockSize_)
			{
				frontBlock->readerIndex = 0;
				frontBlock->writerIndex = 0;
				bool isPositonBlock = (frontBlock == position_);
				blockList_.splice(blockList_.end(), blockList_, frontBlock);
				frontBlock = blockList_.begin();
				if (isPositonBlock)
				{
					position_ = frontBlock;
				}
				writableSize_ += fixBlockSize_;
			}
		}
		else
		{
			frontBlock->readerIndex += n;
			readbleSize_ -= n;
			n = 0;
		}
	}
}
Пример #4
0
RVector interpolate(const Mesh & mesh, const RVector & data,
                    const RVector & x, const RVector & y,
                    const RVector & z, bool verbose){
    
    if (x.size() != y.size() || x.size() != z.size()) {
        throwLengthError(EXIT_VECTOR_SIZE_INVALID, " x.size invalid y.size invalid z.size() "
                + toStr(x.size()) + " != " + toStr(y.size()) + " != " + toStr(z.size()));
    }

    std::vector < RVector3 > pos(x.size());
    for (uint i = 0; i < x.size(); i ++) pos[i] = RVector3(x[i], y[i], z[i]);

    RVector iData;
    interpolate(mesh, data, pos, iData, verbose);
    return iData;
}
Пример #5
0
template < class ValueType > Vector < ValueType >
_mult(const Matrix< ValueType > & M, const Vector < ValueType > & b, Index startI, Index endI) {
    Index cols = M.cols();
    Index rows = M.rows();
    Index bsize = Index(endI - startI);

    if (bsize != cols) {
        throwLengthError(1, WHERE_AM_I + " " + toStr(cols) + " < " + toStr(endI) + "-" + toStr(startI));
    }
    Vector < ValueType > ret(rows, 0.0);
    for (Index i = 0; i < rows; ++i){
        for (Index j = startI; j < endI; j++) {
            ret[i] += M.mat_[i][j] * b[j];
        }
    }
    return ret;
}
Пример #6
0
template < class ValueType > Vector < ValueType >
_transMult(const Matrix< ValueType > & M, const Vector < ValueType > & b) {
    Index cols = M.cols();
    Index rows = M.rows();
    Vector < ValueType > ret(cols, 0.0);

    if (b.size() == rows){
        for (Index i = 0; i < rows; i++){
            // ret += M.mat_[i] * b[i];
            for (Index j = 0; j < cols; j++){
                ret[j] += M.mat_[i][j] * b[i];
            }
        }
    } else {
        throwLengthError(1, WHERE_AM_I + " " + toStr(rows) + " != " + toStr(b.size()));
    }
    return ret;
}
Пример #7
0
template < class ValueType > Vector < ValueType >
_mult(const Matrix< ValueType > & M, const Vector < ValueType > & b) {
    Index cols = M.cols();
    Index rows = M.rows();

    Vector < ValueType > ret(rows, 0.0);
    
    //ValueType tmpval = 0;
    if (b.size() == cols){
        for (Index i = 0; i < rows; ++i){
            ret[i] = sum(M.mat_[i] * b);
            // for (Index j = 0; j < cols; j++){
            //     ret[i] += M.mat_[i][j] * b[j];
            // }
        }
    } else {
        throwLengthError(1, WHERE_AM_I + " " + toStr(cols) + " != " + toStr(b.size()));
    }
    return ret;
}
Пример #8
0
RVector cellDataToPointData(const Mesh & mesh, const RVector & cellData){
    if (cellData.size() != mesh.cellCount()){
        throwLengthError(EXIT_VECTOR_SIZE_INVALID, " vector size invalid mesh.cellCount "
                        + toStr(mesh.cellCount()) + " != " + toStr(cellData.size()));
    }

    RVector ret(mesh.nodeCount());

    std::set < Cell * > cset;
    for (uint i = 0; i < mesh.nodeCount(); i ++){
        cset = mesh.node(i).cellSet();
        for (std::set < Cell * >::iterator it = cset.begin(); it != cset.end(); it ++){
            ret[i] += cellData[(*it)->id()];
        }
        ret[i] /= cset.size();
    }

    return ret;


}
Пример #9
0
void interpolate(const Mesh & mesh, const RMatrix & vData,
                 const R3Vector & ipos, RMatrix & iData,
                 bool verbose){

    R3Vector pos(ipos);
    
    if (mesh.dim() == 2){
        if ((zVari(pos) || max(abs(z(pos))) > 0.) && 
            (!yVari(pos) && max(abs(y(pos))) < 1e-8)) {
            if (verbose) 
                std::cout << "Warning! swap YZ coordinates for query "
                            "positions to meet mesh dimensions." << std::endl;
            swapYZ(pos);
        }
    }
        
    if (iData.rows() != vData.rows()){
        iData.resize(vData.rows(), pos.size());
    }

    std::vector < Cell * > cells(pos.size());
    size_t count = 0;
    
    Cell * c = 0;
    for (uint i = 0; i < pos.size(); i ++) {
        
        c = mesh.findCell(pos[i], count, false);
//         if (!c) {__MS(pos[i])
//             c = mesh.findCell(pos[i], count, true);
//             if (!c) exit(0);
//         }
        cells[i] = c;
        if (verbose) std::cout << "\r" << i + 1 << " \t/ " << pos.size();
//                             << "\t searched: " << count << std::endl;
    }
    if (verbose) std::cout << std::endl;

    for (uint i = 0; i < vData.rows(); i ++) {
        if (verbose) std::cout << "\r" << i + 1 << " \t/ " << vData.rows();
        
        RVector data;
        
        if (vData[i].size() != 0){

            if (vData[i].size() == mesh.nodeCount()){
                data = vData[i];
            } else if (vData[i].size() == mesh.cellCount()){
                data = cellDataToPointData(mesh, vData[i]);
            } else {
                throwLengthError(EXIT_VECTOR_SIZE_INVALID,
                                 WHERE_AM_I + 
                                 " data.size not nodeCount and cellCount " + 
                                 toStr(vData[i].size()) + " != " + 
                                 toStr(mesh.nodeCount()) + " != " + 
                                 toStr(mesh.cellCount()));
            }

            for (uint j = 0; j < pos.size(); j ++) {
                if (cells[j]){
                    iData[i][j] = cells[j]->pot(pos[j], data);
                    
//              this check is obsolete if the findCell (from above) is working properly                     
//                     if (cells[j]->shape().isInside(pos[j])){
//                         iData[i][j] = cells[j]->pot(pos[j], data);
//                     } else {
//                         std::cout << WHERE_AM_I << " here is somethng wrong" << std::endl;
//                     }

//                    std::cout << j << " " << iData[i][j] << std::endl;
                    //** return cell data
//                    iData[i][j] = vData[i][cells[j]->id()];
                } else {        
                    iData[i][j] = 0.0;
                    //std::cout << "Cant find cell for " << pos[j]<< std::endl;
//                     for (uint i = 0; i < mesh.cellCount(); i ++){
//                     	if (mesh.cell(i).shape().isInside(pos[j], true)){
//                         	std::cout << mesh.cell(i) << std::endl;
//                         }
//                     }
//                     exit(0);
                }
            }
        } // if vData.size() != 0
    }  // for each in vData
    if (verbose) std::cout << std::endl;
}