FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
antenna_factory.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 antenna_factory.h
10 * @brief Header file defining various types of antennas and their gain patterns.
11 */
12
13#pragma once
14
15#include <memory>
16#include <string>
17#include <string_view>
18#include <utility>
19#include <vector>
20
21#include "core/config.h"
22#include "core/logging.h"
24#include "math/geometry_ops.h"
25
26namespace serial
27{
28 std::vector<std::vector<RealType>> readPattern(const std::string& name, const std::string& datasetName);
29}
30
31namespace antenna
32{
33 /**
34 * @class Antenna
35 * @brief Abstract base class representing an antenna.
36 */
37 class Antenna
38 {
39 public:
40 /**
41 * @brief Constructs an Antenna object with the given name.
42 *
43 * @param name The name of the antenna.
44 */
45 explicit Antenna(std::string name) noexcept : _loss_factor(1), _name(std::move(name)) {}
46
47 virtual ~Antenna() = default;
48
49 Antenna(const Antenna&) = delete;
50
51 Antenna& operator=(const Antenna&) = delete;
52
53 Antenna(Antenna&&) = default;
54
55 Antenna& operator=(Antenna&&) = default;
56
57 /**
58 * @brief Computes the gain of the antenna based on the input angle and reference angle.
59 *
60 * @param angle The angle at which the gain is to be computed.
61 * @param refangle The reference angle.
62 * @param wavelength The wavelength of the signal.
63 * @return The gain of the antenna at the specified angle and wavelength.
64 */
65 [[nodiscard]] virtual RealType getGain(const math::SVec3& angle, const math::SVec3& refangle,
66 RealType wavelength) const = 0;
67
68 /**
69 * @brief Retrieves the efficiency factor of the antenna.
70 *
71 * @return The efficiency factor of the antenna.
72 */
73 [[nodiscard]] RealType getEfficiencyFactor() const noexcept { return _loss_factor; }
74
75 /**
76 * @brief Retrieves the name of the antenna.
77 *
78 * @return The name of the antenna.
79 */
80 [[nodiscard]] std::string getName() const noexcept { return _name; }
81
82 /**
83 * @brief Computes the noise temperature of the antenna based on the angle.
84 *
85 * @param angle The angle at which the noise temperature is to be computed.
86 * @return The noise temperature of the antenna.
87 */
88 // TODO: Implement noise temperature calculation
89 [[nodiscard]] virtual RealType getNoiseTemperature(const math::SVec3& /*angle*/) const noexcept { return 0; }
90
91 /**
92 * @brief Sets the efficiency factor of the antenna.
93 *
94 * @param loss The new efficiency factor.
95 */
96 void setEfficiencyFactor(RealType loss) noexcept;
97
98 protected:
99 /**
100 * @brief Computes the angle between the input and reference angles.
101 *
102 * @param angle The input angle.
103 * @param refangle The reference angle.
104 * @return The computed angle.
105 */
106 static RealType getAngle(const math::SVec3& angle, const math::SVec3& refangle) noexcept;
107
108 private:
109 RealType _loss_factor; ///< Efficiency factor of the antenna.
110 std::string _name; ///< Name of the antenna.
111 };
112
113 /**
114 * @class Isotropic
115 * @brief Represents an isotropic antenna with uniform gain in all directions.
116 *
117 * This class models an ideal isotropic antenna, which has a directivity of 1 (0 dB).
118 */
119 class Isotropic final : public Antenna
120 {
121 public:
122 /**
123 * @brief Constructs an Isotropic antenna with the given name.
124 *
125 * @param name The name of the antenna.
126 */
127 explicit Isotropic(const std::string_view name) : Antenna(name.data()) {}
128
129 ~Isotropic() override = default;
130
131 Isotropic(const Isotropic&) = delete;
132
133 Isotropic& operator=(const Isotropic&) = delete;
134
135 Isotropic(Isotropic&&) = delete;
136
138
139 /**
140 * @brief Computes the gain of the isotropic antenna.
141 *
142 * @return The gain of the antenna, which is equal to the efficiency factor.
143 */
144 [[nodiscard]] RealType getGain(const math::SVec3& /*angle*/, const math::SVec3& /*refangle*/,
145 RealType /*wavelength*/) const override
146 {
147 // David Young: Isotropic antennas have a directivity of 1 (or 0 dB),
148 // therefore, the gain of the antenna is the efficiency factor
149 return getEfficiencyFactor();
150 }
151 };
152
153 /**
154 * @class Sinc
155 * @brief Represents a sinc function-based antenna gain pattern.
156 *
157 * This antenna has a gain pattern defined by a sinc function, with customizable parameters.
158 */
159 class Sinc final : public Antenna
160 {
161 public:
162 /**
163 * @brief Constructs a Sinc antenna with the given parameters.
164 *
165 * @param name The name of the antenna.
166 * @param alpha The alpha parameter.
167 * @param beta The beta parameter.
168 * @param gamma The gamma parameter.
169 */
170 Sinc(const std::string_view name, const RealType alpha, const RealType beta, const RealType gamma) :
171 Antenna(name.data()), _alpha(alpha), _beta(beta), _gamma(gamma)
172 {
173 }
174
175 ~Sinc() override = default;
176
177 Sinc(const Sinc&) = delete;
178
179 Sinc& operator=(const Sinc&) = delete;
180
181 Sinc(Sinc&&) = delete;
182
183 Sinc& operator=(Sinc&&) = delete;
184
185 /** @brief Gets the alpha parameter of the sinc function. */
186 [[nodiscard]] RealType getAlpha() const noexcept { return _alpha; }
187
188 /** @brief Gets the beta parameter of the sinc function. */
189 [[nodiscard]] RealType getBeta() const noexcept { return _beta; }
190
191 /** @brief Gets the gamma parameter of the sinc function. */
192 [[nodiscard]] RealType getGamma() const noexcept { return _gamma; }
193
194 /**
195 * @brief Computes the gain of the sinc antenna based on the input parameters.
196 *
197 * @param angle The angle at which the gain is to be computed.
198 * @param refangle The reference angle.
199 * @param wavelength The wavelength of the signal.
200 * @return The computed gain of the antenna.
201 */
202 [[nodiscard]] RealType getGain(const math::SVec3& angle, const math::SVec3& refangle,
203 RealType wavelength) const noexcept override;
204
205 private:
206 RealType _alpha; ///< Parameter defining the shape of the gain pattern.
207 RealType _beta; ///< Parameter defining the shape of the gain pattern.
208 RealType _gamma; ///< Parameter defining the shape of the gain pattern.
209 };
210
211 /**
212 * @class Gaussian
213 * @brief Represents a Gaussian-shaped antenna gain pattern.
214 *
215 * This antenna has a gain pattern that follows a Gaussian distribution.
216 */
217 class Gaussian final : public Antenna
218 {
219 public:
220 /**
221 * @brief Constructs a Gaussian antenna with the given parameters.
222 *
223 * @param name The name of the antenna.
224 * @param azscale The azimuth scale factor.
225 * @param elscale The elevation scale factor.
226 */
227 Gaussian(const std::string_view name, const RealType azscale, const RealType elscale) :
228 Antenna(name.data()), _azscale(azscale), _elscale(elscale)
229 {
230 }
231
232 ~Gaussian() override = default;
233
234 Gaussian(const Gaussian&) = delete;
235
236 Gaussian& operator=(const Gaussian&) = delete;
237
238 Gaussian(Gaussian&&) = delete;
239
241
242 /**
243 * @brief Computes the gain of the Gaussian antenna.
244 *
245 * @param angle The angle at which the gain is to be computed.
246 * @param refangle The reference angle.
247 * @param wavelength The wavelength of the signal.
248 * @return The computed gain of the antenna.
249 */
250 [[nodiscard]] RealType getGain(const math::SVec3& angle, const math::SVec3& refangle,
251 RealType wavelength) const noexcept override;
252
253 /** @brief Gets the azimuth scale factor. */
254 [[nodiscard]] RealType getAzimuthScale() const noexcept { return _azscale; }
255
256 /** @brief Gets the elevation scale factor. */
257 [[nodiscard]] RealType getElevationScale() const noexcept { return _elscale; }
258
259 private:
260 RealType _azscale; ///< Azimuth scale factor.
261 RealType _elscale; ///< Elevation scale factor.
262 };
263
264 /**
265 * @class SquareHorn
266 * @brief Represents a square horn antenna.
267 *
268 * This antenna models a square horn with a specific dimension.
269 */
270 class SquareHorn final : public Antenna
271 {
272 public:
273 /**
274 * @brief Constructs a SquareHorn antenna with the given dimension.
275 *
276 * @param name The name of the antenna.
277 * @param dimension The dimension of the square horn.
278 */
279 SquareHorn(const std::string_view name, const RealType dimension) : Antenna(name.data()), _dimension(dimension)
280 {
281 }
282
283 ~SquareHorn() override = default;
284
285 SquareHorn(const SquareHorn&) = delete;
286
287 SquareHorn& operator=(const SquareHorn&) = delete;
288
290
292
293 /**
294 * @brief Computes the gain of the square horn antenna.
295 *
296 * @param angle The angle at which the gain is to be computed.
297 * @param refangle The reference angle.
298 * @param wavelength The wavelength of the signal.
299 * @return The computed gain of the antenna.
300 */
301 [[nodiscard]] RealType getGain(const math::SVec3& angle, const math::SVec3& refangle,
302 RealType wavelength) const noexcept override;
303
304 /** @brief Gets the dimension of the square horn. */
305 [[nodiscard]] RealType getDimension() const noexcept { return _dimension; }
306
307 private:
308 RealType _dimension; ///< Dimension of the square horn.
309 };
310
311 /**
312 * @class Parabolic
313 * @brief Represents a parabolic reflector antenna.
314 *
315 * This antenna models a parabolic reflector with a specific diameter.
316 */
317 class Parabolic final : public Antenna
318 {
319 public:
320 /**
321 * @brief Constructs a Parabolic antenna with the given diameter.
322 *
323 * @param name The name of the antenna.
324 * @param diameter The diameter of the parabolic reflector.
325 */
326 Parabolic(const std::string_view name, const RealType diameter) : Antenna(name.data()), _diameter(diameter) {}
327
328 ~Parabolic() override = default;
329
330 Parabolic(const Parabolic&) = delete;
331
332 Parabolic& operator=(const Parabolic&) = delete;
333
334 Parabolic(Parabolic&&) = delete;
335
337
338 /**
339 * @brief Computes the gain of the parabolic antenna.
340 *
341 * @param angle The angle at which the gain is to be computed.
342 * @param refangle The reference angle.
343 * @param wavelength The wavelength of the signal.
344 * @return The computed gain of the antenna.
345 */
346 [[nodiscard]] RealType getGain(const math::SVec3& angle, const math::SVec3& refangle,
347 RealType wavelength) const noexcept override;
348
349 /** @brief Gets the diameter of the parabolic reflector. */
350 [[nodiscard]] RealType getDiameter() const noexcept { return _diameter; }
351
352 private:
353 RealType _diameter; ///< Diameter of the parabolic reflector.
354 };
355
356 /**
357 * @class XmlAntenna
358 * @brief Represents an antenna whose gain pattern is defined by an XML file.
359 *
360 * This class models an antenna where the gain pattern is read from an XML file.
361 */
362 class XmlAntenna final : public Antenna
363 {
364 public:
365 /**
366 * @brief Constructs an XmlAntenna with the specified name and XML configuration file.
367 *
368 * The constructor loads the azimuth and elevation gain patterns from the provided XML file.
369 *
370 * @param name The name of the antenna.
371 * @param filename The path to the XML file containing the antenna's gain pattern data.
372 */
373 XmlAntenna(const std::string_view name, const std::string_view filename) :
374 Antenna(name.data()), _azi_samples(std::make_unique<interp::InterpSet>()),
375 _elev_samples(std::make_unique<interp::InterpSet>())
376 {
377 loadAntennaDescription(filename);
378 }
379
380 ~XmlAntenna() override = default;
381
382 XmlAntenna(const XmlAntenna&) = delete;
383
384 XmlAntenna& operator=(const XmlAntenna&) = delete;
385
387
389
390 /**
391 * @brief Computes the gain of the antenna based on the input angle and reference angle.
392 *
393 * @param angle The angle at which the gain is to be computed.
394 * @param refangle The reference angle.
395 * @param wavelength The wavelength of the signal (not used in this antenna type).
396 * @return The gain of the antenna at the specified angle.
397 * @throws std::runtime_error If gain values cannot be retrieved from the interpolation sets.
398 */
399 [[nodiscard]] RealType getGain(const math::SVec3& angle, const math::SVec3& refangle,
400 RealType wavelength) const override;
401
402 /** @brief Gets the filename of the antenna description. */
403 [[nodiscard]] const std::string& getFilename() const noexcept { return _filename; }
404
405 /** @brief Gets the maximum gain of the antenna. */
406 [[nodiscard]] RealType getMaxGain() const noexcept { return _max_gain; }
407
408 /** @brief Gets the interpolation set for azimuth gain samples. */
409 [[nodiscard]] const interp::InterpSet* getAzimuthSamples() const noexcept { return _azi_samples.get(); }
410
411 /** @brief Gets the interpolation set for elevation gain samples. */
412 [[nodiscard]] const interp::InterpSet* getElevationSamples() const noexcept { return _elev_samples.get(); }
413
414 private:
415 /**
416 * @brief Loads the antenna gain pattern from the specified XML file.
417 *
418 * @param filename The path to the XML file containing the antenna's gain pattern data.
419 * @throws std::runtime_error If the XML file cannot be loaded or parsed.
420 */
421 void loadAntennaDescription(std::string_view filename);
422
423 std::string _filename; ///< The original filename for the antenna description.
424 RealType _max_gain{}; ///< The maximum gain of the antenna.
425 std::unique_ptr<interp::InterpSet> _azi_samples; ///< Interpolation set for azimuth gain samples.
426 std::unique_ptr<interp::InterpSet> _elev_samples; ///< Interpolation set for elevation gain samples.
427 };
428
429 /**
430 * @class H5Antenna
431 * @brief Represents an antenna whose gain pattern is loaded from a HDF5 file.
432 *
433 * This class models an antenna with a gain pattern defined in an HDF5 file. The gain pattern is stored in a
434 * `Pattern` object, which is used to compute the antenna's gain based on the input angle and reference angle.
435 */
436 class H5Antenna final : public Antenna
437 {
438 public:
439 /**
440 * @brief Constructs a H5Antenna with the specified name and gain pattern file.
441 *
442 * @param name The name of the antenna.
443 * @param filename The path to the file containing the antenna's gain pattern.
444 */
445 H5Antenna(const std::string_view name, const std::string& filename) :
446 Antenna(name.data()), _pattern(serial::readPattern(filename, "antenna")), _filename(filename)
447 {
448 }
449
450 ~H5Antenna() override = default;
451
452 H5Antenna(const H5Antenna&) = delete;
453
454 H5Antenna& operator=(const H5Antenna&) = delete;
455
456 H5Antenna(H5Antenna&&) = delete;
457
459
460 /**
461 * @brief Computes the gain of the antenna based on the input angle and reference angle.
462 *
463 * @param angle The angle at which the gain is to be computed.
464 * @param refangle The reference angle.
465 * @return The gain of the antenna at the specified angle.
466 */
467 [[nodiscard]] RealType getGain(const math::SVec3& angle, const math::SVec3& refangle,
468 RealType /*wavelength*/) const override;
469
470 /** @brief Gets the filename of the antenna description. */
471 [[nodiscard]] const std::string& getFilename() const noexcept { return _filename; }
472
473 /** @brief Gets the gain pattern object. */
474 [[nodiscard]] const std::vector<std::vector<RealType>>& getPattern() const noexcept { return _pattern; }
475
476 private:
477 std::vector<std::vector<RealType>> _pattern; ///< The 2D pattern data.
478 std::string _filename; ///< The original filename for the antenna description.
479 };
480}
Abstract base class representing an antenna.
Antenna(Antenna &&)=default
virtual RealType getGain(const math::SVec3 &angle, const math::SVec3 &refangle, RealType wavelength) const =0
Computes the gain of the antenna based on the input angle and reference angle.
Antenna(std::string name) noexcept
Constructs an Antenna object with the given name.
static RealType getAngle(const math::SVec3 &angle, const math::SVec3 &refangle) noexcept
Computes the angle between the input and reference angles.
Antenna & operator=(Antenna &&)=default
Antenna & operator=(const Antenna &)=delete
void setEfficiencyFactor(RealType loss) noexcept
Sets the efficiency factor of the antenna.
virtual ~Antenna()=default
RealType getEfficiencyFactor() const noexcept
Retrieves the efficiency factor of the antenna.
Antenna(const Antenna &)=delete
std::string getName() const noexcept
Retrieves the name of the antenna.
virtual RealType getNoiseTemperature(const math::SVec3 &) const noexcept
Computes the noise temperature of the antenna based on the angle.
Represents a Gaussian-shaped antenna gain pattern.
Gaussian & operator=(Gaussian &&)=delete
Gaussian(const Gaussian &)=delete
Gaussian & operator=(const Gaussian &)=delete
RealType getGain(const math::SVec3 &angle, const math::SVec3 &refangle, RealType wavelength) const noexcept override
Computes the gain of the Gaussian antenna.
Gaussian(Gaussian &&)=delete
RealType getAzimuthScale() const noexcept
Gets the azimuth scale factor.
RealType getElevationScale() const noexcept
Gets the elevation scale factor.
Gaussian(const std::string_view name, const RealType azscale, const RealType elscale)
Constructs a Gaussian antenna with the given parameters.
~Gaussian() override=default
Represents an antenna whose gain pattern is loaded from a HDF5 file.
H5Antenna(const std::string_view name, const std::string &filename)
Constructs a H5Antenna with the specified name and gain pattern file.
H5Antenna & operator=(const H5Antenna &)=delete
H5Antenna & operator=(H5Antenna &&)=delete
~H5Antenna() override=default
const std::string & getFilename() const noexcept
Gets the filename of the antenna description.
H5Antenna(H5Antenna &&)=delete
H5Antenna(const H5Antenna &)=delete
RealType getGain(const math::SVec3 &angle, const math::SVec3 &refangle, RealType) const override
Computes the gain of the antenna based on the input angle and reference angle.
const std::vector< std::vector< RealType > > & getPattern() const noexcept
Gets the gain pattern object.
Represents an isotropic antenna with uniform gain in all directions.
Isotropic(const std::string_view name)
Constructs an Isotropic antenna with the given name.
Isotropic & operator=(Isotropic &&)=delete
~Isotropic() override=default
Isotropic & operator=(const Isotropic &)=delete
RealType getGain(const math::SVec3 &, const math::SVec3 &, RealType) const override
Computes the gain of the isotropic antenna.
Isotropic(Isotropic &&)=delete
Isotropic(const Isotropic &)=delete
Represents a parabolic reflector antenna.
Parabolic(const Parabolic &)=delete
~Parabolic() override=default
Parabolic & operator=(const Parabolic &)=delete
Parabolic(const std::string_view name, const RealType diameter)
Constructs a Parabolic antenna with the given diameter.
RealType getDiameter() const noexcept
Gets the diameter of the parabolic reflector.
Parabolic & operator=(Parabolic &&)=delete
Parabolic(Parabolic &&)=delete
RealType getGain(const math::SVec3 &angle, const math::SVec3 &refangle, RealType wavelength) const noexcept override
Computes the gain of the parabolic antenna.
Represents a sinc function-based antenna gain pattern.
RealType getAlpha() const noexcept
Gets the alpha parameter of the sinc function.
RealType getGain(const math::SVec3 &angle, const math::SVec3 &refangle, RealType wavelength) const noexcept override
Computes the gain of the sinc antenna based on the input parameters.
Sinc(Sinc &&)=delete
Sinc & operator=(Sinc &&)=delete
Sinc & operator=(const Sinc &)=delete
RealType getGamma() const noexcept
Gets the gamma parameter of the sinc function.
Sinc(const Sinc &)=delete
RealType getBeta() const noexcept
Gets the beta parameter of the sinc function.
~Sinc() override=default
Sinc(const std::string_view name, const RealType alpha, const RealType beta, const RealType gamma)
Constructs a Sinc antenna with the given parameters.
Represents a square horn antenna.
SquareHorn & operator=(SquareHorn &&)=delete
RealType getGain(const math::SVec3 &angle, const math::SVec3 &refangle, RealType wavelength) const noexcept override
Computes the gain of the square horn antenna.
RealType getDimension() const noexcept
Gets the dimension of the square horn.
SquareHorn(SquareHorn &&)=delete
SquareHorn & operator=(const SquareHorn &)=delete
SquareHorn(const std::string_view name, const RealType dimension)
Constructs a SquareHorn antenna with the given dimension.
~SquareHorn() override=default
SquareHorn(const SquareHorn &)=delete
Represents an antenna whose gain pattern is defined by an XML file.
XmlAntenna(const std::string_view name, const std::string_view filename)
Constructs an XmlAntenna with the specified name and XML configuration file.
XmlAntenna & operator=(const XmlAntenna &)=delete
RealType getMaxGain() const noexcept
Gets the maximum gain of the antenna.
XmlAntenna(XmlAntenna &&)=delete
XmlAntenna & operator=(XmlAntenna &&)=delete
RealType getGain(const math::SVec3 &angle, const math::SVec3 &refangle, RealType wavelength) const override
Computes the gain of the antenna based on the input angle and reference angle.
~XmlAntenna() override=default
const interp::InterpSet * getAzimuthSamples() const noexcept
Gets the interpolation set for azimuth gain samples.
const interp::InterpSet * getElevationSamples() const noexcept
Gets the interpolation set for elevation gain samples.
const std::string & getFilename() const noexcept
Gets the filename of the antenna description.
XmlAntenna(const XmlAntenna &)=delete
Wrapper class for managing interpolation sets using smart pointers.
A class representing a vector in spherical coordinates.
Global configuration file for the project.
double RealType
Type for real numbers.
Definition config.h:27
Classes and operations for 3D geometry.
Header file for the interpolation of sets of data.
Header file for the logging system.
std::vector< std::vector< RealType > > readPattern(const std::string &name, const std::string &datasetName)
Reads a 2D pattern dataset from an HDF5 file.