author | Nicola Baldo <nbaldo@cttc.es> |
Wed, 21 Dec 2011 19:36:45 +0100 | |
changeset 7831 | 6cf69d27f292 |
parent 7830 | c462e6fad794 |
child 7832 | efa48ada840f |
--- a/src/antenna/model/antenna-model.cc Fri Dec 16 18:51:18 2011 +0100 +++ b/src/antenna/model/antenna-model.cc Wed Dec 21 19:36:45 2011 +0100 @@ -20,7 +20,7 @@ #include <ns3/log.h> - +#include <math.h> #include "antenna-model.h" @@ -31,6 +31,24 @@ NS_OBJECT_ENSURE_REGISTERED (AntennaModel); + +double DegreesToRadians (double degrees) +{ + return degrees * M_PI / 180.0; + +} + +double RadiansToDegrees (double radians) +{ + return radians * 180.0 / M_PI; +} + +std::ostream& operator<< (std::ostream& os, const AntennaModel::Angles& a) +{ + os << "(" << a.phi << ", " << a.theta << ")"; + return os; +} + AntennaModel::AntennaModel () { }
--- a/src/antenna/model/antenna-model.h Fri Dec 16 18:51:18 2011 +0100 +++ b/src/antenna/model/antenna-model.h Wed Dec 21 19:36:45 2011 +0100 @@ -29,6 +29,24 @@ /** + * \brief converts degrees to radians + * + * \param degrees the angle in degrees + * + * \return the angle in radians + */ +double DegreesToRadians (double degrees); + +/** + * \brief converts radians to degrees + * + * \param radians the angle in radians + * + * \return the angle in degrees + */ +double RadiansToDegrees (double radians); + +/** * \ingroup antenna * * \brief interface for antenna radiation pattern models @@ -126,6 +144,17 @@ }; +/** + * print a struct AntennaModel::Angles to output + * + * \param os the output stream + * \param a the Angles struct + * + * \return a reference to the output stream + */ +std::ostream& operator<< ( std::ostream& os, const AntennaModel::Angles& a); + + } // namespace ns3 #endif // ANTENNA_MODEL_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/antenna/model/cosine-antenna-model.cc Wed Dec 21 19:36:45 2011 +0100 @@ -0,0 +1,135 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2011 CTTC + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Nicola Baldo <nbaldo@cttc.es> + */ + + +#include <ns3/log.h> +#include <ns3/double.h> +#include <math.h> + +#include "antenna-model.h" +#include "cosine-antenna-model.h" + + +NS_LOG_COMPONENT_DEFINE ("CosineAntennaModel"); + +namespace ns3 { + +NS_OBJECT_ENSURE_REGISTERED (CosineAntennaModel); + + +TypeId +CosineAntennaModel::GetTypeId () +{ + static TypeId tid = TypeId ("ns3::CosineAntennaModel") + .SetParent<AntennaModel> () + .AddConstructor<CosineAntennaModel> () + .AddAttribute ("Beamwidth", + "The 3dB beamwidth (degrees)", + DoubleValue (60), + MakeDoubleAccessor (&CosineAntennaModel::SetBeamwidth, + &CosineAntennaModel::GetBeamwidth), + MakeDoubleChecker<double> (0, 180)) + .AddAttribute ("Orientation", + "The angle (degrees) that expresses the orientation of the antenna on the x-y plane relative to the x axis", + DoubleValue (0.0), + MakeDoubleAccessor (&CosineAntennaModel::SetOrientation, + &CosineAntennaModel::GetOrientation), + MakeDoubleChecker<double> (-360, 360)) + .AddAttribute ("MaxGain", + "The gain (dB) at the antenna boresight (the direction of maximum gain)", + DoubleValue (0.0), + MakeDoubleAccessor (&CosineAntennaModel::m_maxGain), + MakeDoubleChecker<double> ()) + ; + return tid; +} + +void +CosineAntennaModel::SetBeamwidth (double beamwidthDegrees) +{ + NS_LOG_FUNCTION (this << beamwidthDegrees); + m_beamwidthRadians = DegreesToRadians (beamwidthDegrees); + m_exponent = - 3.0 / (20*log10 (cos (m_beamwidthRadians / 4.0))); + NS_LOG_LOGIC (this << " m_exponent = " << m_exponent); +} + +double +CosineAntennaModel::GetBeamwidth () const +{ + return RadiansToDegrees (m_beamwidthRadians); +} + +void +CosineAntennaModel::SetOrientation (double orientationDegrees) +{ + NS_LOG_FUNCTION (this << orientationDegrees); + m_orientationRadians = DegreesToRadians (orientationDegrees); +} + +double +CosineAntennaModel::GetOrientation () const +{ + return RadiansToDegrees (m_orientationRadians); +} + +double +CosineAntennaModel::GetGainDb (Angles a) +{ + NS_LOG_FUNCTION (this << a); + // azimuth angle w.r.t. the reference system of the antenna + double phi = a.phi - m_orientationRadians; + + // make sure phi is in (-pi, pi] + while (phi <= -M_PI) + { + phi += M_PI+M_PI; + } + while (phi > M_PI) + { + phi -= M_PI+M_PI; + } + + NS_LOG_LOGIC ("phi = " << phi ); + + if ((phi >= M_PI_2) || (phi <= -M_PI_2)) + { + NS_LOG_LOGIC ("radiation in the back --> infinite attenuation"); + return -INFINITY; + } + else + { + // element factor: amplitude gain of a single antenna element in linear units + double ef = pow (cos (phi / 2.0), m_exponent); + + // the array factor is not considered. Note that if we did consider + // the array factor, the actual beawidth would change, and in + // particular it would be different from the one specified by the + // user. Hence it is not desirable to use the array factor, for the + // ease of use of this model. + + double gainDb = 20*log10 (ef); + NS_LOG_LOGIC ("gain = " << gainDb << " + " << m_maxGain << " dB"); + return gainDb + m_maxGain; + } +} + + +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/antenna/model/cosine-antenna-model.h Wed Dec 21 19:36:45 2011 +0100 @@ -0,0 +1,80 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2011 CTTC + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Nicola Baldo <nbaldo@cttc.es> + */ + +#ifndef COSINE_ANTENNA_MODEL_H +#define COSINE_ANTENNA_MODEL_H + + +#include <ns3/object.h> +#include <ns3/antenna-model.h> + +namespace ns3 { + +/** + * + * \brief Cosine Antenna Model + * + * This class implements the cosine model as described in [1] + * + * Li Chunjian, "Efficient Antenna Patterns for Three-Sector WCDMA Systems" + * + * Note that only the element factor of the above model is + * considered. Also, an additional constant gain is added to model the + * radiation pattern on the vertical plane (to account for the fact + * that the elevation angle is not included in the model). + */ +class CosineAntennaModel : public AntennaModel +{ +public: + + // inherited from Object + static TypeId GetTypeId (); + + // inherited from AntennaModel + virtual double GetGainDb (Angles a); + + + // attribute getters/setters + void SetBeamwidth (double beamwidthDegrees); + double GetBeamwidth () const; + void SetOrientation (double orientationDegrees); + double GetOrientation () const; + +private: + + /** + * this is the variable "n" in [1] + * + */ + double m_exponent; + + double m_beamwidthRadians; + + double m_orientationRadians; + + double m_maxGain; +}; + + + +} // namespace ns3 + + +#endif // COSINE_ANTENNA_MODEL_H
--- a/src/antenna/model/isotropic-antenna-model.h Fri Dec 16 18:51:18 2011 +0100 +++ b/src/antenna/model/isotropic-antenna-model.h Wed Dec 21 19:36:45 2011 +0100 @@ -28,8 +28,9 @@ namespace ns3 { /** - * Isotropic antenna model + * \brief Isotropic antenna model * + * This is the simplest antenna model. The gain of this antenna is unitary (=0dB) in all directions. */ class IsotropicAntennaModel : public AntennaModel {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/antenna/test/test-cosine-antenna.cc Wed Dec 21 19:36:45 2011 +0100 @@ -0,0 +1,180 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2011 CTTC + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Nicola Baldo <nbaldo@cttc.es> + */ + +#include <ns3/log.h> +#include <ns3/test.h> +#include <ns3/double.h> +#include <ns3/cosine-antenna-model.h> +#include <ns3/simulator.h> +#include <math.h> +#include <string> +#include <iostream> +#include <sstream> + + +NS_LOG_COMPONENT_DEFINE ("TestCosineAntennaModel"); + +namespace ns3 { + +class CosineAntennaModelTestCase : public TestCase +{ +public: + static std::string BuildNameString (AntennaModel::Angles a, double b, double o, double g); + CosineAntennaModelTestCase (AntennaModel::Angles a, double b, double o, double g, double expectedGainDb); + + +private: + virtual void DoRun (void); + + AntennaModel::Angles m_a; + double m_b; + double m_o; + double m_g; + double m_expectedGain; +}; + +std::string CosineAntennaModelTestCase::BuildNameString (AntennaModel::Angles a, double b, double o, double g) +{ + std::ostringstream oss; + oss << "theta=" << a.theta << " , phi=" << a.phi + << ", beamdwidth=" << b << "deg" + << ", orientation=" << o + << ", maxGain=" << g << " dB"; + return oss.str (); +} + + +CosineAntennaModelTestCase::CosineAntennaModelTestCase (AntennaModel::Angles a, double b, double o, double g, double expectedGainDb) + : TestCase (BuildNameString (a, b, o, g)), + m_a (a), + m_b (b), + m_o (o), + m_g (g), + m_expectedGain (expectedGainDb) +{ +} + +void +CosineAntennaModelTestCase::DoRun () +{ + NS_LOG_FUNCTION (this << BuildNameString (m_a, m_b, m_o, m_g)); + + Ptr<CosineAntennaModel> a = CreateObject<CosineAntennaModel> (); + a->SetAttribute ("Beamwidth", DoubleValue (m_b)); + a->SetAttribute ("Orientation", DoubleValue (m_o)); + a->SetAttribute ("MaxGain", DoubleValue (m_g)); + double actualGain = a->GetGainDb (m_a); + NS_TEST_EXPECT_MSG_EQ_TOL (actualGain, m_expectedGain, 0.001, "wrong value of the radiation pattern"); +} + + + + +class CosineAntennaModelTestSuite : public TestSuite +{ +public: + CosineAntennaModelTestSuite (); +}; + +CosineAntennaModelTestSuite::CosineAntennaModelTestSuite () + : TestSuite ("cosine-antenna-model", UNIT) +{ + // phi, theta, beamwidth, orientation, maxGain, expectedGain + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (0), 0), 60, 0, 0, 0)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (30), 0), 60, 0, 0, -3)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-30), 0), 60, 0, 0, -3)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-90), 0), 60, 0, 0, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (90), 0), 60, 0, 0, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (100), 0), 60, 0, 0, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (150), 0), 60, 0, 0, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (180), 0), 60, 0, 0, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-100), 0), 60, 0, 0, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-150), 0), 60, 0, 0, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-180), 0), 60, 0, 0, -INFINITY)); + + // test positive orientation + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (60), 0), 60, 60, 0, 0)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (90), 0), 60, 60, 0, -3)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (30), 0), 60, 60, 0, -3)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-30), 0), 60, 60, 0, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (150), 0), 60, 60, 0, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (160), 0), 60, 60, 0, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (210), 0), 60, 60, 0, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (240), 0), 60, 60, 0, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-40), 0), 60, 60, 0, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-90), 0), 60, 60, 0, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-120), 0), 60, 60, 0, -INFINITY)); + + // test negative orientation and different beamwidth + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-150), 0), 100, -150, 0, 0)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-100), 0), 100, -150, 0, -3)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-200), 0), 100, -150, 0, -3)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-30), 0), 100, -150, 0, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (0), 0), 100, -150, 0, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (60), 0), 100, -150, 0, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (110), 0), 100, -150, 0, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (30), 0), 100, -150, 0, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (90), 0), 100, -150, 0, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (110), 0), 100, -150, 0, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (120), 0), 100, -150, 0, -INFINITY)); + + // test maxGain + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (0), 0), 60, 0, 10, 10)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (30), 0), 60, 0, 22, 19)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-30), 0), 60, 0, -4, -7)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-90), 0), 60, 0, 10, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (90), 0), 60, 0, -20, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (100), 0), 60, 0, 40, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-150), 0), 100, -150, 2, 2)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-100), 0), 100, -150, 4, 1)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-200), 0), 100, -150, -1, -4)); + + + // test elevation angle + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (0), 2), 60, 0, 0, 0)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (30), 2), 60, 0, 0, -3)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-30), 2), 60, 0, 0, -3)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-90), 2), 60, 0, 0, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-180), 2), 60, 0, 0, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (60), -3), 60, 60, 0, 0)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (90), -3), 60, 60, 0, -3)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (30), -3), 60, 60, 0, -3)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-120), -3), 60, 60, 0, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-150), -3), 100, -150, 0, 0)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-100), -3), 100, -150, 0, -3)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-200), -3), 100, -150, 0, -3)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-30), -3), 100, -150, 0, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (120), 9.5), 100, -150, 0, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (0), 9.5), 60, 0, 10, 10)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (30), 9.5), 60, 0, 22, 19)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-30), 9.5), 60, 0, -4, -7)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (100), 9.5), 60, 0, 40, -INFINITY)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-150), 9.5), 100, -150, 2, 2)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-100), 9.5), 100, -150, 4, 1)); + AddTestCase (new CosineAntennaModelTestCase (AntennaModel::Angles (DegreesToRadians (-200), 9.5), 100, -150, -1, -4)); + +}; + +static CosineAntennaModelTestSuite staticCosineAntennaModelTestSuiteInstance; + + + + +} // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/antenna/test/test-degrees-radians.cc Wed Dec 21 19:36:45 2011 +0100 @@ -0,0 +1,139 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2011 CTTC + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Nicola Baldo <nbaldo@cttc.es> + */ + +#include <ns3/log.h> +#include <ns3/test.h> +#include <ns3/antenna-model.h> +#include <math.h> +#include <string> +#include <iostream> +#include <sstream> + +namespace ns3 { + +class DegreesToRadiansTestCase : public TestCase +{ +public: + static std::string BuildNameString (double a); + DegreesToRadiansTestCase (double a, double b); + + +private: + virtual void DoRun (void); + + double m_a; + double m_b; +}; + +std::string DegreesToRadiansTestCase::BuildNameString (double a) +{ + std::ostringstream oss; + oss << "angle = " << a << " degrees"; + return oss.str (); +} + + +DegreesToRadiansTestCase::DegreesToRadiansTestCase (double a, double b) + : TestCase (BuildNameString (a)), + m_a (a), + m_b (b) +{ +} + +void +DegreesToRadiansTestCase::DoRun () +{ + + NS_TEST_EXPECT_MSG_EQ_TOL (DegreesToRadians (m_a), m_b, 1e-10, "wrong conversion"); +} + + + +class RadiansToDegreesTestCase : public TestCase +{ +public: + static std::string BuildNameString (double a); + RadiansToDegreesTestCase (double a, double b); + + +private: + virtual void DoRun (void); + + double m_a; + double m_b; +}; + +std::string RadiansToDegreesTestCase::BuildNameString (double a) +{ + std::ostringstream oss; + oss << "angle = " << a << " degrees"; + return oss.str (); +} + + +RadiansToDegreesTestCase::RadiansToDegreesTestCase (double a, double b) + : TestCase (BuildNameString (a)), + m_a (a), + m_b (b) +{ +} + +void +RadiansToDegreesTestCase::DoRun () +{ + + NS_TEST_EXPECT_MSG_EQ_TOL (RadiansToDegrees (m_a), m_b, 1e-10, "wrong conversion"); +} + + + +class DegreesRadiansTestSuite : public TestSuite +{ +public: + DegreesRadiansTestSuite (); +}; + +DegreesRadiansTestSuite::DegreesRadiansTestSuite () + : TestSuite ("degrees-radians", UNIT) +{ + AddTestCase (new DegreesToRadiansTestCase (0, 0)); + AddTestCase (new DegreesToRadiansTestCase (90, M_PI_2)); + AddTestCase (new DegreesToRadiansTestCase (180, M_PI)); + AddTestCase (new DegreesToRadiansTestCase (270, M_PI + M_PI_2)); + AddTestCase (new DegreesToRadiansTestCase (360, M_PI + M_PI)); + AddTestCase (new DegreesToRadiansTestCase (-90, -M_PI_2)); + AddTestCase (new DegreesToRadiansTestCase (810, 4.5*M_PI)); + + AddTestCase (new RadiansToDegreesTestCase (0, 0)); + AddTestCase (new RadiansToDegreesTestCase (M_PI_2, 90)); + AddTestCase (new RadiansToDegreesTestCase (M_PI, 180)); + AddTestCase (new RadiansToDegreesTestCase (M_PI + M_PI_2, 270)); + AddTestCase (new RadiansToDegreesTestCase (M_PI + M_PI, 360)); + AddTestCase (new RadiansToDegreesTestCase (-M_PI_2, -90)); + AddTestCase (new RadiansToDegreesTestCase (4.5*M_PI, 810)); + +}; + +static DegreesRadiansTestSuite staticDegreesRadiansTestSuiteInstance; + + + + +} // namespace ns3
--- a/src/antenna/wscript Fri Dec 16 18:51:18 2011 +0100 +++ b/src/antenna/wscript Wed Dec 21 19:36:45 2011 +0100 @@ -7,11 +7,14 @@ module.source = [ 'model/antenna-model.cc', 'model/isotropic-antenna-model.cc', + 'model/cosine-antenna-model.cc', ] module_test = bld.create_ns3_module_test_library('antenna') - module_test.source = [ + module_test.source = [ + 'test/test-degrees-radians.cc', 'test/test-isotropic-antenna.cc', + 'test/test-cosine-antenna.cc', ] headers = bld.new_task_gen(features=['ns3header']) @@ -19,6 +22,7 @@ headers.source = [ 'model/antenna-model.h', 'model/isotropic-antenna-model.h', + 'model/cosine-antenna-model.h', ]