Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
cheroy-ntia committed Dec 6, 2024
1 parent cbf03b1 commit 3e6d6f8
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 100 deletions.
3 changes: 1 addition & 2 deletions app/include/Structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ struct LFMFParams {
double d__km; ///< Path distance, in km
double epsilon; ///< Relative permittivity
double sigma; ///< Conductivity
ITS::Propagation::LFMF::Polarization
pol; ///< Polarization: 0 = Horizontal, 1 = Vertical
int pol; ///< Polarization: 0 = Horizontal, 1 = Vertical
};

/** Key names for LFMF Model input file parameters */
Expand Down
7 changes: 1 addition & 6 deletions app/src/LFMFModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,9 @@ DrvrReturnCode ParseLFMFInputStream(std::istream &stream, LFMFParams &lfmf_param
if (rtn == DRVRERR__PARSE)
rtn = DRVRERR__PARSE_SIGMA;
} else if (key.compare(LFMFInputKeys::pol) == 0) {
int i_pol;
rtn = ParseInteger(
value, i_pol
);
rtn = ParseInteger(value, lfmf_params.pol);
if (rtn == DRVRERR__PARSE)
rtn = DRVRERR__PARSE_POLARIZATION;
else
lfmf_params.pol = static_cast<Polarization>(i_pol);
} else {
std::cerr << "Unknown parameter: " << key << std::endl;
rtn = DRVRERR__PARSE;
Expand Down
55 changes: 29 additions & 26 deletions include/ITS.Propagation.LFMF/LFMF.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
#define __ITS_PROPAGATION_LFMF_LFMF_H__

#include <complex>
#include <cfloat>

#include "LFMFConfig.h"
#include "ReturnCodes.h"

using std::complex;
using std::abs;
Expand Down Expand Up @@ -90,6 +88,26 @@ enum AiryFunctionScaling {
};
// clang-format on

/*******************************************************************************
* Return Codes defined by this software (0-127)
******************************************************************************/
// clang-format off
enum ReturnCode {
SUCCESS = 0, ///< Return Success

// Invalid Inputs
ERROR__TX_TERMINAL_HEIGHT = 32, ///< TX terminal height is out of range
ERROR__RX_TERMINAL_HEIGHT, ///< RX terminal height is out of range
ERROR__FREQUENCY, ///< Frequency is out of range
ERROR__TX_POWER, ///< Transmit power is out of range
ERROR__SURFACE_REFRACTIVITY, ///< Surface refractivity is out of range
ERROR__PATH_DISTANCE, ///< Path distance is out of range
ERROR__EPSILON, ///< Epsilon is out of range
ERROR__SIGMA, ///< Sigma is out of range
ERROR__POLARIZATION, ///< Invalid value for polarization
};
// clang-format on

//////////////////////////////////////
// Data Structures

Expand All @@ -108,42 +126,27 @@ struct Result
//////////////////////////////////////
// Public Functions

DLLEXPORT ReturnCode LFMF(double h_tx__meter, double h_rx__meter, double f__mhz, double P_tx__watt,
double N_s,
double d__km,
double epsilon,
double sigma,
Polarization pol,
Result *result
);
DLLEXPORT ReturnCode LFMF(double h_tx__meter, double h_rx__meter, double f__mhz, double P_tx__watt, double N_s,
double d__km, double epsilon, double sigma, int pol, Result *result);

DLLEXPORT char *GetReturnStatusCharArray(const int code);
DLLEXPORT void FreeReturnStatusCharArray(char *c_msg);

//////////////////////////////////////
// Private Functions

ReturnCode LFMF_CPP(double h_tx__meter, double h_rx__meter, double f__mhz, double P_tx__watt, double N_s,
double d__km, double epsilon, double sigma, Polarization pol, Result *result);
std::string GetReturnStatus(const int code);
double FlatEarthCurveCorrection(complex<double> delta, complex<double> q, double h_1__km, double h_2__km, double d, double k, double a_e__km);
double ResidueSeries(double k, double h_1__km, double h_2__km, double nu, double theta, complex<double> q);
complex<double> wofz(complex<double> qi);
complex<double>
Airy(complex<double> Z, AiryFunctionKind kind, AiryFunctionScaling scaling);
complex<double> WiRoot(
int i,
complex<double> *DWi,
complex<double> q,
complex<double> *Wi,
AiryFunctionKind kind,
AiryFunctionScaling scaling
);
complex<double> Airy(complex<double> Z, AiryFunctionKind kind, AiryFunctionScaling scaling);
complex<double> WiRoot(int i, complex<double> *DWi, complex<double> q, complex<double> *Wi,
AiryFunctionKind kind, AiryFunctionScaling scaling);
ReturnCode ValidateInput(double h_tx__meter, double h_rx__meter, double f__mhz, double P_tx__watt,
double N_s,
double d__km,
double epsilon,
double sigma,
Polarization pol
);
double N_s, double d__km, double epsilon, double sigma);
ReturnCode ValidatePolarization(int pol);
bool AlmostEqualRelative(double A, double B, double maxRelDiff = DBL_EPSILON);

