mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
COMP: DiagonalMatrix: avoid clang's over-eager optimisation (fixes #2650)
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2019-2020 OpenCFD Ltd.
|
Copyright (C) 2019-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -74,11 +74,9 @@ void Foam::DiagonalMatrix<Type>::invert()
|
|||||||
{
|
{
|
||||||
for (Type& val : *this)
|
for (Type& val : *this)
|
||||||
{
|
{
|
||||||
if (mag(val) < VSMALL)
|
// If mag(val)<VSMALL, leave untouched
|
||||||
{
|
// forcing of val=Zero sometimes confuses compiler
|
||||||
val = Zero;
|
if (mag(val) > VSMALL)
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
val = Type(1)/val;
|
val = Type(1)/val;
|
||||||
}
|
}
|
||||||
@ -149,21 +147,19 @@ namespace Foam
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
//- Return the matrix inverse as a DiagonalMatrix if no elem is equal to zero
|
//- Return the matrix inverse as a DiagonalMatrix
|
||||||
template<class Type>
|
template<class Type>
|
||||||
DiagonalMatrix<Type> inv(const DiagonalMatrix<Type>& mat)
|
DiagonalMatrix<Type> inv(const DiagonalMatrix<Type>& mat)
|
||||||
{
|
{
|
||||||
DiagonalMatrix<Type> Ainv(mat.size());
|
// Construct with fall-back value conditional calculation
|
||||||
|
// of invert to avoid over-eager compiler optimisation
|
||||||
|
DiagonalMatrix<Type> Ainv(mat.size(), Zero);
|
||||||
|
|
||||||
Type* iter = Ainv.begin();
|
Type* iter = Ainv.begin();
|
||||||
|
|
||||||
for (const Type& val : mat)
|
for (const Type& val : mat)
|
||||||
{
|
{
|
||||||
if (mag(val) < VSMALL)
|
if (mag(val) > VSMALL)
|
||||||
{
|
|
||||||
*iter = Zero;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
*iter = Type(1)/val;
|
*iter = Type(1)/val;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2019-2020 OpenCFD Ltd.
|
Copyright (C) 2019-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -94,7 +94,7 @@ public:
|
|||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
//- Return the matrix inverse into itself if no elem is equal to zero
|
//- Return the matrix inverse into itself
|
||||||
void invert();
|
void invert();
|
||||||
|
|
||||||
//- Return a sort permutation labelList according to
|
//- Return a sort permutation labelList according to
|
||||||
|
|||||||
Reference in New Issue
Block a user