Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide proper support for complex quantities #618

Open
mpusz opened this issue Sep 20, 2024 · 1 comment
Open

Provide proper support for complex quantities #618

mpusz opened this issue Sep 20, 2024 · 1 comment
Assignees
Labels
design Design-related discussion enhancement New feature or request
Milestone

Comments

@mpusz
Copy link
Owner

mpusz commented Sep 20, 2024

For example the following should be supported (as much as possible):

template<template<auto, typename> typename Q>
concept complex_operations =
  requires(Q<isq::voltage_phasor[si::kilo<si::volt>], std::complex<double>> voltage_phasor,
           Q<isq::electric_current_phasor[si::ampere], std::complex<double>> electric_current_phasor,
           Q<isq::phase_angle[si::radian], double> phase_angle,
           Q<isq::complex_power[si::kilo<si::volt> * si::ampere], std::complex<double>> complex_power,
           Q<isq::apparent_power[si::kilo<si::volt> * si::ampere], double> apparent_power,
           Q<isq::active_power[si::watt], double> active_power,
           Q<isq::reactive_power[iec::volt_ampere_reactive_power], double> reactive_power,
           Q<isq::power_factor[one], double> power_factor) {
    // valid operations
    { voltage_phasor* conj(electric_current_phasor) } -> std::convertible_to<decltype(complex_power)>;
    { complex(active_power, reactive_power) } -> std::convertible_to<decltype(complex_power)>;
    { mod(complex_power) } -> std::convertible_to<decltype(apparent_power)>;
    { re(complex_power) } -> std::convertible_to<decltype(active_power)>;
    { im(complex_power) } -> std::convertible_to<decltype(reactive_power)>;
    { arg(complex_power) } -> std::convertible_to<decltype(phase_angle)>;
    { active_power / apparent_power } -> std::convertible_to<decltype(power_factor)>;
    { reactive_power.in(si::volt * si::ampere) };  // has to work according to ISO 80000
    // invalid operations
    requires !requires { active_power + reactive_power; };
    requires !requires { complex(apparent_power, reactive_power); } -> std::convertible_to<decltype(complex_power)>;  // ?
    requires !requires { complex(reactive_power, active_power); } -> std::convertible_to<decltype(complex_power)>;
    requires !requires { complex_power = apparent_power; };
    requires !requires { complex_power = active_power; };
    requires !requires { complex_power = reactive_power; };
    requires !requires { active_power = complex_power; };
    requires !requires { active_power = reactive_power; };
    requires !requires { active_power = apparent_power; };  // ?
    requires !requires { reactive_power = complex_power; };
    requires !requires { reactive_power = active_power; };
    requires !requires { reactive_power = apparent_power; };
    requires !requires { complex_power.in(iec::volt_ampere_reactive_power); };
    requires !requires { active_power.in(iec::volt_ampere_reactive_power); };
    requires !requires { apparent_power.in(iec::volt_ampere_reactive_power); };
    requires !requires { complex_power.in(si::watt); };
    requires !requires { apparent_power.in(si::watt); };
    // probably impossible to enforce
    requires !requires { active_power.in(si::watt * si::ampere); };
  };

static_assert(complex_operations<quantity>);
@mpusz mpusz added the enhancement New feature or request label Sep 20, 2024
@mpusz mpusz added this to the v2.4.0 milestone Sep 20, 2024
@mpusz mpusz self-assigned this Sep 20, 2024
@AlexVermette-Eaton
Copy link

This bug might be problematic in Clang (not present in MSVC). llvm/llvm-project#55370

@mpusz mpusz added the design Design-related discussion label Oct 12, 2024
@mpusz mpusz modified the milestones: v2.4.0, v2.5.0 Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Design-related discussion enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants