Skip to content

Commit

Permalink
Merge branch 'StlPi' into 'master'
Browse files Browse the repository at this point in the history
Use std::numbers::pi replacing boost constants

See merge request ogs/ogs!5053
  • Loading branch information
endJunction committed Jul 22, 2024
2 parents f161b20 + 38aa8c2 commit fc1ee20
Show file tree
Hide file tree
Showing 20 changed files with 62 additions and 76 deletions.
8 changes: 3 additions & 5 deletions Applications/Utils/GeoTools/addDataToRaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
#endif

#include <algorithm>
#include <boost/math/constants/constants.hpp>
#include <cmath>
#include <memory>
#include <numbers>
#include <numeric>

#include "GeoLib/AABB.h"
Expand All @@ -45,10 +45,8 @@ double computeSinXSinY(GeoLib::Point const& point, GeoLib::AABB const& aabb)
auto const aabb_size = aabb.getMaxPoint() - aabb.getMinPoint();
auto const offset = aabb.getMinPoint();

return std::sin((point[0] - offset[0]) / aabb_size[0] *
boost::math::double_constants::pi) *
std::sin((point[1] - offset[1]) / aabb_size[1] *
boost::math::double_constants::pi);
return std::sin((point[0] - offset[0]) / aabb_size[0] * std::numbers::pi) *
std::sin((point[1] - offset[1]) / aabb_size[1] * std::numbers::pi);
}

double computeStepFunction(GeoLib::Point const& point, GeoLib::AABB const& aabb)
Expand Down
1 change: 0 additions & 1 deletion GeoLib/Polygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "Polygon.h"

#include <algorithm>
#include <boost/math/constants/constants.hpp>

#include "AnalyticalGeometry.h"
#include "BaseLib/quicksort.h"
Expand Down
1 change: 0 additions & 1 deletion MaterialLib/MPL/Properties/Exponential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include "MaterialLib/MPL/Properties/Exponential.h"

#include <boost/math/special_functions/pow.hpp>
#include <cmath>

namespace MaterialPropertyLib
Expand Down
34 changes: 17 additions & 17 deletions MeshToolsLib/MeshQuality/AngleSkewMetric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@

#include "AngleSkewMetric.h"

#include <boost/math/constants/constants.hpp>
#include <cmath>
#include <numbers>

#include "MathLib/MathTools.h"
#include "MeshLib/Node.h"

using namespace boost::math::double_constants;

namespace MeshToolsLib
{
namespace
Expand All @@ -30,7 +28,7 @@ template <unsigned long N>
std::tuple<double, double> getMinMaxAngle(
std::array<MeshLib::Node, N> const& nodes)
{
double min_angle(two_pi);
double min_angle(2 * std::numbers::pi);
double max_angle(0.0);

for (decltype(N) i = 0; i < N; ++i)
Expand All @@ -45,11 +43,11 @@ std::tuple<double, double> getMinMaxAngle(

double checkTriangle(MeshLib::Element const& elem)
{
using namespace std::numbers;
std::array const nodes = {*elem.getNode(0), *elem.getNode(1),
*elem.getNode(2)};
auto const& [min_angle, max_angle] = getMinMaxAngle(nodes);
return std::max((max_angle - third_pi) / two_thirds_pi,
(third_pi - min_angle) / third_pi);
return std::max((max_angle - pi / 3) / 2, (pi / 3 - min_angle)) * 3 / pi;
}

double checkQuad(MeshLib::Element const& elem)
Expand All @@ -58,8 +56,8 @@ double checkQuad(MeshLib::Element const& elem)
*elem.getNode(2), *elem.getNode(3)};
auto const& [min_angle, max_angle] = getMinMaxAngle(nodes);

return std::max((max_angle - half_pi) / half_pi,
(half_pi - min_angle) / half_pi);
using namespace std::numbers;
return std::max((max_angle - pi / 2), (pi / 2 - min_angle)) * 2 / pi;
}

double checkTetrahedron(MeshLib::Element const& elem)
Expand All @@ -77,8 +75,8 @@ double checkTetrahedron(MeshLib::Element const& elem)
double const min_angle = *std::min_element(min.begin(), min.end());
double const max_angle = *std::max_element(max.begin(), max.end());

return std::max((max_angle - third_pi) / two_thirds_pi,
(third_pi - min_angle) / third_pi);
using namespace std::numbers;
return std::max((max_angle - pi / 3) / 2, (pi / 3 - min_angle)) * 3 / pi;
}

