From 9322f32150e267e3696d04fd85cf2e247532a667 Mon Sep 17 00:00:00 2001 From: Julian Hammerl Date: Fri, 5 May 2023 10:01:33 -0600 Subject: [PATCH 1/4] Clean up code No functional changes --- .../msgPayloadDefC/PlasmaFluxMsgPayload.h | 2 +- .../dentonFluxModel/dentonFluxModel.cpp | 55 ++++++++----------- .../dentonFluxModel/dentonFluxModel.h | 54 ++++++++---------- 3 files changed, 48 insertions(+), 63 deletions(-) diff --git a/src/architecture/msgPayloadDefC/PlasmaFluxMsgPayload.h b/src/architecture/msgPayloadDefC/PlasmaFluxMsgPayload.h index 7992d490e0..d8b3926f3a 100755 --- a/src/architecture/msgPayloadDefC/PlasmaFluxMsgPayload.h +++ b/src/architecture/msgPayloadDefC/PlasmaFluxMsgPayload.h @@ -23,7 +23,7 @@ #define MAX_PLASMA_FLUX_SIZE 50 -//!@brief GEO space weather flux message definition. +//!@brief space weather ambient plasma flux message definition. typedef struct { double meanElectronFlux[MAX_PLASMA_FLUX_SIZE]; //!< [cm^-2 s^-1 sr^-2 eV^-1] differential flux double meanIonFlux[MAX_PLASMA_FLUX_SIZE]; //!< [cm^-2 s^-1 sr^-2 eV^-1] differential flux diff --git a/src/simulation/environment/dentonFluxModel/dentonFluxModel.cpp b/src/simulation/environment/dentonFluxModel/dentonFluxModel.cpp index 2be476ef82..70d685ed5b 100644 --- a/src/simulation/environment/dentonFluxModel/dentonFluxModel.cpp +++ b/src/simulation/environment/dentonFluxModel/dentonFluxModel.cpp @@ -20,25 +20,16 @@ #include "simulation/environment/dentonFluxModel/dentonFluxModel.h" #include "architecture/utilities/linearAlgebra.h" #include "architecture/utilities/astroConstants.h" - #include -#include #include -#include // trig +#include /*! This is the constructor for the module class. It sets default variable values and initializes the various parts of the model */ - - // Final Desired Constructor -DentonFluxModel::DentonFluxModel() -{ -} +DentonFluxModel::DentonFluxModel() = default; /*! Module Destructor */ -DentonFluxModel::~DentonFluxModel() -{ - -} +DentonFluxModel::~DentonFluxModel() = default; /*! This method is used to reset the module and checks that required input messages are connect. @param CurrentSimNanos current simulation time in nano-seconds @@ -82,7 +73,8 @@ void DentonFluxModel::Reset(uint64_t CurrentSimNanos) // Check that the Kp index is a string of length 2 if (!(this->kpIndex.length() == 2)) { - bskLogger.bskLog(BSK_ERROR, "DentonFluxModel.kpIndex must be a string of length 2, such as '1-', '3o', '4+' etc."); + bskLogger.bskLog(BSK_ERROR, + "DentonFluxModel.kpIndex must be a string of length 2, such as '1-', '3o', '4+' etc."); } // Convert Kp index (such as '0o', '1-', '5+' etc.) to Kp index counter (int 0-27) char kpMain = this->kpIndex[0]; // main Kp index, between 0 and 9 @@ -106,7 +98,8 @@ void DentonFluxModel::Reset(uint64_t CurrentSimNanos) // Check that Kp index is between 0o and 9o (corresponding to Kp index counter 0-27) if (this->kpIndexCounter < 0 || this->kpIndexCounter > MAX_NUM_KPS - 1) { - bskLogger.bskLog(BSK_ERROR, "DentonFluxModel: Kp index must be between 0o and 9o. Indices 0- and 9+ do not exist."); + bskLogger.bskLog(BSK_ERROR, + "DentonFluxModel: Kp index must be between 0o and 9o. Indices 0- and 9+ do not exist."); } // convert energies to log10 values @@ -119,7 +112,9 @@ void DentonFluxModel::Reset(uint64_t CurrentSimNanos) // Define Energy Array double step = (40000 - 1)/this->numOutputEnergies; - // start at 100eV (fluxes of smaller energies are unreliable due to contamination with secondary electrons and photoelectrons, according to Denton) + // start at 100eV + // (fluxes of smaller energies are unreliable due to contamination with secondary electrons and photoelectrons, + // according to Denton) this->inputEnergies[0] = 100; for (int i = 1; i < numOutputEnergies; i++) { @@ -132,7 +127,6 @@ void DentonFluxModel::Reset(uint64_t CurrentSimNanos) } - /*! This is the main method that gets called every time the module is updated. Provide an appropriate description. @param CurrentSimNanos current simulation time in nano-seconds @return void @@ -168,7 +162,8 @@ void DentonFluxModel::UpdateState(uint64_t CurrentSimNanos) double tol = 4000e3; // tolerance how far spacecraft can be away from GEO if (v2Norm(r_BE_N) < r_GEO - tol || v2Norm(r_BE_N) > r_GEO + tol || abs(r_BE_N[2]) > tol) { - bskLogger.bskLog(BSK_WARNING, "DentonFluxModel: Spacecraft not in GEO regime. Denton Model not valid outside of GEO."); + bskLogger.bskLog(BSK_WARNING, + "DentonFluxModel: Spacecraft not in GEO regime. Denton Model not valid outside of GEO."); } // Find local lime from spacecraft and Earth state messages @@ -201,9 +196,6 @@ void DentonFluxModel::UpdateState(uint64_t CurrentSimNanos) eLowerIndex = k-1; break; } - else - { - } } // IONS: Find nearest neighbors in energy @@ -227,9 +219,6 @@ void DentonFluxModel::UpdateState(uint64_t CurrentSimNanos) iLowerIndex = k-1; break; } - else - { - } } int localTimeFloor = floor(this->localTime); @@ -248,7 +237,8 @@ void DentonFluxModel::UpdateState(uint64_t CurrentSimNanos) flux14 = this->mean_e_flux[this->kpIndexCounter][eHigherIndex][localTimeCeil]; // ELECTRON: Find flux - finalElec = bilinear(localTimeFloor, localTimeCeil, logEnElec[eLowerIndex], logEnElec[eHigherIndex], logInputEnergy, flux11, flux12, flux13, flux14); + finalElec = bilinear(localTimeFloor, localTimeCeil, logEnElec[eLowerIndex], logEnElec[eHigherIndex], + logInputEnergy, flux11, flux12, flux13, flux14); finalElec = pow(10.0, finalElec); // ION: Gather four nearest *MEAN* flux values @@ -258,7 +248,8 @@ void DentonFluxModel::UpdateState(uint64_t CurrentSimNanos) flux14 = this->mean_i_flux[this->kpIndexCounter][iHigherIndex][localTimeCeil]; // ION: Find flux - finalIon = bilinear(localTimeFloor, localTimeCeil, logEnProt[iLowerIndex], logEnProt[iHigherIndex], logInputEnergy, flux11, flux12, flux13, flux14); + finalIon = bilinear(localTimeFloor, localTimeCeil, logEnProt[iLowerIndex], logEnProt[iHigherIndex], + logInputEnergy, flux11, flux12, flux13, flux14); finalIon = pow(10.0, finalIon); // Store the output message @@ -278,7 +269,8 @@ void DentonFluxModel::UpdateState(uint64_t CurrentSimNanos) */ void DentonFluxModel::calcLocalTime(double r_SE_N[3], double r_BE_N[3]) { - // r_SE_N and r_BE_N are projected onto the equatorial plane to compute angle, thus only x and y components are used (z component is perpendicular to equator) + // r_SE_N and r_BE_N are projected onto the equatorial plane to compute angle, + // thus only x and y components are used (z component is perpendicular to equator) double r_BE_N_hat[2]; /* unit vector from Earth to spacecraft */ double r_SE_N_hat[2]; /* unit vector from Earth to Sun */ v2Normalize(r_BE_N, r_BE_N_hat); @@ -305,7 +297,8 @@ void DentonFluxModel::calcLocalTime(double r_SE_N[3], double r_BE_N[3]) /*! Bilinear interpolation method @return void */ -double DentonFluxModel::bilinear(int x1, int x2, double y1, double y2, double y, double f11, double f12, double f13, double f14) +double DentonFluxModel::bilinear(int x1, int x2, double y1, double y2, double y, double f11, double f12, double f13, + double f14) { // Define variables double R1, R2, bilinear = 0.0; @@ -325,13 +318,13 @@ double DentonFluxModel::bilinear(int x1, int x2, double y1, double y2, double y, } - /*! Read in the Denton data file @param fileName data file name @param data data array pointer @return void */ -void DentonFluxModel::readDentonDataFile(std::string fileName, double data[MAX_NUM_KPS][MAX_NUM_ENERGIES][MAX_NUM_LOCAL_TIMES]) +void DentonFluxModel::readDentonDataFile(std::string fileName, + double data[MAX_NUM_KPS][MAX_NUM_ENERGIES][MAX_NUM_LOCAL_TIMES]) { double temp = 0.0; @@ -341,7 +334,8 @@ void DentonFluxModel::readDentonDataFile(std::string fileName, double data[MAX_N // Read data from file: inputFile.open(this->dataPath + fileName); - // Read information into array: Data includes information about mean, standard deviation, median and percentiles (7 types of values in total). Only mean is relevant for this module + // Read information into array: Data includes information about mean, standard deviation, + // median and percentiles (7 types of values in total). Only mean is relevant for this module if (inputFile.is_open()) { for (int i = 0; i < MAX_NUM_KPS*MAX_NUM_VALUE_TYPES; i++) { for (int j = 0; j < MAX_NUM_ENERGIES; j++) @@ -367,4 +361,3 @@ void DentonFluxModel::readDentonDataFile(std::string fileName, double data[MAX_N return; } - diff --git a/src/simulation/environment/dentonFluxModel/dentonFluxModel.h b/src/simulation/environment/dentonFluxModel/dentonFluxModel.h index 9e812715c6..741ac80aab 100644 --- a/src/simulation/environment/dentonFluxModel/dentonFluxModel.h +++ b/src/simulation/environment/dentonFluxModel/dentonFluxModel.h @@ -17,7 +17,6 @@ */ - #ifndef DENTONFLUXMODEL_H #define DENTONFLUXMODEL_H @@ -28,56 +27,56 @@ #include "architecture/utilities/bskLogging.h" #include "architecture/messaging/messaging.h" - #define MAX_NUM_KPS 28 #define MAX_NUM_ENERGIES 40 #define MAX_NUM_LOCAL_TIMES 24 #define MAX_NUM_VALUE_TYPES 7 - /*! @brief This module provides the 10-year averaged GEO elecon and ion flux as discussed in the paper by Denton. */ class DentonFluxModel: public SysModel { public: - // Constructor And Destructor DentonFluxModel(); ~DentonFluxModel(); // Methods - void Reset(uint64_t CurrentSimNanos); - void UpdateState(uint64_t CurrentSimNanos); + void Reset(uint64_t CurrentSimNanos) override; + void UpdateState(uint64_t CurrentSimNanos) override; /* public variables */ - int numOutputEnergies = -1; //!< number of energy bins used in the output message - std::string kpIndex = ""; //!< Kp index - std::string dataPath = ""; //!< -- String with the path to the Denton GEO data - std::string eDataFileName = "model_e_array_all.txt"; //!< file name of the electron data file - std::string iDataFileName = "model_i_array_all.txt"; //!< file name of the ion data file + int numOutputEnergies = -1; //!< number of energy bins used in the output message + std::string kpIndex = ""; //!< Kp index + std::string dataPath = ""; //!< -- String with the path to the Denton GEO data + std::string eDataFileName = "model_e_array_all.txt"; //!< file name of the electron data file + std::string iDataFileName = "model_i_array_all.txt"; //!< file name of the ion data file - ReadFunctor scStateInMsg; //!< spacecraft state input message - ReadFunctor earthStateInMsg; //!< Earth planet state input message - ReadFunctor sunStateInMsg; //!< sun state input message + ReadFunctor scStateInMsg; //!< spacecraft state input message + ReadFunctor earthStateInMsg; //!< Earth planet state input message + ReadFunctor sunStateInMsg; //!< sun state input message - Message fluxOutMsg; //!< output message with ion and electron fluxes + Message fluxOutMsg; //!< output message with ion and electron fluxes - BSKLogger bskLogger; //!< -- BSK Logging + BSKLogger bskLogger; //!< -- BSK Logging private: + void calcLocalTime(double v1[3], double v2[3]); + double bilinear(int, int, double, double, double, double, double, double, double); + void readDentonDataFile(std::string fileName, double data[MAX_NUM_KPS][MAX_NUM_ENERGIES][MAX_NUM_LOCAL_TIMES]); - int kpIndexCounter; //!< Kp index counter (betweeen 0 and 27) - double localTime; /* spacecraft location time relative to sun heading at GEO */ - double logEnElec[MAX_NUM_ENERGIES]; /* log of the electron energies */ - double logEnProt[MAX_NUM_ENERGIES]; /* log of the proton energies */ - double inputEnergies[MAX_NUM_ENERGIES]; /* input energies considered in this module */ + int kpIndexCounter; //!< Kp index counter (betweeen 0 and 27) + double localTime; //!< spacecraft location time relative to sun heading at GEO + double logEnElec[MAX_NUM_ENERGIES]; //!< log of the electron energies + double logEnProt[MAX_NUM_ENERGIES]; //!< log of the proton energies + double inputEnergies[MAX_NUM_ENERGIES]; //!< input energies considered in this module - // Electron Flux: + //!< Electron Flux: double mean_e_flux[MAX_NUM_KPS][MAX_NUM_ENERGIES][MAX_NUM_LOCAL_TIMES]; - // Ion Flux: + //!< Ion Flux: double mean_i_flux[MAX_NUM_KPS][MAX_NUM_ENERGIES][MAX_NUM_LOCAL_TIMES]; - // Fill average centre energies, normalized by satellite + //!< Fill average centre energies, normalized by satellite double enElec[40] = {1.034126, 1.346516, 1.817463, 2.399564, 3.161048, 4.153217, 5.539430, 7.464148, 9.836741, 12.543499, 16.062061, 20.876962, @@ -99,13 +98,6 @@ class DentonFluxModel: public SysModel { 2170.886474, 2829.989013, 3691.509765, 4822.499023, 6300.260742, 8217.569335, 10726.390625, 14001.280273, 18276.244140, 23856.085937, 31140.962890, 40649.562500}; - - - void calcLocalTime(double v1[3], double v2[3]); //!< calculate the local time - double bilinear(int, int, double, double, double, double, double, double, double); - void readDentonDataFile(std::string fileName, double data[MAX_NUM_KPS][MAX_NUM_ENERGIES][MAX_NUM_LOCAL_TIMES]); - }; - #endif From b4d0bd8a4b8900c02877fde742c665f79336b970 Mon Sep 17 00:00:00 2001 From: Julian Hammerl Date: Fri, 5 May 2023 10:25:20 -0600 Subject: [PATCH 2/4] Change flux unit From [cm^-2 s^-1 sr^-2 eV^-1] to [m^-2 s^-1 sr^-2 eV^-1] --- .../msgPayloadDefC/PlasmaFluxMsgPayload.h | 5 ++--- .../_UnitTest/test_dentonFluxModel.py | 15 +++++++++------ .../dentonFluxModel/dentonFluxModel.cpp | 14 +++++++------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/architecture/msgPayloadDefC/PlasmaFluxMsgPayload.h b/src/architecture/msgPayloadDefC/PlasmaFluxMsgPayload.h index d8b3926f3a..aea011c8b2 100755 --- a/src/architecture/msgPayloadDefC/PlasmaFluxMsgPayload.h +++ b/src/architecture/msgPayloadDefC/PlasmaFluxMsgPayload.h @@ -25,10 +25,9 @@ //!@brief space weather ambient plasma flux message definition. typedef struct { - double meanElectronFlux[MAX_PLASMA_FLUX_SIZE]; //!< [cm^-2 s^-1 sr^-2 eV^-1] differential flux - double meanIonFlux[MAX_PLASMA_FLUX_SIZE]; //!< [cm^-2 s^-1 sr^-2 eV^-1] differential flux + double meanElectronFlux[MAX_PLASMA_FLUX_SIZE]; //!< [m^-2 s^-1 sr^-2 eV^-1] differential flux + double meanIonFlux[MAX_PLASMA_FLUX_SIZE]; //!< [m^-2 s^-1 sr^-2 eV^-1] differential flux double energies[MAX_PLASMA_FLUX_SIZE]; //!< [eV] }PlasmaFluxMsgPayload; - #endif diff --git a/src/simulation/environment/dentonFluxModel/_UnitTest/test_dentonFluxModel.py b/src/simulation/environment/dentonFluxModel/_UnitTest/test_dentonFluxModel.py index a0b19c7d93..5152662f10 100644 --- a/src/simulation/environment/dentonFluxModel/_UnitTest/test_dentonFluxModel.py +++ b/src/simulation/environment/dentonFluxModel/_UnitTest/test_dentonFluxModel.py @@ -166,26 +166,29 @@ def dentonFluxModelTestFunction(show_plots, param1_Kp, param2_LT, param3_z, para trueIonFluxData = np.array([0.0] * messaging.MAX_PLASMA_FLUX_SIZE) with open(filepath, 'r') as file: rows = np.loadtxt(file, delimiter=",", unpack=False) + # true flux data provided by Denton is in Units of [cm^-2 s^-1 sr^-2 eV^-1], but DentonFluxModel converts it to + # [m^-2 s^-1 sr^-2 eV^-1]. Need to multiply by 1e4 trueEnergyData[0:module.numOutputEnergies] = rows[0] - trueElectronFluxData[0:module.numOutputEnergies] = 10.**(rows[1]) - trueIonFluxData[0:module.numOutputEnergies] = 10.**(rows[2]) + trueElectronFluxData[0:module.numOutputEnergies] = 10.**(rows[1]) * 1e4 + trueIonFluxData[0:module.numOutputEnergies] = 10.**(rows[2]) * 1e4 # make sure module output data is correct ParamsString = ' for Kp-Index=' + param1_Kp + ', LT=' + str(param2_LT) testFailCount, testMessages = unitTestSupport.compareDoubleArray( - trueEnergyData, energyData, accuracy, ('electron and ion energies' + ParamsString), + trueEnergyData, energyData, accuracy * 1e4, ('particle energies' + ParamsString), testFailCount, testMessages) testFailCount, testMessages = unitTestSupport.compareDoubleArray( - trueElectronFluxData, electronFluxData, accuracy, ('electron and ion energies' + ParamsString), + trueElectronFluxData, electronFluxData, accuracy * 1e4, ('electron flux' + ParamsString), testFailCount, testMessages) testFailCount, testMessages = unitTestSupport.compareDoubleArray( - trueIonFluxData, ionFluxData, accuracy, ('electron and ion energies' + ParamsString), + trueIonFluxData, ionFluxData, accuracy * 1e4, ('ion flux' + ParamsString), testFailCount, testMessages) # print out success or failure message if testFailCount == 0: print("PASSED: " + module.ModelTag) - print("This test uses an accuracy value of " + str(accuracy) + " (true values don't have higher precision)") + print("This test uses an accuracy value of " + str(accuracy * 1e4) + + " (true values don't have higher precision)") else: print("FAILED " + module.ModelTag) print(testMessages) diff --git a/src/simulation/environment/dentonFluxModel/dentonFluxModel.cpp b/src/simulation/environment/dentonFluxModel/dentonFluxModel.cpp index 70d685ed5b..5a435df01d 100644 --- a/src/simulation/environment/dentonFluxModel/dentonFluxModel.cpp +++ b/src/simulation/environment/dentonFluxModel/dentonFluxModel.cpp @@ -235,8 +235,8 @@ void DentonFluxModel::UpdateState(uint64_t CurrentSimNanos) flux12 = this->mean_e_flux[this->kpIndexCounter][eHigherIndex][localTimeFloor]; flux13 = this->mean_e_flux[this->kpIndexCounter][eLowerIndex][localTimeCeil]; flux14 = this->mean_e_flux[this->kpIndexCounter][eHigherIndex][localTimeCeil]; - - // ELECTRON: Find flux + + // ELECTRON: Find flux (differential flux in units of [cm^-2 s^-1 sr^-2 eV^-1]) finalElec = bilinear(localTimeFloor, localTimeCeil, logEnElec[eLowerIndex], logEnElec[eHigherIndex], logInputEnergy, flux11, flux12, flux13, flux14); finalElec = pow(10.0, finalElec); @@ -246,15 +246,15 @@ void DentonFluxModel::UpdateState(uint64_t CurrentSimNanos) flux12 = this->mean_i_flux[this->kpIndexCounter][iHigherIndex][localTimeFloor]; flux13 = this->mean_i_flux[this->kpIndexCounter][iLowerIndex][localTimeCeil]; flux14 = this->mean_i_flux[this->kpIndexCounter][iHigherIndex][localTimeCeil]; - - // ION: Find flux + + // ION: Find flux (differential flux in units of [cm^-2 s^-1 sr^-2 eV^-1]) finalIon = bilinear(localTimeFloor, localTimeCeil, logEnProt[iLowerIndex], logEnProt[iHigherIndex], logInputEnergy, flux11, flux12, flux13, flux14); finalIon = pow(10.0, finalIon); - // Store the output message - fluxOutMsgBuffer.meanElectronFlux[i] = finalElec; - fluxOutMsgBuffer.meanIonFlux[i] = finalIon; + // Store the output message (differential flux in units of [m^-2 s^-1 sr^-2 eV^-1]) + fluxOutMsgBuffer.meanElectronFlux[i] = finalElec * 1e4; + fluxOutMsgBuffer.meanIonFlux[i] = finalIon * 1e4; fluxOutMsgBuffer.energies[i] = inputEnergies[i]; } From 2f3df720489e4bc1cd6cddafac6bae2fc5732860 Mon Sep 17 00:00:00 2001 From: Julian Hammerl Date: Tue, 30 May 2023 10:33:37 -0600 Subject: [PATCH 3/4] Use numpy assert capability for UnitTest --- .../_UnitTest/test_dentonFluxModel.py | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/simulation/environment/dentonFluxModel/_UnitTest/test_dentonFluxModel.py b/src/simulation/environment/dentonFluxModel/_UnitTest/test_dentonFluxModel.py index 5152662f10..08c6aa5968 100644 --- a/src/simulation/environment/dentonFluxModel/_UnitTest/test_dentonFluxModel.py +++ b/src/simulation/environment/dentonFluxModel/_UnitTest/test_dentonFluxModel.py @@ -36,7 +36,6 @@ bskPath = __path__[0] from Basilisk.utilities import SimulationBaseClass -from Basilisk.utilities import unitTestSupport from Basilisk.architecture import messaging from Basilisk.utilities import macros from Basilisk.simulation import dentonFluxModel @@ -46,7 +45,7 @@ z_offsets = [0., 3500e3] r_EN_Ns = np.array([[0., 0., 0.], [400e3, 300e3, -200e3]]) -@pytest.mark.parametrize("accuracy", [1e-2]) +@pytest.mark.parametrize("accuracy", [1e2]) @pytest.mark.parametrize("param1_Kp, param2_LT, param3_z, param4_r_EN", [ (Kps[0], LTs[0], z_offsets[0], r_EN_Ns[0]), (Kps[1], LTs[1], z_offsets[1], r_EN_Ns[0]), @@ -78,15 +77,12 @@ def test_dentonFluxModel(show_plots, param1_Kp, param2_LT, param3_z, param4_r_EN The electron and ion energies are compared to make sure the flux data is computed for the same energy. The main part of the unitTest is to compare the electron and ion flux. """ - [testResults, testMessage] = dentonFluxModelTestFunction(show_plots, param1_Kp, param2_LT, param3_z, param4_r_EN, + dentonFluxModelTestFunction(show_plots, param1_Kp, param2_LT, param3_z, param4_r_EN, accuracy) - assert testResults < 1, testMessage def dentonFluxModelTestFunction(show_plots, param1_Kp, param2_LT, param3_z, param4_r_EN, accuracy): """Test method""" - testFailCount = 0 - testMessages = [] unitTaskName = "unitTask" unitProcessName = "TestProcess" @@ -173,25 +169,31 @@ def dentonFluxModelTestFunction(show_plots, param1_Kp, param2_LT, param3_z, para trueIonFluxData[0:module.numOutputEnergies] = 10.**(rows[2]) * 1e4 # make sure module output data is correct - ParamsString = ' for Kp-Index=' + param1_Kp + ', LT=' + str(param2_LT) - testFailCount, testMessages = unitTestSupport.compareDoubleArray( - trueEnergyData, energyData, accuracy * 1e4, ('particle energies' + ParamsString), - testFailCount, testMessages) - testFailCount, testMessages = unitTestSupport.compareDoubleArray( - trueElectronFluxData, electronFluxData, accuracy * 1e4, ('electron flux' + ParamsString), - testFailCount, testMessages) - testFailCount, testMessages = unitTestSupport.compareDoubleArray( - trueIonFluxData, ionFluxData, accuracy * 1e4, ('ion flux' + ParamsString), - testFailCount, testMessages) - - # print out success or failure message - if testFailCount == 0: - print("PASSED: " + module.ModelTag) - print("This test uses an accuracy value of " + str(accuracy * 1e4) + - " (true values don't have higher precision)") - else: - print("FAILED " + module.ModelTag) - print(testMessages) + paramsString = ' for Kp-Index={}, LT={}, accuracy={}'.format( + str(param1_Kp), + str(param2_LT), + str(accuracy)) + + np.testing.assert_allclose(energyData, + trueEnergyData, + rtol=0, + atol=accuracy, + err_msg=('Variable: energyData,' + paramsString), + verbose=True) + + np.testing.assert_allclose(electronFluxData, + trueElectronFluxData, + rtol=0, + atol=accuracy, + err_msg=('Variable: electronFluxData,' + paramsString), + verbose=True) + + np.testing.assert_allclose(ionFluxData, + trueIonFluxData, + rtol=0, + atol=accuracy, + err_msg=('Variable: ionFluxData,' + paramsString), + verbose=True) plt.figure(1) fig = plt.gcf() @@ -203,8 +205,6 @@ def dentonFluxModelTestFunction(show_plots, param1_Kp, param2_LT, param3_z, para if show_plots: plt.show() - return [testFailCount, ''.join(testMessages)] - if __name__ == "__main__": - test_dentonFluxModel(False, '4-', LTs[1], z_offsets[1], r_EN_Ns[1], 1e-2) + test_dentonFluxModel(False, '4-', LTs[1], z_offsets[1], r_EN_Ns[1], 1e2) From 3e20b24b86f42eee25453dc1573c199f9c513260 Mon Sep 17 00:00:00 2001 From: Julian Hammerl Date: Mon, 8 May 2023 08:42:17 -0600 Subject: [PATCH 4/4] Add release notes --- docs/source/Support/bskReleaseNotes.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/source/Support/bskReleaseNotes.rst b/docs/source/Support/bskReleaseNotes.rst index 2f4dcf4e10..fd08bbaf51 100644 --- a/docs/source/Support/bskReleaseNotes.rst +++ b/docs/source/Support/bskReleaseNotes.rst @@ -58,6 +58,8 @@ Version |release| :ref:`prescribedMotionStateEffector` dynamics module. - Corrected default value of ``accuracyNanos`` in :ref:`simSynch` to be 0.01 seconds. - Added a deprecation system for Basilisk. For developers, see :ref:`deprecatingCode`. +- Changed the units of plasma flux in :ref:`dentonFluxModel` and :ref:`PlasmaFluxMsgPayload` from + [cm^-2 s^-1 sr^-2 eV^-1] to [m^-2 s^-1 sr^-2 eV^-1], because m^-2 is used more frequently in computations Version 2.1.7 (March 24, 2023)