Files
pws2mqtt-qt/utcicalculator.h
2025-10-16 12:35:53 +02:00

45 lines
1.5 KiB
C++

#pragma once
#include <QObject>
#include <QVector>
#include <QString>
/*
UtciCalculator
- lit un fichier de coefficients (format ESM_3/tab-delimited)
- calcule UTCI via l'approximation polynomiale : UTCI = Ta + Offset(Ta, va, tm, pa)
where tm = Tr - Ta and pa is water vapour pressure in kPa.
- fournit une fonction utilitaire pour calculer pa depuis Ta et relative humidity (Magnus-Tetens).
*/
class UtciCalculator : public QObject
{
Q_OBJECT
public:
explicit UtciCalculator(QObject *parent = nullptr);
// Load coefficients from a file (ESM_3 table or exported txt)
// Return true on success.
//bool loadCoefficientsFromFile(const QString &path);
// Calculate UTCI.
// Ta: air temperature (°C)
// va: wind speed at 10 m (m/s)
// Tr: mean radiant temperature (°C)
// rh: relative humidity in % (0..100). If rh < 0, supply pa directly (next param) and set pa_provided=true.
// pa_kpa: vapour pressure in kPa (used if pa_provided==true)
double computeUTCI(double Ta, double va, double Tr, double rh) const;
// Utility: compute water vapour pressure (kPa) from Ta and relative humidity (Magnus formula)
// Ta in °C, rh in %
static double vapourPressureFromRH(double Ta, double rh_percent);
private:
// coefficients in the same order as the ESM_3 polynomial table terms.
QVector<double> m_coeffs;
// Evaluate the polynomial offset = f(Ta, va, tm, pa)
double evalOffset(double Ta, double va, double tm, double pa) const;
void initCoefficients(); // initialise m_coeffs avec les 210 valeurs
};