Check failure on line 150 in include/ITS.Propagation.LFMF/LFMF.h

View workflow job for this annotation

GitHub Actions / ubuntu-latest / x64 / CMake 3.21

‘DBL_EPSILON’ was not declared in this scope

} // namespace LFMF
Expand Down
35 changes: 0 additions & 35 deletions include/ITS.Propagation.LFMF/ReturnCodes.h

This file was deleted.

5 changes: 2 additions & 3 deletions src/Airy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ namespace LFMF {
* Ai(z) + j*Bi(z) = -8.611221e-002 + 2.242080e-001 i
*
*****************************************************************************/
complex<double> Airy(
complex<double> Z, AiryFunctionKind kind, AiryFunctionScaling scaling
) {
complex<double> Airy(complex<double> Z, AiryFunctionKind kind, AiryFunctionScaling scaling)
{
// NQTT, ASLT data
int NQTT[15] = { 1,3,7,12,17,23,29,35,41,47,53,59,64,68,71 }; // Centers of Expansion of Taylor series on real axis indices into the
// AV, APV, BV and BPV arrays
Expand Down
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ set(LIB_FILES
wofz.cpp
"${LIB_HEADERS}/${PROJECT_NAME}/LFMF.h"
"${LIB_HEADERS}/${PROJECT_NAME}/${LIB_NAME}Config.h"
"${LIB_HEADERS}/${PROJECT_NAME}/ReturnCodes.h"
)

# By default, create shared library
Expand Down
54 changes: 49 additions & 5 deletions src/LFMF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace ITS {
namespace Propagation {
namespace LFMF {

/******************************************************************************
/******************************************************************************
*
* Description: Compute the LFMF propagation prediction
*
Expand All @@ -27,16 +27,60 @@ namespace LFMF {
* @return error - Error code
*
*****************************************************************************/
ReturnCode LFMF(double h_tx__meter, double h_rx__meter, double f__mhz, double P_tx__watt,
ReturnCode LFMF(
double h_tx__meter,
double h_rx__meter,
double f__mhz,
double P_tx__watt,
double N_s,
double d__km,
double epsilon,
double sigma,
Polarization pol,
int pol,
Result *result
) {
ReturnCode rtn = ValidatePolarization(pol);
if (rtn != SUCCESS)
return rtn;

return LFMF_CPP(
h_tx__meter,
h_rx__meter,
f__mhz,
P_tx__watt,
N_s,
d__km,
epsilon,
sigma,
static_cast<Polarization>(pol),
result
);
}

/******************************************************************************
*
* Description: Compute the LFMF propagation prediction
*
* @param[in] h_tx__meter - Height of the transmitter, in meter
* @param[in] h_rx__meter - Height of the receiver, in meter
* @param[in] f__mhz - Frequency, in MHz
* @param[in] P_tx__watt - Transmitter power, in Watts
* @param[in] N_s - Surface refractivity, in N-Units
* @param[in] d__km - Path distance, in km
* @param[in] epsilon - Relative permittivity
* @param[in] sigma - Conductivity
* @param[in] pol - Polarization: 0 = Horizontal, 1 = Vertical
*
* @param[out] result - Result structure
*
* @return error - Error code
*
*****************************************************************************/
ReturnCode LFMF_CPP(double h_tx__meter, double h_rx__meter, double f__mhz, double P_tx__watt,
double N_s, double d__km, double epsilon, double sigma, Polarization pol, Result *result)
{
ReturnCode rtn = ValidateInput(h_tx__meter, h_rx__meter, f__mhz, P_tx__watt,
N_s, d__km, epsilon, sigma, pol);
N_s, d__km, epsilon, sigma);
if (rtn != SUCCESS)
return rtn;

Expand Down Expand Up @@ -121,7 +165,7 @@ ReturnCode LFMF(double h_tx__meter, double h_rx__meter, double f__mhz, double P_
*
* @param[in] A - First double to compare
* @param[in] B - Second double to compare
* @param[in] maxRelDiff - Maximum relative difference
* @param[in] maxRelDiff - Maximum relative difference, by default is DBL_EPSILON
*
* @return equal - if it is equal of the two doubles
*
Expand Down
27 changes: 17 additions & 10 deletions src/ValidateInputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,13 @@ namespace LFMF {
* @param[in] d__km - Path distance, in km
* @param[in] epsilon - Relative permittivity
* @param[in] sigma - Conductivity
* @param[in] pol - Polarization
* + 0 : POLARIZATION__HORIZONTAL
* + 1 : POLARIZATION__VERTICAL
*
* @return error - Error code
*
*****************************************************************************/
ReturnCode ValidateInput(double h_tx__meter, double h_rx__meter, double f__mhz, double P_tx__watt,
double N_s,
double d__km,
double epsilon,
double sigma,
Polarization pol
) {
double N_s, double d__km, double epsilon, double sigma)
{
if (h_tx__meter < 0 || h_tx__meter > 50)
return ERROR__TX_TERMINAL_HEIGHT;

Expand All @@ -58,9 +51,23 @@ ReturnCode ValidateInput(double h_tx__meter, double h_rx__meter, double f__mhz,
if (sigma <= 0)
return ERROR__SIGMA;

return SUCCESS;
}


/******************************************************************************
*
* Description: Perform input Polarization validation
*
* @param[in] pol - Polarization
*
* @return error - Error code
*
*****************************************************************************/
ReturnCode ValidatePolarization(int pol)
{
if (pol != POLARIZATION__HORIZONTAL && pol != POLARIZATION__VERTICAL)
return ERROR__POLARIZATION;

return SUCCESS;
}

Expand Down
11 changes: 3 additions & 8 deletions src/WiRoot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,9 @@ namespace LFMF {
* @return tw - ith complex root of the "Airy function of the third kind"
*
*****************************************************************************/
complex<double> WiRoot(
int i,
complex<double> *DWi,
complex<double> q,
complex<double> *Wi,
AiryFunctionKind kind,
AiryFunctionScaling scaling
) {
complex<double> WiRoot(int i, complex<double> *DWi, complex<double> q, complex<double> *Wi,
AiryFunctionKind kind, AiryFunctionScaling scaling)
{
complex<double> ph; // Airy root phase
complex<double> ti; // the ith complex root of Wi'(2)(ti) - q*Wi(2)(ti) = 0

Expand Down
2 changes: 1 addition & 1 deletion tests/LFMFGTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct LFMFInputsAndResult {
double d__km; ///< Path distance, in km
double epsilon; ///< Relative permittivity
double sigma; ///< Conductivity
Polarization pol; ///< Polarization: 0 = Horizontal, 1 = Vertical
int pol; ///< Polarization: 0 = Horizontal, 1 = Vertical
int expectedReturn; ///< Expected Return Code
Result expectedResult; ///< Expected Outputs in Result Struct
};
Expand Down
2 changes: 1 addition & 1 deletion tests/LFMFGTestUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ std::vector<LFMFInputsAndResult> ReadLFMFInputsAndResult(const std::string &file
c++;
}
if (csvRows[0][i] == "pol") {
d.pol = static_cast<Polarization>(std::stoi(csvRows[r][i]));
d.pol = std::stoi(csvRows[r][i]);
c++;
}

Expand Down
3 changes: 1 addition & 2 deletions tests/TestLFMFReturnCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ TEST_F(TestLFMFReturnCode, InvalidSigma) {
* Description: Test case to verify LFMF input polarization is invalid
*
*****************************************************************************/
/*
TEST_F(TestLFMFReturnCode, InvalidPolarization) {
for (const auto &data : testData) {
Result result;
Expand Down Expand Up @@ -427,4 +426,4 @@ TEST_F(TestLFMFReturnCode, InvalidPolarization) {

EXPECT_EQ(rtn, ERROR__POLARIZATION);
}
}*/
}

0 comments on commit 3e6d6f8

Please sign in to comment.