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 "ns3/double.h"
25#include "ns3/enum.h"
26#include "ns3/log.h"
27#include "ns3/mobility-model.h"
28#include "ns3/pointer.h"
29#include "ns3/propagation-loss-model.h"
30#include <ns3/mobility-building-info.h>
31
32#include <cmath>
33
34namespace ns3
35{
36
37NS_LOG_COMPONENT_DEFINE("BuildingsPropagationLossModel");
38
39NS_OBJECT_ENSURE_REGISTERED(BuildingsPropagationLossModel);
40
42{
43}
44
46 Ptr<MobilityModel> receiver)
47 : m_shadowingValue(shadowingValue),
48 m_receiver(receiver)
49{
50 NS_LOG_INFO(this << " New Shadowing value " << m_shadowingValue);
51}
52
53double
55{
56 return (m_shadowingValue);
57}
58
61{
62 return m_receiver;
63}
64
67{
68 static TypeId tid =
69 TypeId("ns3::BuildingsPropagationLossModel")
70
72 .SetGroupName("Buildings")
73
74 .AddAttribute(
75 "ShadowSigmaOutdoor",
76 "Standard deviation of the normal distribution used to calculate the shadowing for "
77 "outdoor nodes",
78 DoubleValue(7.0),
80 MakeDoubleChecker<double>())
81
82 .AddAttribute(
83 "ShadowSigmaIndoor",
84 "Standard deviation of the normal distribution used to calculate the shadowing for "
85 "indoor nodes",
86 DoubleValue(8.0),
88 MakeDoubleChecker<double>())
89 .AddAttribute(
90 "ShadowSigmaExtWalls",
91 "Standard deviation of the normal distribution used to calculate the shadowing due "
92 "to ext walls",
93 DoubleValue(5.0),
95 MakeDoubleChecker<double>())
96
97 .AddAttribute("InternalWallLoss",
98 "Additional loss for each internal wall [dB]",
99 DoubleValue(5.0),
101 MakeDoubleChecker<double>());
102
103 return tid;
104}
105
107{
108 m_randVariable = CreateObject<NormalRandomVariable>();
109}
110
111double
113{
114 double loss = 0.0;
115 Ptr<Building> aBuilding = a->GetBuilding();
116 if (aBuilding->GetExtWallsType() == Building::Wood)
117 {
118 loss = 4;
119 }
120 else if (aBuilding->GetExtWallsType() == Building::ConcreteWithWindows)
121 {
122 loss = 7;
123 }
124 else if (aBuilding->GetExtWallsType() == Building::ConcreteWithoutWindows)
125 {
126 loss = 15; // 10 ~ 20 dB
127 }
128 else if (aBuilding->GetExtWallsType() == Building::StoneBlocks)
129 {
130 loss = 12;
131 }
132 return (loss);
133}
134
135double
137{
138 double loss = 0.0;
139
140 int nfloors = node->GetFloorNumber() - 1;
141 loss = -2 * (nfloors);
142 return (loss);
143}
144
145double
148{
149 // approximate the number of internal walls with the Manhattan distance in "rooms" units
150 double dx = std::abs(a->GetRoomNumberX() - b->GetRoomNumberX());
151 double dy = std::abs(a->GetRoomNumberY() - b->GetRoomNumberY());
152 return m_lossInternalWall * (dx + dy);
153}
154
155double
157{
160 NS_ASSERT_MSG(a1 && b1, "BuildingsPropagationLossModel only works with MobilityBuildingInfo");
161
162 std::map<Ptr<MobilityModel>, std::map<Ptr<MobilityModel>, ShadowingLoss>>::iterator ait =
163 m_shadowingLossMap.find(a);
164 if (ait != m_shadowingLossMap.end())
165 {
166 std::map<Ptr<MobilityModel>, ShadowingLoss>::iterator 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
192double
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
224double
227 Ptr<MobilityModel> b) const
228{
229 return txPowerDbm - GetLoss(a, b) - GetShadowing(a, b);
230}
231
232int64_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:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
#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
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition: double.h:43
#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:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.