2022-12-20 10:43:55 +01:00
|
|
|
/*
|
|
|
|
Copyright (c) 2003-2020 Andy Little.
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see http://www.gnu.org/licenses./
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
capacitor discharge curve using compile_time
|
|
|
|
physical_quantities
|
|
|
|
*/
|
|
|
|
|
2023-05-25 12:47:10 +02:00
|
|
|
#include <mp-units/iostream.h>
|
|
|
|
#include <mp-units/math.h> // IWYU pragma: keep
|
|
|
|
#include <mp-units/systems/isq/electromagnetism.h>
|
|
|
|
#include <mp-units/systems/si/si.h>
|
2022-12-20 10:43:55 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2022-12-29 20:18:48 +01:00
|
|
|
using namespace mp_units;
|
|
|
|
using namespace mp_units::si::unit_symbols;
|
2022-12-20 10:43:55 +01:00
|
|
|
|
|
|
|
std::cout << "mp-units capacitor time curve example...\n";
|
|
|
|
std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield);
|
|
|
|
std::cout.precision(3);
|
|
|
|
|
2023-06-16 17:19:21 +03:00
|
|
|
constexpr auto CC = isq::capacitance(0.47 * uF);
|
2023-02-08 21:47:48 -08:00
|
|
|
constexpr auto V0 = isq::voltage(5.0 * V);
|
2023-06-16 17:19:21 +03:00
|
|
|
constexpr auto RR = isq::resistance(4.7 * si::kilo<si::ohm>);
|
2022-12-20 10:43:55 +01:00
|
|
|
|
2023-06-16 17:19:21 +03:00
|
|
|
for (auto tt = 0 * ms; tt <= 50 * ms; ++tt) {
|
|
|
|
const QuantityOf<isq::voltage> auto Vt = V0 * exp(dimensionless(-tt / (RR * CC)));
|
2023-05-25 12:15:52 +02:00
|
|
|
// TODO try to make the below work instead
|
2023-06-16 17:19:21 +03:00
|
|
|
// const QuantityOf<isq::voltage> auto Vt = V0 * exp(-tt / (RR * CC));
|
2022-12-20 10:43:55 +01:00
|
|
|
|
2023-06-16 17:19:21 +03:00
|
|
|
std::cout << "at " << tt << " voltage is ";
|
2022-12-20 10:43:55 +01:00
|
|
|
|
2023-02-08 21:47:48 -08:00
|
|
|
if (Vt >= 1 * V)
|
2022-12-20 10:43:55 +01:00
|
|
|
std::cout << Vt[V];
|
2023-02-08 21:47:48 -08:00
|
|
|
else if (Vt >= 1 * mV)
|
2022-12-20 10:43:55 +01:00
|
|
|
std::cout << Vt[mV];
|
2023-02-08 21:47:48 -08:00
|
|
|
else if (Vt >= 1 * uV)
|
2022-12-20 10:43:55 +01:00
|
|
|
std::cout << Vt[uV];
|
2023-02-08 21:47:48 -08:00
|
|
|
else if (Vt >= 1 * nV)
|
2022-12-20 10:43:55 +01:00
|
|
|
std::cout << Vt[nV];
|
|
|
|
else
|
|
|
|
std::cout << Vt[pV];
|
|
|
|
std::cout << "\n";
|
|
|
|
}
|
|
|
|
}
|