src/buildings/model/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
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 "ns3/propagation-loss-model.h"
    24 #include "ns3/log.h"
    25 #include "ns3/mobility-model.h"
    26 #include "ns3/double.h"
    27 #include "ns3/pointer.h"
    28 #include <cmath>
    29 #include "buildings-propagation-loss-model.h"
    30 #include <ns3/mobility-building-info.h>
    31 #include "ns3/enum.h"
    32 
    33 
    34 namespace ns3 {
    35 
    36 NS_LOG_COMPONENT_DEFINE ("BuildingsPropagationLossModel");
    37 
    38 NS_OBJECT_ENSURE_REGISTERED (BuildingsPropagationLossModel);
    39 
    40 BuildingsPropagationLossModel::ShadowingLoss::ShadowingLoss ()
    41 {
    42 }
    43 
    44 BuildingsPropagationLossModel::ShadowingLoss::ShadowingLoss (double shadowingValue, Ptr<MobilityModel> receiver)
    45   : m_shadowingValue (shadowingValue), m_receiver (receiver)
    46 {
    47   NS_LOG_INFO (this << " New Shadowing value " << m_shadowingValue);
    48 }
    49 
    50 double
    51 BuildingsPropagationLossModel::ShadowingLoss::GetLoss () const
    52 {
    53   return (m_shadowingValue);
    54 }
    55 
    56 Ptr<MobilityModel>
    57 BuildingsPropagationLossModel::ShadowingLoss::GetReceiver () const
    58 {
    59   return m_receiver;
    60 }
    61 
    62 TypeId
    63 BuildingsPropagationLossModel::GetTypeId (void)
    64 {
    65   static TypeId tid = TypeId ("ns3::BuildingsPropagationLossModel")
    66 
    67     .SetParent<PropagationLossModel> ()
    68     .SetGroupName ("Buildings")
    69 
    70 
    71     .AddAttribute ("ShadowSigmaOutdoor",
    72                    "Standard deviation of the normal distribution used for calculate the shadowing for outdoor nodes",
    73                    DoubleValue (7.0),
    74                    MakeDoubleAccessor (&BuildingsPropagationLossModel::m_shadowingSigmaOutdoor),
    75                    MakeDoubleChecker<double> ())
    76 
    77     .AddAttribute ("ShadowSigmaIndoor",
    78                    "Standard deviation of the normal distribution used for calculate the shadowing for indoor nodes ",
    79                    DoubleValue (8.0),
    80                    MakeDoubleAccessor (&BuildingsPropagationLossModel::m_shadowingSigmaIndoor),
    81                    MakeDoubleChecker<double> ())
    82     .AddAttribute ("ShadowSigmaExtWalls",
    83                    "Standard deviation of the normal distribution used for calculate the shadowing due to ext walls ",
    84                    DoubleValue (5.0),
    85                    MakeDoubleAccessor (&BuildingsPropagationLossModel::m_shadowingSigmaExtWalls),
    86                    MakeDoubleChecker<double> ())
    87 
    88     .AddAttribute ("InternalWallLoss",
    89                    "Additional loss for each internal wall [dB]",
    90                    DoubleValue (5.0),
    91                    MakeDoubleAccessor (&BuildingsPropagationLossModel::m_lossInternalWall),
    92                    MakeDoubleChecker<double> ());
    93 
    94 
    95   return tid;
    96 }
    97 
    98 BuildingsPropagationLossModel::BuildingsPropagationLossModel ()
    99 {
   100   m_randVariable = CreateObject<NormalRandomVariable> ();
   101 }
   102 
   103 double
   104 BuildingsPropagationLossModel::ExternalWallLoss (Ptr<MobilityBuildingInfo> a) const
   105 {
   106   double loss = 0.0;
   107   Ptr<Building> aBuilding = a->GetBuilding ();
   108   if (aBuilding->GetExtWallsType () == Building::Wood)
   109     {
   110       loss = 4;
   111     }
   112   else if (aBuilding->GetExtWallsType () == Building::ConcreteWithWindows)
   113     {
   114       loss = 7;
   115     }
   116   else if (aBuilding->GetExtWallsType () == Building::ConcreteWithoutWindows)
   117     {
   118       loss = 15; // 10 ~ 20 dB
   119     }
   120   else if (aBuilding->GetExtWallsType () == Building::StoneBlocks)
   121     {
   122       loss = 12;
   123     }
   124   return (loss);
   125 }
   126 
   127 double
   128 BuildingsPropagationLossModel::HeightLoss (Ptr<MobilityBuildingInfo> node) const
   129 {
   130   double loss = 0.0;
   131 
   132   int nfloors  = node->GetFloorNumber () - 1;
   133   loss = -2 * (nfloors);
   134   return (loss);
   135 }
   136 
   137 double
   138 BuildingsPropagationLossModel::InternalWallsLoss (Ptr<MobilityBuildingInfo> a, Ptr<MobilityBuildingInfo>b) const
   139 {
   140   // approximate the number of internal walls with the Manhattan distance in "rooms" units
   141   double dx = std::abs (a->GetRoomNumberX () - b->GetRoomNumberX ());
   142   double dy = std::abs (a->GetRoomNumberY () - b->GetRoomNumberY ());    
   143   return m_lossInternalWall * (dx+dy);
   144 }
   145 
   146 
   147 
   148 double
   149 BuildingsPropagationLossModel::GetShadowing (Ptr<MobilityModel> a, Ptr<MobilityModel> b)
   150 const
   151 {
   152     Ptr<MobilityBuildingInfo> a1 = a->GetObject <MobilityBuildingInfo> ();
   153     Ptr<MobilityBuildingInfo> b1 = b->GetObject <MobilityBuildingInfo> ();
   154     NS_ASSERT_MSG ((a1 != 0) && (b1 != 0), "BuildingsPropagationLossModel only works with MobilityBuildingInfo");
   155   
   156   std::map<Ptr<MobilityModel>,  std::map<Ptr<MobilityModel>, ShadowingLoss> >::iterator ait = m_shadowingLossMap.find (a);
   157   if (ait != m_shadowingLossMap.end ())
   158     {
   159       std::map<Ptr<MobilityModel>, ShadowingLoss>::iterator bit = ait->second.find (b);
   160       if (bit != ait->second.end ())
   161         {
   162           return (bit->second.GetLoss ());
   163         }
   164       else
   165         {
   166           double sigma = EvaluateSigma (a1, b1);
   167           // side effect: will create new entry          
   168           // sigma is standard deviation, not variance
   169           double shadowingValue = m_randVariable->GetValue (0.0, (sigma*sigma));
   170           ait->second[b] = ShadowingLoss (shadowingValue, b);          
   171           return (ait->second[b].GetLoss ());
   172         }
   173     }
   174   else
   175     {
   176       double sigma = EvaluateSigma (a1, b1);
   177       // side effect: will create new entries in both maps
   178       // sigma is standard deviation, not variance
   179       double shadowingValue = m_randVariable->GetValue (0.0, (sigma*sigma));
   180       m_shadowingLossMap[a][b] = ShadowingLoss (shadowingValue, b);  
   181       return (m_shadowingLossMap[a][b].GetLoss ());       
   182     }
   183 }
   184 
   185 
   186 
   187 double
   188 BuildingsPropagationLossModel::EvaluateSigma (Ptr<MobilityBuildingInfo> a, Ptr<MobilityBuildingInfo> b)
   189 const
   190 {
   191   if (a->IsOutdoor ())
   192     {
   193       if (b->IsOutdoor ())
   194         {
   195           return (m_shadowingSigmaOutdoor);
   196         }
   197       else
   198         {
   199           double sigma = std::sqrt ((m_shadowingSigmaOutdoor * m_shadowingSigmaOutdoor) + (m_shadowingSigmaExtWalls * m_shadowingSigmaExtWalls));
   200           return (sigma);
   201         }
   202     }
   203   else
   204   if (b->IsIndoor ())
   205     {
   206       return (m_shadowingSigmaIndoor);
   207     }
   208   else
   209     {
   210       double sigma = std::sqrt ((m_shadowingSigmaOutdoor * m_shadowingSigmaOutdoor) + (m_shadowingSigmaExtWalls * m_shadowingSigmaExtWalls));
   211       return (sigma);
   212     }
   213 }
   214 
   215 
   216 double
   217 BuildingsPropagationLossModel::DoCalcRxPower (double txPowerDbm, Ptr<MobilityModel> a, Ptr<MobilityModel> b) const
   218 {
   219   return txPowerDbm - GetLoss (a, b) - GetShadowing (a, b);
   220 }
   221 
   222 int64_t
   223 BuildingsPropagationLossModel::DoAssignStreams (int64_t stream)
   224 {
   225   m_randVariable->SetStream (stream);
   226   return 1;
   227 }
   228 
   229 
   230 } // namespace ns3