Skip to content

Commit

Permalink
Support TeraSim
Browse files Browse the repository at this point in the history
  • Loading branch information
AmirAshtariG committed May 13, 2021
1 parent 49fcd95 commit 287988e
Show file tree
Hide file tree
Showing 21 changed files with 165 additions and 1 deletion.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified doc/Makefile
100644 → 100755
Empty file.
Empty file modified doc/qd-channel.rst
100644 → 100755
Empty file.
Empty file modified doc/source/conf.py
100644 → 100755
Empty file.
Empty file modified doc/source/qd-channel.rst
100644 → 100755
Empty file.
Empty file modified examples/qd-channel-model-example.cc
100644 → 100755
Empty file.
Empty file modified examples/wscript
100644 → 100755
Empty file.
Empty file modified model/QD/Indoor1/Input/Box.xml
100644 → 100755
Empty file.
Empty file modified model/QD/Indoor1/Input/paraCfgCurrent.txt
100644 → 100755
Empty file.
Empty file modified model/QD/Indoor1/Output/Ns3/NodesPosition/NodesPosition.csv
100644 → 100755
Empty file.
Empty file modified model/QD/Indoor1/Output/Ns3/QdFiles/Tx0Rx1.txt
100644 → 100755
Empty file.
Empty file modified model/QD/Indoor1/Output/Ns3/QdFiles/Tx1Rx0.txt
100644 → 100755
Empty file.
Empty file modified model/QD/Indoor1/Output/TriangList/Tx0Rx1.txt
100644 → 100755
Empty file.
Empty file modified model/QD/Indoor1/Output/TriangList/Tx1Rx0.txt
100644 → 100755
Empty file.
155 changes: 154 additions & 1 deletion model/qd-channel-model.cc
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <sstream>
#include <ns3/node-list.h>
#include "ns3/csv-reader.h"
#include "ns3/thz-dir-antenna.h"


namespace ns3 {
Expand Down Expand Up @@ -175,7 +176,7 @@ QdChannelModel::ReadNodesPosition ()
NS_LOG_ERROR ("Position not found: " << nodePosition);
}

NS_ABORT_MSG_IF (!found, "Position not matched - did you install the mobility model before the channel is created");
// NS_ABORT_MSG_IF (!found, "Position not matched - did you install the mobility model before the channel is created");

rtIdToNs3IdMap.insert (std::make_pair (id, matchedNodeId));
m_ns3IdToRtIdMap.insert (std::make_pair (matchedNodeId, id));
Expand Down Expand Up @@ -660,6 +661,158 @@ QdChannelModel::GetNewChannel (Ptr<const MobilityModel> aMob,
return channelParams;
}



Ptr<const MatrixBasedChannelModel::ChannelMatrix>
QdChannelModel::GetRTChannel (Ptr<const MobilityModel> aMob,
Ptr<const MobilityModel> bMob,
Ptr<const THzDirectionalAntenna> aAntenna)
{
NS_LOG_FUNCTION (this << aMob << bMob << aAntenna );

// Compute the channel keys
uint32_t aId = aMob->GetObject<Node> ()->GetId ();
uint32_t bId = bMob->GetObject<Node> ()->GetId ();

uint32_t channelId = GetKey (aId, bId);


NS_LOG_DEBUG ("channelId " << channelId <<
", ns-3 aId=" << aId << " bId=" << bId <<
", RT sim. aId=" << m_ns3IdToRtIdMap[aId] << " bId=" << m_ns3IdToRtIdMap[bId]);

// Check if the channel is present in the map and return it, otherwise
// generate a new channel
bool update = false;
bool notFound = false;
Ptr<const MatrixBasedChannelModel::ChannelMatrix> channelMatrix;
if (m_channelMap.find (channelId) != m_channelMap.end ())
{
// channel matrix present in the map
NS_LOG_LOGIC ("channel matrix present in the map");
channelMatrix = m_channelMap[channelId];

// check if it has to be updated
update = ChannelMatrixNeedsUpdate (channelMatrix);
}
else
{
NS_LOG_LOGIC ("channel matrix not found");
notFound = true;
}

// If the channel is not present in the map or if it has to be updated
// generate a new channel
if (notFound || update)
{
NS_LOG_LOGIC ("channelMatrix notFound=" << notFound << " || update=" << update);
channelMatrix = GetNewRTChannel (aMob, bMob, aAntenna);

// store the channel matrix in the channel map
m_channelMap[channelId] = channelMatrix;
}

return channelMatrix;
}

