Skip to content

dubious cumulative area calculation in triangulatedPatch

By code inspection this appears incorrect:

    const scalar offset = procSumWght[Pstream::myProcNo()];
    forAll(triWght, i)
    {
        if (i)
        {
            // Convert to cumulative
            triWght[i] += triWght[i-1];
        }

        // Apply processor offset
        triWght[i] += offset;
    }

    // Normalise
    const scalar sumWght = procSumWght.back();
    for (scalar& w : triWght)
    {
        w /= sumWght;
    }

Although the proc offset is being added after the local accumulation, that value will be again in the following steps of triWght[i] += triWght[i-1]

I think the correct code would look like this:

    // Convert to cumulative
    for (label i = 1; i < triWght.size(); ++i)
    {
        triWght[i] += triWght[i-1];
    }

    const scalar offset = procSumWght[Pstream::myProcNo()];
    const scalar totalArea = procSumWght.back();

    // Apply processor offset and normalise
    for (scalar& w : triWght)
    {
        w = (w + offset) / totalArea;
    }
Edited by Mark OLESEN