Commit 8ea386e6 authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Merge branch 'master' into python-bindings

parents 848b5204 c18c4b8b
Pipeline #35949 failed with stages
in 8 minutes and 17 seconds
......@@ -21,10 +21,14 @@
* Available MACROs:
* radix(arg) - std::cerr << arg - Pushes content to stderr
* radix_line(arg) - std::cerr << arg << std::endl - Push newline terminated
* content to stderr radix(arg) - std::cerr << arg - Pushes content to stderr
* content to stderr
* radix_eol() - std::cerr << std::endl - Push newline to stderr
* radix(arg) - std::cerr << arg - Pushes content to stderr
* radix_warning(arg) - std::cerr << arg << std::endl - Push newline terminated
* content to stderr radix_tagged_line(arg) - Same as radixLine, prefixed with
* FILE and LINE radix_tagged(arg) - Same as radix, prefixed with FILE and LINE
* content to stderr
* radix_tagged_line(arg) - Same as radixLine, prefixed with
* FILE and LINE
* radix_tagged(arg) - Same as radix, prefixed with FILE and LINE
* radix_tagged_warning(arg) - Same as radixWarning, prefixed with FILE and Line
* radix_block(block) - block - Simply places code block in preprocessor
*/
......@@ -36,6 +40,7 @@
#endif
#define radix_define_stream
#define radix_line(arg) radix_stream << arg << std::endl
#define radix_eol() radix_stream << std::endl
#define radix_flush_line(arg) \
radix_stream << arg << std::endl; \
fflush(stderr)
......@@ -63,6 +68,7 @@
#else
#define radix(arg)
#define radix_line(arg)
#define radix_eol()
#define radix_flush_line(arg)
#define radix_warning(arg)
#define radix_flush_warning(arg)
......
......@@ -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
......@@ -797,4 +807,4 @@ TEST(radix, relativeHumidityDewPoint)
dewPointToRelativeHumidity(testDewPoints[i], testTemperatures[i]),
toleranceRH);
}
}
\ No newline at end of file
}
/*
* 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
......
Supports Markdown
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