Skip to content
Snippets Groups Projects
Commit dfe98fdf authored by Andrew Heather's avatar Andrew Heather Committed by Mattijs Janssens
Browse files

ENH: linearInterpolationWeights - protect against and provide early exit if input values are equal

parent 2811c054
No related branches found
No related tags found
1 merge request!414Feature function1 limit range
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2015 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -160,7 +160,7 @@ bool Foam::linearInterpolationWeights::integrationWeights
scalarField& weights
) const
{
if (t2 < t1-VSMALL)
if (t2 < t1 - ROOTVSMALL)
{
FatalErrorInFunction
<< "Integration should be in positive direction."
......@@ -173,6 +173,20 @@ bool Foam::linearInterpolationWeights::integrationWeights
//- Find lower or equal index
const label i1 = findLower(samples_, t1, 0, lessEqOp<scalar>());
if (t2 <= t1 + ROOTVSMALL)
{
// Early exit if 1 and t2 are approximately equal
bool anyChanged = (indices.size() != 1 || indices[0] != i1);
indices.setSize(1);
weights.setSize(1);
indices[0] = i1;
weights[0] = scalar(0);
return anyChanged;
}
//- Find lower index
const label i2 = findLower(samples_, t2);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment