tworayground.cc

Go to the documentation of this file.
00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 /*
00003  * Copyright (c) 1997 Regents of the University of California.
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. All advertising materials mentioning features or use of this software
00015  *    must display the following acknowledgement:
00016  *  This product includes software developed by the Computer Systems
00017  *  Engineering Group at Lawrence Berkeley Laboratory.
00018  * 4. Neither the name of the University nor of the Laboratory may be used
00019  *    to endorse or promote products derived from this software without
00020  *    specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00023  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00026  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00028  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00029  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00031  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00032  * SUCH DAMAGE.
00033  */
00034 /* tworayground.cc
00035    $Id: tworayground.cc,v 1.7 2005/02/03 20:15:00 haldar Exp $
00036  */
00037 
00038 #include <math.h>
00039 
00040 #include <delay.h>
00041 #include <packet.h>
00042 
00043 #include <packet-stamp.h>
00044 #include <antenna.h>
00045 #include <mobilenode.h>
00046 #include <propagation.h>
00047 #include <wireless-phy.h>
00048 #include <tworayground.h>
00049 
00050 static class TwoRayGroundClass: public TclClass {
00051 public:
00052         TwoRayGroundClass() : TclClass("Propagation/TwoRayGround") {}
00053         TclObject* create(int, const char*const*) {
00054                 return (new TwoRayGround);
00055         }
00056 } class_tworayground;
00057 
00058 TwoRayGround::TwoRayGround()
00059 {
00060   last_hr = last_ht = 0.0;
00061   crossover_dist = 0.0;
00062 }
00063 
00064 // use Friis at less than crossover distance
00065 // use two-ray at more than crossover distance
00066 //static double
00067 double TwoRayGround::TwoRay(double Pt, double Gt, double Gr, double ht, double hr, double L, double d)
00068 {
00069         /*
00070          *  Two-ray ground reflection model.
00071          *
00072          *       Pt * Gt * Gr * (ht^2 * hr^2)
00073          *  Pr = ----------------------------
00074          *           d^4 * L
00075          *
00076          * The original equation in Rappaport's book assumes L = 1.
00077          * To be consistant with the free space equation, L is added here.
00078          */
00079   return Pt * Gt * Gr * (hr * hr * ht * ht) / (d * d * d * d * L);
00080 }
00081 
00082 double
00083 TwoRayGround::Pr(PacketStamp *t, PacketStamp *r, WirelessPhy *ifp)
00084 {
00085   double rX, rY, rZ;        // location of receiver
00086   double tX, tY, tZ;        // location of transmitter
00087   double d;             // distance
00088   double hr, ht;        // height of recv and xmit antennas
00089   double Pr;            // received signal power
00090 
00091   double L = ifp->getL();           // system loss
00092   double lambda = ifp->getLambda(); // wavelength
00093 
00094   r->getNode()->getLoc(&rX, &rY, &rZ);
00095   t->getNode()->getLoc(&tX, &tY, &tZ);
00096 
00097   rX += r->getAntenna()->getX();
00098   rY += r->getAntenna()->getY();
00099   tX += t->getAntenna()->getX();
00100   tY += t->getAntenna()->getY();
00101 
00102   d = sqrt((rX - tX) * (rX - tX) 
00103        + (rY - tY) * (rY - tY) 
00104        + (rZ - tZ) * (rZ - tZ));
00105     
00106   /* We're going to assume the ground is essentially flat.
00107      This empirical two ground ray reflection model doesn't make 
00108      any sense if the ground is not a plane. */
00109 
00110   if (rZ != tZ) {
00111     printf("%s: TwoRayGround propagation model assume flat ground\n",
00112        __FILE__);
00113   }
00114 
00115   hr = rZ + r->getAntenna()->getZ();
00116   ht = tZ + t->getAntenna()->getZ();
00117 
00118   if (hr != last_hr || ht != last_ht)
00119     { // recalc the cross-over distance
00120       /* 
00121              4 * PI * hr * ht
00122      d = ----------------------------
00123                  lambda
00124        * At the crossover distance, the received power predicted by the two-ray
00125        * ground model equals to that predicted by the Friis equation.
00126        */
00127 
00128       crossover_dist = (4 * PI * ht * hr) / lambda;
00129       last_hr = hr; last_ht = ht;
00130 #if DEBUG > 3
00131       printf("TRG: xover %e.10 hr %f ht %f\n",
00132           crossover_dist, hr, ht);
00133 #endif
00134     }
00135 
00136   /*
00137    *  If the transmitter is within the cross-over range , use the
00138    *  Friis equation.  Otherwise, use the two-ray
00139    *  ground reflection model.
00140    */
00141 
00142   double Gt = t->getAntenna()->getTxGain(rX - tX, rY - tY, rZ - tZ, 
00143                      t->getLambda());
00144   double Gr = r->getAntenna()->getRxGain(tX - rX, tY - rY, tZ - rZ,
00145                      r->getLambda());
00146 
00147 #if DEBUG > 3
00148   printf("TRG %.9f %d(%d,%d)@%d(%d,%d) d=%f xo=%f :",
00149      Scheduler::instance().clock(), 
00150      t->getNode()->index(), (int)tX, (int)tY,
00151      r->getNode()->index(), (int)rX, (int)rY,
00152      d, crossover_dist);
00153   //  printf("\n\t Pt %e Gt %e Gr %e lambda %e L %e :",
00154   //         t->getTxPr(), Gt, Gr, lambda, L);
00155 #endif
00156 
00157   if(d <= crossover_dist) {
00158     Pr = Friis(t->getTxPr(), Gt, Gr, lambda, L, d);
00159 #if DEBUG > 3
00160     printf("Friis %e\n",Pr);
00161 #endif
00162     return Pr;
00163   }
00164   else {
00165     Pr = TwoRay(t->getTxPr(), Gt, Gr, ht, hr, L, d);
00166 #if DEBUG > 3
00167     printf("TwoRay %e\n",Pr);
00168 #endif    
00169     return Pr;
00170   }
00171 }
00172 
00173 double TwoRayGround::getDist(double Pr, double Pt, double Gt, double Gr, double hr, double ht, double L, double lambda)
00174 {
00175        /* Get quartic root */
00176        return sqrt(sqrt(Pt * Gt * Gr * (hr * hr * ht * ht) / Pr));
00177 }

Generated on Tue Mar 6 16:47:53 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6