A Discrete-Event Network Simulator
API
buildings-propagation-loss-model.cc
Go to the documentation of this file.
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>
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 
41 {
42 }
43 
45  : m_shadowingValue (shadowingValue), m_receiver (receiver)
46 {
47  NS_LOG_INFO (this << " New Shadowing value " << m_shadowingValue);
48 }
49 
50 double
52 {
53  return (m_shadowingValue);
54 }
55 
58 {
59  return m_receiver;
60 }
61 
62 TypeId
64 {
65  static TypeId tid = TypeId ("ns3::BuildingsPropagationLossModel")
66 
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),
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),
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),
86  MakeDoubleChecker<double> ())
87 
88  .AddAttribute ("InternalWallLoss",
89  "Additional loss for each internal wall [dB]",
90  DoubleValue (5.0),
92  MakeDoubleChecker<double> ());
93 
94 
95  return tid;
96 }
97 
99 {
100  m_randVariable = CreateObject<NormalRandomVariable> ();
101 }
102 
103 double
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
129 {
130  double loss = 0.0;
131 
132  int nfloors = node->GetFloorNumber () - 1;
133  loss = -2 * (nfloors);
134  return (loss);
135 }
136 
137 double
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
150 const
151 {
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
189 const
190 {
191  bool isAIndoor = a->IsIndoor ();
192  bool isBIndoor = b->IsIndoor ();
193 
194  if (!isAIndoor) // a is outdoor
195  {
196  if (!isBIndoor) // b is outdoor
197  {
198  return (m_shadowingSigmaOutdoor);
199  }
200  else
201  {
203  return (sigma);
204  }
205  }
206  else
207  if (isBIndoor) // b is indoor
208  {
209  return (m_shadowingSigmaIndoor);
210  }
211  else
212  {
214  return (sigma);
215  }
216 }
217 
218 
219 double
221 {
222  return txPowerDbm - GetLoss (a, b) - GetShadowing (a, b);
223 }
224 
225 int64_t
227 {
228  m_randVariable->SetStream (stream);
229  return 1;
230 }
231 
232 
233 } // namespace ns3
@ ConcreteWithWindows
Definition: building.h:60
@ ConcreteWithoutWindows
Definition: building.h:60
This model allows the computation of shadowing loss.
static TypeId GetTypeId(void)
Get the type ID.
std::map< Ptr< MobilityModel >, std::map< Ptr< MobilityModel >, ShadowingLoss > > m_shadowingLossMap
Map of the shadowng loss.
double GetShadowing(Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Calculate the shadowing loss.
double HeightLoss(Ptr< MobilityBuildingInfo > n) const
Calculate the height loss.
double m_shadowingSigmaOutdoor
Standard deviation of the normal distribution used to calculate the shadowing for outdoor nodes.
virtual double GetLoss(Ptr< MobilityModel > a, Ptr< MobilityModel > b) const =0
double m_shadowingSigmaExtWalls
Standard deviation of the normal distribution used to calculate the shadowing due to ext walls.
double m_shadowingSigmaIndoor
Standard deviation of the normal distribution used to calculate the shadowing for indoor nodes.
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
PropagationLossModel.
double ExternalWallLoss(Ptr< MobilityBuildingInfo > a) const
Calculate the external wall loss.
virtual int64_t DoAssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
double m_lossInternalWall
loss from internal walls (in dBm)
double EvaluateSigma(Ptr< MobilityBuildingInfo > a, Ptr< MobilityBuildingInfo > b) const
Calculate the Standard deviation of the normal distribution used to calculate the shadowing.
Ptr< NormalRandomVariable > m_randVariable
Random variable.
double InternalWallsLoss(Ptr< MobilityBuildingInfo > a, Ptr< MobilityBuildingInfo > b) const
Calculate the internal wall loss.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
mobility buildings information (to be used by mobility models)
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
Models the propagation loss through a transmission medium.
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:88
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: double.h:42
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.