mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
BUG: potential divide-by-zero in x3d surface output (#1212)
- eg, for a uniform field and auto range.
This commit is contained in:
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2019 OpenCFD Ltd.
|
Copyright (C) 2019-2020 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -50,13 +50,30 @@ namespace surfaceWriters
|
|||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//- A (0-1) range for colouring
|
||||||
|
inline scalar srange01(const scalarMinMax& range, scalar x)
|
||||||
|
{
|
||||||
|
if (x >= range.max())
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
x -= range.min();
|
||||||
|
|
||||||
|
if (x < VSMALL)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return x / (range.max() - range.min());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//- A (0-1) range for colouring
|
//- A (0-1) range for colouring
|
||||||
template<class Type>
|
template<class Type>
|
||||||
static inline scalar rangex(const scalarMinMax& range, const Type& val)
|
static inline scalar rangex(const scalarMinMax& range, const Type& val)
|
||||||
{
|
{
|
||||||
scalar x = Foam::mag(val);
|
return srange01(range, Foam::mag(val));
|
||||||
|
|
||||||
return (x - range.min()) / (range.max() - range.min());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -64,8 +81,7 @@ static inline scalar rangex(const scalarMinMax& range, const Type& val)
|
|||||||
template<>
|
template<>
|
||||||
inline scalar rangex(const scalarMinMax& range, const scalar& val)
|
inline scalar rangex(const scalarMinMax& range, const scalar& val)
|
||||||
{
|
{
|
||||||
scalar x = val;
|
return srange01(range, val);
|
||||||
return (x - range.min()) / (range.max() - range.min());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -73,8 +89,7 @@ inline scalar rangex(const scalarMinMax& range, const scalar& val)
|
|||||||
template<>
|
template<>
|
||||||
inline scalar rangex(const scalarMinMax& range, const label& val)
|
inline scalar rangex(const scalarMinMax& range, const label& val)
|
||||||
{
|
{
|
||||||
scalar x = val;
|
return srange01(range, val);
|
||||||
return (x - range.min()) / (range.max() - range.min());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -266,7 +281,16 @@ Foam::fileName Foam::surfaceWriters::x3dWriter::writeTemplate
|
|||||||
if (!range.valid())
|
if (!range.valid())
|
||||||
{
|
{
|
||||||
range = minMaxMag(values);
|
range = minMaxMag(values);
|
||||||
|
|
||||||
|
if (equal(range.mag(), 0))
|
||||||
|
{
|
||||||
|
range.add(range.centre());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Slight rounding
|
||||||
|
range.min() -= VSMALL;
|
||||||
|
range.max() += VSMALL;
|
||||||
|
|
||||||
if (!isDir(outputFile.path()))
|
if (!isDir(outputFile.path()))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user