added isotropic antenna model with test suite
authorNicola Baldo <nbaldo@cttc.es>
Fri, 16 Dec 2011 18:50:05 +0100
changeset 7829 30080a27a039
parent 7828 13f61df87d67
child 7830 c462e6fad794
added isotropic antenna model with test suite
src/antenna/model/antenna-model.cc
src/antenna/model/isotropic-antenna-model.cc
src/antenna/model/isotropic-antenna-model.h
src/antenna/test/test-isotropic-antenna.cc
src/antenna/wscript
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/antenna/model/antenna-model.cc	Fri Dec 16 18:50:05 2011 +0100
@@ -0,0 +1,67 @@
+/* -*- 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 "antenna-model.h"
+
+
+NS_LOG_COMPONENT_DEFINE ("AntennaModel");
+
+namespace ns3 {
+
+NS_OBJECT_ENSURE_REGISTERED (AntennaModel);
+
+
+AntennaModel::AntennaModel ()
+{
+}
+  
+AntennaModel::~AntennaModel ()
+{
+}
+
+TypeId 
+AntennaModel::GetTypeId ()
+{
+  static TypeId tid = TypeId ("ns3::AntennaModel")
+    .SetParent<Object> ()
+    ;
+  return tid;
+}
+
+  
+  
+AntennaModel::Angles::Angles ()
+  : phi (0),
+    theta (0)
+{
+}
+
+
+AntennaModel::Angles::Angles (double p, double t)
+  : phi (p),
+    theta (t)
+{
+}
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/antenna/model/isotropic-antenna-model.cc	Fri Dec 16 18:50:05 2011 +0100
@@ -0,0 +1,51 @@
+/* -*- 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 "antenna-model.h"
+#include "isotropic-antenna-model.h"
+
+
+NS_LOG_COMPONENT_DEFINE ("IsotropicAntennaModel");
+
+namespace ns3 {
+
+NS_OBJECT_ENSURE_REGISTERED (IsotropicAntennaModel);
+
+
+TypeId 
+IsotropicAntennaModel::GetTypeId ()
+{
+  static TypeId tid = TypeId ("ns3::IsotropicAntennaModel")
+    .SetParent<AntennaModel> ()
+    ;
+  return tid;
+}
+
+double 
+IsotropicAntennaModel::GetGainDb (Angles a)
+{
+  return 0.0;
+}
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/antenna/model/isotropic-antenna-model.h	Fri Dec 16 18:50:05 2011 +0100
@@ -0,0 +1,50 @@
+/* -*- 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 ISOTROPIC_ANTENNA_MODEL_H
+#define ISOTROPIC_ANTENNA_MODEL_H
+
+
+#include <ns3/object.h>
+#include <ns3/antenna-model.h>
+
+namespace ns3 {
+
+/**
+ * Isotropic antenna model
+ * 
+ */
+class IsotropicAntennaModel : public AntennaModel
+{
+public:
+
+  // inherited from Object
+  static TypeId GetTypeId ();
+
+  // inherited from AntennaModel
+  virtual double GetGainDb (Angles a);
+};
+
+
+
+} // namespace ns3
+
+
+#endif // ISOTROPIC_ANTENNA_MODEL_H
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/antenna/test/test-isotropic-antenna.cc	Fri Dec 16 18:50:05 2011 +0100
@@ -0,0 +1,97 @@
+/* -*- 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/isotropic-antenna-model.h>
+#include <math.h>
+#include <string>
+#include <iostream>
+#include <sstream>
+
+namespace ns3 {
+
+class IsotropicAntennaModelTestCase : public TestCase
+{
+public:
+  static std::string BuildNameString (AntennaModel::Angles a);
+  IsotropicAntennaModelTestCase (AntennaModel::Angles a, double expectedGainDb);
+
+
+private:
+  virtual void DoRun (void);
+
+  AntennaModel::Angles m_a;
+  double m_expectedGain;
+};
+
+std::string IsotropicAntennaModelTestCase::BuildNameString (AntennaModel::Angles a)
+{
+  std::ostringstream oss;
+  oss <<  "theta=" << a.theta << " , phi=" << a.phi;
+  return oss.str ();
+}
+
+
+IsotropicAntennaModelTestCase::IsotropicAntennaModelTestCase (AntennaModel::Angles a, double expectedGainDb)
+  : TestCase (BuildNameString (a)),
+    m_a (a),
+    m_expectedGain (expectedGainDb)
+{
+}
+
+void
+IsotropicAntennaModelTestCase::DoRun ()
+{
+  Ptr<IsotropicAntennaModel> a = Create<IsotropicAntennaModel> ();
+  double actualGain = a->GetGainDb (m_a);
+  NS_TEST_EXPECT_MSG_EQ_TOL (actualGain, m_expectedGain, 0.01, "wrong value of the radiation pattern");
+}
+
+
+
+
+class IsotropicAntennaModelTestSuite : public TestSuite
+{
+public:
+  IsotropicAntennaModelTestSuite ();
+};
+
+IsotropicAntennaModelTestSuite::IsotropicAntennaModelTestSuite ()
+  : TestSuite ("isotropic-antenna-model", UNIT)
+{
+  AddTestCase (new IsotropicAntennaModelTestCase (AntennaModel::Angles (0, 0),           0.0));
+  AddTestCase (new IsotropicAntennaModelTestCase (AntennaModel::Angles (0, M_PI),        0.0));
+  AddTestCase (new IsotropicAntennaModelTestCase (AntennaModel::Angles (0, M_PI_2),      0.0));
+  AddTestCase (new IsotropicAntennaModelTestCase (AntennaModel::Angles (M_PI, 0),        0.0));
+  AddTestCase (new IsotropicAntennaModelTestCase (AntennaModel::Angles (M_PI, M_PI),     0.0));
+  AddTestCase (new IsotropicAntennaModelTestCase (AntennaModel::Angles (M_PI, M_PI_2),   0.0));
+  AddTestCase (new IsotropicAntennaModelTestCase (AntennaModel::Angles (M_PI_2, 0),      0.0));
+  AddTestCase (new IsotropicAntennaModelTestCase (AntennaModel::Angles (M_PI_2, M_PI),   0.0));
+  AddTestCase (new IsotropicAntennaModelTestCase (AntennaModel::Angles (M_PI_2, M_PI_2), 0.0));
+
+};
+
+static IsotropicAntennaModelTestSuite staticIsotropicAntennaModelTestSuiteInstance;
+
+
+
+
+} // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/antenna/wscript	Fri Dec 16 18:50:05 2011 +0100
@@ -0,0 +1,27 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+
+    module = bld.create_ns3_module('antenna', ['core'])
+
+    module.source = [
+        'model/antenna-model.cc',
+        'model/isotropic-antenna-model.cc',	
+	 ]		
+	 
+    module_test = bld.create_ns3_module_test_library('antenna')
+    module_test.source = [	
+        'test/test-isotropic-antenna.cc',
+        ]
+    
+    headers = bld.new_task_gen(features=['ns3header'])
+    headers.module = 'antenna'
+    headers.source = [
+        'model/antenna-model.h',
+        'model/isotropic-antenna-model.h',		
+	]
+    
+
+
+
+