IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 61b64724 authored by Nikos Karastathis's avatar Nikos Karastathis :ocean:
Browse files

add a few more unit tests in antennas

parent dbc504fd
No related branches found
No related tags found
1 merge request!329Radio interface
......@@ -257,113 +257,128 @@ TEST_CASE("Radio", "[processes]") {
} // END: SECTION("ZHS process")
SECTION("TimeDomainAntenna") {
// create an environment so we can get a coordinate system
using EnvType = Environment<IRefractiveIndexModel<IMediumModel>>;
EnvType env6;
using UniRIndex =
UniformRefractiveIndex<HomogeneousMedium<IRefractiveIndexModel<IMediumModel>>>;
// the antenna location
const auto point1{Point(env6.getCoordinateSystem(), 1_m, 2_m, 3_m)};
const auto point2{Point(env6.getCoordinateSystem(), 4_m, 5_m, 6_m)};
// get a coordinate system
const CoordinateSystemPtr rootCS6 = env6.getCoordinateSystem();
auto Medium6 = EnvType::createNode<Sphere>(
Point{rootCS6, 0_m, 0_m, 0_m}, 1_km * std::numeric_limits<double>::infinity());
auto const props6 = Medium6->setModelProperties<UniRIndex>(
1, 1_kg / (1_m * 1_m * 1_m), NuclearComposition({Code::Nitrogen}, {1.}));
env6.getUniverse()->addChild(std::move(Medium6));
// create times for the antenna
const TimeType t1{10_s};
const TimeType t2{10_s};
const InverseTimeType t3{1 / 1_s};
const TimeType t4{11_s};
// check that I can create an antenna at (1, 2, 3)
TimeDomainAntenna ant1("antenna_name", point1, t1, t2, t3, t1);
TimeDomainAntenna ant2("antenna_name2", point2, t4, t2, t3, t4);
// assert that the antenna name is correct
REQUIRE(ant1.getName() == "antenna_name");
REQUIRE(ant2.getName() == "antenna_name2");
// and check that the antenna is at the right location
REQUIRE((ant1.getLocation() - point1).getNorm() < 1e-12 * 1_m);
REQUIRE((ant2.getLocation() - point2).getNorm() < 1e-12 * 1_m);
} // END: TEST_CASE("Radio", "[processes]")
// construct a radio detector instance to store our antennas
AntennaCollection<TimeDomainAntenna> detector;
TEST_CASE("Antennas") {
// add this antenna to the process
detector.addAntenna(ant1);
detector.addAntenna(ant2);
CHECK(detector.size() == 2);
SECTION("TimeDomainAntenna") {
// get a unit vector
Vector<dimensionless_d> v1(rootCS6, {0, 0, 1});
Vector<ElectricFieldType::dimension_type> v11(rootCS6,
{10_V / 1_m, 10_V / 1_m, 10_V / 1_m});
Vector<dimensionless_d> v2(rootCS6, {0, 1, 0});
Vector<ElectricFieldType::dimension_type> v22(rootCS6,
{20_V / 1_m, 20_V / 1_m, 20_V / 1_m});
// use receive methods
ant1.receive(15_s, v1, v11);
ant2.receive(16_s, v2, v22);
// use getWaveform() methods
auto [tx, Ex] = ant1.getWaveformX();
CHECK(Ex[5] - 10 == 0);
CHECK(tx[5] - 5 * 1_s / 1_ns == Approx(0.0));
auto [ty, Ey] = ant1.getWaveformY();
CHECK(Ey[5] - 10 == 0);
auto [tz, Ez] = ant1.getWaveformZ();
CHECK(Ez[5] - 10 == 0);
CHECK(tx[5] - ty[5] == 0);
CHECK(ty[5] - tz[5] == 0);
auto [tx2, Ex2] = ant2.getWaveformX();
CHECK(Ex2[5] - 20 == 0);
auto [ty2, Ey2] = ant2.getWaveformY();
CHECK(Ey2[5] - 20 == 0);
auto [tz2, Ez2] = ant2.getWaveformZ();
CHECK(Ez2[5] - 20 == 0);
// the following creates a star-shaped pattern of antennas in the ground
AntennaCollection<TimeDomainAntenna> detector__;
const auto point11{Point(env6.getCoordinateSystem(), 1000_m, 20_m, 30_m)};
const TimeType t2222{1e-6_s};
const InverseTimeType t3333{1e+9_Hz};
for (auto radius_ = 100_m; radius_ <= 200_m; radius_ += 100_m) {
for (auto phi_ = 0; phi_ <= 315; phi_ += 45) {
auto phiRad_ = phi_ / 180. * M_PI;
auto const point_{Point(env6.getCoordinateSystem(), radius_ * cos(phiRad_),
radius_ * sin(phiRad_), 0_m)};
auto time__{(point11 - point_).getNorm() / constants::c};
const int rr_ = static_cast<int>(radius_ / 1_m);
std::string var_ = "antenna_R=" + std::to_string(rr_) +
"_m-Phi=" + std::to_string(phi_) + "degrees";
TimeDomainAntenna ant111(var_, point_, time__, t2222, t3333, time__);
detector__.addAntenna(ant111);
}
}
// create an environment so we can get a coordinate system
using EnvType = Environment<IRefractiveIndexModel<IMediumModel>>;
EnvType env6;
// this prints out the antenna names and locations
for (auto const antenna : detector__.getAntennas()) {
CORSIKA_LOG_DEBUG("Antenna name: {} ", antenna.getName());
CORSIKA_LOG_DEBUG("Antenna location: {} ", antenna.getLocation());
}
using UniRIndex =
UniformRefractiveIndex<HomogeneousMedium<IRefractiveIndexModel<IMediumModel>>>;
} // END: SECTION("TimeDomainAntenna")
// the antenna location
const auto point1{Point(env6.getCoordinateSystem(), 1_m, 2_m, 3_m)};
const auto point2{Point(env6.getCoordinateSystem(), 4_m, 5_m, 6_m)};
// get a coordinate system
const CoordinateSystemPtr rootCS6 = env6.getCoordinateSystem();
auto Medium6 = EnvType::createNode<Sphere>(
Point{rootCS6, 0_m, 0_m, 0_m}, 1_km * std::numeric_limits<double>::infinity());
auto const props6 = Medium6->setModelProperties<UniRIndex>(
1, 1_kg / (1_m * 1_m * 1_m), NuclearComposition({Code::Nitrogen}, {1.}));
env6.getUniverse()->addChild(std::move(Medium6));
// create times for the antenna
const TimeType t1{10_s};
const TimeType t2{10_s};
const InverseTimeType t3{1 / 1_s};
const TimeType t4{11_s};
// check that I can create an antenna at (1, 2, 3)
TimeDomainAntenna ant1("antenna_name", point1, t1, t2, t3, t1);
TimeDomainAntenna ant2("antenna_name2", point2, t4, t2, t3, t4);
// assert that the antenna name is correct
REQUIRE(ant1.getName() == "antenna_name");
REQUIRE(ant2.getName() == "antenna_name2");
// and check that the antenna is at the right location
REQUIRE((ant1.getLocation() - point1).getNorm() < 1e-12 * 1_m);
REQUIRE((ant2.getLocation() - point2).getNorm() < 1e-12 * 1_m);
// construct a radio detector instance to store our antennas
AntennaCollection<TimeDomainAntenna> detector;
// add this antenna to the process
detector.addAntenna(ant1);
detector.addAntenna(ant2);
CHECK(detector.size() == 2);
// get a unit vector
Vector<dimensionless_d> v1(rootCS6, {0, 0, 1});
Vector<ElectricFieldType::dimension_type> v11(rootCS6,
{10_V / 1_m, 10_V / 1_m, 10_V / 1_m});
Vector<dimensionless_d> v2(rootCS6, {0, 1, 0});
Vector<ElectricFieldType::dimension_type> v22(rootCS6,
{20_V / 1_m, 20_V / 1_m, 20_V / 1_m});
// use receive methods
ant1.receive(15_s, v1, v11);
ant2.receive(16_s, v2, v22);
// use getWaveform() methods
auto[tx, Ex] = ant1.getWaveformX();
CHECK(Ex[5] - 10 == 0);
CHECK(tx[5] - 5 * 1_s / 1_ns == Approx(0.0));
auto[ty, Ey] = ant1.getWaveformY();
CHECK(Ey[5] - 10 == 0);
auto[tz, Ez] = ant1.getWaveformZ();
CHECK(Ez[5] - 10 == 0);
CHECK(tx[5] - ty[5] == 0);
CHECK(ty[5] - tz[5] == 0);
auto[tx2, Ex2] = ant2.getWaveformX();
CHECK(Ex2[5] - 20 == 0);
auto[ty2, Ey2] = ant2.getWaveformY();
CHECK(Ey2[5] - 20 == 0);
auto[tz2, Ez2] = ant2.getWaveformZ();
CHECK(Ez2[5] - 20 == 0);
// the following creates a star-shaped pattern of antennas in the ground
AntennaCollection<TimeDomainAntenna> detector__;
const auto point11{Point(env6.getCoordinateSystem(), 1000_m, 20_m, 30_m)};
const TimeType t2222{1e-6_s};
const InverseTimeType t3333{1e+9_Hz};
std::vector<std::string> antenna_names;
std::vector<Point> antenna_locations;
for (auto radius_ = 100_m; radius_ <= 200_m; radius_ += 100_m) {
for (auto phi_ = 0; phi_ <= 315; phi_ += 45) {
auto phiRad_ = phi_ / 180. * M_PI;
auto const point_{Point(env6.getCoordinateSystem(), radius_ * cos(phiRad_),
radius_ * sin(phiRad_), 0_m)};
antenna_locations.push_back(point_);
auto time__{(point11 - point_).getNorm() / constants::c};
const int rr_ = static_cast<int>(radius_ / 1_m);
std::string var_ = "antenna_R=" + std::to_string(rr_) +
"_m-Phi=" + std::to_string(phi_) + "degrees";
antenna_names.push_back(var_);
TimeDomainAntenna ant111(var_, point_, time__, t2222, t3333, time__);
detector__.addAntenna(ant111);
}
}
CHECK(detector__.getAntennas().size() == 16);
int i = 0;
// this prints out the antenna names and locations
for (auto const antenna: detector__.getAntennas()) {
CHECK(antenna.getName() == antenna_names[i]);
CHECK(distance(antenna.getLocation(), antenna_locations[i]) / 1_m == 0);
i++;
}
} // END: SECTION("TimeDomainAntenna")
} // END: TEST_CASE("Antennas")
TEST_CASE("Propagators") {
SECTION("Simple Propagator w/ Uniform Refractive Index") {
......@@ -656,4 +671,4 @@ TEST_CASE("Radio", "[processes]") {
} // END: SECTION("Straight Propagator w/ Exponential Refractive Index")
} // END: TEST_CASE("Radio", "[processes]")
} // END: TEST_CASE("Propagators")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment