From 8230a42cb080fa60829f00baa3c69b2565258591 Mon Sep 17 00:00:00 2001 From: Mike Ford Date: Fri, 29 May 2020 00:57:35 +0100 Subject: [PATCH 1/4] added some units for the foot-pound-second system and the static tests --- src/include/units/physical/fps/acceleration.h | 45 +++++ src/include/units/physical/fps/area.h | 47 +++++ src/include/units/physical/fps/energy.h | 54 ++++++ src/include/units/physical/fps/force.h | 58 ++++++ src/include/units/physical/fps/length.h | 47 +++++ src/include/units/physical/fps/mass.h | 47 +++++ src/include/units/physical/fps/power.h | 55 ++++++ src/include/units/physical/fps/pressure.h | 56 ++++++ src/include/units/physical/fps/speed.h | 46 +++++ src/include/units/physical/fps/time.h | 42 +++++ test/unit_test/static/CMakeLists.txt | 2 + test/unit_test/static/fps_test.cpp | 102 +++++++++++ test/unit_test/static/si_fps_test.cpp | 165 ++++++++++++++++++ 13 files changed, 766 insertions(+) create mode 100644 src/include/units/physical/fps/acceleration.h create mode 100644 src/include/units/physical/fps/area.h create mode 100644 src/include/units/physical/fps/energy.h create mode 100644 src/include/units/physical/fps/force.h create mode 100644 src/include/units/physical/fps/length.h create mode 100644 src/include/units/physical/fps/mass.h create mode 100644 src/include/units/physical/fps/power.h create mode 100644 src/include/units/physical/fps/pressure.h create mode 100644 src/include/units/physical/fps/speed.h create mode 100644 src/include/units/physical/fps/time.h create mode 100644 test/unit_test/static/fps_test.cpp create mode 100644 test/unit_test/static/si_fps_test.cpp diff --git a/src/include/units/physical/fps/acceleration.h b/src/include/units/physical/fps/acceleration.h new file mode 100644 index 00000000..7d7ef0fb --- /dev/null +++ b/src/include/units/physical/fps/acceleration.h @@ -0,0 +1,45 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include +#include +#include + +namespace units::physical::fps { + +struct foot_per_second_sq : unit {}; +struct dim_acceleration : physical::dim_acceleration {}; + +template +using acceleration = quantity; + +inline namespace literals { + +// ft_per_s2 +constexpr auto operator"" q_ft_per_s2(unsigned long long l) { return acceleration(l); } +constexpr auto operator"" q_ft_per_s2(long double l) { return acceleration(l); } + +} // namespace literals + +} // namespace units::physical::fps diff --git a/src/include/units/physical/fps/area.h b/src/include/units/physical/fps/area.h new file mode 100644 index 00000000..cd83c0be --- /dev/null +++ b/src/include/units/physical/fps/area.h @@ -0,0 +1,47 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include +#include +// #include +#include + +namespace units::physical::fps { + +struct square_foot : unit {}; +struct dim_area : physical::dim_area {}; + + +template +using area = quantity; + +inline namespace literals { + +// fm2 +constexpr auto operator"" q_ft2(unsigned long long l) { return area(l); } +constexpr auto operator"" q_ft2(long double l) { return area(l); } + +} + +} // namespace units::physical::fps diff --git a/src/include/units/physical/fps/energy.h b/src/include/units/physical/fps/energy.h new file mode 100644 index 00000000..d3cbd5e7 --- /dev/null +++ b/src/include/units/physical/fps/energy.h @@ -0,0 +1,54 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include +#include +#include +#include + +namespace units::physical::fps { + +// https://en.wikipedia.org/wiki/Foot-poundal +struct foot_poundal : unit {}; + +// https://en.wikipedia.org/wiki/Foot-pound_(energy) +struct foot_pound_force : named_scaled_unit, foot_poundal> {}; + +struct dim_energy : physical::dim_energy {}; + +template +using energy = quantity; + +inline namespace literals { + +constexpr auto operator"" q_ft_pdl(unsigned long long l) { return energy(l); } +constexpr auto operator"" q_ft_pdl(long double l) { return energy(l); } + +// foot_pound force +constexpr auto operator"" q_ft_lbf(unsigned long long l) { return energy(l); } +constexpr auto operator"" q_ft_lbf(long double l) { return energy(l); } + +} // namespace literals + +} // namespace units::physical::fps diff --git a/src/include/units/physical/fps/force.h b/src/include/units/physical/fps/force.h new file mode 100644 index 00000000..cb038e09 --- /dev/null +++ b/src/include/units/physical/fps/force.h @@ -0,0 +1,58 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include +#include +#include +#include +#include + +namespace units::physical::fps { + +// https://en.wikipedia.org/wiki/Poundal +struct poundal : named_unit {}; + +// https://en.wikipedia.org/wiki/Pound_(force) +struct pound_force : named_scaled_unit, poundal> {}; + + + +struct dim_force : physical::dim_force {}; + +template +using force = quantity; + +inline namespace literals { + +// poundal +constexpr auto operator"" q_pdl(unsigned long long l) { return force(l); } +constexpr auto operator"" q_pdl(long double l) { return force(l); } + +// pound force +constexpr auto operator"" q_lbf(unsigned long long l) { return force(l); } +constexpr auto operator"" q_lbf(long double l) { return force(l); } + +} // namespace literals + +} // namespace units::physical::fps diff --git a/src/include/units/physical/fps/length.h b/src/include/units/physical/fps/length.h new file mode 100644 index 00000000..c7e5a54c --- /dev/null +++ b/src/include/units/physical/fps/length.h @@ -0,0 +1,47 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include +#include +#include + +namespace units::physical::fps { + +// https://en.wikipedia.org/wiki/Foot_(unit) +struct foot : named_scaled_unit, si::metre> {}; + +struct dim_length : physical::dim_length {}; + +template +using length = quantity; + +inline namespace literals { + +// ft +constexpr auto operator"" q_ft(unsigned long long l) { return length(l); } +constexpr auto operator"" q_ft(long double l) { return length(l); } + +} + +} // namespace units::physical::fps diff --git a/src/include/units/physical/fps/mass.h b/src/include/units/physical/fps/mass.h new file mode 100644 index 00000000..7d57d181 --- /dev/null +++ b/src/include/units/physical/fps/mass.h @@ -0,0 +1,47 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include +#include +#include + +namespace units::physical::fps { + +// https://en.wikipedia.org/wiki/Pound_(mass) +struct pound : named_scaled_unit, si::kilogram> {}; + +struct dim_mass : physical::dim_mass {}; + +template +using mass = quantity; + +inline namespace literals { + +// g +constexpr auto operator"" q_lb(unsigned long long l) { return mass(l); } +constexpr auto operator"" q_lb(long double l) { return mass(l); } + +} + +} // namespace units::physical::fps diff --git a/src/include/units/physical/fps/power.h b/src/include/units/physical/fps/power.h new file mode 100644 index 00000000..3e572968 --- /dev/null +++ b/src/include/units/physical/fps/power.h @@ -0,0 +1,55 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include +#include +#include +#include + +namespace units::physical::fps { + +struct foot_poundal_per_second : unit {}; + +struct foot_pound_force_per_second : scaled_unit, foot_poundal_per_second> {}; + + +struct dim_power : physical::dim_power {}; + +template +using power = quantity; + +inline namespace literals { + +// foot pound force per second +constexpr auto operator"" q_ft_pdl_per_s(unsigned long long l) { return power(l); } +constexpr auto operator"" q_ft_pdl_per_s(long double l) { return power(l); } + + +// foot pound force per second +constexpr auto operator"" q_ft_lbf_per_s(unsigned long long l) { return power(l); } +constexpr auto operator"" q_ft_lbf_per_s(long double l) { return power(l); } + +} // namespace literals + +} // namespace units::physical::fps diff --git a/src/include/units/physical/fps/pressure.h b/src/include/units/physical/fps/pressure.h new file mode 100644 index 00000000..deb705e0 --- /dev/null +++ b/src/include/units/physical/fps/pressure.h @@ -0,0 +1,56 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include +#include +#include +#include +#include + +namespace units::physical::fps { + +struct poundal_per_foot_sq : unit {}; + +struct pound_force_per_foot_sq : named_scaled_unit, poundal_per_foot_sq> {}; + + +struct dim_pressure : physical::dim_pressure {}; + +template +using pressure = quantity; + +struct pound_force_per_inch_sq : named_scaled_unit, pound_force_per_foot_sq> {}; + +inline namespace literals { +// Poundal per square foot +constexpr auto operator"" q_pdl_per_ft2(unsigned long long l) { return pressure(l); } +constexpr auto operator"" q_pdl_per_ft2(long double l) { return pressure(l); } + +// Pounds per square inch +constexpr auto operator"" q_psi(unsigned long long l) { return pressure(l); } +constexpr auto operator"" q_psi(long double l) { return pressure(l); } + +} // namespace literals + +} // namespace units::physical::fps diff --git a/src/include/units/physical/fps/speed.h b/src/include/units/physical/fps/speed.h new file mode 100644 index 00000000..222cc96c --- /dev/null +++ b/src/include/units/physical/fps/speed.h @@ -0,0 +1,46 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include +#include +#include +#include + +namespace units::physical::fps { + +struct foot_per_second : unit {}; +struct dim_speed : physical::dim_speed {}; + +template +using speed = quantity; + +inline namespace literals { + +// cmps +constexpr auto operator"" q_ft_per_s(unsigned long long l) { return speed(l); } +constexpr auto operator"" q_ft_per_s(long double l) { return speed(l); } + +} // namespace literals + +} // namespace units::physical::fps diff --git a/src/include/units/physical/fps/time.h b/src/include/units/physical/fps/time.h new file mode 100644 index 00000000..869897e0 --- /dev/null +++ b/src/include/units/physical/fps/time.h @@ -0,0 +1,42 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include +#include +#include + +namespace units::physical::fps { + +using si::second; + +using si::dim_time; +using si::time; + +inline namespace literals { + +using si::literals::operator"" q_s; + +} + +} // namespace units::physical::fps diff --git a/test/unit_test/static/CMakeLists.txt b/test/unit_test/static/CMakeLists.txt index 8c4610b0..640ecc9b 100644 --- a/test/unit_test/static/CMakeLists.txt +++ b/test/unit_test/static/CMakeLists.txt @@ -28,11 +28,13 @@ add_library(unit_tests_static dimension_op_test.cpp dimensions_concepts_test.cpp fixed_string_test.cpp + fps_test.cpp math_test.cpp quantity_test.cpp ratio_test.cpp si_test.cpp si_cgs_test.cpp + si_fps_test.cpp symbol_text_test.cpp type_list_test.cpp unit_test.cpp diff --git a/test/unit_test/static/fps_test.cpp b/test/unit_test/static/fps_test.cpp new file mode 100644 index 00000000..e435f056 --- /dev/null +++ b/test/unit_test/static/fps_test.cpp @@ -0,0 +1,102 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { + +using namespace units; +using namespace units::physical::fps; + +/* ************** BASE DIMENSIONS **************** */ + +// length + +static_assert(foot::symbol == "ft"); + +// mass + +// time + +/* ************** DERIVED DIMENSIONS IN TERMS OF BASE UNITS **************** */ + +// speed + +static_assert(10q_ft / 5q_s == 2q_ft_per_s); +static_assert(10q_ft / 2q_ft_per_s == 5q_s); +static_assert(10q_ft == 2q_ft_per_s * 5q_s); + +static_assert(detail::unit_text() == "ft/s"); + +// area +static_assert(std::is_same_v::ratio>, ratio<1>>); + +static_assert(1q_ft * 1q_ft == 1q_ft2); +static_assert(100q_ft2 / 10q_ft == 10q_ft); + +static_assert(detail::unit_text() == basic_symbol_text("ft²", "ft^2")); + +/* ************** DERIVED DIMENSIONS WITH NAMED UNITS **************** */ + +// acceleration + +static_assert(10q_ft_per_s / 10q_s == 1q_ft_per_s2); +static_assert(10q_ft_per_s / 1q_ft_per_s2 == 10q_s); +static_assert(1q_ft_per_s2 * 10q_s == 10q_ft_per_s); + +// force + +static_assert(10q_lb * 10q_ft_per_s2 == 100q_pdl); +static_assert(100q_pdl / 10q_lb == 10q_ft_per_s2); +static_assert(100q_pdl / 10q_ft_per_s2 == 10q_lb); + +// pressure +static_assert(10q_pdl / 10q_ft2 == 1q_pdl_per_ft2); +static_assert(10q_pdl / 1q_pdl_per_ft2 == 10q_ft2); +static_assert(1q_pdl_per_ft2 * 10q_ft2 == 10q_pdl); + +// energy + +static_assert(10q_pdl * 10q_ft == 100q_ft_pdl); +static_assert(100q_ft_pdl / 10q_ft == 10q_pdl); +static_assert(100q_ft_pdl / 10q_pdl == 10q_ft); + +/* ************** DERIVED DIMENSIONS IN TERMS OF OTHER UNITS **************** */ + +// power + +static_assert(10q_ft_pdl / 10q_s == 1q_ft_pdl_per_s); +static_assert(1q_ft_pdl_per_s * 10q_s == 10q_ft_pdl); +static_assert(10q_ft_pdl / 1q_ft_pdl_per_s == 10q_s); + +// static_assert(detail::unit_text() == "ft_lbf/s"); + +} diff --git a/test/unit_test/static/si_fps_test.cpp b/test/unit_test/static/si_fps_test.cpp new file mode 100644 index 00000000..bd1b6577 --- /dev/null +++ b/test/unit_test/static/si_fps_test.cpp @@ -0,0 +1,165 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { + +using namespace units::physical; + +static_assert(fps::length(1) == si::length(0.3048)); +static_assert(fps::mass(1) == si::mass(0.45359237)); +static_assert(fps::time(1) == si::time(1)); +static_assert(fps::speed(1) == si::speed(0.3048)); +static_assert(fps::area(1) == si::area(0.09290304)); +static_assert(fps::acceleration(1) == si::acceleration(0.3048)); +static_assert(fps::force(1) >= si::force(0.138254) && + fps::force(1) <= si::force(0.138256)); +static_assert(fps::energy(1) >= si::energy(0.042140110093804) && + fps::energy(1) <= si::energy(0.042140110093806)); +static_assert(fps::power(1) >= si::power(0.042140110093804) && + fps::power(1) <= si::power(0.042140110093806)); +static_assert(fps::pressure(1) >= si::pressure(1.4881639435) && + fps::pressure(1) <= si::pressure(1.4881639437)); + +namespace si_literals { + +using namespace units::physical::si::literals; + +static_assert(fps::length(1) == 0.3048q_m); +static_assert(fps::mass(1) == 0.45359237q_kg); +static_assert(fps::time(1) == 1q_s); +static_assert(fps::speed(1) == 0.3048q_m_per_s); +static_assert(fps::area(1) == 0.09290304q_m2); +static_assert(fps::acceleration(1) == 0.3048q_m_per_s2); +static_assert(fps::force(1) >= 0.138254q_N && + fps::force(1) <= 0.138256q_N); +static_assert(fps::energy(1) >= 0.042140110093804q_J && + fps::energy(1) <= 0.042140110093806q_J); +static_assert(fps::power(1) >= 0.042140110093804q_W && + fps::power(1) <= 0.042140110093806q_W); +static_assert(fps::pressure(1) >= 1.4881639435q_Pa && + fps::pressure(1) <= 1.4881639437q_Pa); +} + +namespace fps_literals { + +using namespace units::physical::fps::literals; + +static_assert(1q_ft == si::length(0.3048)); +static_assert(1q_lb == si::mass(0.45359237)); +static_assert(1q_s == si::time(1)); +static_assert(1q_ft_per_s == si::speed(0.3048)); +static_assert(1q_ft2 == si::area(0.09290304)); +static_assert(1q_ft_per_s2 == si::acceleration(0.3048)); +static_assert(1q_pdl >= si::force(0.138254) && + 1q_pdl <= si::force(0.138256)); +static_assert(1q_ft_pdl >= si::energy(0.042140110093804) && + 1q_ft_pdl <= si::energy(0.042140110093806)); +static_assert(1q_ft_pdl_per_s >= si::power(0.042140110093804) && + 1q_ft_pdl_per_s <= si::power(0.042140110093806)); +static_assert(1q_pdl_per_ft2>= si::pressure(1.4881639435) && + 1q_pdl_per_ft2 <= si::pressure(1.4881639437)); +} + +namespace fps_plus_si_literals { + +using namespace units::physical::si::literals; +using namespace units::physical::fps::literals; + +// static_assert(100q_cm == 1q_m); // ambiguous +// static_assert(1'000q_g == 1q_kg); // ambiguous +static_assert(1q_ft == 0.3048q_m); +static_assert(1q_lb == 0.45359237q_kg); +static_assert(1q_s == 1q_s); +static_assert(1q_ft_per_s == 0.3048q_m_per_s); +static_assert(1q_ft2 == 0.09290304q_m2); +static_assert(1q_ft_per_s2 == 0.3048q_m_per_s2); +static_assert(1q_pdl >= 0.138254q_N && + 1q_pdl <= 0.138256q_N); +static_assert(1q_ft_pdl >= 0.042140110093804q_J && + 1q_ft_pdl <= 0.042140110093806q_J); +static_assert(1q_ft_pdl_per_s >= 0.042140110093804q_W && + 1q_ft_pdl_per_s <= 0.042140110093806q_W); +static_assert(1q_pdl_per_ft2>= 1.4881639435q_Pa && + 1q_pdl_per_ft2 <=1.4881639437q_Pa); + +} + +namespace cgs_test { + +using namespace units::physical::fps::literals; + +// addition + +// static_assert(si::length(1) + 1q_ft == si::length(1.3048)); // should not compile (different dimensions) +// static_assert(1q_ft / 0.3048 + si::length(1) == si::length(1.3048)); // should not compile (different dimensions) +static_assert(quantity_cast>(1q_ft / 0.3048) + si::length(1) == si::length(2)); // 1 m in ft + 1 m +static_assert(si::length(1) + quantity_cast>(1q_ft / 0.3048) == si::length(2)); // 1 m + 1 m in ft +static_assert(1q_ft + quantity_cast>(si::length(0.3048)) == 2q_ft); // 1 ft + 1 ft in m +static_assert(quantity_cast>(si::length(0.3048)) + 1q_ft == 2q_ft); // 1 ft in m + 1 ft + +// substraction + +// static_assert(1q_ft - si::length(1) == -si::length(0.6952)); // should not compile (different dimensions) +// static_assert(si::length(1) - 1q_ft == si::length(0.6952)); // should not compile (different dimensions) +static_assert(quantity_cast>(6.q_ft) - si::length(1) == si::length(0.8288)); // 6 ft in m - 1 m = ... m +static_assert(si::length(5) - quantity_cast>(6q_ft) == si::length(3.1712)); // 5 m - 6 ft in m = ... +static_assert(6.q_ft - quantity_cast>(si::length(0.3048)) == 5.q_ft); // 6 ft - 1 ft in m = 5 ft +static_assert(quantity_cast>(si::length(1.8288)) - 1.q_ft == 5.q_ft); // 6 ft in m - 1 ft = 5 ft + +// multiplication + +// static_assert(2q_ft * si::length(2) == si::area(1.2192)); // should not compile (unknown dimension) +// static_assert(quantity_cast>(2.q_ft) * si::length(2) == si::area(1.2192)); +static_assert(quantity_cast>(2.q_ft) * si::length(0.6096) == si::area(0.371612160)); // 2 ft * 2 ft == 4 sq ft +static_assert(2.q_ft * quantity_cast>(si::length(0.6096)) == 4.q_ft2); + +// division + +// static_assert(si::area(4) / 200q_cm == si::length(2)); // should not compile (unknown dimension) +static_assert(si::area(1.48644864) / quantity_cast>(4q_ft) == si::length(1.2192)); // 16 ft2 / 4 ft = 4 ft +static_assert(quantity_cast>(si::area(1.48644864)) / 4.q_ft == 4.q_ft); // 16 ft2 / 4 ft = 4 ft + +} + +} From 5b9203d9d69c78048fbccfa8c98e5c5776bce67d Mon Sep 17 00:00:00 2001 From: Mike Ford Date: Sat, 30 May 2020 16:19:17 +0100 Subject: [PATCH 2/4] Added the "named_deduced_unit" type and more units to the fps system The named_deduced_unit type can be used as a named type for child for child deduced units --- src/include/units/physical/fps/area.h | 2 +- src/include/units/physical/fps/density.h | 46 +++++++++++++++++++++ src/include/units/physical/fps/energy.h | 9 +++-- src/include/units/physical/fps/force.h | 2 +- src/include/units/physical/fps/power.h | 5 +-- src/include/units/physical/fps/volume.h | 51 ++++++++++++++++++++++++ src/include/units/unit.h | 23 +++++++++++ 7 files changed, 130 insertions(+), 8 deletions(-) create mode 100644 src/include/units/physical/fps/density.h create mode 100644 src/include/units/physical/fps/volume.h diff --git a/src/include/units/physical/fps/area.h b/src/include/units/physical/fps/area.h index cd83c0be..d5b7276e 100644 --- a/src/include/units/physical/fps/area.h +++ b/src/include/units/physical/fps/area.h @@ -38,7 +38,7 @@ using area = quantity; inline namespace literals { -// fm2 +// ft2 constexpr auto operator"" q_ft2(unsigned long long l) { return area(l); } constexpr auto operator"" q_ft2(long double l) { return area(l); } diff --git a/src/include/units/physical/fps/density.h b/src/include/units/physical/fps/density.h new file mode 100644 index 00000000..91f8d58f --- /dev/null +++ b/src/include/units/physical/fps/density.h @@ -0,0 +1,46 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include +#include +#include +#include + +namespace units::physical::fps { + +struct pound_per_foot_cub : unit {}; + +struct dim_density : physical::dim_density {}; + +template +using density = quantity; + +inline namespace literals { + +constexpr auto operator"" q_lb_per_ft3(unsigned long long l) { return density(l); } +constexpr auto operator"" q_lb_per_ft3(long double l) { return density(l); } + +} // namespace literals + +} // namespace units::physical::fps diff --git a/src/include/units/physical/fps/energy.h b/src/include/units/physical/fps/energy.h index d3cbd5e7..2cef53bd 100644 --- a/src/include/units/physical/fps/energy.h +++ b/src/include/units/physical/fps/energy.h @@ -32,14 +32,17 @@ namespace units::physical::fps { // https://en.wikipedia.org/wiki/Foot-poundal struct foot_poundal : unit {}; -// https://en.wikipedia.org/wiki/Foot-pound_(energy) -struct foot_pound_force : named_scaled_unit, foot_poundal> {}; - struct dim_energy : physical::dim_energy {}; +// https://en.wikipedia.org/wiki/Foot-pound_(energy) +struct foot_pound_force : named_deduced_unit {}; + + + template using energy = quantity; + inline namespace literals { constexpr auto operator"" q_ft_pdl(unsigned long long l) { return energy(l); } diff --git a/src/include/units/physical/fps/force.h b/src/include/units/physical/fps/force.h index cb038e09..cbd7e88b 100644 --- a/src/include/units/physical/fps/force.h +++ b/src/include/units/physical/fps/force.h @@ -34,7 +34,7 @@ namespace units::physical::fps { struct poundal : named_unit {}; // https://en.wikipedia.org/wiki/Pound_(force) -struct pound_force : named_scaled_unit, poundal> {}; +struct pound_force : named_scaled_unit, poundal> {}; diff --git a/src/include/units/physical/fps/power.h b/src/include/units/physical/fps/power.h index 3e572968..0110360a 100644 --- a/src/include/units/physical/fps/power.h +++ b/src/include/units/physical/fps/power.h @@ -31,11 +31,10 @@ namespace units::physical::fps { struct foot_poundal_per_second : unit {}; -struct foot_pound_force_per_second : scaled_unit, foot_poundal_per_second> {}; - - struct dim_power : physical::dim_power {}; +struct foot_pound_force_per_second : deduced_unit {}; + template using power = quantity; diff --git a/src/include/units/physical/fps/volume.h b/src/include/units/physical/fps/volume.h new file mode 100644 index 00000000..07b6f5f0 --- /dev/null +++ b/src/include/units/physical/fps/volume.h @@ -0,0 +1,51 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include +#include +#include + +namespace units::physical::fps { + +struct cubic_foot : unit {}; +struct dim_volume : physical::dim_volume {}; + +struct cubic_yard : deduced_unit {}; + +template +using volume = quantity; + +inline namespace literals { + +// ft3 +constexpr auto operator"" q_ft3(unsigned long long l) { return volume(l); } +constexpr auto operator"" q_ft3(long double l) { return volume(l); } + +// yard3 +constexpr auto operator"" q_yd3(unsigned long long l) { return volume(l); } +constexpr auto operator"" q_yd3(long double l) { return volume(l); } + +} // namespace literals + +} // namespace units::physical::fps diff --git a/src/include/units/unit.h b/src/include/units/unit.h index 1c32ae24..500c2f5c 100644 --- a/src/include/units/unit.h +++ b/src/include/units/unit.h @@ -165,6 +165,29 @@ struct deduced_unit : downcast_child + requires detail::same_scaled_units && + (U::is_named && (URest::is_named && ... && true)) +struct named_deduced_unit : downcast_child> { + static constexpr bool is_named = true; + static constexpr auto symbol = detail::deduced_symbol_text(); + using prefix_family = no_prefix; +}; + // template // struct named_deduced_derived_unit : downcast_child> { // static constexpr bool is_named = true; From aa84dcb9efe35a86b76d92171dcbb18a302d7a13 Mon Sep 17 00:00:00 2001 From: Mike Ford Date: Sun, 31 May 2020 00:37:19 +0100 Subject: [PATCH 3/4] added example and some more units to fps system --- example/CMakeLists.txt | 1 + example/foot_pound_second.cpp | 104 ++++++++++++++++++++++ src/include/units/physical/fps/length.h | 23 +++++ src/include/units/physical/fps/mass.h | 22 ++++- src/include/units/physical/fps/power.h | 6 ++ src/include/units/physical/fps/pressure.h | 7 +- src/include/units/physical/fps/speed.h | 15 +++- src/include/units/physical/fps/time.h | 2 + 8 files changed, 175 insertions(+), 5 deletions(-) create mode 100644 example/foot_pound_second.cpp diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 7d0e2403..1074642c 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -36,6 +36,7 @@ add_example(clcpp_response) add_example(conversion_factor) add_example(kalman_filter-alpha_beta_filter_example2) add_example(experimental_angle) +add_example(foot_pound_second) conan_check_testing(linear_algebra) add_example(linear_algebra) diff --git a/example/foot_pound_second.cpp b/example/foot_pound_second.cpp new file mode 100644 index 00000000..e54e54e6 --- /dev/null +++ b/example/foot_pound_second.cpp @@ -0,0 +1,104 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +using namespace units::physical; + + +// Some basic specs for the warship +struct Ship { + fps::length length; + fps::length draft; + fps::length beam; + + fps::speed speed; + fps::mass mass; + + fps::length mainGuns; + fps::mass shellMass; + fps::speed shellSpeed; + fps::power power; + + +}; + +// Print 'a' in its current units and print its value cast to the units in each of Args +template +auto fmt_line(const Q a) { + return fmt::format("{:22}",a) + (fmt::format(",{:20}", units::quantity_cast(a)) + ...); +} + +// Print the ship details in the units as defined in the Ship struct, in other imperial units, and in SI +std::ostream& print_details(std::string_view description, const Ship& ship) { + using namespace units::physical::fps::literals; + const auto waterDensity = 62.4q_lb_per_ft3; + std::cout << fmt::format("{}\n", description); + std::cout << fmt::format("{:20} : {}\n", "length", fmt_line, si::length>(ship.length)) + << fmt::format("{:20} : {}\n", "draft", fmt_line, si::length>(ship.draft)) + << fmt::format("{:20} : {}\n", "beam", fmt_line, si::length>(ship.beam)) + << fmt::format("{:20} : {}\n", "mass", fmt_line, si::mass>(ship.mass)) + << fmt::format("{:20} : {}\n", "speed", fmt_line, si::speed>(ship.speed)) + << fmt::format("{:20} : {}\n", "power", fmt_line, si::power>(ship.power)) + << fmt::format("{:20} : {}\n", "main guns", fmt_line, si::length>(ship.mainGuns)) + << fmt::format("{:20} : {}\n", "fire shells weighing",fmt_line, si::mass>(ship.shellMass)) + << fmt::format("{:20} : {}\n", "fire shells at",fmt_line, si::speed>(ship.shellSpeed)) + << fmt::format("{:20} : {}\n", "volume underwater", fmt_line, si::volume>(ship.mass / waterDensity)); + return std::cout; +} + +int main() +{ + using namespace units::physical::si::literals; + using namespace units::physical::fps::literals; + + + // KMS Bismark, using the units the Germans would use, taken from Wiki + auto bismark = Ship{.length{251.q_m}, .draft{9.3q_m}, .beam{36q_m}, .speed{56q_km_per_h}, .mass{50.3q_t}, .mainGuns{380q_mm}, .shellMass{800q_kg}, .shellSpeed{820.q_m_per_s}, .power{110.45q_kW}}; + + // USS Iowa, using units from the foot-pound-second system + auto iowa = Ship{.length{860.q_ft}, .draft{37.q_ft + 2.q_in}, .beam{108.q_ft + 2.q_in}, .speed{33q_knot}, .mass{57'540q_lton}, .mainGuns{16q_in}, .shellMass{2700q_lb}, .shellSpeed{2690.q_ft_per_s}, .power{212'000q_hp}}; + + // HMS King George V, using units from the foot-pound-second system + auto kgv = Ship{.length{745.1q_ft}, .draft{33.q_ft + 7.5q_in}, .beam{103.2q_ft + 2.5q_in}, .speed{28.3q_knot}, .mass{42'245q_lton}, .mainGuns{14q_in}, .shellMass{1'590q_lb}, .shellSpeed{2483.q_ft_per_s}, .power{110'000q_hp}}; + + print_details("KMS Bismark, defined in appropriate units from the SI system", bismark) << "\n\n"; + print_details("USS Iowa, defined in appropriate units foot-pound-second system", iowa) << "\n\n"; + print_details("HMS King George V, defined in appropriate units foot-pound-second system", kgv); + +} diff --git a/src/include/units/physical/fps/length.h b/src/include/units/physical/fps/length.h index c7e5a54c..1c962c08 100644 --- a/src/include/units/physical/fps/length.h +++ b/src/include/units/physical/fps/length.h @@ -31,6 +31,16 @@ namespace units::physical::fps { // https://en.wikipedia.org/wiki/Foot_(unit) struct foot : named_scaled_unit, si::metre> {}; +struct yard : named_scaled_unit, foot> {}; + +struct inch : named_scaled_unit, foot> {}; + +struct mile : named_scaled_unit, foot> {}; + +struct nautical_mile : named_scaled_unit, yard> {}; + + + struct dim_length : physical::dim_length {}; template @@ -38,10 +48,23 @@ using length = quantity; inline namespace literals { +constexpr auto operator"" q_in(unsigned long long l) { return length(l); } +constexpr auto operator"" q_in(long double l) { return length(l); } + // ft constexpr auto operator"" q_ft(unsigned long long l) { return length(l); } constexpr auto operator"" q_ft(long double l) { return length(l); } +constexpr auto operator"" q_yd(unsigned long long l) { return length(l); } +constexpr auto operator"" q_yd(long double l) { return length(l); } + +constexpr auto operator"" q_mile(unsigned long long l) { return length(l); } +constexpr auto operator"" q_mile(long double l) { return length(l); } + +constexpr auto operator"" q_naut_mi(unsigned long long l) { return length(l); } +constexpr auto operator"" q_naut_mi(long double l) { return length(l); } + + } } // namespace units::physical::fps diff --git a/src/include/units/physical/fps/mass.h b/src/include/units/physical/fps/mass.h index 7d57d181..2fe1c738 100644 --- a/src/include/units/physical/fps/mass.h +++ b/src/include/units/physical/fps/mass.h @@ -36,12 +36,32 @@ struct dim_mass : physical::dim_mass {}; template using mass = quantity; +struct ounce : named_scaled_unit, pound>{}; + +struct short_ton : named_scaled_unit, pound>{}; + +struct long_ton : named_scaled_unit, pound>{}; + inline namespace literals { -// g + +constexpr auto operator"" q_oz(unsigned long long l) { return mass(l); } +constexpr auto operator"" q_oz(long double l) { return mass(l); } + + +// lb constexpr auto operator"" q_lb(unsigned long long l) { return mass(l); } constexpr auto operator"" q_lb(long double l) { return mass(l); } + +constexpr auto operator"" q_ston(unsigned long long l) { return mass(l); } +constexpr auto operator"" q_ston(long double l) { return mass(l); } + + +constexpr auto operator"" q_lton(unsigned long long l) { return mass(l); } +constexpr auto operator"" q_lton(long double l) { return mass(l); } + + } } // namespace units::physical::fps diff --git a/src/include/units/physical/fps/power.h b/src/include/units/physical/fps/power.h index 0110360a..40df542d 100644 --- a/src/include/units/physical/fps/power.h +++ b/src/include/units/physical/fps/power.h @@ -35,6 +35,8 @@ struct dim_power : physical::dim_power {}; +struct horse_power : named_scaled_unit, foot_pound_force_per_second> {}; + template using power = quantity; @@ -49,6 +51,10 @@ constexpr auto operator"" q_ft_pdl_per_s(long double l) { return power(l); } constexpr auto operator"" q_ft_lbf_per_s(long double l) { return power(l); } + +constexpr auto operator"" q_hp(unsigned long long l) { return power(l); } +constexpr auto operator"" q_hp(long double l) { return power(l); } + } // namespace literals } // namespace units::physical::fps diff --git a/src/include/units/physical/fps/pressure.h b/src/include/units/physical/fps/pressure.h index deb705e0..7fc7e5af 100644 --- a/src/include/units/physical/fps/pressure.h +++ b/src/include/units/physical/fps/pressure.h @@ -32,14 +32,15 @@ namespace units::physical::fps { struct poundal_per_foot_sq : unit {}; -struct pound_force_per_foot_sq : named_scaled_unit, poundal_per_foot_sq> {}; - - struct dim_pressure : physical::dim_pressure {}; template using pressure = quantity; +struct pound_force_per_foot_sq : named_scaled_unit, poundal_per_foot_sq> {}; + +// struct pound_force_per_foot_sq : named_deduced_unit {}; + struct pound_force_per_inch_sq : named_scaled_unit, pound_force_per_foot_sq> {}; inline namespace literals { diff --git a/src/include/units/physical/fps/speed.h b/src/include/units/physical/fps/speed.h index 222cc96c..d0091760 100644 --- a/src/include/units/physical/fps/speed.h +++ b/src/include/units/physical/fps/speed.h @@ -35,12 +35,25 @@ struct dim_speed : physical::dim_speed using speed = quantity; +struct mile_per_hour : deduced_unit{}; + +struct nautical_mile_per_hour : deduced_unit{}; + +struct knot : alias_unit {}; + + inline namespace literals { -// cmps constexpr auto operator"" q_ft_per_s(unsigned long long l) { return speed(l); } constexpr auto operator"" q_ft_per_s(long double l) { return speed(l); } +constexpr auto operator"" q_mph(unsigned long long l) { return speed(l); } +constexpr auto operator"" q_mph(long double l) { return speed(l); } + +constexpr auto operator"" q_knot(unsigned long long l) { return speed(l); } +constexpr auto operator"" q_knot(long double l) { return speed(l); } + + } // namespace literals } // namespace units::physical::fps diff --git a/src/include/units/physical/fps/time.h b/src/include/units/physical/fps/time.h index 869897e0..4862c736 100644 --- a/src/include/units/physical/fps/time.h +++ b/src/include/units/physical/fps/time.h @@ -29,6 +29,8 @@ namespace units::physical::fps { using si::second; +using si::minute; +using si::hour; using si::dim_time; using si::time; From c97a438807ada06041bae8e3515bbebca531ffa4 Mon Sep 17 00:00:00 2001 From: Mike Ford Date: Sun, 31 May 2020 12:32:14 +0100 Subject: [PATCH 4/4] playing with named derived units to allow knots to be deduced from nautical miles & hours but be called knot instead of mi(naut) / h --- src/include/units/physical/fps/energy.h | 2 +- src/include/units/physical/fps/pressure.h | 2 +- src/include/units/physical/fps/speed.h | 4 +-- src/include/units/unit.h | 32 ++++++++++++++++++----- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/include/units/physical/fps/energy.h b/src/include/units/physical/fps/energy.h index 2cef53bd..d3bdd14e 100644 --- a/src/include/units/physical/fps/energy.h +++ b/src/include/units/physical/fps/energy.h @@ -35,7 +35,7 @@ struct foot_poundal : unit {}; struct dim_energy : physical::dim_energy {}; // https://en.wikipedia.org/wiki/Foot-pound_(energy) -struct foot_pound_force : named_deduced_unit {}; +struct foot_pound_force : noble_deduced_unit {}; diff --git a/src/include/units/physical/fps/pressure.h b/src/include/units/physical/fps/pressure.h index 7fc7e5af..673843ce 100644 --- a/src/include/units/physical/fps/pressure.h +++ b/src/include/units/physical/fps/pressure.h @@ -39,7 +39,7 @@ using pressure = quantity; struct pound_force_per_foot_sq : named_scaled_unit, poundal_per_foot_sq> {}; -// struct pound_force_per_foot_sq : named_deduced_unit {}; +// struct pound_force_per_foot_sq : noble_deduced_unit {}; struct pound_force_per_inch_sq : named_scaled_unit, pound_force_per_foot_sq> {}; diff --git a/src/include/units/physical/fps/speed.h b/src/include/units/physical/fps/speed.h index d0091760..1f9badf7 100644 --- a/src/include/units/physical/fps/speed.h +++ b/src/include/units/physical/fps/speed.h @@ -37,9 +37,9 @@ using speed = quantity; struct mile_per_hour : deduced_unit{}; -struct nautical_mile_per_hour : deduced_unit{}; +struct nautical_mile_per_hour :named_deduced_derived_unit{}; -struct knot : alias_unit {}; +struct knot : alias_unit {}; inline namespace literals { diff --git a/src/include/units/unit.h b/src/include/units/unit.h index 500c2f5c..e4c06b4d 100644 --- a/src/include/units/unit.h +++ b/src/include/units/unit.h @@ -182,18 +182,36 @@ struct deduced_unit : downcast_child requires detail::same_scaled_units && (U::is_named && (URest::is_named && ... && true)) -struct named_deduced_unit : downcast_child> { +// TODO - 'noble' is placeholder to sort of mean can pass its name on to other deduced units +struct noble_deduced_unit : downcast_child> { static constexpr bool is_named = true; static constexpr auto symbol = detail::deduced_symbol_text(); using prefix_family = no_prefix; }; -// template -// struct named_deduced_derived_unit : downcast_child> { -// static constexpr bool is_named = true; -// static constexpr auto symbol = Symbol; -// using prefix_family = PF; -// }; + +/** + * @brief A named unit with a deduced ratio + * + * Defines a new unit with a deduced ratio and the given symbol based on the recipe from the provided + * derived dimension. The number and order of provided units should match the recipe of the + * derived dimension. All of the units provided should also be a named ones so it is possible + * to create a deduced symbol text. + * + * @tparam Child inherited class type used by the downcasting facility (CRTP Idiom) + * @tparam Dim a derived dimension recipe to use for deduction + * @tparam Symbol a short text representation of the unit + * @tparam PF no_prefix or a type of prefix family + * @tparam U the unit of the first composite dimension from provided derived dimension's recipe + * @tparam URest the units for the rest of dimensions from the recipe + */ +template + requires detail::same_scaled_units +struct named_deduced_derived_unit : downcast_child> { + static constexpr bool is_named = true; + static constexpr auto symbol = Symbol; + using prefix_family = PF; +}; /** * @brief An aliased named unit