Skip to content

Commit

Permalink
Upgrade mp-units to v2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiashienzsch committed May 20, 2024
1 parent e7d3711 commit 1d87a0d
Show file tree
Hide file tree
Showing 19 changed files with 146 additions and 148 deletions.
16 changes: 6 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- name: Windows
os: windows-latest
osx_target: ""
cxx_flags: "/EHsc /arch:AVX"
cxx_flags: "-march=x86-64-v2"

steps:
- name: Checkout code
Expand All @@ -59,7 +59,7 @@ jobs:
run: |
sudo apt update -y
sudo apt install -y libasound2-dev mesa-common-dev libx11-xcb-dev xorg-dev libx11-dev libxinerama-dev libxext-dev libfreetype6-dev libglu1-mesa-dev xvfb ninja-build ccache
pip3 install --user --upgrade conan
pip3 install --break-system-packages conan
- name: Install dependencies (macOS)
if: runner.os == 'macOS'
Expand All @@ -73,17 +73,13 @@ jobs:
pip3 install --upgrade conan
- name: Install clang
if: runner.os == 'Linux'
if: runner.os != 'macOS'
uses: egor-tensin/setup-clang@v1

- name: Set up Visual Studio shell
if: runner.os == 'Windows'
uses: egor-tensin/vs-shell@v2
with:
arch: x64

- name: Setup conan
run: conan profile detect -f
run: |
conan profile detect -f
conan remote add conan-mpusz https://mpusz.jfrog.io/artifactory/api/conan/conan-oss
- name: Install ccache
uses: hendrikmuhs/ccache-action@main
Expand Down
2 changes: 1 addition & 1 deletion conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[requires]
catch2/3.6.0
mp-units/0.8.0
mp-units/2.2.0@mpusz/testing

[options]

