Skip to content

iporoskun/longman

Repository files navigation

C++ implementation of Longman tidal equation

ci codecov Language grade: C++ CodeQL

Getting started

How to use it

ip::longman is a header only library. You can simply take the file include\iporoskun\longman.hpp and include it into your project.

Usage example

For convenience, we declare namespace alias ip

namespace ip = iporoskun::longman;

First, we need to specify the geographical position of the point on earth for which the computation should be performed. The position is descripted by latitude (in degrees), longitude (in degrees), and the height above mean sea level (in meters).

As an example, we will use the location of Brandenburger Tor (Berlin): N 52.51628 E 13.377702 and 38 m height.

const auto position = ip::position {
    ip::latitude_t<>(52.51628),
    ip::longitude_t<>(13.377702),
    ip::height_t<>(38.)
};

To specify the position, the library provides the class template position as well as three class templates for the position components.

Second, we need a time point for which we want to perform the computation. The time point for the calculation must be given as UTC time. Here I will just use the current time on my machine:

const auto current_time = std::chrono::utc_clock::now();

The function template ip::longman takes the position and time point, and computes the tidal acceleration in meters per second squared. The results is returned as a floating point number:

const double delta_acceleration = ip::longman(position, current_time);

Details

The function template ip::longman has the following signature:

template<std::floating_point FloatingType, class DurationType, class TimePoint>
[[nodiscard]] inline auto ip::longman(const ip::position<FloatingType>& position, const TimePoint& utc_time)
	-> FloatingType

As the first argument, the used floating point type can be specified; any of float, double, and long double.

The time point (TimePoint) can be provided by (theoretically) any clock type; although it was only tested for std::chrono::system_clock and std::chrono::gps_clock.

No matter what clock is used, the time must always be in UTC format.

The duration (DurationType) can be anything from std::chrono::nanoseconds to std::chrono::minutes. (Usage of std::chrono::hours gave slightly different results, probably due to rounding of the minutes to whole hours.)

Benchmark

Benchmark results from running in release mode:

Run on (8 X 1500.44 MHz CPU s)
CPU Caches:
  L1 Data 48 KiB (x4)
  L1 Instruction 32 KiB (x4)
  L2 Unified 512 KiB (x4)
  L3 Unified 6144 KiB (x1)
--------------------------------------------------------
Benchmark              Time             CPU   Iterations
--------------------------------------------------------
longman_bench       1122 ns         1116 ns       560000

Useful references

Following sources can be referred for further details on Longman equations:

Used libraries