Commit c18c4b8b authored by Lefebvre, Jordan P's avatar Lefebvre, Jordan P

Merge branch 'geopotential-height' into 'master'

Adding geopotentialHeight and gravity equation to radixmath.

See merge request !64
parents 2acc8df9 890656e1
Pipeline #29218 failed with stages
in 15 minutes and 29 seconds
......@@ -4,7 +4,13 @@
#include "radixmath/util.hh"
using namespace radix;
TEST(radix, gravity)
{
EXPECT_FLOAT_EQ(9.8216047f, radix::gravity(float(-5000)));
EXPECT_FLOAT_EQ(9.80616f, radix::gravity(float(0)));
EXPECT_FLOAT_EQ(9.5475969f, radix::gravity(float(85500)));
EXPECT_FLOAT_EQ(7.3214531f, radix::gravity(float(1000000)));
}
TEST(radix, hpaToAltitude)
{
std::vector<double> alt;
......@@ -53,7 +59,7 @@ TEST(radix, hpaToAltitude)
-53.2, -53.6, -51, -50.9, -46, -47.2, -44.1, -41.5, -42.1, -42.7,
-40.5, -41, -41, -41.5, -38.5};
double true_altitude = 0;
double hypo_altitude = 0;
for (size_t i = 0; i < alt.size(); ++i)
{
double blessed_altitude = alt[i];
......@@ -65,13 +71,17 @@ TEST(radix, hpaToAltitude)
prev_pres = pres[i - 1];
}
// calculates thinkness in meters between prev_pres and pres[i]
true_altitude += hypsometric(prev_pres, pres[i], temperature);
hypo_altitude += hypsometric(prev_pres, pres[i], temperature);
double geo_altitude = radix::geopotentialHeight(alt[i]);
// we augment by assumed surface elevation (alt[0])
radix_tagged_line(std::setw(10) << (alt[0] + true_altitude)
<< " = hpaToAltitude(" << pres[i] << ", "
<< temperature << ", " << prev_pres << ")");
EXPECT_NEAR(blessed_altitude, (alt[0] + true_altitude), 80.2);
radix_tagged_line(std::setw(10)
<< blessed_altitude << ", " << (alt[0] + hypo_altitude)
<< "," << ((alt[0] + hypo_altitude) - blessed_altitude)
<< ", " << geo_altitude << ","
<< (geo_altitude - blessed_altitude) << ",");
EXPECT_NEAR(blessed_altitude, (alt[0] + hypo_altitude), 80.2);
EXPECT_NEAR(blessed_altitude, geo_altitude, 177);
}
// convert temperature to kelvin
......
/*
* File: Util.h
* Author: a16
*
* Created on January 17, 2013, 9:27 AM
*/
#ifndef RADIX_RADIXMATH_UTIL_H
......@@ -75,6 +72,30 @@ hypsometricProfile(const std::vector<type> &pressure,
return altitude;
}
/**
* @brief The gravitational-field strength near the surface of the earth as a
* function of altitude
* @param z geometric height in meters above sea-level
*/
template <typename type>
type gravity(type z)
{
return GRAVITATIONAL_ACCELERATION *
std::pow(type(1.) + z / wgs84_minor, type(-2));
}
template <typename type>
type geopotentialHeight(type z)
{
size_t zi = std::ceil(z);
type gravity_integral = type(0);
for (size_t i = 0; i < zi; ++i)
{
gravity_integral += gravity(type(i));
}
return gravity_integral / type(GRAVITATIONAL_ACCELERATION);
}
/**
* @brief absoluteTemperature Get the temperature of an air parcel given its
* potential temperature and pressure
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment