FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
parameters.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-only
2//
3// Copyright (c) 2006-2008 Marc Brooker and Michael Inggs
4// Copyright (c) 2008-present FERS Contributors (see AUTHORS.md).
5//
6// See the GNU GPLv2 LICENSE file in the FERS project root for more information.
7
8/**
9 * @file parameters.h
10 * @brief Defines the Parameters struct and provides methods for managing simulation parameters.
11 */
12
13#pragma once
14
15#include <chrono>
16#include <optional>
17#include <string>
18
19#include "config.h"
20#include "logging.h"
21
22namespace params
23{
24 /**
25 * @enum CoordinateFrame
26 * @brief Defines the coordinate systems supported for scenario definition.
27 */
28 enum class CoordinateFrame
29 {
30 ENU, ///< East-North-Up local tangent plane (default)
31 UTM, ///< Universal Transverse Mercator
32 ECEF ///< Earth-Centered, Earth-Fixed
33 };
34
35 /**
36 * @class Parameters
37 * @brief Struct to hold simulation parameters.
38 */
40 {
41 constexpr static RealType DEFAULT_C = 299792458.0; ///< Speed of light (m/s)
42 constexpr static RealType DEFAULT_BOLTZMANN_K = 1.3806503e-23; ///< Boltzmann constant
43 RealType c = DEFAULT_C; ///< Speed of light (modifiable)
44 RealType boltzmann_k = DEFAULT_BOLTZMANN_K; ///< Boltzmann constant
45 RealType start = 0; ///< Start time for the simulation.
46 RealType end = 0; ///< End time for the simulation.
48
49 ///< Temporal sampling rate (Hz) that determines time-step resolution for radar pulse simulation.
50 // Default to the location of the University of Cape Town in South Africa
51 double origin_latitude = -33.957652; ///< Geodetic origin latitude
52 double origin_longitude = 18.4611991; ///< Geodetic origin longitude
53 double origin_altitude = 111.01; ///< Geodetic origin altitude (in meters)
54 CoordinateFrame coordinate_frame = CoordinateFrame::ENU; ///< Scenario coordinate frame
55 int utm_zone = 0; ///< UTM zone (1-60), if applicable
56 bool utm_north_hemisphere = true; ///< UTM hemisphere, if applicable
57 RealType rate = 0; ///< Rendering sample rate.
58 std::optional<unsigned> random_seed; ///< Random seed for simulation.
59 unsigned adc_bits = 0; ///< ADC quantization bits.
60 unsigned filter_length = 33; ///< Default render filter length.
61 unsigned render_threads = 1; ///< Number of worker threads to use for parallel tasks.
62 std::string simulation_name; ///< The name of the simulation, from the XML.
63 unsigned oversample_ratio = 1; ///< Oversampling ratio.
64
65 /**
66 * @brief Resets the parameters to their default-constructed state.
67 * This ensures all members are restored to the values specified by their
68 * default member initializers.
69 */
70 void reset() noexcept { *this = Parameters{}; }
71 };
72
74
75 /**
76 * @brief Get the speed of light.
77 * @return The speed of light in meters per second.
78 */
79 inline RealType c() noexcept { return params.c; }
80
81 /**
82 * @brief Get the Boltzmann constant.
83 * @return The Boltzmann constant.
84 */
85 inline RealType boltzmannK() noexcept { return params.boltzmann_k; }
86
87 /**
88 * @brief Get the start time for the simulation.
89 * @return Start time for the simulation.
90 */
91 inline RealType startTime() noexcept { return params.start; }
92
93 /**
94 * @brief Get the end time for the simulation.
95 * @return End time for the simulation.
96 */
97 inline RealType endTime() noexcept { return params.end; }
98
99 /**
100 * @brief Get the simulation sampling rate.
101 * @return The simulation sampling rate.
102 */
103 inline RealType simSamplingRate() noexcept { return params.sim_sampling_rate; }
104
105 /**
106 * @brief Get the rendering sample rate.
107 * @return The rendering sample rate.
108 */
109 inline RealType rate() noexcept { return params.rate; }
110
111 /**
112 * @brief Get the random seed.
113 * @return The current random seed value.
114 */
115 inline unsigned randomSeed() noexcept { return params.random_seed.value_or(0); }
116
117 /**
118 * @brief Get the ADC quantization bits.
119 * @return Number of ADC quantization bits.
120 */
121 inline unsigned adcBits() noexcept { return params.adc_bits; }
122
123 /**
124 * @brief Get the render filter length.
125 * @return The length of the render filter.
126 */
127 inline unsigned renderFilterLength() noexcept { return params.filter_length; }
128
129 /**
130 * @brief Get the number of worker threads.
131 * @return The number of worker threads.
132 */
133 inline unsigned renderThreads() noexcept { return params.render_threads; }
134
135 /**
136 * @brief Get the oversampling ratio.
137 * @return The oversampling ratio.
138 */
139 inline unsigned oversampleRatio() noexcept { return params.oversample_ratio; }
140
141 /**
142 * @brief Set the speed of light.
143 * @param cValue The new speed of light.
144 */
145 inline void setC(RealType cValue) noexcept
146 {
147 params.c = cValue;
148 LOG(logging::Level::INFO, "Propagation speed (c) set to: {:.5f}", cValue);
149 }
150
151 /**
152 * @brief Set the start and end times for the simulation.
153 * @param startTime Start time for the simulation.
154 * @param endTime End time for the simulation.
155 */
156 inline void setTime(const RealType startTime, const RealType endTime) noexcept
157 {
158 params.start = startTime;
159 params.end = endTime;
160 LOG(logging::Level::INFO, "Simulation time set from {:.5f} to {:.5f} seconds", startTime, endTime);
161 }
162
163 /**
164 * @brief Set the simulation sampling rate.
165 * @param rate The new simulation sampling rate.
166 */
167 inline void setSimSamplingRate(const RealType rate) noexcept
168 {
169 params.sim_sampling_rate = rate;
170 LOG(logging::Level::DEBUG, "Simulation sampling rate set to: {:.5f} Hz", rate);
171 }
172
173 /**
174 * @brief Set the rendering sample rate.
175 * @param rateValue The new sample rate for rendering.
176 */
177 inline void setRate(RealType rateValue)
178 {
179 if (rateValue <= 0)
180 {
181 throw std::runtime_error("Sampling rate must be > 0");
182 }
183 params.rate = rateValue;
184 LOG(logging::Level::DEBUG, "Sample rate set to: {:.5f}", rateValue);
185 }
186
187 /**
188 * @brief Set the random seed.
189 * @param seed The new random seed value.
190 */
191 inline void setRandomSeed(const unsigned seed) noexcept
192 {
193 params.random_seed = seed;
194 LOG(logging::Level::DEBUG, "Random seed set to: {}", seed);
195 }
196
197 /**
198 * @brief Set the ADC quantization bits.
199 * @param bits The new ADC quantization bits.
200 */
201 inline void setAdcBits(const unsigned bits) noexcept
202 {
203 params.adc_bits = bits;
204 LOG(logging::Level::DEBUG, "ADC quantization bits set to: {}", bits);
205 }
206
207 /**
208 * @brief Set the oversampling ratio.
209 * @param ratio The new oversampling ratio.
210 * @throws std::runtime_error if the ratio is zero.
211 */
212 inline void setOversampleRatio(unsigned ratio)
213 {
214 if (ratio == 0)
215 {
216 throw std::runtime_error("Oversample ratio must be >= 1");
217 }
218 params.oversample_ratio = ratio;
219 LOG(logging::Level::DEBUG, "Oversampling enabled with ratio: {}", ratio);
220 }
221
222 /**
223 * @brief Set the geodetic origin for the KML generator.
224 * @param lat The latitude of the origin.
225 * @param lon The longitude of the origin.
226 * @param alt The altitude of the origin (MSL).
227 */
228 inline void setOrigin(const double lat, const double lon, const double alt) noexcept
229 {
230 params.origin_latitude = lat;
231 params.origin_longitude = lon;
232 params.origin_altitude = alt;
233 LOG(logging::Level::INFO, "Origin set to lat: {}, lon: {}, alt: {}", lat, lon, alt);
234 }
235
236 inline double originLatitude() noexcept { return params.origin_latitude; }
237
238 inline double originLongitude() noexcept { return params.origin_longitude; }
239
240 inline double originAltitude() noexcept { return params.origin_altitude; }
241
242 /**
243 * @brief Set the number of worker threads.
244 * @param threads The number of worker threads.
245 * @return A `std::expected<void, std::string>` indicating success or an error message if the number of threads is
246 * invalid.
247 */
248 inline std::expected<void, std::string> setThreads(const unsigned threads) noexcept
249 {
250 if (threads == 0)
251 {
252 return std::unexpected("Thread count must be >= 1");
253 }
254 params.render_threads = threads;
255 LOG(logging::Level::INFO, "Number of worker threads set to: {}", threads);
256 return {};
257 }
258
259 /**
260 * @brief Set the coordinate system for the scenario.
261 * @param frame The coordinate frame (ENU, UTM, ECEF).
262 * @param zone The UTM zone, if applicable.
263 * @param north The UTM hemisphere (true for North), if applicable.
264 */
265 inline void setCoordinateSystem(const CoordinateFrame frame, const int zone, const bool north) noexcept
266 {
267 params.coordinate_frame = frame;
268 params.utm_zone = zone;
269 params.utm_north_hemisphere = north;
270 }
271
272 inline CoordinateFrame coordinateFrame() noexcept { return params.coordinate_frame; }
273
274 inline int utmZone() noexcept { return params.utm_zone; }
275
276 inline bool utmNorthHemisphere() noexcept { return params.utm_north_hemisphere; }
277}
Global configuration file for the project.
double RealType
Type for real numbers.
Definition config.h:27
Header file for the logging system.
#define LOG(level,...)
Definition logging.h:19
@ INFO
Info level for informational messages.
@ DEBUG
Debug level for general debugging information.
unsigned renderThreads() noexcept
Get the number of worker threads.
Definition parameters.h:133
RealType simSamplingRate() noexcept
Get the simulation sampling rate.
Definition parameters.h:103
void setRandomSeed(const unsigned seed) noexcept
Set the random seed.
Definition parameters.h:191
RealType endTime() noexcept
Get the end time for the simulation.
Definition parameters.h:97
std::expected< void, std::string > setThreads(const unsigned threads) noexcept
Set the number of worker threads.
Definition parameters.h:248
RealType rate() noexcept
Get the rendering sample rate.
Definition parameters.h:109
unsigned randomSeed() noexcept
Get the random seed.
Definition parameters.h:115
RealType startTime() noexcept
Get the start time for the simulation.
Definition parameters.h:91
RealType boltzmannK() noexcept
Get the Boltzmann constant.
Definition parameters.h:85
void setTime(const RealType startTime, const RealType endTime) noexcept
Set the start and end times for the simulation.
Definition parameters.h:156
unsigned oversampleRatio() noexcept
Get the oversampling ratio.
Definition parameters.h:139
double originLongitude() noexcept
Definition parameters.h:238
int utmZone() noexcept
Definition parameters.h:274
CoordinateFrame
Defines the coordinate systems supported for scenario definition.
Definition parameters.h:29
@ UTM
Universal Transverse Mercator.
@ ENU
East-North-Up local tangent plane (default)
@ ECEF
Earth-Centered, Earth-Fixed.
void setRate(RealType rateValue)
Set the rendering sample rate.
Definition parameters.h:177
void setOrigin(const double lat, const double lon, const double alt) noexcept
Set the geodetic origin for the KML generator.
Definition parameters.h:228
void setOversampleRatio(unsigned ratio)
Set the oversampling ratio.
Definition parameters.h:212
unsigned renderFilterLength() noexcept
Get the render filter length.
Definition parameters.h:127
void setC(RealType cValue) noexcept
Set the speed of light.
Definition parameters.h:145
unsigned adcBits() noexcept
Get the ADC quantization bits.
Definition parameters.h:121
void setSimSamplingRate(const RealType rate) noexcept
Set the simulation sampling rate.
Definition parameters.h:167
void setAdcBits(const unsigned bits) noexcept
Set the ADC quantization bits.
Definition parameters.h:201
void setCoordinateSystem(const CoordinateFrame frame, const int zone, const bool north) noexcept
Set the coordinate system for the scenario.
Definition parameters.h:265
CoordinateFrame coordinateFrame() noexcept
Definition parameters.h:272
double originLatitude() noexcept
Definition parameters.h:236
bool utmNorthHemisphere() noexcept
Definition parameters.h:276
Parameters params
Definition parameters.h:73
RealType c() noexcept
Get the speed of light.
Definition parameters.h:79
double originAltitude() noexcept
Definition parameters.h:240
Struct to hold simulation parameters.
Definition parameters.h:40
static constexpr RealType DEFAULT_BOLTZMANN_K
Boltzmann constant.
Definition parameters.h:42
RealType rate
Rendering sample rate.
Definition parameters.h:57
double origin_longitude
Geodetic origin longitude.
Definition parameters.h:52
RealType start
Start time for the simulation.
Definition parameters.h:45
double origin_altitude
Geodetic origin altitude (in meters)
Definition parameters.h:53
unsigned render_threads
Number of worker threads to use for parallel tasks.
Definition parameters.h:61
CoordinateFrame coordinate_frame
Scenario coordinate frame.
Definition parameters.h:54
unsigned filter_length
Default render filter length.
Definition parameters.h:60
RealType end
End time for the simulation.
Definition parameters.h:46
int utm_zone
UTM zone (1-60), if applicable.
Definition parameters.h:55
unsigned oversample_ratio
Oversampling ratio.
Definition parameters.h:63
std::optional< unsigned > random_seed
Random seed for simulation.
Definition parameters.h:58
RealType sim_sampling_rate
Temporal sampling rate (Hz) that determines time-step resolution for radar pulse simulation.
Definition parameters.h:47
std::string simulation_name
The name of the simulation, from the XML.
Definition parameters.h:62
RealType boltzmann_k
Boltzmann constant.
Definition parameters.h:44
RealType c
Speed of light (modifiable)
Definition parameters.h:43
static constexpr RealType DEFAULT_C
Speed of light (m/s)
Definition parameters.h:41
unsigned adc_bits
ADC quantization bits.
Definition parameters.h:59
bool utm_north_hemisphere
UTM hemisphere, if applicable.
Definition parameters.h:56
double origin_latitude
Geodetic origin latitude.
Definition parameters.h:51
void reset() noexcept
Resets the parameters to their default-constructed state.
Definition parameters.h:70