Air density calculator: add ability to use relative humidity

Fixes #1383
This commit is contained in:
Alejandro Martinez
2021-05-21 20:28:15 -03:00
parent 489c499ba7
commit 20a7d74c16
2 changed files with 49 additions and 2 deletions

View File

@@ -131,6 +131,26 @@ ToolsRhoEstimator::ToolsRhoEstimator(Context *context, QWidget *parent) : QDialo
dhl->addWidget(dewpSpinBox);
mainVBox->addLayout(dhl);
// The relative humidity box.
QHBoxLayout *hhl = new QHBoxLayout;
rhumLabel = new QLabel(tr("Relative Humidity (%):"));
hhl->addWidget(rhumLabel);
rhumSpinBox = new QDoubleSpinBox(this);
rhumSpinBox->setDecimals(2);
rhumSpinBox->setRange(0, 100);
rhumSpinBox->setWrapping(false);
rhumSpinBox->setAlignment(Qt::AlignRight);
connect(rhumSpinBox, SIGNAL(valueChanged(double)),
this, SLOT(on_valueChanged(double)));
hhl->addWidget(rhumSpinBox);
rhumGroupBox = new QGroupBox(tr("Use Relative Humidity"));
rhumGroupBox->setCheckable(true);
rhumGroupBox->setChecked(false);
rhumGroupBox->setLayout(hhl);
connect(rhumGroupBox, SIGNAL(toggled(bool)),
this, SLOT(on_valueChanged()));
mainVBox->addWidget(rhumGroupBox);
// Label for the computed air density.
mainVBox->addSpacing(15);
mainVBox->addWidget(new QLabel(
@@ -203,7 +223,7 @@ void ToolsRhoEstimator::on_btnOK_clicked() {
}
void ToolsRhoEstimator::on_valueChanged(double newval) {
newval++; // hack to avoid the "unused parameter" g++ warning.
Q_UNUSED(newval)
// scrape the field values, convert to metric if needed.
double temp = tempSpinBox->value();
@@ -216,6 +236,17 @@ void ToolsRhoEstimator::on_valueChanged(double newval) {
dewp = fahrenheit_to_celsius(dewp);
}
if (rhumGroupBox->isChecked()) {
// compute dew point from relative humidity
dewpSpinBox->setEnabled(false);
dewp = dewp_from_rhum(rhumSpinBox->value(), temp);
dewpSpinBox->setValue(impBut->isChecked() ? celsius_to_fahrenheit(dewp) : dewp);
} else {
// compute relative humidity from dew point
rhumSpinBox->setValue(rhum_from_dewp(dewp, temp));
dewpSpinBox->setEnabled(true);
}
// calculate rho, in (kg/m^3)
double rho_met = calculate_rho(temp, press, dewp);
// calculate rho in imperial units.
@@ -251,6 +282,16 @@ double ToolsRhoEstimator::rho_met_to_imp(double rho) {
return rho * ((0.30480061 * 0.30480061 * 0.30480061) / KG_PER_LB);
}
// source: http://bmcnoldy.rsmas.miami.edu/Humidity.html
double ToolsRhoEstimator::dewp_from_rhum(double rhum, double temp) {
return 243.04*(log(rhum/100)+((17.625*temp)/(243.04+temp)))/(17.625-log(rhum/100)-((17.625*temp)/(243.04+temp)));
}
// source: http://bmcnoldy.rsmas.miami.edu/Humidity.html
double ToolsRhoEstimator::rhum_from_dewp(double dewp, double temp) {
return 100*(exp((17.625*dewp)/(243.04+dewp))/exp((17.625*temp)/(243.04+temp)));
}
double ToolsRhoEstimator::calculate_rho(double temp,
double press,
double dewp) {

View File

@@ -25,6 +25,7 @@
#include <QDialog>
#include <QLineEdit>
#include <QLabel>
#include <QGroupBox>
class Context;
@@ -50,18 +51,23 @@ class ToolsRhoEstimator : public QDialog {
QLabel *tempLabel;
QLabel *pressLabel;
QLabel *dewpLabel;
QLabel *rhumLabel;
QDoubleSpinBox *tempSpinBox;
QDoubleSpinBox *pressSpinBox;
QDoubleSpinBox *dewpSpinBox;
QDoubleSpinBox *rhumSpinBox;
QGroupBox *rhumGroupBox;
double fahrenheit_to_celsius(double f);
double celsius_to_fahrenheit(double c);
double hectopascals_to_inchesmercury(double hpa);
double inchesmercury_to_hectopascals(double inhg);
double rho_met_to_imp(double rho);
double dewp_from_rhum(double rhum, double temp);
double rhum_from_dewp(double dewp, double temp);
double calculate_rho(double temp, double press, double dewp);
private slots:
void on_radio_toggled(bool checked);
void on_btnOK_clicked();
void on_valueChanged(double newval);
void on_valueChanged(double newval=0.0);
};