src/buildings/model/hybrid-buildings-propagation-loss-model.cc
author John Abraham <john.abraham.in@gmail.com>
Mon, 09 Oct 2017 09:45:32 -0700
changeset 13111 68978885b6fc
parent 10968 2d29fee2b7b8
child 13845 bcd252959302
permissions -rw-r--r--
NetAnim: change documentation to Qt5
     1 /* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
     2 /*
     3  * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License version 2 as
     7  * published by the Free Software Foundation;
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program; if not, write to the Free Software
    16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    17  *
    18  * Author: Marco Miozzo <marco.miozzo@cttc.es>
    19  *         Nicola Baldo <nbaldo@cttc.es>
    20  * 
    21  */
    22 
    23 #include <cmath>
    24 
    25 #include "ns3/log.h"
    26 #include "ns3/mobility-model.h"
    27 #include "ns3/double.h"
    28 #include "ns3/pointer.h"
    29 #include "ns3/okumura-hata-propagation-loss-model.h"
    30 #include "ns3/itu-r-1411-los-propagation-loss-model.h"
    31 #include "ns3/itu-r-1411-nlos-over-rooftop-propagation-loss-model.h"
    32 #include "ns3/itu-r-1238-propagation-loss-model.h"
    33 #include "ns3/kun-2600-mhz-propagation-loss-model.h"
    34 #include <ns3/mobility-building-info.h>
    35 #include "ns3/enum.h"
    36 
    37 #include "hybrid-buildings-propagation-loss-model.h"
    38 
    39 
    40 namespace ns3 {
    41 
    42 NS_LOG_COMPONENT_DEFINE ("HybridBuildingsPropagationLossModel");
    43 
    44 NS_OBJECT_ENSURE_REGISTERED (HybridBuildingsPropagationLossModel);
    45 
    46 
    47 
    48 HybridBuildingsPropagationLossModel::HybridBuildingsPropagationLossModel ()
    49 {
    50   m_okumuraHata = CreateObject<OkumuraHataPropagationLossModel> ();
    51   m_ituR1411Los = CreateObject<ItuR1411LosPropagationLossModel> ();
    52   m_ituR1411NlosOverRooftop = CreateObject<ItuR1411NlosOverRooftopPropagationLossModel> ();
    53   m_ituR1238 = CreateObject<ItuR1238PropagationLossModel> ();
    54   m_kun2600Mhz = CreateObject<Kun2600MhzPropagationLossModel> ();
    55 }
    56 
    57 HybridBuildingsPropagationLossModel::~HybridBuildingsPropagationLossModel ()
    58 {
    59 }
    60 
    61 TypeId
    62 HybridBuildingsPropagationLossModel::GetTypeId (void)
    63 {
    64   static TypeId tid = TypeId ("ns3::HybridBuildingsPropagationLossModel")
    65     
    66     .SetParent<BuildingsPropagationLossModel> ()
    67     
    68     .AddConstructor<HybridBuildingsPropagationLossModel> ()
    69     .SetGroupName ("Buildings")
    70     
    71     .AddAttribute ("Frequency",
    72                    "The Frequency  (default is 2.106 GHz).",
    73                    DoubleValue (2160e6),
    74                    MakeDoubleAccessor (&HybridBuildingsPropagationLossModel::SetFrequency),
    75                    MakeDoubleChecker<double> ())
    76 
    77     .AddAttribute ("Los2NlosThr",
    78                    " Threshold from LoS to NLoS in ITU 1411 [m].",
    79                    DoubleValue (200.0),
    80                    MakeDoubleAccessor (&HybridBuildingsPropagationLossModel::m_itu1411NlosThreshold),
    81                    MakeDoubleChecker<double> ())
    82 
    83     .AddAttribute ("Environment",
    84                    "Environment Scenario",
    85                    EnumValue (UrbanEnvironment),
    86                    MakeEnumAccessor (&HybridBuildingsPropagationLossModel::SetEnvironment),
    87                    MakeEnumChecker (UrbanEnvironment, "Urban",
    88                                     SubUrbanEnvironment, "SubUrban",
    89                                     OpenAreasEnvironment, "OpenAreas"))
    90 
    91     .AddAttribute ("CitySize",
    92                    "Dimension of the city",
    93                    EnumValue (LargeCity),
    94                    MakeEnumAccessor (&HybridBuildingsPropagationLossModel::SetCitySize),
    95                    MakeEnumChecker (SmallCity, "Small",
    96                                     MediumCity, "Medium",
    97                                     LargeCity, "Large"))
    98 
    99     .AddAttribute ("RooftopLevel",
   100                    "The height of the rooftop level in meters",
   101                    DoubleValue (20.0),
   102                    MakeDoubleAccessor (&HybridBuildingsPropagationLossModel::SetRooftopHeight),
   103                    MakeDoubleChecker<double> (0.0, 90.0))
   104 
   105     ;
   106   
   107   return tid;
   108 }
   109 
   110 void
   111 HybridBuildingsPropagationLossModel::SetEnvironment (EnvironmentType env)
   112 {
   113   m_okumuraHata->SetAttribute ("Environment", EnumValue (env));
   114   m_ituR1411NlosOverRooftop->SetAttribute ("Environment", EnumValue (env));
   115 }
   116 
   117 void
   118 HybridBuildingsPropagationLossModel::SetCitySize (CitySize size)
   119 {
   120   m_okumuraHata->SetAttribute ("CitySize", EnumValue (size));
   121   m_ituR1411NlosOverRooftop->SetAttribute ("CitySize", EnumValue (size));
   122 }
   123 
   124 void
   125 HybridBuildingsPropagationLossModel::SetFrequency (double freq)
   126 {
   127   m_okumuraHata->SetAttribute ("Frequency", DoubleValue (freq));
   128   m_ituR1411Los->SetAttribute ("Frequency", DoubleValue (freq));
   129   m_ituR1411NlosOverRooftop->SetAttribute ("Frequency", DoubleValue (freq));
   130   m_ituR1238->SetAttribute ("Frequency", DoubleValue (freq));
   131   m_frequency = freq;
   132 }
   133 
   134 void
   135 HybridBuildingsPropagationLossModel::SetRooftopHeight (double rooftopHeight)
   136 {
   137   m_rooftopHeight = rooftopHeight;
   138   m_ituR1411NlosOverRooftop->SetAttribute ("RooftopLevel", DoubleValue (rooftopHeight));
   139 }
   140 
   141 
   142 double
   143 HybridBuildingsPropagationLossModel::GetLoss (Ptr<MobilityModel> a, Ptr<MobilityModel> b) const
   144 {
   145   NS_ASSERT_MSG ((a->GetPosition ().z >= 0) && (b->GetPosition ().z >= 0), "HybridBuildingsPropagationLossModel does not support underground nodes (placed at z < 0)");
   146 
   147   
   148   double distance = a->GetDistanceFrom (b);
   149 
   150   // get the MobilityBuildingInfo pointers
   151   Ptr<MobilityBuildingInfo> a1 = a->GetObject<MobilityBuildingInfo> ();
   152   Ptr<MobilityBuildingInfo> b1 = b->GetObject<MobilityBuildingInfo> ();
   153   NS_ASSERT_MSG ((a1 != 0) && (b1 != 0), "HybridBuildingsPropagationLossModel only works with MobilityBuildingInfo");
   154 
   155   double loss = 0.0;
   156 
   157   if (a1->IsOutdoor ())
   158     {
   159       if (b1->IsOutdoor ())
   160         {
   161           if (distance > 1000)
   162             {
   163               NS_LOG_INFO (this << a->GetPosition ().z << b->GetPosition ().z << m_rooftopHeight);
   164               if ((a->GetPosition ().z < m_rooftopHeight)
   165                   && (b->GetPosition ().z < m_rooftopHeight))
   166                 {
   167                   loss = ItuR1411 (a, b);
   168                   NS_LOG_INFO (this << " 0-0 (>1000): below rooftop -> ITUR1411 : " << loss);
   169                 }
   170               else
   171                 {
   172                   // Over the rooftop tranmission -> Okumura Hata
   173                   loss = OkumuraHata (a, b);
   174                   NS_LOG_INFO (this << " O-O (>1000): above rooftop -> OH : " << loss);
   175                 }
   176             }
   177           else
   178             {
   179               // short range outdoor communication
   180               loss = ItuR1411 (a, b);
   181               NS_LOG_INFO (this << " 0-0 (<1000) Street canyon -> ITUR1411 : " << loss);
   182             }
   183         }
   184       else
   185         {
   186           // b indoor
   187           if (distance > 1000)
   188             {
   189               if ((a->GetPosition ().z < m_rooftopHeight)
   190                   && (b->GetPosition ().z < m_rooftopHeight))
   191                 {                  
   192                   loss = ItuR1411 (a, b) + ExternalWallLoss (b1) + HeightLoss (b1);
   193                   NS_LOG_INFO (this << " 0-I (>1000): below rooftop -> ITUR1411 : " << loss);
   194                 }
   195               else
   196                 {
   197                   loss = OkumuraHata (a, b) + ExternalWallLoss (b1);
   198                   NS_LOG_INFO (this << " O-I (>1000): above the rooftop -> OH : " << loss);
   199                 }
   200             }
   201           else
   202             {
   203               loss = ItuR1411 (a, b) + ExternalWallLoss (b1) + HeightLoss (b1);
   204               NS_LOG_INFO (this << " 0-I (<1000) ITUR1411 + BEL : " << loss);
   205             }
   206         } // end b1->isIndoor ()
   207     }
   208   else
   209     {
   210       // a is indoor
   211       if (b1->IsIndoor ())
   212         {
   213           if (a1->GetBuilding () == b1->GetBuilding ())
   214             {
   215               // nodes are in same building -> indoor communication ITU-R P.1238
   216               loss = ItuR1238 (a, b) + InternalWallsLoss (a1, b1);;
   217               NS_LOG_INFO (this << " I-I (same building) ITUR1238 : " << loss);
   218 
   219             }
   220           else
   221             {
   222               // nodes are in different buildings
   223               loss = ItuR1411 (a, b) + ExternalWallLoss (a1) + ExternalWallLoss (b1);
   224               NS_LOG_INFO (this << " I-I (different) ITUR1238 + 2*BEL : " << loss);
   225             }
   226         }
   227       else
   228         {
   229           // b is outdoor
   230           if (distance > 1000)
   231             {
   232               if ((a->GetPosition ().z < m_rooftopHeight)
   233                   && (b->GetPosition ().z < m_rooftopHeight))
   234                 {
   235                   loss = ItuR1411 (a, b) + ExternalWallLoss (a1) + HeightLoss (a1);
   236                   NS_LOG_INFO (this << " I-O (>1000): down rooftop -> ITUR1411 : " << loss);
   237                 }
   238               else
   239                 {
   240                   // above rooftop -> OH
   241                   loss = OkumuraHata (a, b) + ExternalWallLoss (a1) + HeightLoss (a1);
   242                   NS_LOG_INFO (this << " =I-O (>1000) over rooftop OH + BEL + HG: " << loss);
   243                 }
   244             }
   245           else
   246             {
   247               loss = ItuR1411 (a, b) + ExternalWallLoss (a1)  + HeightLoss (a1);
   248               NS_LOG_INFO (this << " I-O (<1000)  ITUR1411 + BEL + HG: " << loss);
   249             }
   250         } // end b1->IsIndoor ()
   251     } // end a1->IsOutdoor ()
   252 
   253   loss = std::max (loss, 0.0);
   254 
   255   return loss;
   256 }
   257 
   258 
   259 double
   260 HybridBuildingsPropagationLossModel::OkumuraHata (Ptr<MobilityModel> a, Ptr<MobilityModel> b) const
   261 {
   262   if (m_frequency <= 2.3e9)
   263     {
   264       return m_okumuraHata->GetLoss (a, b);
   265     }
   266   else
   267     {
   268       return m_kun2600Mhz->GetLoss (a, b);
   269     }
   270 }
   271 
   272 double
   273 HybridBuildingsPropagationLossModel::ItuR1411 (Ptr<MobilityModel> a, Ptr<MobilityModel> b) const
   274 {
   275   if (a->GetDistanceFrom (b) < m_itu1411NlosThreshold)
   276     {
   277       return (m_ituR1411Los->GetLoss (a, b));
   278     }
   279   else
   280     {
   281       return (m_ituR1411NlosOverRooftop->GetLoss (a, b));
   282     }
   283 }
   284 
   285 double
   286 HybridBuildingsPropagationLossModel::ItuR1238 (Ptr<MobilityModel> a, Ptr<MobilityModel> b) const
   287 {
   288   return m_ituR1238->GetLoss (a,b);
   289 }
   290 
   291 
   292 } // namespace ns3