0.3.0
Loading...
Searching...
No Matches
Temperature.cpp
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#include "Temperature.hpp"
10
14#include "util/Logger.hpp"
15#include "util/Assert.h"
16
18
19namespace NAV
20{
21
22bool ComboTemperatureModel(const char* label, TemperatureModel& temperatureModel)
23{
24 bool changed = false;
25 changed |= gui::widgets::EnumCombo(label, temperatureModel._model);
26 if (temperatureModel._model == TemperatureModel::Model::Const)
27 {
28 ImGui::SameLine();
29 ImGui::SetNextItemWidth(62.0F * gui::NodeEditorApplication::windowFontRatio());
30 changed |= ImGui::InputDoubleL(fmt::format("##TemperatureModel constTemp {}", label).c_str(), &temperatureModel._constantTemperature,
31 0.0, std::numeric_limits<double>::max(), 0.0, 0.0, "%.1f K");
32 ImGui::SameLine();
33 ImGui::Text("%.1f°C", temperatureModel._constantTemperature - 273.15);
34 }
35 return changed;
36}
37
38double TemperatureModel::calcAbsoluteTemperature(double altitudeMSL) const
39{
40 switch (_model)
41 {
45 return calcAbsoluteTemperatureStAtm(altitudeMSL);
48 LOG_CRITICAL("GPT2/GPT3 Model needs to be called separately because of parameter lookup.");
49 break;
52 break;
53 }
54
55 return 0.0;
56}
57
58const char* to_string(const TemperatureModel& temperatureModel)
59{
60 return to_string(temperatureModel._model);
61}
62
63const char* to_string(TemperatureModel::Model temperatureModel)
64{
65 switch (temperatureModel)
66 {
68 return "None";
70 return "Const";
72 return "ISA";
74 return "GPT2";
76 return "GPT3";
78 break;
79 }
80 return "";
81}
82
83void to_json(json& j, const TemperatureModel& obj)
84{
85 j = json{
86 { "model", to_string(obj._model) },
87 { "constantTemperature", obj._constantTemperature },
88 };
89}
90
91void from_json(const json& j, TemperatureModel& obj)
92{
93 auto model = j.at("model").get<std::string>();
94 if (model == "None") { obj._model = TemperatureModel::Model::None; }
95 else if (model == "Const") { obj._model = TemperatureModel::Model::Const; }
96 else if (model == "ISA") { obj._model = TemperatureModel::Model::ISA; }
97 else if (model == "GPT2") { obj._model = TemperatureModel::Model::GPT2; }
98 else if (model == "GPT3") { obj._model = TemperatureModel::Model::GPT3; }
99
100 j.at("constantTemperature").get_to(obj._constantTemperature);
101}
102
103} // namespace NAV
Assertion helpers.
Combo representing an enumeration.
nlohmann::json json
json namespace
Utility class for logging to console and file.
#define LOG_CRITICAL(...)
Critical Event, which causes the program to work entirely and throws an exception.
Definition Logger.hpp:75
Standard Atmosphere temperature model.
Temperature calculation formulas.
double _constantTemperature
Temperature for the constant temperature model [K].
TemperatureModel(Model model)
Constructor.
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.
Model _model
Selected model.
static float windowFontRatio()
Ratio to multiply for GUI window elements.
ImGui extensions.
bool InputDoubleL(const char *label, double *v, double v_min, double v_max, double step, double step_fast, const char *format, ImGuiInputTextFlags flags)
Shows a value limited InputText GUI element for 'double'.
Definition imgui_ex.cpp:294
bool EnumCombo(const char *label, T &enumeration, size_t startIdx=0)
Combo representing an enumeration.
Definition EnumCombo.hpp:30
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
constexpr double calcAbsoluteTemperatureStAtm(double altitudeMSL)
Calculates the standard atmosphere absolute temperature.
bool ComboTemperatureModel(const char *label, TemperatureModel &temperatureModel)
Shows a ComboBox to select the temperature model.