vector<CVector> CellInitHelper::generateInitCellNodes() {
	bool isSuccess = false;
	vector<CVector> attemptedPoss;
	while (!isSuccess) {
		attemptedPoss = tryGenInitCellNodes();
		if (isPosQualify(attemptedPoss)) {
			isSuccess = true;
		}
	}
	// also need to make sure center point is (0,0,0).
	CVector tmpSum(0, 0, 0);
	for (uint i = 0; i < attemptedPoss.size(); i++) {
		tmpSum = tmpSum + attemptedPoss[i];
	}
	tmpSum = tmpSum / (double) (attemptedPoss.size());
	for (uint i = 0; i < attemptedPoss.size(); i++) {
		attemptedPoss[i] = attemptedPoss[i] - tmpSum;
	}
	return attemptedPoss;
}
示例#2
0
void Foam::GAMGAgglomeration::createTarget
(
    const labelgpuList& list,
    const labelgpuList& sort,
    labelgpuList& target,
    labelgpuList& targetStart
)
{
    labelgpuList ones(list.size(),1);
    labelgpuList tmpTarget(list.size());
    labelgpuList tmpSum(list.size());

    labelgpuList listSort(list.size());
    
    thrust::copy
    (
        thrust::make_permutation_iterator
        (
            list.begin(),
            sort.begin()
        ),
        thrust::make_permutation_iterator
        (
            list.begin(),
            sort.end()
        ),
        listSort.begin()
    );
 
    target = listSort;

    label targetSize = 
        thrust::unique
        (
            target.begin(),
            target.end()
        ) 
        - target.begin();
    target.setSize(targetSize);

    targetStart.setSize(list.size());
  
    thrust::reduce_by_key
    (
        listSort.begin(),
        listSort.end(),
        ones.begin(),
        tmpTarget.begin(),
        tmpSum.begin()
    );

    thrust::exclusive_scan
    (
        tmpSum.begin(),
        tmpSum.end(),
        targetStart.begin()
    );

    targetStart.setSize(targetSize+1);
    targetStart.set(targetSize,list.size());
}
示例#3
0
void Foam::lduAddressing::calcLosortStart() const
{
    if (losortStartPtr_)
    {
        FatalErrorIn("lduAddressing::calcLosortStart() const")
            << "losort start already calculated"
            << abort(FatalError);
    }

    const labelgpuList& nbr = upperAddr();

    const labelgpuList& lsrt = losortAddr();

    losortStartPtr_ = new labelgpuList(size() + 1, nbr.size());

    labelgpuList& lsrtStart = *losortStartPtr_;

    labelgpuList ones(nbr.size()+size(),1);
    labelgpuList tmpCell(size());
    labelgpuList tmpSum(size());

    labelgpuList nbrSort(nbr.size()+size());

    thrust::copy
    (
        thrust::make_permutation_iterator
        (
            nbr.begin(),
            lsrt.begin()
        ),
        thrust::make_permutation_iterator
        (
            nbr.begin(),
            lsrt.end()
        ),
        nbrSort.begin()
    );
                 
    thrust::copy
    (
        thrust::make_counting_iterator(0),
        thrust::make_counting_iterator(0)+size(),
        nbrSort.begin()+nbr.size()
    );
                 
    thrust::fill
    (
        ones.begin()+nbr.size(),
        ones.end(),
        0
    );
                 

    thrust::stable_sort_by_key
    (
        nbrSort.begin(),
        nbrSort.end(),
        ones.begin()
    );     

    thrust::reduce_by_key
    (
        nbrSort.begin(),
        nbrSort.end(),
        ones.begin(),
        tmpCell.begin(),
        tmpSum.begin()
    );

    thrust::exclusive_scan
    (
        tmpSum.begin(),
        tmpSum.begin()+size(),
        lsrtStart.begin()
    );
}
示例#4
0
void Foam::lduAddressing::calcOwnerStart() const
{
    if (ownerStartPtr_)
    {
        FatalErrorIn("lduAddressing::calcOwnerStart() const")
            << "owner start already calculated"
            << abort(FatalError);
    }

    const labelgpuList& own = lowerAddr();

    ownerStartPtr_ = new labelgpuList(size() + 1, own.size());

    labelgpuList& ownStart = *ownerStartPtr_;

    labelgpuList ones(own.size()+size(),1);
    labelgpuList tmpCell(size());
    labelgpuList tmpSum(size());
    
    labelgpuList ownSort(own.size()+size());
    
    
    thrust::copy
    (
        own.begin(),
        own.end(),
        ownSort.begin()
    );
                 
    thrust::copy
    (
        thrust::make_counting_iterator(0),
        thrust::make_counting_iterator(0)+size(),
        ownSort.begin()+own.size()
    );
                 
    thrust::fill
    (
        ones.begin()+own.size(),
        ones.end(),
        0
    );
    
    thrust::stable_sort_by_key
    (
        ownSort.begin(),
        ownSort.end(),
        ones.begin()
    );  
    

    thrust::reduce_by_key
    (
        ownSort.begin(),
        ownSort.end(),
        ones.begin(),
        tmpCell.begin(),
        tmpSum.begin()
    );

    thrust::exclusive_scan
    (
        tmpSum.begin(),
        tmpSum.end(),
        ownStart.begin()
    );
}
示例#5
0
void Foam::lduAddressing::calcPatchSortStart() const
{
    if (patchSortStartAddr_.size() == nPatches())
    {
        FatalErrorIn("lduAddressing::calcLosortStart() const")
            << "losort start already calculated"
            << abort(FatalError);
    }

    patchSortStartAddr_.setSize(nPatches());

    for(label i = 0; i < nPatches(); i++)
    {
        if( ! patchAvailable(i))
            continue;

        const labelgpuList& nbr = patchAddr(i);

        const labelgpuList& lsrt = patchSortAddr(i);

        labelgpuList* patchSortStartPtr_ = new labelgpuList(nbr.size() + 1, nbr.size());

        patchSortStartAddr_.set(i,patchSortStartPtr_);

        labelgpuList& lsrtStart = *patchSortStartPtr_;

        labelgpuList ones(nbr.size(),1);
        labelgpuList tmpCell(nbr.size());
        labelgpuList tmpSum(nbr.size());

        labelgpuList nbrSort(nbr.size());

        thrust::copy
        (
            thrust::make_permutation_iterator
            (
                nbr.begin(),
                lsrt.begin()
            ),
            thrust::make_permutation_iterator
            (
                nbr.begin(),
                lsrt.end()
            ),
            nbrSort.begin()
        );

        thrust::reduce_by_key
        (
            nbrSort.begin(),
            nbrSort.end(),
            ones.begin(),
            tmpCell.begin(),
            tmpSum.begin()
        );

        thrust::exclusive_scan
        (
            tmpSum.begin(),
            tmpSum.end(),
            lsrtStart.begin()
        );
    }
}
示例#6
0
Slice * PithExtractor::convolution(const Slice &slice, arma::fcolvec verticalFilter, arma::frowvec horizontalFilter) const {
	const uint height = slice.n_rows;
	const uint width = slice.n_cols;
	Slice *resultat = new Slice(height, width);

	arma::fmat tmpSum;
	arma::fvec sum = arma::fvec(width);
	resultat->zeros();
	int kOffset;
	int kCenter;
	int lag;
	int endIndex;

	//convolve horizontal direction

	//find center position of kernel
	kCenter = horizontalFilter.n_cols/2;
	endIndex = width-kCenter;

	tmpSum = arma::fmat(height, width);
	tmpSum.zeros();
	for (uint i=0; i<height; i++) { //height pictures (nb rows)
		kOffset = 0;
		//index=0 to index=kCenter-1
		for (int j=0; j<kCenter; j++) {
			for (int k=kCenter+kOffset, m=0; k>=0; k--, m++) {
				tmpSum(i,j) += slice(i,m) * horizontalFilter[k];
			}
			kOffset++;
		}
		//index=kCenter to index=(width pictures)-kCenter-1)
		for (int j=kCenter; j<endIndex; j++) {
			lag = j-kCenter;
			for (int k=horizontalFilter.n_cols-1, m=0; k >= 0; k--, m++) {
				tmpSum(i,j) += slice(i,(lag+m)) * horizontalFilter[k];
			}
		}
		//index=(width pictures)-kCenter to index=(width pictures)-1
		kOffset = 1;
		for (uint j=endIndex; j<width; j++) {
			lag = j-kCenter;
			for (int k=horizontalFilter.n_cols-1, m=0; k >= kOffset; k--, m++) {
				tmpSum(i,j) += slice(i,lag+m) * horizontalFilter[k];
			}
			kOffset++;
		}
	}


	//convolve vertical direction

	//find center position of kernel
	kCenter = verticalFilter.n_rows/2;
	endIndex = width-kCenter;

	sum.zeros();

	kOffset = 0;
	//index=0 to index=(kCenter-1)
	for (int i=0; i <kCenter; i++) {
		lag = -i;
		for (int k = kCenter + kOffset; k>=0; k--) {			//convolve with partial kernel
			for (uint j=0; j<width; j++) {
				sum[j] += tmpSum(i+lag,j) * verticalFilter[k];
			}
			lag++;
		}
		for (uint n=0; n<width; n++) {				//convert to output format
			if(sum[n]>=0)
				(*resultat)(i,n) = (int)(sum[n] + 0.5f);
			else
				(*resultat)(i,n) = (int)(sum[n] - 0.5f);
			sum[n] = 0;											//reset before next summing
		}
		kOffset++;
	}
	//index=kCenter to index=(height pictures)-kCenter-1
	for (int i=kCenter; i<endIndex; i++) {
		lag = -kCenter;
		for (int k=verticalFilter.n_rows-1; k>=0; k--) {				//convolve with full kernel
			for(uint j=0; j<width; j++){
				sum[j] += tmpSum(i+lag,j) * verticalFilter[k];
			}
			lag++;
		}
		for (uint n=0; n<width; n++) {				//convert to output format
			if(sum[n]>=0)
				(*resultat)(i,n) = (int)(sum[n] + 0.5f);
			else
				(*resultat)(i,n) = (int)(sum[n] - 0.5f);
			sum[n] = 0;											//reset before next summing
		}
	}
	//index=(height pictures)-kcenter to index=(height pictures)-1
	kOffset = 1;
	for (uint i=endIndex; i<height; i++) {
		lag = -kCenter;
		for (int k=verticalFilter.n_rows-1; k>=kOffset; k--) {			//convolve with partial kernel
			for (uint j=0; j<width; j++) {			//height p	corrigeictures
				sum[j] += tmpSum(i+lag,j) * verticalFilter[k];
			}
			lag++;
		}
		for (uint n=0; n<width; n++) {				//convert to output format
			if(sum[n]>=0)
				(*resultat)(i,n) = (int)(sum[n] + 0.5f);
			else
				(*resultat)(i,n) = (int)(sum[n] - 0.5f);
			sum[n] = 0;											//reset before next summing
		}
		kOffset++;
	}

	return resultat;
}