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 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -50,13 +50,30 @@ namespace surfaceWriters
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
template<class Type>
static inline scalar rangex(const scalarMinMax& range, const Type& val)
{
scalar x = Foam::mag(val);
return (x - range.min()) / (range.max() - range.min());
return srange01(range, Foam::mag(val));
}
......@@ -64,8 +81,7 @@ static inline scalar rangex(const scalarMinMax& range, const Type& val)
template<>
inline scalar rangex(const scalarMinMax& range, const scalar& val)
{
scalar x = val;
return (x - range.min()) / (range.max() - range.min());
return srange01(range, val);
}
......@@ -73,8 +89,7 @@ inline scalar rangex(const scalarMinMax& range, const scalar& val)
template<>
inline scalar rangex(const scalarMinMax& range, const label& val)
{
scalar x = val;
return (x - range.min()) / (range.max() - range.min());
return srange01(range, val);
}
......@@ -266,8 +281,17 @@ Foam::fileName Foam::surfaceWriters::x3dWriter::writeTemplate
if (!range.valid())
{
range = minMaxMag(values);
if (equal(range.mag(), 0))
{
range.add(range.centre());
}
}
// Slight rounding
range.min() -= VSMALL;
range.max() += VSMALL;
if (!isDir(outputFile.path()))
{
mkDir(outputFile.path());
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment