A Discrete-Event Network Simulator
API
buildings-propagation-loss-model.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Marco Miozzo <marco.miozzo@cttc.es>,
18  * Nicola Baldo <nbaldo@cttc.es>
19  *
20  */
21 
23 
24 #include "mobility-building-info.h"
25 
26 #include "ns3/double.h"
27 #include "ns3/enum.h"
28 #include "ns3/log.h"
29 #include "ns3/mobility-model.h"
30 #include "ns3/pointer.h"
31 #include "ns3/propagation-loss-model.h"
32 
33 #include <cmath>
34 
35 namespace ns3
36 {
37 
38 NS_LOG_COMPONENT_DEFINE("BuildingsPropagationLossModel");
39 
40 NS_OBJECT_ENSURE_REGISTERED(BuildingsPropagationLossModel);
41 
43 {
44 }
45 
47  Ptr<MobilityModel> receiver)
48  : m_shadowingValue(shadowingValue),
49  m_receiver(receiver)
50 {
51  NS_LOG_INFO(this << " New Shadowing value " << m_shadowingValue);
52 }
53 
54 double
56 {
57  return m_shadowingValue;
58 }
59 
62 {
63  return m_receiver;
64 }
65 
66 TypeId
68 {
69  static TypeId tid =
70  TypeId("ns3::BuildingsPropagationLossModel")
71 
73  .SetGroupName("Buildings")
74 
75  .AddAttribute(
76  "ShadowSigmaOutdoor",
77  "Standard deviation of the normal distribution used to calculate the shadowing for "
78  "outdoor nodes",
79  DoubleValue(7.0),
81  MakeDoubleChecker<double>())
82 
83  .AddAttribute(
84  "ShadowSigmaIndoor",
85  "Standard deviation of the normal distribution used to calculate the shadowing for "
86  "indoor nodes",
87  DoubleValue(8.0),
89  MakeDoubleChecker<double>())
90  .AddAttribute(
91  "ShadowSigmaExtWalls",
92  "Standard deviation of the normal distribution used to calculate the shadowing due "
93  "to ext walls",
94  DoubleValue(5.0),
96  MakeDoubleChecker<double>())
97 
98  .AddAttribute("InternalWallLoss",
99  "Additional loss for each internal wall [dB]",
100  DoubleValue(5.0),
102  MakeDoubleChecker<double>());
103 
104  return tid;
105 }
106 
108 {
109  m_randVariable = CreateObject<NormalRandomVariable>();
110 }
111 
112 double
114 {
115  double loss = 0.0;
116  Ptr<Building> aBuilding = a->GetBuilding();
117  if (aBuilding->GetExtWallsType() == Building::Wood)
118  {
119  loss = 4;
120  }
121  else if (aBuilding->GetExtWallsType() == Building::ConcreteWithWindows)
122  {
123  loss = 7;
124  }
125  else if (aBuilding->GetExtWallsType() == Building::ConcreteWithoutWindows)
126  {
127  loss = 15; // 10 ~ 20 dB
128  }
129  else if (aBuilding->GetExtWallsType() == Building::StoneBlocks)
130  {
131  loss = 12;
132  }
133  return loss;
134 }
135 
136 double
138 {
139  double loss = 0.0;
140 
141  int nfloors = node->GetFloorNumber() - 1;
142  loss = -2 * (nfloors);
143  return loss;
144 }
145 
146 double
149 {
150  // approximate the number of internal walls with the Manhattan distance in "rooms" units
151  double dx = std::abs(a->GetRoomNumberX() - b->GetRoomNumberX());
152  double dy = std::abs(a->GetRoomNumberY() - b->GetRoomNumberY());
153  return m_lossInternalWall * (dx + dy);
154 }
155 
156 double
158 {
161  NS_ASSERT_MSG(a1 && b1, "BuildingsPropagationLossModel only works with MobilityBuildingInfo");
162 
163  auto ait = m_shadowingLossMap.find(a);
164  if (ait != m_shadowingLossMap.end())
165  {
166  auto bit = ait->second.find(b);
167  if (bit != ait->second.end())
168  {
169  return bit->second.GetLoss();
170  }
171  else
172  {
173  double sigma = EvaluateSigma(a1, b1);
174  // side effect: will create new entry
175  // sigma is standard deviation, not variance
176  double shadowingValue = m_randVariable->GetValue(0.0, (sigma * sigma));
177  ait->second[b] = ShadowingLoss(shadowingValue, b);
178  return ait->second[b].GetLoss();
179  }
180  }
181  else
182  {
183  double sigma = EvaluateSigma(a1, b1);
184  // side effect: will create new entries in both maps
185  // sigma is standard deviation, not variance
186  double shadowingValue = m_randVariable->GetValue(0.0, (sigma * sigma));
187  m_shadowingLossMap[a][b] = ShadowingLoss(shadowingValue, b);
188  return m_shadowingLossMap[a][b].GetLoss();
189  }
190 }
191 
192 double
195 {
196  bool isAIndoor = a->IsIndoor();
197  bool isBIndoor = b->IsIndoor();
198 
199  if (!isAIndoor) // a is outdoor
200  {
201  if (!isBIndoor) // b is outdoor
202  {
204  }
205  else
206  {
207  double sigma = std::sqrt((m_shadowingSigmaOutdoor * m_shadowingSigmaOutdoor) +
209  return sigma;
210  }
211  }
212  else if (isBIndoor) // b is indoor
213  {
214  return m_shadowingSigmaIndoor;
215  }
216  else
217  {
218  double sigma = std::sqrt((m_shadowingSigmaOutdoor * m_shadowingSigmaOutdoor) +
220  return sigma;
221  }
222 }
223 
224 double
227  Ptr<MobilityModel> b) const
228 {
229  return txPowerDbm - GetLoss(a, b) - GetShadowing(a, b);
230 }
231 
232 int64_t
234 {
235  m_randVariable->SetStream(stream);
236  return 1;
237 }
238 
239 } // namespace ns3
@ ConcreteWithWindows
Definition: building.h:63
@ ConcreteWithoutWindows
Definition: building.h:64
This model allows the computation of shadowing loss.
double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const override
PropagationLossModel.
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.
double ExternalWallLoss(Ptr< MobilityBuildingInfo > a) const
Calculate the external wall loss.
int64_t DoAssignStreams(int64_t stream) override
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:42
mobility buildings information (to be used by mobility models)
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
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:931
#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:86
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition: double.h:43