Skip to content

Commit

Permalink
refactor: 💥 all iec quantity specifications are now deprecated and …
Browse files Browse the repository at this point in the history
…moved to `isq`

IEC 80000-13 is a part of ISQ so quantity specifications should be in an `isq` namespace.
  • Loading branch information
mpusz committed Sep 28, 2024
1 parent 5a48f19 commit fb8f67c
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 110 deletions.
1 change: 1 addition & 0 deletions src/systems/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ add_mp_units_module(
include/mp-units/systems/isq/atomic_and_nuclear_physics.h
include/mp-units/systems/isq/base_quantities.h
include/mp-units/systems/isq/electromagnetism.h
include/mp-units/systems/isq/information_science_and_technology.h
include/mp-units/systems/isq/light_and_radiation.h
include/mp-units/systems/isq/mechanics.h
include/mp-units/systems/isq/si_quantities.h
Expand Down
104 changes: 57 additions & 47 deletions src/systems/include/mp-units/systems/iec/quantities.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,57 +22,67 @@

#pragma once

#include <mp-units/bits/module_macros.h>
#include <mp-units/systems/isq/mechanics.h>
#include <mp-units/systems/isq/space_and_time.h>

#ifndef MP_UNITS_IN_MODULE_INTERFACE
#include <mp-units/framework/dimension.h>
#include <mp-units/framework/quantity_spec.h>
#endif
#include <mp-units/systems/isq/information_science_and_technology.h>

MP_UNITS_EXPORT
namespace mp_units::iec {

// dimensions of base quantities
// clang-format off
inline constexpr struct dim_traffic_intensity final : base_dimension<"A"> {} dim_traffic_intensity;
// clang-format on

// quantities
QUANTITY_SPEC(traffic_intensity, dim_traffic_intensity);
QUANTITY_SPEC(traffic_offered_intensity, traffic_intensity);
QUANTITY_SPEC(traffic_carried_intensity, traffic_intensity);
inline constexpr auto traffic_load = traffic_carried_intensity;
QUANTITY_SPEC(mean_queue_length, dimensionless);
QUANTITY_SPEC(loss_probability, dimensionless);
QUANTITY_SPEC(waiting_probability, dimensionless);
QUANTITY_SPEC(call_intensity, inverse(isq::duration));
inline constexpr auto calling_rate = call_intensity;
QUANTITY_SPEC(completed_call_intensity, call_intensity);
QUANTITY_SPEC(storage_capacity, dimensionless, is_kind);
inline constexpr auto storage_size = storage_capacity;
QUANTITY_SPEC(equivalent_binary_storage_capacity, storage_capacity);
QUANTITY_SPEC(transfer_rate, storage_capacity / isq::duration);
QUANTITY_SPEC(period_of_data_elements, isq::period, inverse(transfer_rate));
QUANTITY_SPEC(binary_digit_rate, transfer_rate);
inline constexpr auto bit_rate = binary_digit_rate;
QUANTITY_SPEC(period_of_binary_digits, isq::period, inverse(binary_digit_rate));
inline constexpr auto bit_period = period_of_binary_digits;
QUANTITY_SPEC(equivalent_binary_digit_rate, binary_digit_rate);
inline constexpr auto equivalent_bit_rate = bit_rate;
QUANTITY_SPEC(modulation_rate, inverse(isq::duration));
inline constexpr auto line_digit_rate = modulation_rate;
QUANTITY_SPEC(quantizing_distortion_power, isq::power);
QUANTITY_SPEC(carrier_power, isq::power);
QUANTITY_SPEC(signal_energy_per_binary_digit, carrier_power* period_of_binary_digits);
QUANTITY_SPEC(error_probability, dimensionless);
QUANTITY_SPEC(Hamming_distance, dimensionless);
QUANTITY_SPEC(clock_frequency, isq::frequency);
inline constexpr auto clock_rate = clock_frequency;
QUANTITY_SPEC(decision_content, dimensionless);
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto dim_traffic_intensity =
isq::dim_traffic_intensity;

// TODO how to model information_content and the following quantities???
// QUANTITY_SPEC(information_content, ...);
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto traffic_intensity =
isq::traffic_intensity;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto traffic_offered_intensity =
isq::traffic_offered_intensity;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto traffic_carried_intensity =
isq::traffic_carried_intensity;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto traffic_load =
isq::traffic_carried_intensity;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto mean_queue_length =
isq::mean_queue_length;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto loss_probability =
isq::loss_probability;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto waiting_probability =
isq::waiting_probability;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto call_intensity = isq::call_intensity;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto calling_rate = isq::call_intensity;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto completed_call_intensity =
isq::completed_call_intensity;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto storage_capacity =
isq::storage_capacity;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto storage_size = isq::storage_capacity;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto equivalent_binary_storage_capacity =
isq::equivalent_binary_storage_capacity;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto transfer_rate = isq::transfer_rate;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto period_of_data_elements =
isq::period_of_data_elements;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto binary_digit_rate =
isq::binary_digit_rate;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto bit_rate = isq::binary_digit_rate;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto period_of_binary_digits =
isq::period_of_binary_digits;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto bit_period =
isq::period_of_binary_digits;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto equivalent_binary_digit_rate =
isq::equivalent_binary_digit_rate;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto equivalent_bit_rate = isq::bit_rate;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto modulation_rate =
isq::modulation_rate;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto line_digit_rate =
isq::modulation_rate;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto quantizing_distortion_power =
isq::quantizing_distortion_power;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto carrier_power = isq::carrier_power;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto signal_energy_per_binary_digit =
isq::signal_energy_per_binary_digit;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto error_probability =
isq::error_probability;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto Hamming_distance =
isq::Hamming_distance;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto clock_frequency =
isq::clock_frequency;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto clock_rate = isq::clock_frequency;
[[deprecated("Quantity type moved to the `isq` namespace")]] inline constexpr auto decision_content =
isq::decision_content;

} // namespace mp_units::iec
7 changes: 4 additions & 3 deletions src/systems/include/mp-units/systems/iec/units.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <mp-units/bits/module_macros.h>
#include <mp-units/systems/iec/quantities.h>
#include <mp-units/systems/isq/electromagnetism.h>
#include <mp-units/systems/isq/information_science_and_technology.h>
#include <mp-units/systems/si/units.h>

#ifndef MP_UNITS_IN_MODULE_INTERFACE
Expand All @@ -39,11 +40,11 @@ namespace mp_units::iec {
inline constexpr struct volt_ampere_reactive_power final : named_unit<"var", si::volt * si::ampere, kind_of<isq::reactive_power>> {} volt_ampere_reactive_power;

// Information science and technology
inline constexpr struct erlang final : named_unit<"E", kind_of<traffic_intensity>> {} erlang;
inline constexpr struct bit final : named_unit<"bit", one, kind_of<storage_capacity>> {} bit;
inline constexpr struct erlang final : named_unit<"E", kind_of<isq::traffic_intensity>> {} erlang;
inline constexpr struct bit final : named_unit<"bit", one, kind_of<isq::storage_capacity>> {} bit;
inline constexpr struct octet final : named_unit<"o", mag<8> * bit> {} octet;
inline constexpr struct byte final : named_unit<"B", mag<8> * bit> {} byte;
inline constexpr struct baud final : named_unit<"Bd", one / si::second, kind_of<modulation_rate>> {} baud;
inline constexpr struct baud final : named_unit<"Bd", one / si::second, kind_of<isq::modulation_rate>> {} baud;
// clang-format on

} // namespace mp_units::iec
1 change: 1 addition & 0 deletions src/systems/include/mp-units/systems/isq.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <mp-units/systems/isq/atomic_and_nuclear_physics.h>
#include <mp-units/systems/isq/base_quantities.h>
#include <mp-units/systems/isq/electromagnetism.h>
#include <mp-units/systems/isq/information_science_and_technology.h>
#include <mp-units/systems/isq/light_and_radiation.h>
#include <mp-units/systems/isq/mechanics.h>
#include <mp-units/systems/isq/si_quantities.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// 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 <mp-units/bits/module_macros.h>
#include <mp-units/systems/isq/mechanics.h>
#include <mp-units/systems/isq/space_and_time.h>

#ifndef MP_UNITS_IN_MODULE_INTERFACE
#include <mp-units/framework/dimension.h>
#include <mp-units/framework/quantity_spec.h>
#endif

MP_UNITS_EXPORT
namespace mp_units::isq {

// dimensions of base quantities
// clang-format off
inline constexpr struct dim_traffic_intensity final : base_dimension<"A"> {} dim_traffic_intensity;
// clang-format on

// quantities
QUANTITY_SPEC(traffic_intensity, dim_traffic_intensity);
QUANTITY_SPEC(traffic_offered_intensity, traffic_intensity);
QUANTITY_SPEC(traffic_carried_intensity, traffic_intensity);
inline constexpr auto traffic_load = traffic_carried_intensity;
QUANTITY_SPEC(mean_queue_length, dimensionless);
QUANTITY_SPEC(loss_probability, dimensionless);
QUANTITY_SPEC(waiting_probability, dimensionless);
QUANTITY_SPEC(call_intensity, inverse(isq::duration));
inline constexpr auto calling_rate = call_intensity;
QUANTITY_SPEC(completed_call_intensity, call_intensity);
QUANTITY_SPEC(storage_capacity, dimensionless, is_kind);
inline constexpr auto storage_size = storage_capacity;
QUANTITY_SPEC(equivalent_binary_storage_capacity, storage_capacity);
QUANTITY_SPEC(transfer_rate, storage_capacity / isq::duration);
QUANTITY_SPEC(period_of_data_elements, isq::period, inverse(transfer_rate));
QUANTITY_SPEC(binary_digit_rate, transfer_rate);
inline constexpr auto bit_rate = binary_digit_rate;
QUANTITY_SPEC(period_of_binary_digits, isq::period, inverse(binary_digit_rate));
inline constexpr auto bit_period = period_of_binary_digits;
QUANTITY_SPEC(equivalent_binary_digit_rate, binary_digit_rate);
inline constexpr auto equivalent_bit_rate = bit_rate;
QUANTITY_SPEC(modulation_rate, inverse(isq::duration));
inline constexpr auto line_digit_rate = modulation_rate;
QUANTITY_SPEC(quantizing_distortion_power, isq::power);
QUANTITY_SPEC(carrier_power, isq::power);
QUANTITY_SPEC(signal_energy_per_binary_digit, carrier_power* period_of_binary_digits);
QUANTITY_SPEC(error_probability, dimensionless);
QUANTITY_SPEC(Hamming_distance, dimensionless);
QUANTITY_SPEC(clock_frequency, isq::frequency);
inline constexpr auto clock_rate = clock_frequency;
QUANTITY_SPEC(decision_content, dimensionless);

// TODO how to model information_content and the following quantities???
// QUANTITY_SPEC(information_content, ...);

} // namespace mp_units::isq
80 changes: 20 additions & 60 deletions test/static/iec_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,81 +21,41 @@
// SOFTWARE.

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

/* ************** DERIVED DIMENSIONS THAT INCLUDE UNITS WITH SPECIAL NAMES **************** */

namespace {

using namespace mp_units;
using namespace mp_units::iec;
using namespace mp_units::iec::unit_symbols;
using namespace mp_units::si::unit_symbols;
using enum mp_units::quantity_character;

[[nodiscard]] consteval bool verify(QuantitySpec auto q, quantity_character ch, Unit auto... units)
{
return q.character == ch && (... && requires { q[units]; });
}

// quantities
static_assert(verify(traffic_intensity, scalar, E));
static_assert(verify(traffic_offered_intensity, scalar, E));
static_assert(verify(traffic_carried_intensity, scalar, E));
static_assert(verify(traffic_load, scalar, E));
static_assert(verify(mean_queue_length, scalar, one));
static_assert(verify(loss_probability, scalar, one));
static_assert(verify(waiting_probability, scalar, one));
static_assert(verify(call_intensity, scalar, one / s));
static_assert(verify(calling_rate, scalar, one / s));
static_assert(verify(completed_call_intensity, scalar, one / s));
static_assert(verify(storage_capacity, scalar, one, bit, o, B));
static_assert(verify(storage_size, scalar, one, bit, o, B));
static_assert(verify(equivalent_binary_storage_capacity, scalar, one, bit));
static_assert(verify(transfer_rate, scalar, one / s, o / s, B / s));
static_assert(verify(period_of_data_elements, scalar, s));
static_assert(verify(binary_digit_rate, scalar, one / s, bit / s));
static_assert(verify(bit_rate, scalar, one / s, bit / s));
static_assert(verify(period_of_binary_digits, scalar, s));
static_assert(verify(bit_period, scalar, s));
static_assert(verify(equivalent_binary_digit_rate, scalar, one / s, bit / s));
static_assert(verify(equivalent_bit_rate, scalar, one / s, bit / s));
static_assert(verify(modulation_rate, scalar, one / s, Bd));
static_assert(verify(line_digit_rate, scalar, one / s, Bd));
static_assert(verify(quantizing_distortion_power, scalar, W));
static_assert(verify(carrier_power, scalar, W));
static_assert(verify(signal_energy_per_binary_digit, scalar, J));
static_assert(verify(error_probability, scalar, one));
static_assert(verify(Hamming_distance, scalar, one));
static_assert(verify(clock_frequency, scalar, Hz));
static_assert(verify(clock_rate, scalar, Hz));
static_assert(verify(decision_content, scalar, one));


// unit conversions
static_assert(storage_capacity(1 * B) == storage_capacity(8 * bit));
static_assert(storage_capacity(1024 * bit) == storage_capacity(1 * Kibit));
static_assert(storage_capacity(1024 * B) == storage_capacity(1 * KiB));
static_assert(storage_capacity(8 * 1024 * bit) == storage_capacity(1 * KiB));
static_assert(storage_capacity(8 * Kibit) == storage_capacity(1 * KiB));

static_assert(storage_capacity(1 * kbit) == storage_capacity(1000 * bit));
static_assert(storage_capacity(2000 * Mibit) == storage_capacity(2097152 * kbit));

static_assert(storage_capacity(1 * Kibit) == storage_capacity(1024 * bit));
static_assert(storage_capacity(1 * Mibit) == storage_capacity(1024 * Kibit));
static_assert(storage_capacity(1 * Gibit) == storage_capacity(1024 * Mibit));
static_assert(storage_capacity(1 * Tibit) == storage_capacity(1024 * Gibit));
static_assert(storage_capacity(1 * Pibit) == storage_capacity(1024 * Tibit));
static_assert(storage_capacity(1 * Eibit) == storage_capacity(1024 * Pibit));
static_assert(isq::storage_capacity(1 * B) == isq::storage_capacity(8 * bit));
static_assert(isq::storage_capacity(1024 * bit) == isq::storage_capacity(1 * Kibit));
static_assert(isq::storage_capacity(1024 * B) == isq::storage_capacity(1 * KiB));
static_assert(isq::storage_capacity(8 * 1024 * bit) == isq::storage_capacity(1 * KiB));
static_assert(isq::storage_capacity(8 * Kibit) == isq::storage_capacity(1 * KiB));

static_assert(isq::storage_capacity(1 * kbit) == isq::storage_capacity(1000 * bit));
static_assert(isq::storage_capacity(2000 * Mibit) == isq::storage_capacity(2097152 * kbit));

static_assert(isq::storage_capacity(1 * Kibit) == isq::storage_capacity(1024 * bit));
static_assert(isq::storage_capacity(1 * Mibit) == isq::storage_capacity(1024 * Kibit));
static_assert(isq::storage_capacity(1 * Gibit) == isq::storage_capacity(1024 * Mibit));
static_assert(isq::storage_capacity(1 * Tibit) == isq::storage_capacity(1024 * Gibit));
static_assert(isq::storage_capacity(1 * Pibit) == isq::storage_capacity(1024 * Tibit));
static_assert(isq::storage_capacity(1 * Eibit) == isq::storage_capacity(1024 * Pibit));

// transfer rate
static_assert(storage_capacity(16 * B) / isq::duration(2 * s) == transfer_rate(8 * B / s));
static_assert(storage_capacity(120 * kB) / isq::duration(2 * min) == transfer_rate(1000 * B / s));
static_assert(isq::storage_capacity(16 * B) / isq::duration(2 * s) == isq::transfer_rate(8 * B / s));
static_assert(isq::storage_capacity(120 * kB) / isq::duration(2 * min) == isq::transfer_rate(1000 * B / s));

// modulation rate
static_assert(12 / isq::duration(2 * s) == modulation_rate(6 * Bd));
static_assert(6000 / isq::duration(3 * s) == modulation_rate(2 * kBd));
static_assert(12 / isq::duration(2 * s) == isq::modulation_rate(6 * Bd));
static_assert(6000 / isq::duration(3 * s) == isq::modulation_rate(2 * kBd));

} // namespace
Loading

0 comments on commit fb8f67c

Please sign in to comment.