Example #1
0
void MultiDataDistribution2D::computePeriodicOverlaps() {
    int iNew = getNumBlocks()-1;
    BlockParameters2D const& newBlock = blocks[iNew];
    BlockCoordinates2D intersection;
    for (int dx=-1; dx<=+1; dx+=1) {
        for (int dy=-1; dy<=+1; dy+=1) {
            if (dx!=0 || dy!=0) {
                int shiftX = dx*getNx();
                int shiftY = dy*getNy();
                BlockCoordinates2D newBulk(newBlock.getBulk().shift(shiftX,shiftY));
                BlockCoordinates2D newEnvelope(newBlock.getEnvelope().shift(shiftX,shiftY));
                for (int iBlock=0; iBlock<getNumBlocks(); ++iBlock) {
                    if (util::intersect(blocks[iBlock].getBulk(), newEnvelope, intersection)) {
                        periodicOverlaps.push_back( Overlap2D(iBlock, iNew, intersection, shiftX, shiftY) );
                        neighbors[iBlock].push_back(iNew);
                    }
                    if (!(iBlock==iNew) &&
                        util::intersect(newBulk, blocks[iBlock].getEnvelope(), intersection))
                    {
                        intersection = intersection.shift(-shiftX,-shiftY);
                        periodicOverlaps.push_back( Overlap2D(iNew, iBlock, intersection, -shiftX, -shiftY) );
                        neighbors[iNew].push_back(iBlock);
                    }
                }
            }
        }
    }
}
void LocalMultiBlockInfo2D::computeNormalOverlaps (
    SparseBlockStructure2D const& sparseBlock, plint blockId )
{
    Box2D intersection;
    SmartBulk2D bulk(sparseBlock, envelopeWidth, blockId);

    std::vector<plint> neighbors;
    sparseBlock.findNeighbors(blockId, envelopeWidth, neighbors);

    for (pluint iNeighbor=0; iNeighbor<neighbors.size(); ++iNeighbor)
    {
        plint neighborId = neighbors[iNeighbor];
        SmartBulk2D neighborBulk(sparseBlock, envelopeWidth, neighborId);
        if (intersect( neighborBulk.getBulk(),
                       bulk.computeNonPeriodicEnvelope(), intersection) )
        {
            normalOverlaps.push_back(Overlap2D(neighborId, blockId, intersection));
        }
        if (intersect( bulk.getBulk(),
                       neighborBulk.computeNonPeriodicEnvelope(), intersection) )
        {
            normalOverlaps.push_back(Overlap2D(blockId, neighborId, intersection));
        }
    }
}
void LocalMultiBlockInfo2D::computePeriodicOverlaps (
    SparseBlockStructure2D const& sparseBlock, plint blockId )
{
    Box2D intersection; // Temporary variable.
    std::vector<plint> neighbors; // Temporary variable.
    SmartBulk2D bulk(sparseBlock, envelopeWidth, blockId);

    for (plint dx=-1; dx<=+1; dx+=1) {
        for (plint dy=-1; dy<=+1; dy+=1) {
            if (dx!=0 || dy!=0) {
                // The new block is shifted by the length of the full multi block in each space
                //   direction. Consequently, overlaps between the original multi block and the
                //   shifted new block are identified as periodic overlaps.
                plint shiftX = dx*sparseBlock.getBoundingBox().getNx();
                plint shiftY = dy*sparseBlock.getBoundingBox().getNy();
                Box2D shiftedBulk(bulk.getBulk().shift(shiftX,shiftY));
                Box2D shiftedEnvelope(bulk.computeEnvelope().shift(shiftX,shiftY));
                // Speed optimization: perform following checks only if the shifted
                //   domain touches the bounding box.
                Box2D dummyIntersection;
                if (intersect(shiftedEnvelope, sparseBlock.getBoundingBox(), dummyIntersection)) {
                    neighbors.clear();
                    sparseBlock.findNeighbors(shiftedBulk, envelopeWidth, neighbors);
                    // Check overlap with each existing block in the neighborhood, including with the newly added one.
                    for (pluint iNeighbor=0; iNeighbor<neighbors.size(); ++iNeighbor) {
                        plint neighborId = neighbors[iNeighbor];
                        SmartBulk2D neighborBulk(sparseBlock, envelopeWidth, neighborId);
                        // Does the envelope of the shifted new block overlap with the bulk of a previous
                        //   block? If yes, add an overlap, in which the previous block has the "original
                        //   position", and the new block has the "overlap position".
                        if (intersect(neighborBulk.getBulk(), shiftedEnvelope, intersection)) {
                            PeriodicOverlap2D overlap (
                                Overlap2D(neighborId, blockId, intersection, shiftX, shiftY),
                                dx, dy );
                            periodicOverlaps.push_back(overlap);
                            periodicOverlapWithRemoteData.push_back(overlap);
                        }
                        // Does the bulk of the shifted new block overlap with the envelope of a previous
                        //   block? If yes, add an overlap, in which the new block has the "original position",
                        //   and the previous block has the "overlap position".
                        //   If we are in the situation in which the newly added block is periodic with itself,
                        //   this step must be skipped, because otherwise the overlap is counted twice.
                        if (!(neighborId==blockId) &&
                                intersect(shiftedBulk, neighborBulk.computeEnvelope(), intersection))
                        {
                            intersection = intersection.shift(-shiftX,-shiftY);
                            periodicOverlaps.push_back (
                                PeriodicOverlap2D (
                                    Overlap2D(blockId, neighborId, intersection, -shiftX, -shiftY),
                                    -dx, -dy ) );
                        }
                    }
                }
            }
        }
    }
}
Example #4
0
void MultiDataDistribution2D::computeNormalOverlaps(BlockParameters2D const& newBlock) {
    neighbors.resize(getNumBlocks()+1);
    BlockCoordinates2D intersection;
    int iNew = getNumBlocks();
    for (int iBlock=0; iBlock<getNumBlocks(); ++iBlock) {
        if (util::intersect(blocks[iBlock].getBulk(), newBlock.getNonPeriodicEnvelope(), intersection)) {
            normalOverlaps.push_back(Overlap2D(iBlock, iNew, intersection));
            neighbors[iBlock].push_back(iNew);
        }
        if (util::intersect(newBlock.getBulk(), blocks[iBlock].getNonPeriodicEnvelope(), intersection)) {
            normalOverlaps.push_back(Overlap2D(iNew, iBlock, intersection));
            neighbors[iNew].push_back(iBlock);
        }
    }
}