45 return std::sin(theta) / theta;
70 angle_element.
isValid() && gain_element.isValid())
73 const RealType gain = std::stof(gain_element.getText());
74 set->insertSample(angle, gain);
88 LOG(Level::INFO,
"Using greater than unity antenna efficiency.");
95 SVec3 normangle(angle);
97 return std::acos(dotProduct(
Vec3(normangle),
Vec3(refangle)));
102 const SVec3 a = angle - refangle;
108 const RealType theta = getAngle(angle, refangle);
109 const RealType sinc_val = sinc(_beta * theta);
110 const RealType gain_pattern = std::pow(std::abs(sinc_val), _gamma);
111 return _alpha * gain_pattern * getEfficiencyFactor();
116 const RealType ge = 4 *
PI * std::pow(_dimension, 2) / std::pow(wavelength, 2);
117 const RealType x =
PI * _dimension * std::sin(getAngle(angle, refangle)) / wavelength;
118 return ge * std::pow(sinc(x), 2) * getEfficiencyFactor();
123 const RealType ge = std::pow(
PI * _diameter / wavelength, 2);
124 const RealType x =
PI * _diameter * std::sin(getAngle(angle, refangle)) / wavelength;
125 return ge * std::pow(2 * j1C(x), 2) * getEfficiencyFactor();
130 const SVec3 delta_angle = angle - refangle;
132 const std::optional<RealType> azi_value = _azi_samples->getValueAt(std::abs(delta_angle.
azimuth));
134 if (
const std::optional<RealType> elev_value = _elev_samples->getValueAt(std::abs(delta_angle.
elevation));
135 azi_value && elev_value)
140 LOG(Level::FATAL,
"Could not get antenna gain value");
141 throw std::runtime_error(
"Could not get antenna gain value");
144 void XmlAntenna::loadAntennaDescription(
const std::string_view filename)
146 _filename = filename;
148 if (!doc.
loadFile(std::string(filename)))
150 LOG(Level::FATAL,
"Could not load antenna description {}", filename.data());
151 throw std::runtime_error(
"Could not load antenna description");
155 loadAntennaGainAxis(_elev_samples.get(), root.childElement(
"elevation", 0));
156 loadAntennaGainAxis(_azi_samples.get(), root.childElement(
"azimuth", 0));
158 _max_gain = std::max(_azi_samples->getMax(), _elev_samples->getMax());
159 _elev_samples->divide(_max_gain);
160 _azi_samples->divide(_max_gain);
167 const SVec3& pattern_angle = angle - refangle;
169 const double ex1 = (pattern_angle.
azimuth +
PI) / two_pi;
170 const double ey1 = (pattern_angle.
elevation +
PI) / two_pi;
172 const auto calc_grid_point = [](
const double value,
const unsigned size)
174 const double x1 = std::floor(value * (size - 1)) / (size - 1);
175 const double x2 = std::min(x1 + 1.0 / size, 1.0);
176 return std::pair{x1, x2};
179 unsigned size_azi = _pattern.size();
180 unsigned size_elev = _pattern[0].size();
184 const auto [x1, x2] = calc_grid_point(ex1, size_azi);
185 const auto [y1, y2] = calc_grid_point(ey1, size_elev);
187 const double t = (ex1 - x1) / (x2 - x1);
188 const double u = (ey1 - y1) / (y2 - y1);
190 const auto calc_array_index = [](
const double value,
const unsigned size)
191 {
return std::min(
static_cast<unsigned>(std::floor(value * size)), size - 1); };
193 const unsigned arr_x = calc_array_index(x1, size_azi);
194 const unsigned arr_y = calc_array_index(y1, size_elev);
196 const RealType interp = (1.0 - t) * (1.0 - u) * _pattern[arr_x][arr_y] +
197 t * (1.0 - u) * _pattern[(arr_x + 1) % size_azi][arr_y] +
198 t * u * _pattern[(arr_x + 1) % size_azi][(arr_y + 1) % size_elev] +
199 (1.0 - t) * u * _pattern[arr_x][(arr_y + 1) % size_elev];
Header file defining various types of antennas and their gain patterns.
Class for managing XML documents.
XmlElement getRootElement() const
Get the root element of the document.
bool loadFile(std::string_view filename)
Load an XML file into the document.
Class representing a node in an XML document.
XmlElement childElement(const std::string_view name="", const unsigned index=0) const noexcept
Retrieve a child element by name and index.
bool isValid() const noexcept
Check if the XML element is valid.
xmlNodePtr getNode() const noexcept
Get the underlying XML node pointer.
std::string getText() const
Get the text content of the XML element.
static RealType getAngle(const math::SVec3 &angle, const math::SVec3 &refangle) noexcept
Computes the angle between the input and reference angles.
void setEfficiencyFactor(RealType loss) noexcept
Sets the efficiency factor of the antenna.
RealType getEfficiencyFactor() const noexcept
Retrieves the efficiency factor of the antenna.
RealType getGain(const math::SVec3 &angle, const math::SVec3 &refangle, RealType wavelength) const noexcept override
Computes the gain of the Gaussian antenna.
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.
RealType getGain(const math::SVec3 &angle, const math::SVec3 &refangle, RealType wavelength) const noexcept override
Computes the gain of the parabolic antenna.
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.
RealType getGain(const math::SVec3 &angle, const math::SVec3 &refangle, RealType wavelength) const noexcept override
Computes the gain of the square horn antenna.
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.
Wrapper class for managing interpolation sets using smart pointers.
A class representing a vector in spherical coordinates.
RealType elevation
The elevation angle of the vector.
RealType azimuth
The azimuth angle of the vector.
RealType length
The length of the vector.
A class representing a vector in rectangular coordinates.
Global configuration file for the project.
double RealType
Type for real numbers.
constexpr RealType EPSILON
Machine epsilon for real numbers.
constexpr RealType PI
Mathematical constant π (pi).
Classes and operations for 3D geometry.
Wrapper for managing XML documents and elements using libxml2.
Header file for the logging system.
RealType besselJ1(const RealType x) noexcept
Computes the Bessel function of the first kind (order 1) for a given value.
@ TRACE
Trace level for detailed debugging information.
Utility functions for mathematical and system operations.