FERS 0.1.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 <cstdint>
16#include <expected>
17#include <optional>
18#include <string>
19#include <string_view>
20
21#include "config.h"
22#include "logging.h"
23
24namespace params
25{
26 /**
27 * @enum CoordinateFrame
28 * @brief Defines the coordinate systems supported for KML/geospatial export.
29 */
30 enum class CoordinateFrame : std::uint8_t
31 {
32 ENU, ///< East-North-Up local tangent plane (default)
33 UTM, ///< Universal Transverse Mercator
34 ECEF ///< Earth-Centered, Earth-Fixed
35 };
36
37 /**
38 * @enum RotationAngleUnit
39 * @brief Defines the units used at external rotation-path boundaries.
40 */
41 enum class RotationAngleUnit : std::uint8_t
42 {
43 Degrees, ///< Compass azimuth and elevation expressed in degrees
44 Radians ///< Compass azimuth and elevation expressed in radians
45 };
46
47 /**
48 * @class Parameters
49 * @brief Struct to hold simulation parameters.
50 */
52 {
53 constexpr static RealType DEFAULT_C = 299792458.0; ///< Speed of light (m/s)
54 constexpr static RealType DEFAULT_BOLTZMANN_K = 1.3806503e-23; ///< Boltzmann constant
55 RealType c = DEFAULT_C; ///< Speed of light (modifiable)
56 RealType boltzmann_k = DEFAULT_BOLTZMANN_K; ///< Boltzmann constant
57 RealType start = 0; ///< Start time for the simulation.
58 RealType end = 0; ///< End time for the simulation.
59 RealType sim_sampling_rate = 1000; ///< Time-step sampling rate for radar pulse simulation.
60
61 // KML/geospatial export defaults to the location of the University of Cape Town in South Africa.
62 double origin_latitude = -33.957652; ///< KML ENU geodetic origin latitude
63 double origin_longitude = 18.4611991; ///< KML ENU geodetic origin longitude
64 double origin_altitude = 111.01; ///< KML ENU geodetic origin altitude (in meters)
65 CoordinateFrame coordinate_frame = CoordinateFrame::ENU; ///< KML/geospatial export coordinate frame
67 int utm_zone = 0; ///< KML UTM zone (1-60), if applicable
68 bool utm_north_hemisphere = true; ///< KML UTM hemisphere, if applicable
69 RealType rate = 0; ///< Rendering sample rate.
70 std::optional<unsigned> random_seed; ///< Random seed for simulation.
71 unsigned adc_bits = 0; ///< ADC quantization bits.
72 unsigned filter_length = 33; ///< Default render filter length.
73 unsigned render_threads = 1; ///< Number of worker threads to use for parallel tasks.
74 std::string simulation_name; ///< The name of the simulation, from the XML.
75 unsigned oversample_ratio = 1; ///< Oversampling ratio.
76
77 /**
78 * @brief Resets the parameters to their default-constructed state.
79 * This ensures all members are restored to the values specified by their
80 * default member initializers.
81 */
82 void reset() noexcept { *this = Parameters{}; }
83 };
84
85 inline Parameters params; ///< Global simulation parameter state.
86
87 /**
88 * @brief Get the speed of light.
89 * @return The speed of light in meters per second.
90 */
91 inline RealType c() noexcept { return params.c; }
92
93 /**
94 * @brief Get the Boltzmann constant.
95 * @return The Boltzmann constant.
96 */
97 inline RealType boltzmannK() noexcept { return params.boltzmann_k; }
98
99 /**
100 * @brief Get the start time for the simulation.
101 * @return Start time for the simulation.
102 */
103 inline RealType startTime() noexcept { return params.start; }
104
105 /**
106 * @brief Get the end time for the simulation.
107 * @return End time for the simulation.
108 */
109 inline RealType endTime() noexcept { return params.end; }
110
111 /**
112 * @brief Get the simulation sampling rate.
113 * @return The simulation sampling rate.
114 */
115 inline RealType simSamplingRate() noexcept { return params.sim_sampling_rate; }
116
117 /**
118 * @brief Get the rendering sample rate.
119 * @return The rendering sample rate.
120 */
121 inline RealType rate() noexcept { return params.rate; }
122
123 /**
124 * @brief Get the random seed.
125 * @return The current random seed value.
126 */
127 inline unsigned randomSeed() noexcept { return params.random_seed.value_or(0); }
128
129 /**
130 * @brief Get the ADC quantization bits.
131 * @return Number of ADC quantization bits.
132 */
133 inline unsigned adcBits() noexcept { return params.adc_bits; }
134
135 /**
136 * @brief Get the render filter length.
137 * @return The length of the render filter.
138 */
139 inline unsigned renderFilterLength() noexcept { return params.filter_length; }
140
141 /**
142 * @brief Get the number of worker threads.
143 * @return The number of worker threads.
144 */
145 inline unsigned renderThreads() noexcept { return params.render_threads; }
146
147 /**
148 * @brief Get the oversampling ratio.
149 * @return The oversampling ratio.
150 */
151 inline unsigned oversampleRatio() noexcept { return params.oversample_ratio; }
152
153 /**
154 * @brief Gets the maximum supported oversampling ratio.
155 * @return The maximum supported oversampling ratio.
156 */
157 inline constexpr unsigned maxSupportedOversampleRatio() noexcept { return 8u; }
158
159 /**
160 * @brief Validates that an oversampling ratio is supported.
161 * @param ratio The oversampling ratio to validate.
162 * @throws std::runtime_error if the ratio is outside the supported range.
163 */
164 inline void validateOversampleRatio(const unsigned ratio)
165 {
166 if (ratio == 0)
167 {
168 throw std::runtime_error("Oversample ratio must be >= 1");
169 }
170 if (ratio > maxSupportedOversampleRatio())
171 {
172 throw std::runtime_error("Oversampling ratios > 8 are not supported with the current fixed filter length "
173 "of 33. Signal attenuation will occur.");
174 }
175 }
176
177 /**
178 * @brief Set the speed of light.
179 * @param cValue The new speed of light.
180 */
181 inline void setC(RealType cValue) noexcept
182 {
183 params.c = cValue;
184 LOG(logging::Level::INFO, "Propagation speed (c) set to: {:.5f}", cValue);
185 }
186
187 /**
188 * @brief Set the start and end times for the simulation.
189 * @param startTime Start time for the simulation.
190 * @param endTime End time for the simulation.
191 */
192 inline void setTime(const RealType startTime, const RealType endTime) noexcept
193 {
194 params.start = startTime;
195 params.end = endTime;
196 LOG(logging::Level::INFO, "Simulation time set from {:.5f} to {:.5f} seconds", startTime, endTime);
197 }
198
199 /**
200 * @brief Set the simulation sampling rate.
201 * @param rate The new simulation sampling rate.
202 */
203 inline void setSimSamplingRate(const RealType rate) noexcept
204 {
205 params.sim_sampling_rate = rate;
206 LOG(logging::Level::DEBUG, "Simulation sampling rate set to: {:.5f} Hz", rate);
207 }
208
209 /**
210 * @brief Set the rendering sample rate.
211 * @param rateValue The new sample rate for rendering.
212 */
214 {
215 if (rateValue <= 0)
216 {
217 throw std::runtime_error("Sampling rate must be > 0");
218 }
219 params.rate = rateValue;
220 LOG(logging::Level::DEBUG, "Sample rate set to: {:.5f}", rateValue);
221 }
222
223 /**
224 * @brief Set the random seed.
225 * @param seed The new random seed value.
226 */
227 inline void setRandomSeed(const unsigned seed) noexcept
228 {
229 params.random_seed = seed;
230 LOG(logging::Level::DEBUG, "Random seed set to: {}", seed);
231 }
232
233 /**
234 * @brief Set the ADC quantization bits.
235 * @param bits The new ADC quantization bits.
236 */
237 inline void setAdcBits(const unsigned bits) noexcept
238 {
239 params.adc_bits = bits;
240 LOG(logging::Level::DEBUG, "ADC quantization bits set to: {}", bits);
241 }
242
243 /**
244 * @brief Set the oversampling ratio.
245 * @param ratio The new oversampling ratio.
246 * @throws std::runtime_error if the ratio is zero.
247 */
248 inline void setOversampleRatio(unsigned ratio)
249 {
251 params.oversample_ratio = ratio;
252 LOG(logging::Level::DEBUG, "Oversampling enabled with ratio: {}", ratio);
253 }
254
255 /**
256 * @brief Set the geodetic origin for ENU KML/geospatial export.
257 * @param lat The latitude of the KML origin.
258 * @param lon The longitude of the KML origin.
259 * @param alt The altitude of the KML origin (MSL).
260 */
261 inline void setOrigin(const double lat, const double lon, const double alt) noexcept
262 {
263 params.origin_latitude = lat;
264 params.origin_longitude = lon;
265 params.origin_altitude = alt;
266 LOG(logging::Level::INFO, "KML origin set to lat: {}, lon: {}, alt: {}", lat, lon, alt);
267 }
268
269 /**
270 * @brief Gets the KML/geospatial export origin latitude.
271 * @return The KML origin latitude in degrees.
272 */
273 inline double originLatitude() noexcept { return params.origin_latitude; }
274
275 /**
276 * @brief Gets the KML/geospatial export origin longitude.
277 * @return The KML origin longitude in degrees.
278 */
279 inline double originLongitude() noexcept { return params.origin_longitude; }
280
281 /**
282 * @brief Gets the KML/geospatial export origin altitude.
283 * @return The KML origin altitude in meters.
284 */
285 inline double originAltitude() noexcept { return params.origin_altitude; }
286
287 /**
288 * @brief Set the number of worker threads.
289 * @param threads The number of worker threads.
290 * @return A `std::expected<void, std::string>` indicating success or an error message if the number of threads is
291 * invalid.
292 */
293 inline std::expected<void, std::string> setThreads(const unsigned threads) noexcept
294 {
295 if (threads == 0)
296 {
297 return std::unexpected("Thread count must be >= 1");
298 }
299 params.render_threads = threads;
300 LOG(logging::Level::INFO, "Number of worker threads set to: {}", threads);
301 return {};
302 }
303
304 /**
305 * @brief Set the coordinate system for KML/geospatial export.
306 * @param frame The KML coordinate frame (ENU, UTM, ECEF).
307 * @param zone The KML UTM zone, if applicable.
308 * @param north The KML UTM hemisphere (true for North), if applicable.
309 */
310 inline void setCoordinateSystem(const CoordinateFrame frame, const int zone, const bool north) noexcept
311 {
312 params.coordinate_frame = frame;
313 params.utm_zone = zone;
314 params.utm_north_hemisphere = north;
315 }
316
317 /**
318 * @brief Gets the KML/geospatial export coordinate frame.
319 * @return The KML/geospatial export coordinate frame.
320 */
321 inline CoordinateFrame coordinateFrame() noexcept { return params.coordinate_frame; }
322
323 /**
324 * @brief Gets the external rotation angle unit.
325 * @return The active rotation angle unit.
326 */
327 inline RotationAngleUnit rotationAngleUnit() noexcept { return params.rotation_angle_unit; }
328
329 /**
330 * @brief Gets the configured KML UTM zone.
331 * @return The KML UTM zone, or zero when UTM KML export is not configured.
332 */
333 inline int utmZone() noexcept { return params.utm_zone; }
334
335 /**
336 * @brief Gets the configured KML UTM hemisphere.
337 * @return true for northern hemisphere, false for southern hemisphere.
338 */
339 inline bool utmNorthHemisphere() noexcept { return params.utm_north_hemisphere; }
340
341 /**
342 * @brief Sets the external rotation angle unit.
343 * @param unit The rotation angle unit to store.
344 */
345 inline void setRotationAngleUnit(const RotationAngleUnit unit) noexcept { params.rotation_angle_unit = unit; }
346
347 /**
348 * @brief Converts a rotation angle unit to its XML token.
349 * @param unit The rotation angle unit.
350 * @return The corresponding token string.
351 */
352 inline constexpr std::string_view rotationAngleUnitToken(const RotationAngleUnit unit) noexcept
353 {
354 return unit == RotationAngleUnit::Radians ? "rad" : "deg";
355 }
356
357 /**
358 * @brief Parses a rotation angle unit from an XML token.
359 * @param token The token to parse.
360 * @return The parsed unit, or std::nullopt if the token is unknown.
361 */
362 inline std::optional<RotationAngleUnit> rotationAngleUnitFromToken(const std::string_view token) noexcept
363 {
364 if (token == "deg")
365 {
367 }
368 if (token == "rad")
369 {
371 }
372 return std::nullopt;
373 }
374}
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:145
RealType simSamplingRate() noexcept
Get the simulation sampling rate.
Definition parameters.h:115
void setRandomSeed(const unsigned seed) noexcept
Set the random seed.
Definition parameters.h:227
RealType endTime() noexcept
Get the end time for the simulation.
Definition parameters.h:109
std::expected< void, std::string > setThreads(const unsigned threads) noexcept
Set the number of worker threads.
Definition parameters.h:293
RealType rate() noexcept
Get the rendering sample rate.
Definition parameters.h:121
unsigned randomSeed() noexcept
Get the random seed.
Definition parameters.h:127
RealType startTime() noexcept
Get the start time for the simulation.
Definition parameters.h:103
RealType boltzmannK() noexcept
Get the Boltzmann constant.
Definition parameters.h:97
void setTime(const RealType startTime, const RealType endTime) noexcept
Set the start and end times for the simulation.
Definition parameters.h:192
unsigned oversampleRatio() noexcept
Get the oversampling ratio.
Definition parameters.h:151
void setRotationAngleUnit(const RotationAngleUnit unit) noexcept
Sets the external rotation angle unit.
Definition parameters.h:345
double originLongitude() noexcept
Gets the KML/geospatial export origin longitude.
Definition parameters.h:279
int utmZone() noexcept
Gets the configured KML UTM zone.
Definition parameters.h:333
void setRate(RealType rateValue)
Set the rendering sample rate.
Definition parameters.h:213
CoordinateFrame
Defines the coordinate systems supported for KML/geospatial export.
Definition parameters.h:31
@ UTM
Universal Transverse Mercator.
@ ENU
East-North-Up local tangent plane (default)
@ ECEF
Earth-Centered, Earth-Fixed.
void setOrigin(const double lat, const double lon, const double alt) noexcept
Set the geodetic origin for ENU KML/geospatial export.
Definition parameters.h:261
void setOversampleRatio(unsigned ratio)
Set the oversampling ratio.
Definition parameters.h:248
unsigned renderFilterLength() noexcept
Get the render filter length.
Definition parameters.h:139
void setC(RealType cValue) noexcept
Set the speed of light.
Definition parameters.h:181
unsigned adcBits() noexcept
Get the ADC quantization bits.
Definition parameters.h:133
void setSimSamplingRate(const RealType rate) noexcept
Set the simulation sampling rate.
Definition parameters.h:203
RotationAngleUnit rotationAngleUnit() noexcept
Gets the external rotation angle unit.
Definition parameters.h:327
void setAdcBits(const unsigned bits) noexcept
Set the ADC quantization bits.
Definition parameters.h:237
constexpr unsigned maxSupportedOversampleRatio() noexcept
Gets the maximum supported oversampling ratio.
Definition parameters.h:157
void setCoordinateSystem(const CoordinateFrame frame, const int zone, const bool north) noexcept
Set the coordinate system for KML/geospatial export.
Definition parameters.h:310
std::optional< RotationAngleUnit > rotationAngleUnitFromToken(const std::string_view token) noexcept
Parses a rotation angle unit from an XML token.
Definition parameters.h:362
void validateOversampleRatio(const unsigned ratio)
Validates that an oversampling ratio is supported.
Definition parameters.h:164
CoordinateFrame coordinateFrame() noexcept
Gets the KML/geospatial export coordinate frame.
Definition parameters.h:321
RotationAngleUnit
Defines the units used at external rotation-path boundaries.
Definition parameters.h:42
@ Radians
Compass azimuth and elevation expressed in radians.
@ Degrees
Compass azimuth and elevation expressed in degrees.
double originLatitude() noexcept
Gets the KML/geospatial export origin latitude.
Definition parameters.h:273
bool utmNorthHemisphere() noexcept
Gets the configured KML UTM hemisphere.
Definition parameters.h:339
Parameters params
Global simulation parameter state.
Definition parameters.h:85
RealType c() noexcept
Get the speed of light.
Definition parameters.h:91
constexpr std::string_view rotationAngleUnitToken(const RotationAngleUnit unit) noexcept
Converts a rotation angle unit to its XML token.
Definition parameters.h:352
double originAltitude() noexcept
Gets the KML/geospatial export origin altitude.
Definition parameters.h:285
math::Vec3 max
Struct to hold simulation parameters.
Definition parameters.h:52
static constexpr RealType DEFAULT_BOLTZMANN_K
Boltzmann constant.
Definition parameters.h:54
RealType rate
Rendering sample rate.
Definition parameters.h:69
double origin_longitude
KML ENU geodetic origin longitude.
Definition parameters.h:63
RealType start
Start time for the simulation.
Definition parameters.h:57
double origin_altitude
KML ENU geodetic origin altitude (in meters)
Definition parameters.h:64
unsigned render_threads
Number of worker threads to use for parallel tasks.
Definition parameters.h:73
CoordinateFrame coordinate_frame
KML/geospatial export coordinate frame.
Definition parameters.h:65
unsigned filter_length
Default render filter length.
Definition parameters.h:72
RealType end
End time for the simulation.
Definition parameters.h:58
int utm_zone
KML UTM zone (1-60), if applicable.
Definition parameters.h:67
unsigned oversample_ratio
Oversampling ratio.
Definition parameters.h:75
std::optional< unsigned > random_seed
Random seed for simulation.
Definition parameters.h:70
RealType sim_sampling_rate
Time-step sampling rate for radar pulse simulation.
Definition parameters.h:59
std::string simulation_name
The name of the simulation, from the XML.
Definition parameters.h:74
RotationAngleUnit rotation_angle_unit
External rotation angle unit.
Definition parameters.h:66
RealType boltzmann_k
Boltzmann constant.
Definition parameters.h:56
RealType c
Speed of light (modifiable)
Definition parameters.h:55
static constexpr RealType DEFAULT_C
Speed of light (m/s)
Definition parameters.h:53
unsigned adc_bits
ADC quantization bits.
Definition parameters.h:71
bool utm_north_hemisphere
KML UTM hemisphere, if applicable.
Definition parameters.h:68
double origin_latitude
KML ENU geodetic origin latitude.
Definition parameters.h:62
void reset() noexcept
Resets the parameters to their default-constructed state.
Definition parameters.h:82