DESERT 3.5.1
Loading...
Searching...
No Matches
uwem-mpropagation.cpp
Go to the documentation of this file.
1//
2// Copyright (c) 2017 Regents of the SIGNET lab, University of Padova.
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions
7// are met:
8// 1. Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// 2. Redistributions in binary form must reproduce the above copyright
11// notice, this list of conditions and the following disclaimer in the
12// documentation and/or other materials provided with the distribution.
13// 3. Neither the name of the University of Padova (SIGNET lab) nor the
14// names of its contributors may be used to endorse or promote products
15// derived from this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28//
29
39#include <node-core.h>
40#include "uwem-mpropagation.h"
41#include <math.h>
42
43
47static class UwElectroMagneticMPropagationClass : public TclClass {
48public:
49
53 UwElectroMagneticMPropagationClass() : TclClass("Module/UW/ElectroMagnetic/Propagation") {}
58 TclObject* create(int, const char*const*) {
60 }
62
63
65:
66T_(20),
67S_(0)
68{
69 /*bind_error("token_separator_", &token_separator_);*/
70 bind("T_", &T_);
71 bind("S_", &S_);
72 bind("debug_", &debug_);
73}
74
75int UwElectroMagneticMPropagation::command(int argc, const char*const* argv){
76 if (argc == 3) {
77 if (strcasecmp(argv[1], "setT") == 0) {
78 T_ = strtod(argv[2], NULL);
79 return TCL_OK;
80 }
81 else if (strcasecmp(argv[1], "setS") == 0) {
82 S_ = strtod(argv[2], NULL);
83 return TCL_OK;
84 }
85 }
86 return MPropagation::command(argc, argv);
87}
88
90{
91 hdr_MPhy *ph = HDR_MPHY(p);
92 Position* sp = ph->srcPosition;
93 Position* rp = ph->dstPosition;
94 double f_ = ph -> srcSpectralMask-> getFreq();
95
96 assert(sp);
97 assert(rp);
98
99 if(debug_){
100 std::cout << NOW << " UwElectroMagneticMPropagation: Tx position= " << sp -> getX() << " " << sp -> getY() << " " << sp -> getZ() << std::endl;
101 std::cout << NOW << " UwElectroMagneticMPropagation: Rx position= " << rp -> getX() << " " << rp -> getY() << " " << rp -> getZ() << std::endl;
102 }
103
104 double duw;
105 double daw;
106 if(sp -> getZ() < 0 && rp -> getZ() >= 0){
107 duw = fabs(sp -> getZ());
108 daw = sqrt(pow(rp -> getZ(),2) + pow((sp -> getY() - rp -> getY()),2) + pow((sp -> getX() - rp -> getX()),2));
109 }
110 else {
111 if(sp -> getZ() >= 0 && rp -> getZ() < 0){
112 duw = fabs(rp -> getZ());
113 daw = sqrt(pow(sp -> getZ(),2) + pow((sp -> getY() - rp -> getY()),2) + pow((sp -> getX() - rp -> getX()),2));
114 }
115 else {
116 if(sp -> getZ() < 0 && rp -> getZ() < 0){
117 duw = sqrt(pow(sp -> getZ() - rp -> getZ(),2) + pow((sp -> getY() - rp -> getY()),2) + pow((sp -> getX() - rp -> getX()),2));
118 daw = 0;
119 }
120 else
121 cerr << "Devices aren't placed in the right position" << endl;
122 }
123 }
124
125
126 double w = 2 * M_PI * (f_);
127
128 double rel_e[2];
129 getRelativePermittivity(f_,rel_e);
130
131 double sigmaW = rel_e[1] * E_0 * w;
132 double alpha = getAlpha(rel_e,w, sigmaW);
133 double beta = getBeta(rel_e,w,sigmaW);
134
135 double etaW[2];
136 getEtaW(etaW,rel_e,w,sigmaW);
137
138 double modTauSq = getModTauSquared(etaW);
139
140 double PLaw = 0;
141 double PLuw2aw = 0;
142 double PLuw = 0;
143
144 if(daw > 0)
145 PLaw = 20 * log10(daw) + 20 * log10(f_) - 147.5;
146
147 if(daw > 0 && duw > 0)
148 PLuw2aw = 10 * log10(1 / (modTauSq * (etaW[0]/ETA_A)));
149
150 if(duw > 0)
151 PLuw = 8.69 * alpha * duw + 20 * log10(duw) + 20 * log10(beta) + 6;
152
153 double PLtot = PLaw + PLuw2aw + PLuw;
154
155 if (debug_){
156 std::cout << NOW << " UwElectroMagneticMPropagation: distance aw= " << daw << std::endl;
157 std::cout << NOW << " UwElectroMagneticMPropagation: distance uw= " << duw << std::endl;
158 std::cout << NOW << " UwElectroMagneticMPropagation: total attenuation= " << PLtot << std::endl;
159 }
160
161 return PLtot;
162}
163
165{
166 double theta = (300/(T_ + 273.15)) - 1;
167 double es = 77.66 + 103.3 * theta;
168 double e1 = 0.0671 * es;
169 double einf = 3.52 - 7.52 * theta;
170 double f1 = 20.20 - 146.4 * theta + 316 * pow(theta,2);
171 double f2 = 39.8 * f1;
172 double fGhz = f_ / 1e9;
173
174 es = es * exp(-3.56417 * 1e-3 * S_ + 4.74868 * 1e-6 * pow(S_,2) + 1.15574 * 1e-5 * T_ * S_);
175 e1 = e1 * exp(-6.28908 * 1e-3 * S_ + 1.76032 * 1e-4 * pow(S_,2) - 9.22144 * 1e-5 * T_ * S_);
176 einf = einf * (1 + S_* (-2.04265 * 1e-3 + 1.57883 * 1e-4 * T_));
177 f1 = f1 * (1 + S_ * (2.39357 * 1e-3 - 3.13530 * 1e-5 * T_ + 2.52477 * 1e-7 * pow(T_,2)));
178 f2 = f2 * (1 + S_ * (-1.99723 * 1e-2 + 1.81176 * 1e-4 * T_));
179 double sigmaSW = getSigmaSW();
180
181 double a = pow((fGhz/f1),2);
182 double b = pow((fGhz/f2),2);
183
184 e[0] = ((es - e1)/(1 + a)) + ((e1 - einf)/(1 + b)) + einf;
185 e[1] = (((fGhz/f1)*(es - e1))/(1 + a)) + (((fGhz/f2)*(e1 - einf))/(1 + b)) + (18 * sigmaSW)/fGhz;
186
187 if(debug_)
188 std::cout << NOW << " UwElectroMagneticMPropagation: relativePermittivity= " << e[0] << " + "
189 << e[1] << "i" << std::endl;
190}
191
193{
194 double sigma35 = 2.903602 + 8.607 * 1e-2 * T_ + 4.738817 * 1e-4 * pow(T_,2) -2.991 * 1e-6 * pow(T_,3) + 4.3047 * 1e-9 * pow(T_,4);
195 double R35 = S_ * (37.5109+5.45216 * S_ + 1.4409 * 1e-2 * pow (S_,2)) / (1004.75 + 182.283 * S_ + pow(S_,2));
196 double alpha0 = (6.9431 + 3.2841 * S_ -9.9486 * 1e-2 * pow(S_,2)) / (84.850 + 69.024 * S_+ pow(S_,2)) ;
197 double alpha1 = 49.843 - 0.2276*S_ + 0.198 * 1e-2 * pow(S_,2);
198
199 double RT15 = 1 + (alpha0 * (T_ - 15)) / (alpha1 + T_);
200 return sigma35 * R35 * RT15;
201}
202
204 double* rel_e,
205 double w,
206 double sigma
207)
208{
209 double a = MU_0 * rel_e[0] * E_0 / 2;
210 double b = sqrt(1 + pow((sigma /(w * rel_e[0] * E_0)),2)) - 1;
211 double alpha = w * sqrt(a * b);
212 if(debug_)
213 std::cout << NOW << " UwElectroMagneticMPropagation: alpha= " << alpha << std::endl;
214 return alpha;
215}
216
218 double* rel_e,
219 double w,
220 double sigma
221)
222{
223 double a = MU_0 * rel_e[0] * E_0 / 2;
224 double b = sqrt(1 + pow((sigma /(w * rel_e[0] * E_0)),2)) + 1;
225 double beta = w * sqrt(a * b);
226 if(debug_)
227 std::cout << NOW << " UwElectroMagneticMPropagation: beta= " << beta << std::endl;
228 return beta;
229}
230
232 double* etaW,
233 double* rel_e,
234 double w,
235 double sigma
236)
237{
238 double a = MU_0 / (rel_e[0] * E_0);
239 double b = sqrt(1 + pow((sigma/(w * rel_e[0] * E_0)),2));
240 double etaw_m = sqrt(a / b);
241 double etaw_p = 0.5 * atan(sigma / (w * rel_e[0] * E_0));
242 etaW[0] = etaw_m * cos(etaw_p);
243 etaW[1] = etaw_m * sin(etaw_p);
244
245 if(debug_)
246 std::cout << NOW << " UwElectroMagneticMPropagation: etaW= " << etaW[0] << " + "
247 << etaW[1] << "i" << std::endl;
248}
249
251 double* etaW
252)
253{
254 double num_m = pow((2*ETA_A),2);
255 double den_m = pow((etaW[0] + ETA_A),2) + pow(etaW[1],2);
256 if(debug_)
257 std::cout << NOW << " UwElectroMagneticMPropagation: modTauSquared= " << (num_m/den_m) << std::endl;
258 return (num_m/den_m);
259}
260
261
262
263
Class that represents the binding with the tcl configuration script.
UwElectroMagneticMPropagationClass()
Constructor of the class.
TclObject * create(int, const char *const *)
Creates the TCL object needed for the tcl language interpretation.
Class used to represents the UWOPTICAL_MPROPAGATION.
UwElectroMagneticMPropagation()
Constructor of the UwElectroMagneticMPropagation class.
double T_
Temperature [°C].
void getRelativePermittivity(double f_, double *rel_e)
void getEtaW(double *etaW, double *rel_e, double w, double sigma)
double getAlpha(double *rel_e, double w, double sigma)
virtual double getGain(Packet *p)
Calculate the gain of the transmission (attenuation)
virtual int command(int, const char *const *)
TCL command interpreter.
double getModTauSquared(double *etaW)
double getBeta(double *rel_e, double w, double sigma)
double S_
Salinity [(g/kg)^2].
UwElectroMagneticMPropagationClass class_UwElectroMagneticMPropagation
#define ETA_A
#define MU_0
#define E_0