double checkHexahedron(MeshLib::Element const& elem)
Expand All @@ -96,8 +94,8 @@ double checkHexahedron(MeshLib::Element const& elem)
double const min_angle = *std::min_element(min.begin(), min.end());
double const max_angle = *std::max_element(max.begin(), max.end());

return std::max((max_angle - half_pi) / half_pi,
(half_pi - min_angle) / half_pi);
using namespace std::numbers;
return std::max((max_angle - pi / 2), (pi / 2 - min_angle)) * 2 / pi;
}

double checkPrism(MeshLib::Element const& elem)
Expand All @@ -117,9 +115,10 @@ double checkPrism(MeshLib::Element const& elem)
auto const min_angle_tri = std::min(min_angle_tri0, min_angle_tri1);
auto const max_angle_tri = std::max(max_angle_tri0, max_angle_tri1);

double const tri_criterion(
std::max((max_angle_tri - third_pi) / two_thirds_pi,
(third_pi - min_angle_tri) / third_pi));
using namespace std::numbers;
double const tri_criterion =
std::max((max_angle_tri - pi / 3) / 2, (pi / 3 - min_angle_tri)) * 3 /
pi;

std::array<double, 3> min;
std::array<double, 3> max;
Expand All @@ -134,8 +133,9 @@ double checkPrism(MeshLib::Element const& elem)
double const min_angle_quad = *std::min_element(min.begin(), min.end());
double const max_angle_quad = *std::max_element(max.begin(), max.end());

double const quad_criterion(std::max((max_angle_quad - half_pi) / half_pi,
(half_pi - min_angle_quad) / half_pi));
using namespace std::numbers;
double const quad_criterion =
std::max((max_angle_quad - pi / 2), (pi / 2 - min_angle_quad)) * 2 / pi;

return std::min(tri_criterion, quad_criterion);
}
Expand Down
5 changes: 2 additions & 3 deletions MeshToolsLib/MeshSurfaceExtraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

#include "MeshSurfaceExtraction.h"

#include <boost/math/constants/constants.hpp>
#include <memory>
#include <numbers>

#include "BaseLib/Logging.h"
#include "MeshLib/Elements/Line.h"
Expand Down Expand Up @@ -311,8 +311,7 @@ void MeshSurfaceExtraction::get2DSurfaceElements(

bool const complete_surface = (dir.dot(dir) == 0);

double const pi(boost::math::constants::pi<double>());
double const cos_theta(std::cos(angle * pi / 180.0));
double const cos_theta(std::cos(angle * std::numbers::pi / 180.0));
Eigen::Vector3d const norm_dir(dir.normalized());

for (auto const* elem : all_elements)
Expand Down
4 changes: 2 additions & 2 deletions NumLib/Fem/FiniteElement/TemplateIsoparametric.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

#pragma once

#include <boost/math/constants/constants.hpp>
#include <cassert>
#include <numbers>

#include "MeshLib/Elements/Element.h"
#include "MeshLib/Node.h"
Expand Down Expand Up @@ -148,7 +148,7 @@ class TemplateIsoparametric
// located at edge of the unit triangle, it is possible that
// r becomes zero.
auto const r = interpolateZerothCoordinate(shape.N);
shape.integralMeasure = boost::math::constants::two_pi<double>() * r;
shape.integralMeasure = 2. * std::numbers::pi * r;
}

const MeshLib::Element* _ele;
Expand Down
4 changes: 2 additions & 2 deletions ProcessLib/HeatTransportBHE/BHE/BHE_1P.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "BHE_1P.h"

#include <boost/math/constants/constants.hpp>
#include <numbers>