Expand Down
24 changes: 16 additions & 8 deletions src/ra/acoustics/absorber/porous_absorber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@ namespace ra {
auto propertiesOfAbsorber(
PorousAbsorberSpecs specs,
AtmosphericEnvironment env,
si::frequency<si::hertz> frequency,
quantity<isq::frequency[si::hertz]> frequency,
double angle
) -> PorousAbsorberProperties
{
using namespace mp_units::si::unit_symbols;

auto const airDensity = densityOfAir(env.temperature, env.pressure);
auto const airIm = impedanceOfAir(env.temperature, env.pressure);
auto const twoPiC = (2.0 * std::numbers::pi) / soundVelocity(env.temperature).number();
auto const twoPiC = (2.0 * std::numbers::pi) / soundVelocity(env.temperature).numerical_value_in(m / s);
auto const wn = detail::waveNumber(env.temperature, frequency);
auto const nj = std::complex{0.0, -1.0};

auto p = PorousAbsorberProperties{};
{
p.X = detail::delanyBazleyTerm(airDensity, frequency, specs.flowResisitivity);
p.zca = airIm * std::complex{1 + 0.0571 * (std::pow(p.X, -0.754)), -0.087 * (std::pow(p.X, -0.732))};
p.k = twoPiC * frequency.number()
p.k = twoPiC * frequency.numerical_value_in(Hz)
* std::complex{1 + 0.0978 * std::pow(p.X, -0.7), -0.189 * std::pow(p.X, -0.595)};
p.ky = detail::yComponentOfWaveNumber(wn, angle);
p.kx = std::sqrt((p.k * p.k) - std::pow(p.ky, 2));
Expand Down Expand Up @@ -62,21 +64,27 @@ auto propertiesOfAbsorber(

namespace detail {

auto waveNumber(si::thermodynamic_temperature<si::kelvin> temperature, si::frequency<si::hertz> frequency) -> double
auto waveNumber(
quantity<isq::thermodynamic_temperature[si::kelvin]> temperature,
quantity<isq::frequency[si::hertz]> frequency
) -> double
{
// 2p/l
return ((2.0 * std::numbers::pi) / soundVelocity(temperature).number()) * frequency.number();
using namespace mp_units::si::unit_symbols;
return ((2.0 * std::numbers::pi) / soundVelocity(temperature).numerical_value_in(m / s))
* frequency.numerical_value_in(Hz);
}

auto delanyBazleyTerm(
si::density<si::kilogram_per_metre_cub> airDensity,
si::frequency<si::hertz> frequency,
quantity<isq::density[si::kilogram / cubic(si::metre)]> airDensity,
quantity<isq::frequency[si::hertz]> frequency,
double flowResistivity
) -> double
{
// Eq 5.11
using namespace mp_units::si::unit_symbols;
auto const tmp = (airDensity * frequency) / flowResistivity;
return tmp.number();
return tmp.numerical_value_in((kg / m3) * Hz / one);
}

auto yComponentOfWaveNumber(double waveNumber, double angle) -> double
Expand Down
21 changes: 12 additions & 9 deletions src/ra/acoustics/absorber/porous_absorber.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
#include <ra/unit/pressure.hpp>
#include <ra/unit/temperature.hpp>

#include <units/isq/si/density.h>
#include <mp-units/systems/isq.h>
#include <mp-units/systems/si.h>

#include <complex>

namespace ra {

using namespace units::isq;
using namespace mp_units;

struct AtmosphericEnvironment
{
si::thermodynamic_temperature<si::kelvin> temperature{0};
si::pressure<si::pascal> pressure{0};
quantity<isq::thermodynamic_temperature[si::kelvin]> temperature{};
quantity<isq::pressure[si::pascal]> pressure{};
};

struct PorousAbsorberSpecs
Expand Down Expand Up @@ -88,17 +89,19 @@ struct PorousAbsorberProperties
[[nodiscard]] auto propertiesOfAbsorber(
PorousAbsorberSpecs specs,
AtmosphericEnvironment env,
si::frequency<si::hertz> frequency,
quantity<isq::frequency[si::hertz]> frequency,
double angle
) -> PorousAbsorberProperties;

namespace detail {

[[nodiscard]] auto
waveNumber(si::thermodynamic_temperature<si::kelvin> temperature, si::frequency<si::hertz> frequency) -> double;
[[nodiscard]] auto waveNumber(
quantity<isq::thermodynamic_temperature[si::kelvin]> temperature,
quantity<isq::frequency[si::hertz]> frequency
) -> double;
[[nodiscard]] auto delanyBazleyTerm(
si::density<si::kilogram_per_metre_cub> airDensity,
si::frequency<si::hertz> frequency,
quantity<isq::density[si::kilogram / cubic(si::metre)]> airDensity,
quantity<isq::frequency[si::hertz]> frequency,
double flowResistivity
) -> double;
[[nodiscard]] auto yComponentOfWaveNumber(double waveNumber, double angle) -> double;
Expand Down
58 changes: 15 additions & 43 deletions src/ra/acoustics/absorber/porous_absorber.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ TEST_CASE("RaumAkustik: propertiesOfAbsorber", "")
{

{
auto const props
= ra::propertiesOfAbsorber({100.0, 8'000.0, 100.0}, C20, ra::si::frequency<ra::si::hertz>{50.0}, 0.0);
auto const props = ra::propertiesOfAbsorber({100.0, 8'000.0, 100.0}, C20, 50.0 * ra::si::hertz, 0.0);
REQUIRE(props.X == Catch::Approx(0.0075257395));
REQUIRE(props.zca.real() == Catch::Approx(1355.71904994104));
REQUIRE(props.zca.imag() == Catch::Approx(-1289.23418591288));
Expand Down Expand Up @@ -54,7 +53,7 @@ TEST_CASE("RaumAkustik: propertiesOfAbsorber", "")
}

{
auto const props = ra::propertiesOfAbsorber({100.0, 8'000.0}, C22, ra::si::frequency<ra::si::hertz>{50.0}, 0.0);
auto const props = ra::propertiesOfAbsorber({100.0, 8'000.0}, C22, 50.0 * ra::si::hertz, 0.0);
REQUIRE(props.X == Catch::Approx(0.0074747434));
REQUIRE(props.zca.real() == Catch::Approx(1355.9444611324));
REQUIRE(props.zca.imag() == Catch::Approx(-1291.26947073563));
Expand All @@ -63,8 +62,7 @@ TEST_CASE("RaumAkustik: propertiesOfAbsorber", "")
}

{
auto const props
= ra::propertiesOfAbsorber({100.0, 8'000.0, 100.0}, C22, ra::si::frequency<ra::si::hertz>{50.0}, 15.0);
auto const props = ra::propertiesOfAbsorber({100.0, 8'000.0, 100.0}, C22, 50.0 * ra::si::hertz, 15.0);
REQUIRE(props.X == Catch::Approx(0.0074747434));
REQUIRE(props.zca.real() == Catch::Approx(1355.9444611324));
REQUIRE(props.zca.imag() == Catch::Approx(-1291.26947073563));
Expand All @@ -75,73 +73,47 @@ TEST_CASE("RaumAkustik: propertiesOfAbsorber", "")

TEST_CASE("RaumAkustik: detail::waveNumber", "")
{
REQUIRE(
ra::detail::waveNumber(ra::celciusToKelvin(20.0), ra::si::frequency<ra::si::hertz>{50.0})
== Catch::Approx(0.9149)
);
REQUIRE(
ra::detail::waveNumber(ra::celciusToKelvin(22.0), ra::si::frequency<ra::si::hertz>{50.0})
== Catch::Approx(0.9118)
);
REQUIRE(ra::detail::waveNumber(ra::celciusToKelvin(20.0), 50.0 * ra::si::hertz) == Catch::Approx(0.9149));
REQUIRE(ra::detail::waveNumber(ra::celciusToKelvin(22.0), 50.0 * ra::si::hertz) == Catch::Approx(0.9118));
}

TEST_CASE("RaumAkustik: detail::delanyBazleyTerm", "")
{
{
auto const density = ra::densityOfAir(ra::celciusToKelvin(20.0), ra::OneAtmosphere<double>);
REQUIRE(
ra::detail::delanyBazleyTerm(density, ra::si::frequency<ra::si::hertz>{50.0}, 8'000.0)
== Catch::Approx(0.0075257395)
);
REQUIRE(ra::detail::delanyBazleyTerm(density, 50.0 * ra::si::hertz, 8'000.0) == Catch::Approx(0.0075257395));
}
{
auto const density = ra::densityOfAir(ra::celciusToKelvin(22.0), ra::OneAtmosphere<double>);
REQUIRE(
ra::detail::delanyBazleyTerm(density, ra::si::frequency<ra::si::hertz>{50.0}, 8'000.0)
== Catch::Approx(0.0074747434)
);
REQUIRE(ra::detail::delanyBazleyTerm(density, 50.0 * ra::si::hertz, 8'000.0) == Catch::Approx(0.0074747434));
}
}

TEST_CASE("RaumAkustik: detail::yComponentOfWaveNumber", "")
{
using namespace ra::detail;
REQUIRE(
yComponentOfWaveNumber(waveNumber(ra::celciusToKelvin(20.0), ra::si::frequency<ra::si::hertz>{50.0}), 0.0)
== Catch::Approx(0.0)
yComponentOfWaveNumber(waveNumber(ra::celciusToKelvin(20.0), 50.0 * ra::si::hertz), 0.0) == Catch::Approx(0.0)
);
REQUIRE(
yComponentOfWaveNumber(waveNumber(ra::celciusToKelvin(22.0), ra::si::frequency<ra::si::hertz>{50.0}), 0.0)
== Catch::Approx(0.0)
yComponentOfWaveNumber(waveNumber(ra::celciusToKelvin(22.0), 50.0 * ra::si::hertz), 0.0) == Catch::Approx(0.0)
);

REQUIRE(
yComponentOfWaveNumber(waveNumber(ra::celciusToKelvin(20.0), ra::si::frequency<ra::si::hertz>{50.0}), 15.0)
yComponentOfWaveNumber(waveNumber(ra::celciusToKelvin(20.0), 50.0 * ra::si::hertz), 15.0)
== Catch::Approx(0.2367929161)
);
REQUIRE(
yComponentOfWaveNumber(waveNumber(ra::celciusToKelvin(22.0), ra::si::frequency<ra::si::hertz>{50.0}), 15.0)
yComponentOfWaveNumber(waveNumber(ra::celciusToKelvin(22.0), 50.0 * ra::si::hertz), 15.0)
== Catch::Approx(0.2359892724)
);
}

TEST_CASE("RaumAkustik: detail::angleOfPropagation", "")
{
auto const specs = ra::PorousAbsorberSpecs{100.0, 8'000.0};
REQUIRE(
ra::propertiesOfAbsorber(specs, C20, ra::si::frequency<ra::si::hertz>{50.0}, 0.0).betaPorous
== Catch::Approx(0.0)
);
REQUIRE(
ra::propertiesOfAbsorber(specs, C22, ra::si::frequency<ra::si::hertz>{50.0}, 0.0).betaPorous
== Catch::Approx(0.0)
);
REQUIRE(
ra::propertiesOfAbsorber(specs, C20, ra::si::frequency<ra::si::hertz>{50.0}, 15.0).betaPorous
== Catch::Approx(2.8036973865)
);
REQUIRE(
ra::propertiesOfAbsorber(specs, C22, ra::si::frequency<ra::si::hertz>{50.0}, 15.0).betaPorous
== Catch::Approx(2.7931256656)
);
REQUIRE(ra::propertiesOfAbsorber(specs, C20, 50.0 * ra::si::hertz, 0.0).betaPorous == Catch::Approx(0.0));
REQUIRE(ra::propertiesOfAbsorber(specs, C22, 50.0 * ra::si::hertz, 0.0).betaPorous == Catch::Approx(0.0));
REQUIRE(ra::propertiesOfAbsorber(specs, C20, 50.0 * ra::si::hertz, 15.0).betaPorous == Catch::Approx(2.8036973865));
REQUIRE(ra::propertiesOfAbsorber(specs, C22, 50.0 * ra::si::hertz, 15.0).betaPorous == Catch::Approx(2.7931256656));
}
33 changes: 20 additions & 13 deletions src/ra/acoustics/air.cpp
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
#include "air.hpp"

#include <units/isq/si/heat_capacity.h>

#include <units/math.h>
#include <mp-units/math.h>

namespace ra {
auto densityOfAir(si::thermodynamic_temperature<si::kelvin> temp, si::pressure<si::pascal> pressure) noexcept
-> si::density<si::kilogram_per_metre_cub>
auto densityOfAir(
quantity<isq::thermodynamic_temperature[si::kelvin]> temp,
quantity<isq::pressure[si::pascal]> pressure
) noexcept -> quantity<isq::density[si::kilogram / cubic(si::metre)]>
{
static constexpr auto GasConstant = si::specific_heat_capacity<si::joule_per_kilogram_kelvin>{287.05};
using namespace mp_units::si::unit_symbols;

static constexpr auto GasConstant = 287.05 * J / (kg * K);
return pressure / (GasConstant * temp);
}

auto soundVelocity(si::thermodynamic_temperature<si::kelvin> temp) noexcept -> si::speed<si::metre_per_second>
auto soundVelocity(quantity<isq::thermodynamic_temperature[si::kelvin]> temp
) noexcept -> quantity<isq::speed[si::metre / si::second]>
{
using namespace mp_units::si::unit_symbols;

static constexpr auto SpecificHeatRatio = 1.402;
static constexpr auto DensityAtZeroC = si::density<si::kilogram_per_metre_cub>{1.293};
return sqrt((SpecificHeatRatio * OneAtmosphere<double>) / DensityAtZeroC)
* sqrt(temp / si::thermodynamic_temperature<si::kelvin>{273.15});
static constexpr auto DensityAtZeroC = 1.293 * si::kilogram / cubic(si::metre);
return sqrt((SpecificHeatRatio * OneAtmosphere<double>) / DensityAtZeroC) * sqrt(temp / (273.15 * si::kelvin));
}

auto impedanceOfAir(si::thermodynamic_temperature<si::kelvin> temp, si::pressure<si::pascal> pressure) noexcept
-> double
auto impedanceOfAir(
quantity<isq::thermodynamic_temperature[si::kelvin]> temp,
quantity<isq::pressure[si::pascal]> pressure
) noexcept -> double
{
using namespace mp_units::si::unit_symbols;
auto const i = soundVelocity(temp) * densityOfAir(temp, pressure);
return i.number();
return i.numerical_value_in((m / s) * (kg / m3));
}

} // namespace ra
24 changes: 13 additions & 11 deletions src/ra/acoustics/air.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@
#include <ra/unit/pressure.hpp>
#include <ra/unit/temperature.hpp>

#include <units/isq/si/density.h>
#include <units/isq/si/speed.h>
#include <mp-units/systems/isq.h>
#include <mp-units/systems/si.h>

namespace ra {

using namespace units::isq;
using namespace mp_units;

[[nodiscard]] auto
densityOfAir(si::thermodynamic_temperature<si::kelvin> temperature, si::pressure<si::pascal> pressure) noexcept
-> si::density<si::kilogram_per_metre_cub>;
[[nodiscard]] auto soundVelocity(si::thermodynamic_temperature<si::kelvin> temperature
) noexcept -> si::speed<si::metre_per_second>;
[[nodiscard]] auto
impedanceOfAir(si::thermodynamic_temperature<si::kelvin> temperature, si::pressure<si::pascal> pressure) noexcept
-> double;
[[nodiscard]] auto densityOfAir(
quantity<isq::thermodynamic_temperature[si::kelvin]> temperature,
quantity<isq::pressure[si::pascal]> pressure
) noexcept -> quantity<isq::density[si::kilogram / cubic(si::metre)]>;
[[nodiscard]] auto soundVelocity(quantity<isq::thermodynamic_temperature[si::kelvin]> temperature
) noexcept -> quantity<isq::speed[si::metre / si::second]>;
[[nodiscard]] auto impedanceOfAir(
quantity<isq::thermodynamic_temperature[si::kelvin]> temperature,
quantity<isq::pressure[si::pascal]> pressure
) noexcept -> double;

} // namespace ra
Loading

0 comments on commit 1d87a0d

Please sign in to comment.