Ptr<const MatrixBasedChannelModel::ChannelMatrix>
QdChannelModel::GetNewRTChannel (Ptr<const MobilityModel> aMob,
Ptr<const MobilityModel> bMob,
Ptr<const THzDirectionalAntenna> aAntenna) const
{
NS_LOG_FUNCTION (this << aMob << bMob << aAntenna);

Ptr< MatrixBasedChannelModel::ChannelMatrix> channelParams = Create<MatrixBasedChannelModel::ChannelMatrix> ();

uint32_t timestep = GetTimestep ();
uint32_t aId = aMob->GetObject<Node> ()->GetId ();
uint32_t bId = bMob->GetObject<Node> ()->GetId ();
uint32_t channelId = GetKey (aId, bId);

QdInfo qdInfo = m_qdInfoMap.at (channelId)[timestep];


NS_LOG_DEBUG ("timestep=" << timestep <<
", aId=" << aId <<
", bId=" << bId <<
", m_ns3IdToRtIdMap[aId]=" << m_ns3IdToRtIdMap.at (aId) <<
", m_ns3IdToRtIdMap[bId]=" << m_ns3IdToRtIdMap.at (bId) <<
", channelId=" << channelId);

// channel coffecient H[u][s][n];
// One Antenna per each device
// considering numMPCs cluster
MatrixBasedChannelModel::Complex3DVector H;

H.resize (1);
for (uint64_t bIndex = 0; bIndex < 1; bIndex++)
{
H[bIndex].resize (1);
for (uint64_t aIndex = 0; aIndex < 1; aIndex++)
{
if (qdInfo.numMpcs > 0)
{
H[bIndex][aIndex].resize (qdInfo.numMpcs, std::complex<double> (0,0));
}
else
{
H[bIndex][aIndex].resize (0, std::complex<double> (0,0));
}
}
}

for (uint64_t mpcIndex = 0; mpcIndex < qdInfo.numMpcs; ++mpcIndex)
{
double initialPhase = -2 * M_PI * qdInfo.delay_s[mpcIndex] * m_frequency;
std::complex<double> pathGain = pow (10, qdInfo.pathGain_dbpow[mpcIndex] / 20);

Angles aAngle = Angles (qdInfo.azAod_rad[mpcIndex], qdInfo.elAod_rad[mpcIndex]);
NS_LOG_DEBUG ("aAngle: " << aAngle);


// double TxAntennaPatern = pow (10, aAntenna->GetTxGainDbAngle (aAngle)/20);
double TxAntennaPatern =1; //??????
std::complex<double> ray = pathGain * TxAntennaPatern * std::polar (1.0, initialPhase);

NS_LOG_DEBUG ("qdInfo.delay_s[mpcIndex]=" << qdInfo.delay_s[mpcIndex] <<
", qdInfo.phase_rad[mpcIndex]=" << qdInfo.phase_rad[mpcIndex] <<
", qdInfo.pathGain_dbpow[mpcIndex]=" << qdInfo.pathGain_dbpow[mpcIndex] <<
", aAngle=" << aAngle <<
", initialPhase=" << initialPhase <<
", pathGain=" << pathGain <<
", TxAntennaPatern=" << TxAntennaPatern);

H[0][0][mpcIndex] += ray;

}

channelParams->m_channel = H;
channelParams->m_delay = qdInfo.delay_s;

channelParams->m_angle.clear ();
channelParams->m_angle.push_back (qdInfo.azAoa_rad);
channelParams->m_angle.push_back (qdInfo.elAoa_rad);
channelParams->m_angle.push_back (qdInfo.azAod_rad);
channelParams->m_angle.push_back (qdInfo.elAod_rad);

channelParams->m_generatedTime = Simulator::Now ();
channelParams->m_nodeIds = std::make_pair (aId, bId);

// std::cout << "H matrix at timestep " << +timestep << std::endl;
// for (uint64_t bIndex = 0; bIndex < bSize; ++bIndex)
// {
// for (uint64_t aIndex = 0; aIndex < aSize; ++aIndex)
// {
// std::cout << std::showpos << std::real (H[bIndex][aIndex][0]) << std::imag (H[bIndex][aIndex][0]) << "j,";
// }
// std::cout << ";..." << std::endl;
// }

return channelParams;
}



uint64_t
QdChannelModel::GetTimestep (void) const
{
Expand Down
9 changes: 9 additions & 0 deletions model/qd-channel-model.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
namespace ns3 {

class PhasedArrayModel;
class THzDirectionalAntenna;
class MobilityModel;

/**
Expand Down Expand Up @@ -75,6 +76,9 @@ class QdChannelModel : public MatrixBasedChannelModel
Ptr<const PhasedArrayModel> aAntenna,
Ptr<const PhasedArrayModel> bAntenna) override;

Ptr<const MatrixBasedChannelModel::ChannelMatrix> GetRTChannel (Ptr<const MobilityModel> aMob,
Ptr<const MobilityModel> bMob,
Ptr<const THzDirectionalAntenna> aAntenna);
/*
* Set the folder path containing the scenario of interest
*
Expand Down Expand Up @@ -143,6 +147,11 @@ class QdChannelModel : public MatrixBasedChannelModel
Ptr<const PhasedArrayModel> aAntenna,
Ptr<const PhasedArrayModel> bAntenna) const;


Ptr<const MatrixBasedChannelModel::ChannelMatrix> GetNewRTChannel (Ptr<const MobilityModel> aMob,
Ptr<const MobilityModel> bMob,
Ptr<const THzDirectionalAntenna> aAntenna) const;

/**
* Check if the channel matrix has to be updated
* \param channelMatrix channel matrix
Expand Down
1 change: 1 addition & 0 deletions model/qd-channel-utils.cc
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "ns3/qd-channel-model.h"
#include "ns3/uniform-planar-array.h"
#include "ns3/qd-channel-utils.h"
#include "ns3/thz-dir-antenna.h"

NS_LOG_COMPONENT_DEFINE ("ThreeGppChannelExampleUtils");

Expand Down
1 change: 1 addition & 0 deletions model/qd-channel-utils.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace ns3 {

class MatrixBasedChannelModel;
class PhasedArrayModel;
class THzDirectionalAntenna;

/**
* Compute the eigenvector associated to the largest eigenvalue.
Expand Down
Empty file modified test/qd-channel-test-suite.cc
100644 → 100755
Empty file.
Empty file modified wscript
100644 → 100755
Empty file.

0 comments on commit 287988e

Please sign in to comment.