Skip to content

Commit

Permalink
Added a helper function for converting angles from degrees to radians
Browse files Browse the repository at this point in the history
  • Loading branch information
avdg81 committed May 26, 2023
1 parent dc3b086 commit 2a69cd4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
// Application includes
#include "custom_elements/steady_state_Pw_piping_element.hpp"
#include "custom_utilities/element_utilities.hpp"
#include "utilities/math_utils.h"
#include <cmath>


namespace Kratos
{

Expand Down Expand Up @@ -328,7 +331,7 @@ double SteadyStatePwPipingElement<TDim,TNumNodes>:: CalculateEquilibriumPipeHeig
return 1e10;
}

return modelFactor * M_PI / 3.0 * particle_d * (SolidDensity / FluidDensity - 1) * eta * sin((theta + pipeSlope) * M_PI / 180.0) / cos(theta * M_PI / 180.0) / dhdx;
return modelFactor * M_PI / 3.0 * particle_d * (SolidDensity / FluidDensity - 1) * eta * sin(MathUtils<>::DegreesToRadians(theta + pipeSlope)) / cos(MathUtils<>::DegreesToRadians(theta)) / dhdx;

}

Expand Down
11 changes: 11 additions & 0 deletions kratos/tests/cpp_tests/utilities/test_math_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,5 +892,16 @@ namespace Kratos
KRATOS_CHECK_MATRIX_NEAR(exp_A, A, 1.0e-8);
}

/** Checks whether the angle conversion from degrees to radians is performed correctly
*/
KRATOS_TEST_CASE_IN_SUITE(MathUtilsDegreesToRadians, KratosCoreFastSuite)
{
const double abs_tolerance = 1e-9;
KRATOS_CHECK_NEAR( 0.0, MathUtils<>::DegreesToRadians( 0.0), abs_tolerance);
KRATOS_CHECK_NEAR(Globals::Pi/2, MathUtils<>::DegreesToRadians( 90.0), abs_tolerance);
KRATOS_CHECK_NEAR( -Globals::Pi, MathUtils<>::DegreesToRadians(-180.0), abs_tolerance);
KRATOS_CHECK_NEAR(4*Globals::Pi, MathUtils<>::DegreesToRadians( 720.0), abs_tolerance);
}

} // namespace Testing
} // namespace Kratos.
7 changes: 7 additions & 0 deletions kratos/utilities/math_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
// Project includes
#include "input_output/logger.h"
#include "includes/ublas_interface.h"
#include "includes/global_variables.h"

namespace Kratos
{
Expand Down Expand Up @@ -1819,6 +1820,12 @@ class KRATOS_API(KRATOS_CORE) MathUtils
}
}


static double DegreesToRadians(double AngleInDegrees)
{
return (AngleInDegrees * Globals::Pi) / 180.0;
}

///@}

private:
Expand Down

0 comments on commit 2a69cd4

Please sign in to comment.