0.4.1
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
Temperature.hpp
Go to the documentation of this file.
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>
19using json = nlohmann::json; ///< json namespace
20
21namespace NAV
22{
23
24/// Temperature Model parameters
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 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
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
73constexpr bool operator==(const TemperatureModel& lhs, const TemperatureModel& rhs)
74{
75 if (lhs._model == rhs._model)
76 {
78 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
87constexpr 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
92constexpr 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
97bool 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
102const 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
106const 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
111void 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
115void from_json(const json& j, TemperatureModel& obj);
116
117} // namespace NAV
118
119#ifndef DOXYGEN_IGNORE
120
121/// @brief Formatter
122template<>
123struct 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
nlohmann::json json
json namespace
Temperature Model parameters.
double _constantTemperature
Temperature for the constant temperature model [K].
friend const char * to_string(const TemperatureModel &temperatureModel)
Converts the enum to a string.
friend bool ComboTemperatureModel(const char *label, TemperatureModel &temperatureModel)
Shows a ComboBox to select the temperature model.
TemperatureModel(Model model)
Constructor.
friend void from_json(const json &j, TemperatureModel &obj)
Converts the provided json object into a node object.
friend void to_json(json &j, const TemperatureModel &obj)
Converts the provided object into json.
double calcAbsoluteTemperature(double altitudeMSL) const
Calculates the absolute temperature.
Model
Available temperature Models.
@ None
No temperature model.
@ ISA
ICAO Standard Atmosphere.
@ Const
Constant value.
@ COUNT
Amount of items in the enum.
friend constexpr bool operator==(const TemperatureModel &lhs, const TemperatureModel &rhs)
Equal compares Pin::Kind values.
Model _model
Selected model.
void to_json(json &j, const Node &node)
Converts the provided node into a json object.
Definition Node.cpp:990
const char * to_string(gui::widgets::PositionWithFrame::ReferenceFrame refFrame)
Converts the enum to a string.
void from_json(const json &j, Node &node)
Converts the provided json object into a node object.
Definition Node.cpp:1007
bool ComboTemperatureModel(const char *label, TemperatureModel &temperatureModel)
Shows a ComboBox to select the temperature model.
constexpr bool operator==(const Node::Kind &lhs, const Node::Kind &rhs)
Equal compares Node::Kind values.
Definition Node.hpp:501