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 <expected>
16#include <optional>
17#include <string>
18#include <string_view>
19
20#include "config.h"
21#include "logging.h"
22
23namespace params
24{
25 /**
26 * @enum CoordinateFrame
27 * @brief Defines the coordinate systems supported for scenario definition.
28 */
29 enum class CoordinateFrame
30 {
31 ENU, ///< East-North-Up local tangent plane (default)
32 UTM, ///< Universal Transverse Mercator
33 ECEF ///< Earth-Centered, Earth-Fixed
34 };
35
36 /**
37 * @enum RotationAngleUnit
38 * @brief Defines the units used at external rotation-path boundaries.
39 */
41 {
42 Degrees, ///< Compass azimuth and elevation expressed in degrees
43 Radians ///< Compass azimuth and elevation expressed in radians
44 };
45
46 /**
47 * @class Parameters
48 * @brief Struct to hold simulation parameters.
49 */
51 {
52 constexpr static RealType DEFAULT_C = 299792458.0; ///< Speed of light (m/s)
53 constexpr static RealType DEFAULT_BOLTZMANN_K = 1.3806503e-23; ///< Boltzmann constant
54 RealType c = DEFAULT_C; ///< Speed of light (modifiable)
55 RealType boltzmann_k = DEFAULT_BOLTZMANN_K; ///< Boltzmann constant
56 RealType start = 0; ///< Start time for the simulation.
57 RealType end = 0; ///< End time for the simulation.
59
60 ///< Temporal sampling rate (Hz) that determines time-step resolution for radar pulse simulation.
61 // Default to the location of the University of Cape Town in South Africa
62 double origin_latitude = -33.957652; ///< Geodetic origin latitude
63 double origin_longitude = 18.4611991; ///< Geodetic origin longitude
64 double origin_altitude = 111.01; ///< Geodetic origin altitude (in meters)
65 CoordinateFrame coordinate_frame = CoordinateFrame::ENU; ///< Scenario coordinate frame
67 int utm_zone = 0; ///< UTM zone (1-60), if applicable
68 bool utm_north_hemisphere = true; ///< 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
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 Set the speed of light.
155 * @param cValue The new speed of light.
156 */
157 inline void setC(RealType cValue) noexcept
158 {
159 params.c = cValue;
160 LOG(logging::Level::INFO, "Propagation speed (c) set to: {:.5f}", cValue);
161 }
162
163 /**
164 * @brief Set the start and end times for the simulation.
165 * @param startTime Start time for the simulation.
166 * @param endTime End time for the simulation.
167 */
168 inline void setTime(const RealType startTime, const RealType endTime) noexcept
169 {
170 params.start = startTime;
171 params.end = endTime;
172 LOG(logging::Level::INFO, "Simulation time set from {:.5f} to {:.5f} seconds", startTime, endTime);
173 }
174
175 /**
176 * @brief Set the simulation sampling rate.
177 * @param rate The new simulation sampling rate.
178 */
179 inline void setSimSamplingRate(const RealType rate) noexcept
180 {
181 params.sim_sampling_rate = rate;
182 LOG(logging::Level::DEBUG, "Simulation sampling rate set to: {:.5f} Hz", rate);
183 }
184
185 /**
186 * @brief Set the rendering sample rate.
187 * @param rateValue The new sample rate for rendering.
188 */
189 inline void setRate(RealType rateValue)
190 {
191 if (rateValue <= 0)
192 {
193 throw std::runtime_error("Sampling rate must be > 0");
194 }
195 params.rate = rateValue;
196 LOG(logging::Level::DEBUG, "Sample rate set to: {:.5f}", rateValue);
197 }
198
199 /**
200 * @brief Set the random seed.
201 * @param seed The new random seed value.
202 */
203 inline void setRandomSeed(const unsigned seed) noexcept
204 {
205 params.random_seed = seed;
206 LOG(logging::Level::DEBUG, "Random seed set to: {}", seed);
207 }
208
209 /**
210 * @brief Set the ADC quantization bits.
211 * @param bits The new ADC quantization bits.
212 */
213 inline void setAdcBits(const unsigned bits) noexcept
214 {
215 params.adc_bits = bits;
216 LOG(logging::Level::DEBUG, "ADC quantization bits set to: {}", bits);
217 }
218
219 /**
220 * @brief Set the oversampling ratio.
221 * @param ratio The new oversampling ratio.
222 * @throws std::runtime_error if the ratio is zero.
223 */
224 inline void setOversampleRatio(unsigned ratio)
225 {
226 if (ratio == 0)
227 {
228 throw std::runtime_error("Oversample ratio must be >= 1");
229 }
230 params.oversample_ratio = ratio;
231 LOG(logging::Level::DEBUG, "Oversampling enabled with ratio: {}", ratio);
232 }
233
234 /**
235 * @brief Set the geodetic origin for the KML generator.
236 * @param lat The latitude of the origin.
237 * @param lon The longitude of the origin.
238 * @param alt The altitude of the origin (MSL).
239 */
240 inline void setOrigin(const double lat, const double lon, const double alt) noexcept
241 {
242 params.origin_latitude = lat;
243 params.origin_longitude = lon;
244 params.origin_altitude = alt;
245 LOG(logging::Level::INFO, "Origin set to lat: {}, lon: {}, alt: {}", lat, lon, alt);
246 }
247
248 inline double originLatitude() noexcept { return params.origin_latitude; }
249
250 inline double originLongitude() noexcept { return params.origin_longitude; }
251
252 inline double originAltitude() noexcept { return params.origin_altitude; }
253
254 /**
255 * @brief Set the number of worker threads.
256 * @param threads The number of worker threads.
257 * @return A `std::expected<void, std::string>` indicating success or an error message if the number of threads is
258 * invalid.
259 */
260 inline std::expected<void, std::string> setThreads(const unsigned threads) noexcept
261 {
262 if (threads == 0)
263 {
264 return std::unexpected("Thread count must be >= 1");
265 }
266 params.render_threads = threads;
267 LOG(logging::Level::INFO, "Number of worker threads set to: {}", threads);
268 return {};
269 }
270
271 /**
272 * @brief Set the coordinate system for the scenario.
273 * @param frame The coordinate frame (ENU, UTM, ECEF).
274 * @param zone The UTM zone, if applicable.
275 * @param north The UTM hemisphere (true for North), if applicable.
276 */
277 inline void setCoordinateSystem(const CoordinateFrame frame, const int zone, const bool north) noexcept
278 {
279 params.coordinate_frame = frame;
280 params.utm_zone = zone;
281 params.utm_north_hemisphere = north;
282 }
283
284 inline CoordinateFrame coordinateFrame() noexcept { return params.coordinate_frame; }
285
286 inline RotationAngleUnit rotationAngleUnit() noexcept { return params.rotation_angle_unit; }
287
288 inline int utmZone() noexcept { return params.utm_zone; }
289
290 inline bool utmNorthHemisphere() noexcept { return params.utm_north_hemisphere; }
291
292 inline void setRotationAngleUnit(const RotationAngleUnit unit) noexcept { params.rotation_angle_unit = unit; }
293
294 inline constexpr std::string_view rotationAngleUnitToken(const RotationAngleUnit unit) noexcept
295 {
296 return unit == RotationAngleUnit::Radians ? "rad" : "deg";
297 }
298
299 inline std::optional<RotationAngleUnit> rotationAngleUnitFromToken(const std::string_view token) noexcept
300 {
301 if (token == "deg")
302 {
304 }
305 if (token == "rad")
306 {
308 }
309 return std::nullopt;
310 }
311}
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:203
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:260
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:168
unsigned oversampleRatio() noexcept
Get the oversampling ratio.
Definition parameters.h:151
void setRotationAngleUnit(const RotationAngleUnit unit) noexcept
Definition parameters.h:292
RotationAngleUnit
Defines the units used at external rotation-path boundaries.
Definition parameters.h:41
@ Radians
Compass azimuth and elevation expressed in radians.
@ Degrees
Compass azimuth and elevation expressed in degrees.
double originLongitude() noexcept
Definition parameters.h:250
int utmZone() noexcept
Definition parameters.h:288
CoordinateFrame
Defines the coordinate systems supported for scenario definition.
Definition parameters.h:30
@ 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:189
void setOrigin(const double lat, const double lon, const double alt) noexcept
Set the geodetic origin for the KML generator.
Definition parameters.h:240
void setOversampleRatio(unsigned ratio)
Set the oversampling ratio.
Definition parameters.h:224
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:157
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:179
RotationAngleUnit rotationAngleUnit() noexcept
Definition parameters.h:286
void setAdcBits(const unsigned bits) noexcept
Set the ADC quantization bits.
Definition parameters.h:213
void setCoordinateSystem(const CoordinateFrame frame, const int zone, const bool north) noexcept
Set the coordinate system for the scenario.
Definition parameters.h:277
std::optional< RotationAngleUnit > rotationAngleUnitFromToken(const std::string_view token) noexcept
Definition parameters.h:299
CoordinateFrame coordinateFrame() noexcept
Definition parameters.h:284
double originLatitude() noexcept
Definition parameters.h:248
bool utmNorthHemisphere() noexcept
Definition parameters.h:290
Parameters params
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
Definition parameters.h:294
double originAltitude() noexcept
Definition parameters.h:252
Struct to hold simulation parameters.
Definition parameters.h:51
static constexpr RealType DEFAULT_BOLTZMANN_K
Boltzmann constant.
Definition parameters.h:53
RealType rate
Rendering sample rate.
Definition parameters.h:69
double origin_longitude
Geodetic origin longitude.
Definition parameters.h:63
RealType start
Start time for the simulation.
Definition parameters.h:56
double origin_altitude
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
Scenario 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:57
int utm_zone
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
Temporal sampling rate (Hz) that determines time-step resolution for radar pulse simulation.
Definition parameters.h:58
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:55
RealType c
Speed of light (modifiable)
Definition parameters.h:54
static constexpr RealType DEFAULT_C
Speed of light (m/s)
Definition parameters.h:52
unsigned adc_bits
ADC quantization bits.
Definition parameters.h:71
bool utm_north_hemisphere
UTM hemisphere, if applicable.
Definition parameters.h:68
double origin_latitude
Geodetic origin latitude.
Definition parameters.h:62
void reset() noexcept
Resets the parameters to their default-constructed state.
Definition parameters.h:82