void Foam::searchableExtrudedCircle::boundingSpheres
(
    pointField& centres,
    scalarField& radiusSqr
) const
{
    centres = eMeshPtr_().points();
    radiusSqr.setSize(centres.size());
    radiusSqr = Foam::sqr(radius_);
    // Add a bit to make sure all points are tested inside
    radiusSqr += Foam::sqr(SMALL);
}
void Foam::searchableCylinder::boundingSpheres
(
    pointField& centres,
    scalarField& radiusSqr
) const
{
    centres.setSize(1);
    centres[0] = 0.5*(point1_ + point2_);

    radiusSqr.setSize(1);
    radiusSqr[0] = Foam::magSqr(point1_-centres[0]) + Foam::sqr(radius_);

    // Add a bit to make sure all points are tested inside
    radiusSqr += Foam::sqr(SMALL);
}
Beispiel #3
0
void Foam::searchablePlate::boundingSpheres
(
    pointField& centres,
    scalarField& radiusSqr
) const
{
    centres.setSize(1);
    centres[0] = origin_ + 0.5*span_;

    radiusSqr.setSize(1);
    radiusSqr[0] = Foam::magSqr(0.5*span_);

    // Add a bit to make sure all points are tested inside
    radiusSqr += Foam::sqr(SMALL);
}
Beispiel #4
0
void Foam::searchableDisk::boundingSpheres
(
    pointField& centres,
    scalarField& radiusSqr
) const
{
    centres.setSize(1);
    centres[0] = origin_;

    radiusSqr.setSize(1);
    radiusSqr[0] = sqr(radius_);

    // Add a bit to make sure all points are tested inside
    radiusSqr += Foam::sqr(small);
}
void Foam::AMIInterpolation<SourcePatch, TargetPatch>::normaliseWeights
(
    const scalarField& patchAreas,
    const word& patchName,
    const labelListList& addr,
    scalarListList& wght,
    scalarField& wghtSum,
    const bool conformal,
    const bool output,
    const scalar lowWeightTol
)
{
    // Normalise the weights
    wghtSum.setSize(wght.size(), 0.0);
    label nLowWeight = 0;

    forAll(wght, facei)
    {
        scalarList& w = wght[facei];

        if (w.size())
        {
            scalar denom = patchAreas[facei];

            scalar s = sum(w);
            scalar t = s/denom;

            if (conformal)
            {
                denom = s;
            }

            forAll(w, i)
            {
                w[i] /= denom;
            }

            wghtSum[facei] = t;

            if (t < lowWeightTol)
            {
                nLowWeight++;
            }
        }
Beispiel #6
0
void Foam::pointMVCWeight::calcWeights
(
    const Map<label>& toLocal,
    const face& f,
    const DynamicList<point>& u,
    const scalarField& dist,
    scalarField& weights
) const
{
    weights.setSize(toLocal.size());
    weights = 0.0;

    scalarField theta(f.size());

    // recompute theta, the theta computed previously are not robust
    forAll(f, j)
    {
        label jPlus1 = f.fcIndex(j);
        scalar l = mag(u[j] - u[jPlus1]);
        theta[j] = 2.0*Foam::asin(l/2.0);
    }
bool splineInterpolationWeights::valueWeights
(
    const scalar t,
    labelList& indices,
    scalarField& weights
) const
{
    bool indexChanged = false;

    // linear interpolation
    if (samples_.size() <= 2)
    {
        return linearInterpolationWeights(samples_).valueWeights
        (
            t,
            indices,
            weights
        );
    }

    // Check if current timeIndex is still valid
    if
    (
        index_ >= 0
     && index_ < samples_.size()
     && (
            samples_[index_] <= t
         && (index_ == samples_.size()-1 || t <= samples_[index_+1])
        )
    )
    {
        // index_ still at correct slot
    }
    else
    {
        // search for correct index
        index_ = findLower(samples_, t);
        indexChanged = true;
    }


    // Clamp if outside table
    if (index_ == -1)
    {
        indices.setSize(1);
        weights.setSize(1);

        indices[0] = 0;
        weights[0] = 1;
        return indexChanged;
    }
    else if (index_ == samples_.size()-1)
    {
        indices.setSize(1);
        weights.setSize(1);

        indices[0] = samples_.size()-1;
        weights[0] = 1;
        return indexChanged;
    }



    label lo = index_;
    label hi = index_+1;

    // weighting
    scalar mu = (t - samples_[lo])/(samples_[hi] - samples_[lo]);

    scalar w0 = 0.5*(mu*(-1+mu*(2-mu)));            // coeff of lo-1
    scalar w1 = 0.5*(2+mu*(mu*(-5 + mu*(3))));      // coeff of lo
    scalar w2 = 0.5*(mu*(1 + mu*(4 + mu*(-3))));    // coeff of hi
    scalar w3 = 0.5*(mu*mu*(-1 + mu));              // coeff of hi+1

    if (lo > 0)
    {
        if (hi < samples_.size()-1)
        {
            // Four points available
            indices.setSize(4);
            weights.setSize(4);

            indices[0] = lo-1;
            indices[1] = lo;
            indices[2] = hi;
            indices[3] = hi+1;

            weights[0] = w0;
            weights[1] = w1;
            weights[2] = w2;
            weights[3] = w3;
        }
        else
        {
            // No y3 available. Extrapolate: y3=3*y2-y1
            indices.setSize(3);
            weights.setSize(3);

            indices[0] = lo-1;
            indices[1] = lo;
            indices[2] = hi;

            weights[0] = w0;
            weights[1] = w1 - w3;
            weights[2] = w2 + 2*w3;
        }
    }
    else
    {
        // No y0 available. Extrapolate: y0=2*y1-y2;
        if (hi < samples_.size()-1)
        {
            indices.setSize(3);
            weights.setSize(3);

            indices[0] = lo;
            indices[1] = hi;
            indices[2] = hi+1;

            weights[0] = w1 + 2*w0;
            weights[1] = w2 - w0;
            weights[2] = w3;
        }
        else
        {
            indices.setSize(2);
            weights.setSize(2);

            indices[0] = lo;
            indices[1] = hi;

            weights[0] = w1 + 2*w0 - w3;
            weights[1] = w2 - w0 + 2*w3;
        }
    }

    return indexChanged;
}
bool linearInterpolationWeights::valueWeights
(
    const scalar t,
    labelList& indices,
    scalarField& weights
) const
{
    bool indexChanged = false;

    // Check if current timeIndex is still valid
    if
    (
        index_ >= 0
     && index_ < samples_.size()
     && (
            samples_[index_] <= t
         && (index_ == samples_.size()-1 || t <= samples_[index_+1])
        )
    )
    {
        // index_ still at correct slot
    }
    else
    {
        // search for correct index
        index_ = findLower(samples_, t);
        indexChanged = true;
    }


    if (index_ == -1)
    {
        // Use first element only
        indices.setSize(1);
        weights.setSize(1);
        indices[0] = 0;
        weights[0] = 1.0;
    }
    else if (index_ == samples_.size()-1)
    {
        // Use last element only
        indices.setSize(1);
        weights.setSize(1);
        indices[0] = samples_.size()-1;
        weights[0] = 1.0;
    }
    else
    {
        // Interpolate
        indices.setSize(2);
        weights.setSize(2);

        indices[0] = index_;
        indices[1] = index_+1;

        scalar t0 = samples_[indices[0]];
        scalar t1 = samples_[indices[1]];
        scalar deltaT = t1-t0;

        weights[0] = (t1-t)/deltaT;
        weights[1] = 1.0-weights[0];
    }

    return indexChanged;
}
bool linearInterpolationWeights::integrationWeights
(
    const scalar t1,
    const scalar t2,
    labelList& indices,
    scalarField& weights
) const
{
    if (t2 < t1-VSMALL)
    {
        FatalErrorIn("linearInterpolationWeights::integrationWeights(..)")
            << "Integration should be in positive direction."
            <<  " t1:" << t1 << " t2:" << t2
            << exit(FatalError);
    }

    // Currently no fancy logic on cached index like in value

    //- Find lower or equal index
    label i1 = findLower(samples_, t1, 0, lessEqOp<scalar>());
    //- Find lower index
    label i2 = findLower(samples_, t2);

    // For now just fail if any outside table
    if (i1 == -1 || i2 == samples_.size()-1)
    {
        FatalErrorIn("linearInterpolationWeights::integrationWeights(..)")
            << "Integrating outside table " << samples_[0] << ".."
            << samples_.last() << " not implemented."
            << " t1:" << t1 << " t2:" << t2 << exit(FatalError);
    }

    label nIndices = i2-i1+2;


    // Determine if indices already correct
    bool anyChanged = false;

    if (nIndices != indices.size())
    {
        anyChanged = true;
    }
    else
    {
        // Closer check

        label index = i1;
        forAll(indices, i)
        {
            if (indices[i] != index)
            {
                anyChanged = true;
                break;
            }
            index++;
        }
    }

    indices.setSize(nIndices);
    weights.setSize(nIndices);
    weights = 0.0;

    // Sum from i1+1 to i2+1
    for (label i = i1+1; i <= i2; i++)
    {
        scalar d = samples_[i+1]-samples_[i];
        indices[i-i1] = i;
        weights[i-i1] += 0.5*d;
        indices[i+1-i1] = i+1;
        weights[i+1-i1] += 0.5*d;
    }

    // Add from i1 to t1
    {
        Pair<scalar> i1Tot1 = integrationWeights(i1, t1);
        indices[0] = i1;
        weights[0] += i1Tot1.first();
        indices[1] = i1+1;
        weights[1] += i1Tot1.second();
    }

    // Subtract from t2 to i2+1
    {
        Pair<scalar> wghts = integrationWeights(i2, t2);
        indices[i2-i1] = i2;
        weights[i2-i1] += -wghts.first();
        indices[i2-i1+1] = i2+1;
        weights[i2-i1+1] += -wghts.second();
    }

    return anyChanged;
}
void Foam::meshRefinement::snapToSurface
(
    labelList& pointSurfaceRegion,
    labelList& edgeSurfaceRegion,
    scalarField& edgeWeight
)
{
    const edgeList& edges = mesh_.edges();
    const pointField& points = mesh_.points();

    pointSurfaceRegion.setSize(points.size());
    pointSurfaceRegion = -1;

    edgeSurfaceRegion.setSize(edges.size());
    edgeSurfaceRegion = -1;

    edgeWeight.setSize(edges.size());
    edgeWeight = -GREAT;


    // Do test for intersections
    // ~~~~~~~~~~~~~~~~~~~~~~~~~

    labelList surface1;
    List<pointIndexHit> hit1;
    labelList region1;
    //vectorField normal1;

    labelList surface2;
    List<pointIndexHit> hit2;
    labelList region2;
    //vectorField normal2;
    {
        vectorField start(edges.size());
        vectorField end(edges.size());
        forAll(edges, edgei)
        {
            const edge& e = edges[edgei];
            start[edgei] = points[e[0]];
            end[edgei] = points[e[1]];
        }
        
        surfaces_.findNearestIntersection
        (
            //labelList(1, 0),    //identity(surfaces_.surfaces().size()),
            identity(surfaces_.surfaces().size()),
            start,
            end,

            surface1,
            hit1,
            region1,
            //normal1,

            surface2,
            hit2,
            region2
            //normal2
        );
    }

    // Adjust location
    // ~~~~~~~~~~~~~~~

    pointField newPoints(points);
    label nAdjusted = 0;

    const labelListList& pointEdges = mesh_.pointEdges();
    forAll(pointEdges, pointi)
    {
        const point& pt = points[pointi];
        const labelList& pEdges = pointEdges[pointi];

        // Get the nearest intersection
        label minEdgei = -1;
        scalar minFraction = 0.5;   // Harpoon 0.25; // Samm?
        forAll(pEdges, pEdgei)
        {
            label edgei = pEdges[pEdgei];
            if (hit1[edgei].hit())
            {
                const point& hitPt = hit1[edgei].hitPoint();

                const edge& e = edges[edgei];
                label otherPointi = e.otherVertex(pointi);
                const point& otherPt = points[otherPointi];

                vector eVec(otherPt-pt);
                scalar f = eVec&(hitPt-pt)/magSqr(eVec);

                if (f < minFraction)
                {
                    minEdgei = edgei;
                    minFraction = f;
                }
            }
        }
        if (minEdgei != -1 && minFraction >= 0.01)
        {
            // Move point to intersection with minEdgei
            if (pointSurfaceRegion[pointi] == -1)
            {
                pointSurfaceRegion[pointi] = surfaces_.globalRegion
                (
                    surface1[minEdgei],
                    region1[minEdgei]
                );
                newPoints[pointi] = hit1[minEdgei].hitPoint();
                nAdjusted++;
            }
        }
    }