FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
antenna Namespace Reference

Classes

class  Antenna
 Abstract base class representing an antenna. More...
 
class  Gaussian
 Represents a Gaussian-shaped antenna gain pattern. More...
 
class  H5Antenna
 Represents an antenna whose gain pattern is loaded from a HDF5 file. More...
 
class  Isotropic
 Represents an isotropic antenna with uniform gain in all directions. More...
 
class  Parabolic
 Represents a parabolic reflector antenna. More...
 
class  Sinc
 Represents a sinc function-based antenna gain pattern. More...
 
class  SquareHorn
 Represents a square horn antenna. More...
 
class  XmlAntenna
 Represents an antenna whose gain pattern is defined by an XML file. More...
 

Functions

void to_json (nlohmann::json &j, const Antenna &a)
 
void from_json (const nlohmann::json &j, std::unique_ptr< Antenna > &ant)
 

Function Documentation

◆ from_json()

void antenna::from_json ( const nlohmann::json &  j,
std::unique_ptr< Antenna > &  ant 
)

Definition at line 324 of file json_serializer.cpp.

325 {
326 const auto name = j.at("name").get<std::string>();
327 const auto pattern = j.value("pattern", "isotropic");
328
329 if (pattern == "isotropic")
330 {
331 ant = std::make_unique<Isotropic>(name);
332 }
333 else if (pattern == "sinc")
334 {
335 ant = std::make_unique<Sinc>(name, j.at("alpha").get<RealType>(), j.at("beta").get<RealType>(),
336 j.at("gamma").get<RealType>());
337 }
338 else if (pattern == "gaussian")
339 {
340 ant = std::make_unique<Gaussian>(name, j.at("azscale").get<RealType>(), j.at("elscale").get<RealType>());
341 }
342 else if (pattern == "squarehorn")
343 {
344 ant = std::make_unique<SquareHorn>(name, j.at("diameter").get<RealType>());
345 }
346 else if (pattern == "parabolic")
347 {
348 ant = std::make_unique<Parabolic>(name, j.at("diameter").get<RealType>());
349 }
350 else if (pattern == "xml")
351 {
352 const auto filename = j.value("filename", "");
353 if (filename.empty())
354 {
355 LOG(logging::Level::WARNING, "Skipping load of XML antenna '{}': filename is empty.", name);
356 return; // ant remains nullptr
357 }
358 ant = std::make_unique<XmlAntenna>(name, filename);
359 }
360 else if (pattern == "file")
361 {
362 const auto filename = j.value("filename", "");
363 if (filename.empty())
364 {
365 LOG(logging::Level::WARNING, "Skipping load of H5 antenna '{}': filename is empty.", name);
366 return; // ant remains nullptr
367 }
368 ant = std::make_unique<H5Antenna>(name, filename);
369 }
370 else
371 {
372 throw std::runtime_error("Unsupported antenna pattern in from_json: " + pattern);
373 }
374
375 ant->setEfficiencyFactor(j.value("efficiency", 1.0));
376 }
double RealType
Type for real numbers.
Definition config.h:27
#define LOG(level,...)
Definition logging.h:19
@ WARNING
Warning level for potentially harmful situations.

References LOG, and logging::WARNING.

◆ to_json()

void antenna::to_json ( nlohmann::json &  j,
const Antenna a 
)

Definition at line 281 of file json_serializer.cpp.

282 {
283 j = {{"name", a.getName()}, {"efficiency", a.getEfficiencyFactor()}};
284
285 if (const auto* sinc = dynamic_cast<const Sinc*>(&a))
286 {
287 j["pattern"] = "sinc";
288 j["alpha"] = sinc->getAlpha();
289 j["beta"] = sinc->getBeta();
290 j["gamma"] = sinc->getGamma();
291 }
292 else if (const auto* gaussian = dynamic_cast<const Gaussian*>(&a))
293 {
294 j["pattern"] = "gaussian";
295 j["azscale"] = gaussian->getAzimuthScale();
296 j["elscale"] = gaussian->getElevationScale();
297 }
298 else if (const auto* sh = dynamic_cast<const SquareHorn*>(&a))
299 {
300 j["pattern"] = "squarehorn";
301 j["diameter"] = sh->getDimension();
302 }
303 else if (const auto* parabolic = dynamic_cast<const Parabolic*>(&a))
304 {
305 j["pattern"] = "parabolic";
306 j["diameter"] = parabolic->getDiameter();
307 }
308 else if (const auto* xml = dynamic_cast<const XmlAntenna*>(&a))
309 {
310 j["pattern"] = "xml";
311 j["filename"] = xml->getFilename();
312 }
313 else if (const auto* h5 = dynamic_cast<const H5Antenna*>(&a))
314 {
315 j["pattern"] = "file";
316 j["filename"] = h5->getFilename();
317 }
318 else
319 {
320 j["pattern"] = "isotropic";
321 }
322 }
RealType getEfficiencyFactor() const noexcept
Retrieves the efficiency factor of the antenna.
std::string getName() const noexcept
Retrieves the name of the antenna.

References antenna::Antenna::getEfficiencyFactor(), and antenna::Antenna::getName().

+ Here is the call graph for this function: