A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
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>
29
#include "
buildings-propagation-loss-model.h
"
30
#include "ns3/buildings-mobility-model.h"
31
#include "ns3/enum.h"
32
33
34
NS_LOG_COMPONENT_DEFINE
(
"BuildingsPropagationLossModel"
);
35
36
namespace
ns3 {
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
69
70
.AddAttribute (
"ShadowSigmaOutdoor"
,
71
"Standard deviation of the normal distribution used for calculate the shadowing for outdoor nodes"
,
72
DoubleValue
(7.0),
73
MakeDoubleAccessor (&
BuildingsPropagationLossModel::m_shadowingSigmaOutdoor
),
74
MakeDoubleChecker<double> ())
75
76
.AddAttribute (
"ShadowSigmaIndoor"
,
77
"Standard deviation of the normal distribution used for calculate the shadowing for indoor nodes "
,
78
DoubleValue
(8.0),
79
MakeDoubleAccessor (&
BuildingsPropagationLossModel::m_shadowingSigmaIndoor
),
80
MakeDoubleChecker<double> ())
81
.AddAttribute (
"ShadowSigmaExtWalls"
,
82
"Standard deviation of the normal distribution used for calculate the shadowing due to ext walls "
,
83
DoubleValue
(5.0),
84
MakeDoubleAccessor (&
BuildingsPropagationLossModel::m_shadowingSigmaExtWalls
),
85
MakeDoubleChecker<double> ())
86
87
.AddAttribute (
"InternalWallLoss"
,
88
"Additional loss for each internal wall [dB]"
,
89
DoubleValue
(5.0),
90
MakeDoubleAccessor (&
BuildingsPropagationLossModel::m_lossInternalWall
),
91
MakeDoubleChecker<double> ());
92
93
94
return
tid;
95
}
96
97
BuildingsPropagationLossModel::BuildingsPropagationLossModel
()
98
{
99
m_randVariable
= CreateObject<NormalRandomVariable> ();
100
}
101
102
double
103
BuildingsPropagationLossModel::ExternalWallLoss
(
Ptr<BuildingsMobilityModel>
a)
const
104
{
105
double
loss = 0.0;
106
Ptr<Building>
aBuilding = a->
GetBuilding
();
107
if
(aBuilding->
GetExtWallsType
() ==
Building::Wood
)
108
{
109
loss = 4;
110
}
111
else
if
(aBuilding->
GetExtWallsType
() ==
Building::ConcreteWithWindows
)
112
{
113
loss = 7;
114
}
115
else
if
(aBuilding->
GetExtWallsType
() ==
Building::ConcreteWithoutWindows
)
116
{
117
loss = 15;
// 10 ~ 20 dB
118
}
119
else
if
(aBuilding->
GetExtWallsType
() ==
Building::StoneBlocks
)
120
{
121
loss = 12;
122
}
123
return
(loss);
124
}
125
126
double
127
BuildingsPropagationLossModel::HeightLoss
(
Ptr<BuildingsMobilityModel>
node)
const
128
{
129
double
loss = 0.0;
130
131
int
nfloors = node->
GetFloorNumber
() - 1;
132
loss = -2 * (nfloors);
133
return
(loss);
134
}
135
136
double
137
BuildingsPropagationLossModel::InternalWallsLoss
(
Ptr<BuildingsMobilityModel>
a,
Ptr<BuildingsMobilityModel>
b)
const
138
{
139
// approximate the number of internal walls with the Manhattan distance in "rooms" units
140
double
dx = abs (a->
GetRoomNumberX
() - b->
GetRoomNumberX
());
141
double
dy = abs (a->
GetRoomNumberY
() - b->
GetRoomNumberY
());
142
return
m_lossInternalWall
* (dx+dy);
143
}
144
145
146
147
double
148
BuildingsPropagationLossModel::GetShadowing
(
Ptr<MobilityModel>
a,
Ptr<MobilityModel>
b)
149
const
150
{
151
Ptr<BuildingsMobilityModel>
a1 = DynamicCast<BuildingsMobilityModel> (a);
152
Ptr<BuildingsMobilityModel>
b1 = DynamicCast<BuildingsMobilityModel> (b);
153
NS_ASSERT_MSG
((a1 != 0) && (b1 != 0),
"BuildingsPropagationLossModel only works with BuildingsMobilityModel"
);
154
155
std::map<Ptr<MobilityModel>, std::map<Ptr<MobilityModel>,
ShadowingLoss
> >::iterator ait =
m_shadowingLossMap
.find (a);
156
if
(ait !=
m_shadowingLossMap
.end ())
157
{
158
std::map<Ptr<MobilityModel>,
ShadowingLoss
>::iterator bit = ait->second.find (b);
159
if
(bit != ait->second.end ())
160
{
161
return
(bit->second.GetLoss ());
162
}
163
else
164
{
165
double
sigma =
EvaluateSigma
(a1, b1);
166
// side effect: will create new entry
167
// sigma is standard deviation, not variance
168
double
shadowingValue =
m_randVariable
->
GetValue
(0.0, (sigma*sigma));
169
ait->second[b] =
ShadowingLoss
(shadowingValue, b);
170
return
(ait->second[b].GetLoss ());
171
}
172
}
173
else
174
{
175
double
sigma =
EvaluateSigma
(a1, b1);
176
// side effect: will create new entries in both maps
177
// sigma is standard deviation, not variance
178
double
shadowingValue =
m_randVariable
->
GetValue
(0.0, (sigma*sigma));
179
m_shadowingLossMap
[a][b] =
ShadowingLoss
(shadowingValue, b);
180
return
(
m_shadowingLossMap
[a][b].
GetLoss
());
181
}
182
}
183
184
185
186
double
187
BuildingsPropagationLossModel::EvaluateSigma
(
Ptr<BuildingsMobilityModel>
a,
Ptr<BuildingsMobilityModel>
b)
188
const
189
{
190
if
(a->
IsOutdoor
())
191
{
192
if
(b->
IsOutdoor
())
193
{
194
return
(
m_shadowingSigmaOutdoor
);
195
}
196
else
197
{
198
double
sigma = sqrt ((
m_shadowingSigmaOutdoor
*
m_shadowingSigmaOutdoor
) + (
m_shadowingSigmaExtWalls
*
m_shadowingSigmaExtWalls
));
199
return
(sigma);
200
}
201
}
202
else
203
if
(b->
IsIndoor
())
204
{
205
return
(
m_shadowingSigmaIndoor
);
206
}
207
else
208
{
209
double
sigma = sqrt ((
m_shadowingSigmaOutdoor
*
m_shadowingSigmaOutdoor
) + (
m_shadowingSigmaExtWalls
*
m_shadowingSigmaExtWalls
));
210
return
(sigma);
211
}
212
}
213
214
215
double
216
BuildingsPropagationLossModel::DoCalcRxPower
(
double
txPowerDbm,
Ptr<MobilityModel>
a,
Ptr<MobilityModel>
b)
const
217
{
218
return
txPowerDbm -
GetLoss
(a, b) -
GetShadowing
(a, b);
219
}
220
221
int64_t
222
BuildingsPropagationLossModel::DoAssignStreams
(int64_t stream)
223
{
224
m_randVariable
->
SetStream
(stream);
225
return
1;
226
}
227
228
229
}
// namespace ns3
src
buildings
model
buildings-propagation-loss-model.cc
Generated on Tue Nov 13 2012 10:32:09 for ns-3 by
1.8.1.2