#include "FlowAndTemperatureControl.h"
#include "Physics.h"
Expand Down Expand Up @@ -112,7 +112,7 @@ void BHE_1P::updateHeatTransferCoefficients(double const flow_rate)
std::array<double, BHE_1P::number_of_unknowns> BHE_1P::calcThermalResistances(
double const Nu)
{
constexpr double pi = boost::math::constants::pi<double>();
constexpr double pi = std::numbers::pi;

double const lambda_r = refrigerant.thermal_conductivity;
double const lambda_g = grout.lambda_g;
Expand Down
4 changes: 2 additions & 2 deletions ProcessLib/HeatTransportBHE/BHE/BHE_1U.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "BHE_1U.h"

#include <boost/math/constants/constants.hpp>
#include <numbers>

#include "FlowAndTemperatureControl.h"
#include "Physics.h"
Expand Down Expand Up @@ -173,7 +173,7 @@ void BHE_1U::updateHeatTransferCoefficients(double const flow_rate)
std::array<double, BHE_1U::number_of_unknowns> BHE_1U::calcThermalResistances(
double const Nu)
{
constexpr double pi = boost::math::constants::pi<double>();
constexpr double pi = std::numbers::pi;

double const lambda_r = refrigerant.thermal_conductivity;
double const lambda_g = grout.lambda_g;
Expand Down
4 changes: 2 additions & 2 deletions ProcessLib/HeatTransportBHE/BHE/BHE_2U.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "BHE_2U.h"

#include <boost/math/constants/constants.hpp>
#include <numbers>

#include "FlowAndTemperatureControl.h"
#include "Physics.h"
Expand Down Expand Up @@ -193,7 +193,7 @@ void BHE_2U::updateHeatTransferCoefficients(double const flow_rate)
std::array<double, BHE_2U::number_of_unknowns> BHE_2U::calcThermalResistances(
double const Nu)
{
constexpr double pi = boost::math::constants::pi<double>();
constexpr double pi = std::numbers::pi;

double const lambda_r = refrigerant.thermal_conductivity;
double const lambda_g = grout.lambda_g;
Expand Down
8 changes: 2 additions & 6 deletions ProcessLib/HeatTransportBHE/BHE/BoreholeGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#pragma once

#include <boost/math/constants/constants.hpp>
#include <numbers>

namespace BaseLib
{
Expand All @@ -36,11 +36,7 @@ struct BoreholeGeometry
*/
double const diameter;

double area() const
{
constexpr double pi = boost::math::constants::pi<double>();
return pi * diameter * diameter / 4;
}
double area() const { return std::numbers::pi * diameter * diameter / 4; }
};

BoreholeGeometry createBoreholeGeometry(BaseLib::ConfigTree const& config);
Expand Down
10 changes: 4 additions & 6 deletions ProcessLib/HeatTransportBHE/BHE/Pipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

#pragma once

#include <boost/math/constants/constants.hpp>
#include <cmath>
#include <numbers>

namespace BaseLib
{
Expand Down Expand Up @@ -38,19 +39,16 @@ struct Pipe

double wallThermalResistance() const
{
constexpr double pi = boost::math::constants::pi<double>();

double const outside_diameter = outsideDiameter();

return std::log(outside_diameter / diameter) /
(2.0 * pi * wall_thermal_conductivity);
(2.0 * std::numbers::pi * wall_thermal_conductivity);
}

private:
double circleArea(double const diameter) const
{
constexpr double pi = boost::math::constants::pi<double>();
return pi * diameter * diameter / 4;
return std::numbers::pi * diameter * diameter / 4;
}
};

Expand Down
13 changes: 7 additions & 6 deletions ProcessLib/HeatTransportBHE/BHE/ThermalResistancesCoaxial.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#pragma once

#include <numbers>

#include "GroutParameters.h"
#include "Pipe.h"
#include "RefrigerantProperties.h"
Expand Down Expand Up @@ -47,9 +49,10 @@ inline AdvectiveThermalResistanceCoaxial calculateAdvectiveThermalResistance(
double const hydraulic_diameter =
coaxialPipesAnnulusDiameter(inner_pipe, outer_pipe);

auto advective_thermal_resistance = [&](double Nu, double diameter_ratio) {
constexpr double pi = boost::math::constants::pi<double>();
return 1.0 / (Nu * fluid.thermal_conductivity * pi) * diameter_ratio;
auto advective_thermal_resistance = [&](double Nu, double diameter_ratio)
{
return 1.0 / (Nu * fluid.thermal_conductivity * std::numbers::pi) *
diameter_ratio;
};
return {advective_thermal_resistance(Nu_inner_pipe, 1.),
advective_thermal_resistance(
Expand All @@ -70,8 +73,6 @@ calculateGroutAndGroutSoilExchangeThermalResistance(
Pipe const& outer_pipe, GroutParameters const& grout_parameters,
double const borehole_diameter)
{
constexpr double pi = boost::math::constants::pi<double>();

double const outer_pipe_outside_diameter = outer_pipe.outsideDiameter();
double const chi =
std::log(std::sqrt(borehole_diameter * borehole_diameter +
Expand All @@ -81,7 +82,7 @@ calculateGroutAndGroutSoilExchangeThermalResistance(
std::log(borehole_diameter / outer_pipe_outside_diameter);
double const R_g =
std::log(borehole_diameter / outer_pipe_outside_diameter) / 2 /
(pi * grout_parameters.lambda_g);
(std::numbers::pi * grout_parameters.lambda_g);
double const conductive_b = chi * R_g;
double const grout_soil = (1 - chi) * R_g;
return {conductive_b, grout_soil};
Expand Down
6 changes: 4 additions & 2 deletions ProcessLib/PhaseField/PhaseFieldFEM-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/
#pragma once

#include <numbers>

#include "NumLib/DOF/DOFTableUtil.h"
#include "ProcessLib/CoupledSolutionsForStaggeredScheme.h"

Expand Down Expand Up @@ -238,7 +240,7 @@ void PhaseFieldLocalAssembler<ShapeFunction, DisplacementDim>::
case PhaseFieldModel::COHESIVE:
{
auto const local_Jac_COHESIVE =
(2.0 / boost::math::double_constants::pi * gc *
(2.0 / std::numbers::pi * gc *
(-N.transpose() * N / ls + dNdx.transpose() * dNdx * ls) *
w)
.eval();
Expand Down Expand Up @@ -381,7 +383,7 @@ void PhaseFieldLocalAssembler<ShapeFunction, DisplacementDim>::computeEnergy(
case PhaseFieldModel::COHESIVE:
{
element_surface_energy +=
gc / boost::math::double_constants::pi *
gc / std::numbers::pi *
((1 - d_ip * d_ip) / ls + (dNdx * d).dot((dNdx * d)) * ls) *
w;
break;
Expand Down
4 changes: 2 additions & 2 deletions Tests/GeoLib/TestEquidistantPointGeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include <gtest/gtest.h>

#include <boost/math/constants/constants.hpp>
#include <numbers>
#include <random>

#include "GeoLib/Utils.h"
Expand All @@ -22,7 +22,7 @@ struct GeoLibGenerateEquidistantPoints : public testing::Test
// enable random engine
std::random_device rd;
std::mt19937 random_engine_mt19937(rd());
constexpr auto pi = boost::math::double_constants::pi;
constexpr auto pi = std::numbers::pi;
std::normal_distribution<> normal_dist_phi(-pi, pi); // azimuthal angle
std::normal_distribution<> normal_dist_theta(0, pi); // polar angle
// generate point on unit sphere
Expand Down
5 changes: 2 additions & 3 deletions Tests/GeoLib/TestSurfaceIsPointInSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include <gtest/gtest.h>

#include <array>
#include <boost/math/constants/constants.hpp>
#include <memory>
#include <numbers>
#include <random>
#include <vector>

Expand Down Expand Up @@ -114,8 +114,7 @@ TEST(GeoLib, SurfaceIsPointInSurface)
n_steps, f));

// random rotation angles
std::normal_distribution<> normal_dist_angles(
0, boost::math::double_constants::two_pi);
std::normal_distribution<> normal_dist_angles(0, 2. * std::numbers::pi);
std::array<double, 3> euler_angles = {
{normal_dist_angles(random_engine_mt19937),
normal_dist_angles(random_engine_mt19937),
Expand Down
1 change: 0 additions & 1 deletion Tests/MaterialLib/TestGasPressureDependentPermeability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <gtest/gtest.h>

#include <Eigen/Core>
#include <boost/math/constants/constants.hpp>

#include "MaterialLib/MPL/Medium.h"
#include "MaterialLib/MPL/Properties/CreateGasPressureDependentPermeability.h"
Expand Down
Loading

0 comments on commit fc1ee20

Please sign in to comment.