Skip to content

Commit d0dd13e

Browse files
Merge pull request #14274 from KratosMultiphysics/core/minor-optimization-math-utils-pow
[Core] Minor optimization in `MathUtils` avoiding `pow` as VS is struggling to multiply 2 values
2 parents 7cc7075 + 01f1426 commit d0dd13e

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

kratos/utilities/math_utils.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -783,9 +783,9 @@ class KRATOS_API(KRATOS_CORE) MathUtils
783783
* @return The resulting norm
784784
*/
785785
template<class TVectorType>
786-
static inline double Norm3(const TVectorType& a)
786+
static inline double Norm3(const TVectorType& rA)
787787
{
788-
double temp = std::pow(a[0],2) + std::pow(a[1],2) + std::pow(a[2],2);
788+
double temp = rA[0] * rA[0] + rA[1] * rA[1] + rA[2] * rA[2];
789789
temp = std::sqrt(temp);
790790
return temp;
791791
}
@@ -984,13 +984,13 @@ class KRATOS_API(KRATOS_CORE) MathUtils
984984
static inline void OrthonormalBasisFrisvad(const T1& c,T2& a,T3& b ){
985985
KRATOS_DEBUG_ERROR_IF(norm_2(c) < (1.0 - 1.0e-3) || norm_2(c) > (1.0 + 1.0e-3)) << "Input should be a normal vector" << std::endl;
986986
if ((c[2] + 1.0) > 1.0e4 * ZeroTolerance) {
987-
a[0] = 1.0 - std::pow(c[0], 2)/(1.0 + c[2]);
987+
a[0] = 1.0 - (c[0] * c[0])/(1.0 + c[2]);
988988
a[1] = - (c[0] * c[1])/(1.0 + c[2]);
989989
a[2] = - c[0];
990990
const double norm_a = norm_2(a);
991991
a /= norm_a;
992992
b[0] = - (c[0] * c[1])/(1.0 + c[2]);
993-
b[1] = 1.0 - std::pow(c[1], 2)/(1.0 + c[2]);
993+
b[1] = 1.0 - (c[1] * c[1])/(1.0 + c[2]);
994994
b[2] = -c[1];
995995
const double norm_b = norm_2(b);
996996
b /= norm_b;

0 commit comments

Comments
 (0)