Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add third body shadow #532

Merged
merged 3 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions data/sample/initialize_files/sample_local_environment.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ magnetic_field_white_noise_standard_deviation_nT = 50.0
[SOLAR_RADIATION_PRESSURE_ENVIRONMENT]
calculation = ENABLE
logging = ENABLE
// The number of shadow generating bodies other than the central body
number_of_third_shadow_source_ = 1
// List of shadow generating bodies other than the central body
// All these bodies must be included in the "selected_body_name" of "[CelestialInformation]"
third_shadow_source_name(0) = MOON


[ATMOSPHERE]
Expand Down
21 changes: 15 additions & 6 deletions src/environment/local/solar_radiation_pressure_environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@
SolarRadiationPressureEnvironment::SolarRadiationPressureEnvironment(LocalCelestialInformation* local_celestial_information)
: local_celestial_information_(local_celestial_information) {
solar_radiation_pressure_N_m2_ = solar_constant_W_m2_ / environment::speed_of_light_m_s;
shadow_source_name_ = local_celestial_information_->GetGlobalInformation().GetCenterBodyName();
shadow_source_name_list_.push_back(local_celestial_information_->GetGlobalInformation().GetCenterBodyName());
sun_radius_m_ = local_celestial_information_->GetGlobalInformation().GetMeanRadiusFromName_m("SUN");
}

void SolarRadiationPressureEnvironment::UpdateAllStates() {
if (!IsCalcEnabled) return;

UpdatePressure();
CalcShadowCoefficient(shadow_source_name_);
shadow_coefficient_ = 1.0; // Initialize for multiple shadow source
for (auto shadow_source_name : shadow_source_name_list_) {
CalcShadowCoefficient(shadow_source_name);
}
}

void SolarRadiationPressureEnvironment::UpdatePressure() {
Expand Down Expand Up @@ -54,7 +57,7 @@ std::string SolarRadiationPressureEnvironment::GetLogValue() const {

void SolarRadiationPressureEnvironment::CalcShadowCoefficient(std::string shadow_source_name) {
if (shadow_source_name == "SUN") {
shadow_coefficient_ = 1.0;
shadow_coefficient_ *= 1.0;
return;
}

Expand All @@ -81,17 +84,17 @@ void SolarRadiationPressureEnvironment::CalcShadowCoefficient(std::string shadow

if (c < fabs(a - b) && a <= b) // The occultation is total (spacecraft is in umbra)
{
shadow_coefficient_ = 0.0;
shadow_coefficient_ *= 0.0;
} else if (c < fabs(a - b) && a > b) // The occultation is partial but maximum
{
shadow_coefficient_ = 1.0 - (b * b) / (a * a);
} else if (fabs(a - b) <= c && c <= (a + b)) // spacecraft is in penumbra
{
double A = a * a * acos(x / a) + b * b * acos((c - x) / b) - c * y; // The area of the occulted segment of the apparent solar disk
shadow_coefficient_ = 1.0 - A / (libra::pi * a * a);
shadow_coefficient_ *= 1.0 - A / (libra::pi * a * a);
} else { // no occultation takes place
assert(c > (a + b));
shadow_coefficient_ = 1.0;
shadow_coefficient_ *= 1.0;
}
}

Expand All @@ -104,5 +107,11 @@ SolarRadiationPressureEnvironment InitSolarRadiationPressureEnvironment(std::str
srp_env.IsCalcEnabled = conf.ReadEnable(section, INI_CALC_LABEL);
srp_env.is_log_enabled_ = conf.ReadEnable(section, INI_LOG_LABEL);

size_t number_of_third_shadow_source = conf.ReadInt(section, "number_of_third_shadow_source");
std::vector<std::string> list = conf.ReadVectorString(section, "third_shadow_source_name", number_of_third_shadow_source);
for (size_t i = 0; i < number_of_third_shadow_source; i++) {
srp_env.AddShadowSource(list[0]);
}

return srp_env;
}
20 changes: 15 additions & 5 deletions src/environment/local/solar_radiation_pressure_environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ class SolarRadiationPressureEnvironment : public ILoggable {
*/
void UpdateAllStates();

/**
* @fn AddShadowSource
* @brief Update pressure and shadow coefficients
* @param [in] shadow_source_name: Shadow source name
*/
void AddShadowSource(const std::string shadow_source_name) {
// TODO: Add assertion
shadow_source_name_list_.push_back(shadow_source_name);
}

// Getter
/**
* @fn GetPressure_N_m2
Expand Down Expand Up @@ -81,11 +91,11 @@ class SolarRadiationPressureEnvironment : public ILoggable {
virtual std::string GetLogValue() const;

private:
double solar_radiation_pressure_N_m2_; //!< Solar radiation pressure [N/m^2]
double solar_constant_W_m2_ = 1366.0; //!< Solar constant [W/m^2] TODO: We need to change the value depends on sun activity.
double shadow_coefficient_ = 1.0; //!< Shadow function
double sun_radius_m_; //!< Sun radius [m]
std::string shadow_source_name_; //!< Shadow source name
double solar_radiation_pressure_N_m2_; //!< Solar radiation pressure [N/m^2]
double solar_constant_W_m2_ = 1366.0; //!< Solar constant [W/m^2] TODO: We need to change the value depends on sun activity.
double shadow_coefficient_ = 1.0; //!< Shadow function
double sun_radius_m_; //!< Sun radius [m]
std::vector<std::string> shadow_source_name_list_; //!< Shadow source name list

LocalCelestialInformation* local_celestial_information_; //!< Local celestial information

Expand Down
Loading