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 388 of file json_serializer.cpp.

389 {
390 const auto name = j.at("name").get<std::string>();
391 const auto id = parse_json_id(j, "id", "Antenna");
392 const auto pattern = j.value("pattern", "isotropic");
393
394 if (pattern == "isotropic")
395 {
396 ant = std::make_unique<Isotropic>(name, id);
397 }
398 else if (pattern == "sinc")
399 {
400 ant = std::make_unique<Sinc>(name, j.at("alpha").get<RealType>(), j.at("beta").get<RealType>(),
401 j.at("gamma").get<RealType>(), id);
402 }
403 else if (pattern == "gaussian")
404 {
405 ant =
406 std::make_unique<Gaussian>(name, j.at("azscale").get<RealType>(), j.at("elscale").get<RealType>(), id);
407 }
408 else if (pattern == "squarehorn")
409 {
410 ant = std::make_unique<SquareHorn>(name, j.at("diameter").get<RealType>(), id);
411 }
412 else if (pattern == "parabolic")
413 {
414 ant = std::make_unique<Parabolic>(name, j.at("diameter").get<RealType>(), id);
415 }
416 else if (pattern == "xml")
417 {
418 const auto filename = j.value("filename", "");
419 if (filename.empty())
420 {
421 LOG(logging::Level::WARNING, "Skipping load of XML antenna '{}': filename is empty.", name);
422 return; // ant remains nullptr
423 }
424 ant = std::make_unique<XmlAntenna>(name, filename, id);
425 }
426 else if (pattern == "file")
427 {
428 const auto filename = j.value("filename", "");
429 if (filename.empty())
430 {
431 LOG(logging::Level::WARNING, "Skipping load of H5 antenna '{}': filename is empty.", name);
432 return; // ant remains nullptr
433 }
434 ant = std::make_unique<H5Antenna>(name, filename, id);
435 }
436 else
437 {
438 throw std::runtime_error("Unsupported antenna pattern in from_json: " + pattern);
439 }
440
441 ant->setEfficiencyFactor(j.value("efficiency", 1.0));
442 }
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.

Referenced by serial::parse_antenna_from_json().

+ Here is the caller graph for this function:

◆ to_json()

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

Definition at line 345 of file json_serializer.cpp.

346 {
347 j = {{"id", sim_id_to_json(a.getId())}, {"name", a.getName()}, {"efficiency", a.getEfficiencyFactor()}};
348
349 if (const auto* sinc = dynamic_cast<const Sinc*>(&a))
350 {
351 j["pattern"] = "sinc";
352 j["alpha"] = sinc->getAlpha();
353 j["beta"] = sinc->getBeta();
354 j["gamma"] = sinc->getGamma();
355 }
356 else if (const auto* gaussian = dynamic_cast<const Gaussian*>(&a))
357 {
358 j["pattern"] = "gaussian";
359 j["azscale"] = gaussian->getAzimuthScale();
360 j["elscale"] = gaussian->getElevationScale();
361 }
362 else if (const auto* sh = dynamic_cast<const SquareHorn*>(&a))
363 {
364 j["pattern"] = "squarehorn";
365 j["diameter"] = sh->getDimension();
366 }
367 else if (const auto* parabolic = dynamic_cast<const Parabolic*>(&a))
368 {
369 j["pattern"] = "parabolic";
370 j["diameter"] = parabolic->getDiameter();
371 }
372 else if (const auto* xml = dynamic_cast<const XmlAntenna*>(&a))
373 {
374 j["pattern"] = "xml";
375 j["filename"] = xml->getFilename();
376 }
377 else if (const auto* h5 = dynamic_cast<const H5Antenna*>(&a))
378 {
379 j["pattern"] = "file";
380 j["filename"] = h5->getFilename();
381 }
382 else
383 {
384 j["pattern"] = "isotropic";
385 }
386 }
SimId getId() const noexcept
Retrieves the unique ID of the antenna.
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(), antenna::Antenna::getId(), and antenna::Antenna::getName().

+ Here is the call graph for this function: