| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // This file is part of INSTINCT, the INS Toolkit for Integrated | ||
| 2 | // Navigation Concepts and Training by the Institute of Navigation of | ||
| 3 | // the University of Stuttgart, Germany. | ||
| 4 | // | ||
| 5 | // This Source Code Form is subject to the terms of the Mozilla Public | ||
| 6 | // License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| 7 | // file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
| 8 | |||
| 9 | /// @file Temperature.hpp | ||
| 10 | /// @brief Temperature calculation formulas | ||
| 11 | /// @author T. Topp (topp@ins.uni-stuttgart.de) | ||
| 12 | /// @date 2023-01-31 | ||
| 13 | |||
| 14 | #pragma once | ||
| 15 | |||
| 16 | #include <cstdint> | ||
| 17 | #include <fmt/format.h> | ||
| 18 | #include <nlohmann/json.hpp> | ||
| 19 | using json = nlohmann::json; ///< json namespace | ||
| 20 | |||
| 21 | namespace NAV | ||
| 22 | { | ||
| 23 | |||
| 24 | /// Temperature Model parameters | ||
| 25 | class TemperatureModel | ||
| 26 | { | ||
| 27 | public: | ||
| 28 | /// Available temperature Models | ||
| 29 | enum Model : uint8_t | ||
| 30 | { | ||
| 31 | None, ///< No temperature model | ||
| 32 | Const, ///< Constant value | ||
| 33 | ISA, ///< ICAO Standard Atmosphere | ||
| 34 | GPT2, ///< GPT2 | ||
| 35 | GPT3, ///< GPT3 | ||
| 36 | COUNT, ///< Amount of items in the enum | ||
| 37 | }; | ||
| 38 | |||
| 39 | /// @brief Constructor | ||
| 40 | /// @param model Model to use | ||
| 41 | 1451 | TemperatureModel(Model model) : _model(model) {} // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) | |
| 42 | |||
| 43 | /// @brief Calculates the absolute temperature | ||
| 44 | /// @param[in] altitudeMSL Geodetic height above MSL (mean sea level) [m] | ||
| 45 | /// @return The absolute temperature in [K] | ||
| 46 | [[nodiscard]] double calcAbsoluteTemperature(double altitudeMSL) const; | ||
| 47 | |||
| 48 | /// @brief Shows a ComboBox to select the temperature model | ||
| 49 | /// @param[in] label Label to show beside the combo box. This has to be a unique id for ImGui. | ||
| 50 | /// @param[in] temperatureModel Reference to the temperature model to select | ||
| 51 | friend bool ComboTemperatureModel(const char* label, TemperatureModel& temperatureModel); | ||
| 52 | |||
| 53 | private: | ||
| 54 | /// Selected model | ||
| 55 | Model _model = Model::ISA; | ||
| 56 | |||
| 57 | /// Temperature for the constant temperature model [K] | ||
| 58 | double _constantTemperature = 290.0; | ||
| 59 | |||
| 60 | friend constexpr bool operator==(const TemperatureModel& lhs, const TemperatureModel& rhs); | ||
| 61 | friend constexpr bool operator==(const TemperatureModel& lhs, const TemperatureModel::Model& rhs); | ||
| 62 | friend constexpr bool operator==(const TemperatureModel::Model& lhs, const TemperatureModel& rhs); | ||
| 63 | friend bool ComboTemperatureModel(const char* label, TemperatureModel& temperatureModel); | ||
| 64 | friend const char* to_string(const TemperatureModel& temperatureModel); | ||
| 65 | friend void to_json(json& j, const TemperatureModel& obj); | ||
| 66 | friend void from_json(const json& j, TemperatureModel& obj); | ||
| 67 | }; | ||
| 68 | |||
| 69 | /// @brief Equal compares Pin::Kind values | ||
| 70 | /// @param[in] lhs Left-hand side of the operator | ||
| 71 | /// @param[in] rhs Right-hand side of the operator | ||
| 72 | /// @return Whether the comparison was successful | ||
| 73 | 421068 | constexpr bool operator==(const TemperatureModel& lhs, const TemperatureModel& rhs) | |
| 74 | { | ||
| 75 |
1/2✓ Branch 0 taken 421077 times.
✗ Branch 1 not taken.
|
421068 | if (lhs._model == rhs._model) |
| 76 | { | ||
| 77 |
2/2✓ Branch 0 taken 186687 times.
✓ Branch 1 taken 234390 times.
|
421077 | if (lhs._model == TemperatureModel::Const) { return lhs._constantTemperature == rhs._constantTemperature; } |
| 78 | 234390 | return true; | |
| 79 | } | ||
| 80 | ✗ | return false; | |
| 81 | } | ||
| 82 | |||
| 83 | /// @brief Equal compares Pin::Kind values | ||
| 84 | /// @param[in] lhs Left-hand side of the operator | ||
| 85 | /// @param[in] rhs Right-hand side of the operator | ||
| 86 | /// @return Whether the comparison was successful | ||
| 87 | 1403547 | constexpr bool operator==(const TemperatureModel& lhs, const TemperatureModel::Model& rhs) { return lhs._model == rhs; } | |
| 88 | /// @brief Equal compares Pin::Kind values | ||
| 89 | /// @param[in] lhs Left-hand side of the operator | ||
| 90 | /// @param[in] rhs Right-hand side of the operator | ||
| 91 | /// @return Whether the comparison was successful | ||
| 92 | constexpr bool operator==(const TemperatureModel::Model& lhs, const TemperatureModel& rhs) { return lhs == rhs._model; } | ||
| 93 | |||
| 94 | /// @brief Shows a ComboBox to select the temperature model | ||
| 95 | /// @param[in] label Label to show beside the combo box. This has to be a unique id for ImGui. | ||
| 96 | /// @param[in] temperatureModel Reference to the temperature model to select | ||
| 97 | bool ComboTemperatureModel(const char* label, TemperatureModel& temperatureModel); | ||
| 98 | |||
| 99 | /// @brief Converts the enum to a string | ||
| 100 | /// @param[in] temperatureModel Enum value to convert into text | ||
| 101 | /// @return String representation of the enum | ||
| 102 | const char* to_string(const TemperatureModel& temperatureModel); | ||
| 103 | /// @brief Converts the enum to a string | ||
| 104 | /// @param[in] temperatureModel Enum value to convert into text | ||
| 105 | /// @return String representation of the enum | ||
| 106 | const char* to_string(TemperatureModel::Model temperatureModel); | ||
| 107 | |||
| 108 | /// @brief Converts the provided object into json | ||
| 109 | /// @param[out] j Json object which gets filled with the info | ||
| 110 | /// @param[in] obj Object to convert into json | ||
| 111 | void to_json(json& j, const TemperatureModel& obj); | ||
| 112 | /// @brief Converts the provided json object into a node object | ||
| 113 | /// @param[in] j Json object with the needed values | ||
| 114 | /// @param[out] obj Object to fill from the json | ||
| 115 | void from_json(const json& j, TemperatureModel& obj); | ||
| 116 | |||
| 117 | } // namespace NAV | ||
| 118 | |||
| 119 | #ifndef DOXYGEN_IGNORE | ||
| 120 | |||
| 121 | /// @brief Formatter | ||
| 122 | template<> | ||
| 123 | struct fmt::formatter<NAV::TemperatureModel> : fmt::formatter<std::string> | ||
| 124 | { | ||
| 125 | /// @brief Defines how to format structs | ||
| 126 | /// @param[in] data Struct to format | ||
| 127 | /// @param[in, out] ctx Format context | ||
| 128 | /// @return Output iterator | ||
| 129 | template<typename FormatContext> | ||
| 130 | auto format(const NAV::TemperatureModel& data, FormatContext& ctx) const | ||
| 131 | { | ||
| 132 | return fmt::formatter<std::string>::format(NAV::to_string(data), ctx); | ||
| 133 | } | ||
| 134 | }; | ||
| 135 | |||
| 136 | #endif | ||
| 137 |