Skip to content
Snippets Groups Projects
Commit a88e67f2 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

BUG: potential divide-by-zero in x3d surface output (#1212)

- eg, for a uniform field and auto range.
parent b4229841
Branches
Tags
No related merge requests found
...@@ -5,7 +5,7 @@ ...@@ -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 ...@@ -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) ...@@ -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) ...@@ -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,8 +281,17 @@ Foam::fileName Foam::surfaceWriters::x3dWriter::writeTemplate ...@@ -266,8 +281,17 @@ 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()))
{ {
mkDir(outputFile.path()); mkDir(outputFile.path());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment