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 DirichletProblem::setBoundaryConstraint( const Function& boundaryConstraint )
{
    const Index nx = getNx();
    const Index ny = getNy();
    const Precision hx=getHx();
    const Precision hy=getHy();
    const Point origin = getOrigin();
    solution_(-1,-1)=boundaryConstraint(origin.x-hx,origin.y-hy);
    for (Index sx=0; sx<=nx; sx++)
    {
        solution_(sx,-1)=boundaryConstraint(origin.x+sx*hx,origin.y-hy);
        solution_(sx,0)=boundaryConstraint(origin.x+sx*hx,origin.y+0.0);       //top border
        solution_(sx,ny)=boundaryConstraint(origin.x+sx*hx,origin.y+ny*hy);     //bottom border
        solution_(sx,ny+1)=boundaryConstraint(origin.x+sx*hx,origin.y+(ny+1)*hy);
    }
    solution_(nx+1,-1)=boundaryConstraint(origin.x+(nx+1)*hx,origin.y-hy);
    solution_(-1,ny+1)=boundaryConstraint(origin.x-hx,origin.y+(ny+1)*hy);
    for (Index sy=1; sy<ny; sy++)
    {
        solution_(-1,sy)=boundaryConstraint(origin.x-hx,origin.y+sy*hy);
        solution_(0,sy)=boundaryConstraint(origin.x+0.0,origin.y+sy*hy);        //left border
        solution_(nx,sy)=boundaryConstraint(origin.x+nx*hx,origin.y+sy*hy);      //right border
        solution_(nx+1,sy)=boundaryConstraint(origin.x+(nx+1)*hx,origin.y+sy*hy);
    }
    solution_(nx+1,ny+1)=boundaryConstraint(origin.x+(nx+1)*hx,origin.y+(ny+1)*hy);
}
void DirichletProblem::fillBorderValues(
        NumericArray& matrix,
        NumericArray& rightSide,
        const Index dimension) const
{
    const Index nx = getNx();
    const Index ny = getNy();
    //border values XDIR
    for (Index sx=0; sx<=nx; ++sx)
    {
        //lower border
        matrix[sx*dimension+sx]=1;
        rightSide[sx]=solution_(sx,0);
        //upper border
        matrix[(dimension-1-sx)*dimension+(dimension-1-sx)]=1;
        rightSide[dimension-1-sx]=solution_(nx-sx,ny);
    }
    //border values YDIR
    //corners have been process in XDIR (y=1..ny-1 instead of y=0..ny)
    for (Index sy=1; sy<ny; ++sy)
    {
        //left border
        matrix[sy*(nx+1)*dimension+sy*(nx+1)]=1;
        rightSide[sy*(nx+1)]=solution_(0,sy);
        //right border
        matrix[(sy*(nx+1)+nx)*dimension+(sy*(nx+1)+nx)]=1;
        rightSide[sy*(nx+1)+nx]=solution_(nx,sy);
    }
}
Example #4
0
Vector3 SphereGridTopology::getPointInGrid(int i, int j, int k) const
{
    //return p0+dx*x+dy*y+dz*z;
    SReal r = d_radius.getValue();
    Vector3 axisZ = d_axis.getValue();
    axisZ.normalize();
    Vector3 axisX = ((axisZ-Vector3(1,0,0)).norm() < 0.000001 ? Vector3(0,1,0) : Vector3(1,0,0));
    Vector3 axisY = cross(axisZ,axisX);
    axisX = cross(axisY,axisZ);
    axisX.normalize();
    axisY.normalize();
    axisZ.normalize();
    int nx = getNx();
    int ny = getNy();
    int nz = getNz();
    // coordonate on a square
    Vector3 p(i*2*r/(nx-1) - r, j*2*r/(ny-1) - r, k*2*r/(nz-1) - r);
    // scale it to be on a circle
    if (p.norm() > 0.0000001){
        SReal maxVal = helper::rmax(helper::rabs(p[0]),helper::rabs(p[1]));
        maxVal = helper::rmax(maxVal,helper::rabs(p[2]));
        p *= maxVal/p.norm();
    }

    return d_center.getValue()+axisX*p[0] + axisY*p[1] + axisZ * p[2];
}
DiscreteFunction DirichletProblem::residuum()
{
    const Index nx = getNx();
    const Index ny = getNy();
    const Precision hx=getHx();
    const Precision hy=getHy();
    const Point origin = getOrigin();
    DiscreteFunction result(0.0,origin,nx,ny,hx,hy);
    if (stencil_.size()<2)
    {
        for (Index sy=1; sy<ny; sy++)
        {
            for(Index sx=1; sx<nx; sx++)
            {
                result(sx,sy)=rightHandSide_(sx,sy)
                            -stencil_.apply(solution_,C,sx,sy);
            }
        }
    }
    else
    {
        //south west corner
        result(1,1)=rightHandSide_(1,1)
                    -stencil_.apply(solution_,SW,1,1);
        //south east corner
        result(nx-1,1)=rightHandSide_(nx-1,1)
                    -stencil_.apply(solution_,SE,nx-1,1);
        //north west corner
        result(1,ny-1)=rightHandSide_(1,ny-1)
                    -stencil_.apply(solution_,NW,1,ny-1);
        //north east corner
        result(nx-1,ny-1)=rightHandSide_(nx-1,ny-1)
                    -stencil_.apply(solution_,NE,nx-1,ny-1);
        //south boarder
        for (Index sx=2; sx<nx-1; sx++)
            result(sx,1)=rightHandSide_(sx,1)
                    -stencil_.apply(solution_,S,sx,1);
        //north boarder
        for (Index sx=2; sx<nx-1; sx++)
            result(sx,ny-1)=rightHandSide_(sx,ny-1)
                    -stencil_.apply(solution_,N,sx,ny-1);
        //west boarder
        for (Index sy=2; sy<ny-1; sy++)
            result(1,sy)=rightHandSide_(1,sy)
                    -stencil_.apply(solution_,W,1,sy);
        //east boarder;
        for (Index sy=2; sy<ny-1; sy++)
            result(nx-1,sy)=rightHandSide_(nx-1,sy)
                    -stencil_.apply(solution_,E,nx-1,sy);
        //the center
        for (Index sy=2; sy<ny-1; sy++)
            for (Index sx=2; sx<nx-1; sx++)
                result(sx,sy)=rightHandSide_(sx,sy)
                        -stencil_.apply(solution_,C,sx,sy);
    }
    return result;
}
Example #6
0
void SuperGeometry2D::printLayer(int direction, int layer, bool linenumber) {
  assert(direction >= 0 && direction <= 2);
  switch (direction) {
  case 0:
    printLayer(layer, layer, 0, getNy() - 1, linenumber);
    break;
  case 1:
    printLayer(0, getNx() - 1, layer, layer, linenumber);
    break;
  }
}
Example #7
0
bool MultiDataDistribution2D::getNextChunkX(int iX, int iY, int& nextLattice, int& nextChunkSize) const {
    nextLattice = locate(iX,iY);
    if (nextLattice == -1) {
        int exploreX = iX+1;
        while(exploreX<getNx() && locate(exploreX,iY)==-1) {
            ++exploreX;
        }
        nextChunkSize = exploreX-iX;
        return false;
    }
    else {
        nextChunkSize = blocks[nextLattice].getBulk().x1-iX+1;
        return true;
    }
}
Example #8
0
Box2D AtomicBlock2D::getBoundingBox() const {
    return Box2D(0, getNx()-1, 0, getNy()-1);
}
Example #9
0
int MRC::getImSize()
{
	return getNx()*getNy()*getWordLength();
}
Example #10
0
Box3D AtomicBlock3D::getBoundingBox() const {
    return Box3D(0, getNx()-1, 0, getNy()-1, 0, getNz()-1);
}