57 : TclClass(
"Module/UW/OPTICAL/Propagation")
76 , omnidirectional_(false)
80 , lut_token_separator_(
',')
95 if (strcasecmp(argv[1],
"setOmnidirectional") == 0) {
98 }
else if (strcasecmp(argv[1],
"setDirectional") == 0) {
101 }
else if (strcasecmp(argv[1],
"setVariableC") == 0) {
104 }
else if (strcasecmp(argv[1],
"setFixedC") == 0) {
107 }
else if (strcasecmp(argv[1],
"setLUT") == 0) {
111 }
else if (argc == 3) {
112 if (strcasecmp(argv[1],
"setAr") == 0) {
113 Ar_ = strtod(argv[2], NULL);
115 }
else if (strcasecmp(argv[1],
"setAt") == 0) {
116 At_ = strtod(argv[2], NULL);
118 }
else if (strcasecmp(argv[1],
"setC") == 0) {
119 c_ = strtod(argv[2], NULL);
121 }
else if (strcasecmp(argv[1],
"setTheta") == 0) {
122 theta_ = strtod(argv[2], NULL);
124 }
else if (strcasecmp(argv[1],
"setLUTFileName") == 0) {
125 string tmp_ = ((
char *) argv[2]);
126 if (tmp_.size() == 0) {
127 fprintf(stderr,
"Empty string for the file name");
132 }
else if (strcasecmp(argv[1],
"setLUTSeparator") == 0) {
133 string tmp_ = ((
char *) argv[2]);
134 if (tmp_.size() == 0) {
135 fprintf(stderr,
"Empty char for the file name");
143 return MPropagation::command(argc, argv);
155 std::cout << NOW <<
" UwOpticalMPropagation::updateC depth = " << depth
159 assert(it !=
lut_c_.end());
160 if (it->first == depth) {
161 c_ = it->second.first;
164 assert(it !=
lut_c_.begin());
166 double d_low = it->first;
167 double c_low = it->second.first;
168 double d_up = (++it)->first;
169 double c_up = it->second.first;
176 if (src->getDist(dest) == 0)
178 double src_depth = -src->getAltitude();
179 double dest_depth = -dest->getAltitude();
181 std::cout << NOW <<
" UwOpticalMPropagation::getWossOrientation() "
182 <<
"src_depth = " << src_depth
183 <<
" dest_depth = " << dest_depth
184 <<
" dist = " << dest->getDist(src) << std::endl;
185 double cosBeta = (dest_depth - src_depth) / src->getDist(dest);
186 cosBeta = cosBeta > 1 ? 1 : cosBeta < -1 ? -1 : cosBeta;
187 return asin(cosBeta);
193 hdr_MPhy *ph = HDR_MPHY(p);
194 Position *source = ph->srcPosition;
195 Position *destination = ph->dstPosition;
199 ? (destination->getAltitude() == source->getAltitude()
202 : (source->getZ() == destination->getZ()
205 (source->getRelZenith(destination) > 0
206 ? source->getRelZenith(
208 : -source->getRelZenith(
223 hdr_MPhy *ph = HDR_MPHY(p);
224 Position *source = ph->srcPosition;
225 Position *destination = ph->dstPosition;
226 double destination_depth =
227 use_woss_ ? -destination->getAltitude() : -destination->getZ();
228 double source_depth =
229 use_woss_ ? -source->getAltitude() : -source->getZ();
230 double min_depth_ = min(destination_depth,source_depth);
231 double max_depth_ = max(destination_depth,source_depth);
232 if ((
lut_c_.empty() ==
true) ||
233 (min_depth_ < ((
lut_c_.begin())->first) ||
234 (max_depth_ > ((
lut_c_.rbegin())->first)))) {
241 assert(lower !=
lut_c_.end());
242 if (lower->first > min_depth_) {
243 assert(lower !=
lut_c_.begin());
246 double first_depth = lower->first;
247 double temp_depth = lower->first;
248 double c_temp = lower->second.first;
250 if (lower->first >= max_depth_) {
254 double average_c = 0;
255 for (; lower->first < max_depth_; ++lower) {
256 average_c = average_c + (c_temp + lower->second.first) * (lower->first-temp_depth)/2;
257 temp_depth = lower->first;
258 c_temp = lower->second.first;
261 return average_c / (temp_depth - first_depth);
271 hdr_MPhy *ph = HDR_MPHY(p);
272 Position *source = ph->srcPosition;
273 Position *destination = ph->dstPosition;
280 if (source != 0 || destination != 0) {
284 : -destination->getZ());
285 double dist = source->getDist(destination);
288 std::cout << NOW <<
" UwOpticalMPropagation::getGain()"
289 <<
" dist=" << dist <<
" gain=" << PCgain << std::endl;
291 double destination_depth =
292 use_woss_ ? -destination->getAltitude() : -destination->getZ();
293 double source_depth =
294 use_woss_ ? -source->getAltitude() : -source->getZ();
297 <<
" UwOpticalMPropagation::getGain() destination_depth "
298 << destination_depth <<
" source_depth " << source_depth
301 min(destination_depth, source_depth),
302 max(destination_depth, source_depth));
304 std::cout << NOW <<
" UwOpticalMPropagation::getGain()"
306 <<
" gain=" << PCgain << std::endl;
309 std::cerr <<
"UwOpticalMPropagation::getGain(), source or destination not found";
318 double L = d / cosBeta;
319 double PCgain = 2 *
Ar_ * cosBeta /
320 (M_PI * pow(L, 2.0) * (1 - cos(
theta_)) + 2 *
At_) * exp(-
c_ * d);
321 return (PCgain == PCgain) ? PCgain : 0;
327 ifstream input_file_;
330 if (input_file_.is_open()) {
332 while (std::getline(input_file_, line_)) {
333 ::std::stringstream line_stream(line_);
342 lut_c_[d] = std::make_pair(c, t);
352 double x,
double x1,
double x2,
double y1,
double y2)
354 double m = (y1 - y2) / (x1 - x2);
355 double q = y1 - m * x1;
361 double beta_,
double min_depth_,
double max_depth_)
364 std::cout << NOW <<
" UwOpticalMPropagation::getLambertBeerGain_"
365 "variableC min_depth_ = "
366 << min_depth_ <<
" max_depth_ = " << max_depth_
367 <<
" beta_ = " << beta_ << std::endl;
371 double dist_bottom = 0;
375 if ((
lut_c_.empty() ==
true) ||
376 (min_depth_ < ((
lut_c_.begin())->first) ||
377 (max_depth_ > ((
lut_c_.rbegin())->first))))
380 assert(lower !=
lut_c_.end());
381 if (lower->first > min_depth_) {
382 assert(lower !=
lut_c_.begin());
386 assert(upper !=
lut_c_.end());
387 if (upper->first > max_depth_) {
388 assert(upper !=
lut_c_.begin());
392 double temp_depth = lower->first;
393 double c_temp = lower->second.first;
396 min_depth_, temp_depth, lower->first, c_temp, lower->second.first);
398 temp_depth = upper->first;
399 c_temp = upper->second.first;
402 max_depth_, temp_depth, upper->first, c_temp, upper->second.first);
407 for (; lower != upper; ++lower) {
408 temp_c = lower->second.first;
409 c_med = (prev_c + temp_c) / 2;
411 temp_depth = lower->first;
412 dist_bottom = (temp_depth - min_depth_) / sin(beta_);
413 PCgain = exp(-c_med * (dist_bottom - dist_top)) * PCgain;
414 dist_top = dist_bottom;
417 c_med = (prev_c + c_up) / 2;
418 dist_bottom = (max_depth_ - min_depth_) / sin(beta_);
422 double L_ = dist_bottom /
424 PCgain = exp(-c_med * (dist_bottom - dist_top)) * PCgain;
425 return (PCgain * 2 *
Ar_ * cosBeta /
426 (M_PI * pow(L_, 2) * (1 - cos(
theta_)) + 2 *
At_));
435 assert(it !=
lut_c_.end());
436 if (it->first == depth) {
437 return it->second.second;
440 double d_low = it->first;
441 double t_low = it->second.second;
442 double d_up = (++it)->first;
443 double t_up = it->second.second;
Class that represents the binding with the tcl configuration script.
TclObject * create(int, const char *const *)
Creates the TCL object needed for the tcl language interpretation.
UwOpticalMPropagationClass()
Constructor of the class.
Class used to represents the UWOPTICAL_MPROPAGATION.
virtual double getGain(Packet *p)
Calculate the gain following the Lambert and Beer's law.
bool variable_c_
Flag to set whether the attenuation is constant or not.
double theta_
Transmitting beam diverge angle [rad].
double linearInterpolator(double x, double x1, double x2, double y1, double y2)
Calculate the linear interpolation between two 2-D points.
char lut_token_separator_
LUT token separator.
virtual double getLambertBeerGain(double d, double beta_)
Calculate the gain following the Lambert and Beer's law.
double getLambertBeerGain_variableC(double beta_, double min_depth_, double max_depth_)
Calculate the gain following the Lambert and Beer's law in the case of variable c model.
virtual void initializeLUT()
Inizialize LUT of c_variable values.
bool omnidirectional_
Flag to set whether the system is omnidirectional or not.
double getC(Packet *p=NULL)
Provide the attenuation coefficient.
bool use_woss_
Flag to set the woss.
double getWossOrientation(Position *src, Position *dest)
Calculate the inclination angle between the transmitter and the receiver.
virtual void setWoss(bool flag)
double getTemperature(double depth)
Provide the temperature from LUT.
void updateC(double d)
Set the attenuation coefficient from lookup table when both the nodes are alligned and at the same de...
bool isOmnidirectional()
Provide if we are assuming omnidirectional tx and rx or not.
double c_
Beam light attenuation coefficient c = a + b [m^-1].
virtual int command(int, const char *const *)
TCL command interpreter.
string lut_file_name_
LUT file name.
LUT_c lut_c_
Lookup table map of the attenuation coefficient and the temperature versus the depth.
double getBeta(Packet *p)
Provide angle between transmitter and receiver.
UwOpticalMPropagation()
Constructor of the UwOpticalMPropagation class.
double At_
Transmitter size [m^2].
double Ar_
Receiver area [m^2].
UwOpticalMPropagationClass class_UwOpticalMPropagation
Definition of UwOpticalMPropagation class.
#define NOT_VARIABLE_TEMPERATURE
LUT_c::iterator LUT_c_iter
#define NOT_FOUND_C_VALUE