From 3e6d6f8ca29cb325afac2cf7f37722fc96a2a4b8 Mon Sep 17 00:00:00 2001 From: Chen Heroy Date: Fri, 6 Dec 2024 14:08:40 -0700 Subject: [PATCH] clean up --- app/include/Structs.h | 3 +- app/src/LFMFModel.cpp | 7 +-- include/ITS.Propagation.LFMF/LFMF.h | 55 ++++++++++++---------- include/ITS.Propagation.LFMF/ReturnCodes.h | 35 -------------- src/Airy.cpp | 5 +- src/CMakeLists.txt | 1 - src/LFMF.cpp | 54 +++++++++++++++++++-- src/ValidateInputs.cpp | 27 +++++++---- src/WiRoot.cpp | 11 ++--- tests/LFMFGTest.h | 2 +- tests/LFMFGTestUtils.cpp | 2 +- tests/TestLFMFReturnCode.cpp | 3 +- 12 files changed, 105 insertions(+), 100 deletions(-) delete mode 100644 include/ITS.Propagation.LFMF/ReturnCodes.h diff --git a/app/include/Structs.h b/app/include/Structs.h index d47a000..48c4c06 100644 --- a/app/include/Structs.h +++ b/app/include/Structs.h @@ -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 */ diff --git a/app/src/LFMFModel.cpp b/app/src/LFMFModel.cpp index 5acb775..aa6a926 100644 --- a/app/src/LFMFModel.cpp +++ b/app/src/LFMFModel.cpp @@ -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(i_pol); } else { std::cerr << "Unknown parameter: " << key << std::endl; rtn = DRVRERR__PARSE; diff --git a/include/ITS.Propagation.LFMF/LFMF.h b/include/ITS.Propagation.LFMF/LFMF.h index 975e857..e675539 100644 --- a/include/ITS.Propagation.LFMF/LFMF.h +++ b/include/ITS.Propagation.LFMF/LFMF.h @@ -5,10 +5,8 @@ #define __ITS_PROPAGATION_LFMF_LFMF_H__ #include -#include #include "LFMFConfig.h" -#include "ReturnCodes.h" using std::complex; using std::abs; @@ -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 @@ -108,14 +126,8 @@ 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); @@ -123,27 +135,18 @@ 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 delta, complex 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 q); complex wofz(complex qi); -complex - Airy(complex Z, AiryFunctionKind kind, AiryFunctionScaling scaling); -complex WiRoot( - int i, - complex *DWi, - complex q, - complex *Wi, - AiryFunctionKind kind, - AiryFunctionScaling scaling -); +complex Airy(complex Z, AiryFunctionKind kind, AiryFunctionScaling scaling); +complex WiRoot(int i, complex *DWi, complex q, complex *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); } // namespace LFMF diff --git a/include/ITS.Propagation.LFMF/ReturnCodes.h b/include/ITS.Propagation.LFMF/ReturnCodes.h deleted file mode 100644 index b13d32a..0000000 --- a/include/ITS.Propagation.LFMF/ReturnCodes.h +++ /dev/null @@ -1,35 +0,0 @@ -/** @file ReturnCodes.h - * Contains return codes used by this software - */ -#ifndef __ITS_PROPAGATION_LFMF_RETURNS_H__ -#define __ITS_PROPAGATION_LFMF_RETURNS_H__ - -namespace ITS { -namespace Propagation { -namespace LFMF { - -/******************************************************************************* - * 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 - -} // namespace LFMF -} // namespace Propagation -} // namespace ITS - -#endif \ No newline at end of file diff --git a/src/Airy.cpp b/src/Airy.cpp index 42da558..ffcc175 100644 --- a/src/Airy.cpp +++ b/src/Airy.cpp @@ -110,9 +110,8 @@ namespace LFMF { * Ai(z) + j*Bi(z) = -8.611221e-002 + 2.242080e-001 i * *****************************************************************************/ -complex Airy( - complex Z, AiryFunctionKind kind, AiryFunctionScaling scaling -) { +complex Airy(complex 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 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d8377ee..e77bbb7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/LFMF.cpp b/src/LFMF.cpp index 554de00..92e603d 100644 --- a/src/LFMF.cpp +++ b/src/LFMF.cpp @@ -8,7 +8,7 @@ namespace ITS { namespace Propagation { namespace LFMF { -/****************************************************************************** + /****************************************************************************** * * Description: Compute the LFMF propagation prediction * @@ -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(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; @@ -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 * diff --git a/src/ValidateInputs.cpp b/src/ValidateInputs.cpp index 578b384..b2d795c 100644 --- a/src/ValidateInputs.cpp +++ b/src/ValidateInputs.cpp @@ -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; @@ -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; } diff --git a/src/WiRoot.cpp b/src/WiRoot.cpp index de4fb25..e0cacb6 100644 --- a/src/WiRoot.cpp +++ b/src/WiRoot.cpp @@ -40,14 +40,9 @@ namespace LFMF { * @return tw - ith complex root of the "Airy function of the third kind" * *****************************************************************************/ -complex WiRoot( - int i, - complex *DWi, - complex q, - complex *Wi, - AiryFunctionKind kind, - AiryFunctionScaling scaling -) { +complex WiRoot(int i, complex *DWi, complex q, complex *Wi, + AiryFunctionKind kind, AiryFunctionScaling scaling) +{ complex ph; // Airy root phase complex ti; // the ith complex root of Wi'(2)(ti) - q*Wi(2)(ti) = 0 diff --git a/tests/LFMFGTest.h b/tests/LFMFGTest.h index 55949b1..dc253e9 100644 --- a/tests/LFMFGTest.h +++ b/tests/LFMFGTest.h @@ -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 }; diff --git a/tests/LFMFGTestUtils.cpp b/tests/LFMFGTestUtils.cpp index 7d1742e..891442c 100644 --- a/tests/LFMFGTestUtils.cpp +++ b/tests/LFMFGTestUtils.cpp @@ -74,7 +74,7 @@ std::vector ReadLFMFInputsAndResult(const std::string &file c++; } if (csvRows[0][i] == "pol") { - d.pol = static_cast(std::stoi(csvRows[r][i])); + d.pol = std::stoi(csvRows[r][i]); c++; } diff --git a/tests/TestLFMFReturnCode.cpp b/tests/TestLFMFReturnCode.cpp index bb71a68..8678eeb 100644 --- a/tests/TestLFMFReturnCode.cpp +++ b/tests/TestLFMFReturnCode.cpp @@ -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; @@ -427,4 +426,4 @@ TEST_F(TestLFMFReturnCode, InvalidPolarization) { EXPECT_EQ(rtn, ERROR__POLARIZATION); } -}*/ \ No newline at end of file +} \ No newline at end of file