Skip to content

Commit

Permalink
Small updates
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicDirkx committed Oct 24, 2023
1 parent 42d60cb commit f148afd
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 155 deletions.
54 changes: 18 additions & 36 deletions include/tudat/astro/electromagnetism/luminosityModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace tudat
namespace electromagnetism
{

double computeLuminosityFromIrradiance( const double irradiance, const double distance );

/*!
* Class modeling the luminosity, or emitted electromagnetic power, of a radiation source.
*
Expand Down Expand Up @@ -81,56 +83,36 @@ class ConstantLuminosityModel : public LuminosityModel
double luminosity_;
};


/*!
* Class modeling luminosity of a radiation source based on the irradiance at a given distance.
*
* This luminosity is useful to model variations in the Sun luminosity based on the solar irradiance measured
* at Earth distance.
*
* The source is assumed to be isotropic such that the irradiance given would be found at any position with the
* same distance from the source.
*/
class IrradianceBasedLuminosityModel : public LuminosityModel
class VariableLuminosityModel : public LuminosityModel
{
public:
/*!
* Constructor.
*
* @param irradianceAtDistanceFunction Function returning the irradiance [W/m²] at a given time
* @param distance Distance from the source at which the irradiance was evaluated/measured
*/
explicit IrradianceBasedLuminosityModel(
const std::function<double(double)>& irradianceAtDistanceFunction,
double distance)
: irradianceAtDistanceFunction_(irradianceAtDistanceFunction), distance_(distance) {}

/*!
* Constructor.
*
* @param irradianceAtDistance Irradiance at the given distance [W/m²]
* @param distance Distance from the source at which the irradiance was evaluated/measured
* @param luminosity Constant luminosity of the source [W]
*/
explicit IrradianceBasedLuminosityModel(
double irradianceAtDistance,
double distance)
: IrradianceBasedLuminosityModel([=] (double) { return irradianceAtDistance; }, distance) {}
explicit VariableLuminosityModel( const std::function< double( const double ) > luminosityFunction ) :
luminosityFunction_( luminosityFunction ), luminosity_( TUDAT_NAN ) {}

double getLuminosity() const override;
double getLuminosity() const override
{
return luminosity_;
}

private:
void updateMembers_(double currentTime) override;

//! Function returning the irradiance [W/m²] at a given time
std::function<double(double)> irradianceAtDistanceFunction_;
virtual void updateMembers_(const double currentTime) override
{
luminosity_ = luminosityFunction_( currentTime );
}

//! Irradiance from the last evaluation of irradianceAtDistanceFunction_ [W/m²]
double irradianceAtDistance_{};
//! Constant luminosity of the source [W]
const std::function< double( const double ) > luminosityFunction_;

//! Distance from the source at which the irradiance was evaluated/measured
double distance_;
double luminosity_;
};


} // tudat
} // electromagnetism

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,26 @@ class SecondDegreeZonalPeriodicSurfacePropertyDistribution : public SurfacePrope
const double angularFrequency;
};

} // tudat
class CustomSurfacePropertyDistribution : public SurfacePropertyDistribution
{
public:
CustomSurfacePropertyDistribution(
const std::function< double( const double, const double, const double ) > customFunction ):
customFunction_( customFunction ){ }

double getValue(double latitude, double longitude)
{
return customFunction_( latitude, longitude, currentTime_ );
}

bool isTimeInvariant( ){ return false; }

private:
std::function< double( const double, const double, const double ) > customFunction_;
};

} // electromagnetism

} // tudat

#endif //TUDAT_SURFACEPROPERTYDISTRIBUTION_H
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class RadiationSourceModelSettings
enum class LuminosityModelType
{
constant_radiant_power,
irradiance_based_radiant_power
time_variable_isotropic_radiant_power
};

/*!
Expand Down Expand Up @@ -117,40 +117,26 @@ class ConstantLuminosityModelSettings : public LuminosityModelSettings
double luminosity_;
};

/*!
* Settings for an irradiance-based luminosity model.
*
* @see IrradianceBasedLuminosityModel
*/
class IrradianceBasedLuminosityModelSettings : public LuminosityModelSettings
class TimeVariableLuminosityModelSettings : public LuminosityModelSettings
{
public:
/*!
* Constructor.
*
* @param irradianceAtDistanceFunction Function returning the irradiance at a given time [W/m²]
* @param distance Distance from the source at which the irradiance was evaluated/measured
* @param luminosity Constant luminosity of the source [W]
*/
explicit IrradianceBasedLuminosityModelSettings(
const std::function<double(double)>& irradianceAtDistanceFunction,
const double distance) :
LuminosityModelSettings(LuminosityModelType::irradiance_based_radiant_power),
irradianceAtDistanceFunction_(irradianceAtDistanceFunction),
distance_(distance) {}

const std::function<double(double)>& getIrradianceAtDistanceFunction() const
{
return irradianceAtDistanceFunction_;
}
explicit TimeVariableLuminosityModelSettings(
const std::function< double( const double ) > luminosityFunction) :
LuminosityModelSettings(LuminosityModelType::time_variable_isotropic_radiant_power),
luminosityFunction_(luminosityFunction) {}

double getDistance() const
std::function< double( const double ) > getLuminosityFuntion() const
{
return distance_;
return luminosityFunction_;
}

private:
std::function<double(double)> irradianceAtDistanceFunction_;
double distance_;
std::function< double( const double ) > luminosityFunction_;
};

/*!
Expand Down Expand Up @@ -200,9 +186,24 @@ inline std::shared_ptr<LuminosityModelSettings>
inline std::shared_ptr<LuminosityModelSettings>
irradianceBasedLuminosityModelSettings(double irradianceAtDistance, double distance)
{
return std::make_shared< IrradianceBasedLuminosityModelSettings >(
[=] (double) { return irradianceAtDistance; },
distance);
return std::make_shared< ConstantLuminosityModelSettings >(
electromagnetism::computeLuminosityFromIrradiance( irradianceAtDistance, distance ) );
}

inline std::shared_ptr<LuminosityModelSettings>
timeVariableLuminosityModelSettings(const std::function< double( const double ) > luminosityFunction )
{
return std::make_shared< TimeVariableLuminosityModelSettings >(luminosityFunction);
}


inline std::shared_ptr<LuminosityModelSettings>
timeVariableIrradianceBasedLuminosityModelSettings(const std::function< double( const double ) > irradianceAtDistanceFunction, double distance)
{
return std::make_shared< TimeVariableLuminosityModelSettings >(
[=](const double time){ return electromagnetism::computeLuminosityFromIrradiance(
irradianceAtDistanceFunction( time ), distance ); }
);
}

/*!
Expand Down Expand Up @@ -540,7 +541,7 @@ inline std::shared_ptr<PanelRadiosityModelSettings>
*/
inline std::shared_ptr<PanelRadiosityModelSettings>
albedoPanelRadiosityModelSettings(
SecondDegreeZonalPeriodicSurfacePropertyDistributionModel albedoModel,
KnockeTypeSurfacePropertyDistributionModel albedoModel,
const std::string& originalSourceName)
{
return std::make_shared< AlbedoPanelRadiosityModelSettings >(
Expand Down Expand Up @@ -586,7 +587,7 @@ inline std::shared_ptr<PanelRadiosityModelSettings>
*/
inline std::shared_ptr<PanelRadiosityModelSettings>
delayedThermalPanelRadiosityModelSettings(
SecondDegreeZonalPeriodicSurfacePropertyDistributionModel emissivityModel,
KnockeTypeSurfacePropertyDistributionModel emissivityModel,
const std::string& originalSourceName)
{
return std::make_shared< DelayedThermalPanelRadiosityModelSettings >(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ enum class SurfacePropertyDistributionType
{
constant,
spherical_harmonics,
second_degree_zonal_periodic
second_degree_zonal_periodic,
custom_surface_distribution
};

/*!
Expand Down Expand Up @@ -138,7 +139,7 @@ class SphericalHarmonicsSurfacePropertyDistributionSettings : public SurfaceProp
Eigen::MatrixXd sineCoefficients_;
};

enum class SecondDegreeZonalPeriodicSurfacePropertyDistributionModel
enum class KnockeTypeSurfacePropertyDistributionModel
{
custom,
albedo_knocke, /**< Knocke Earth albedo model: Knocke, Philip et al. "Earth radiation pressure effects on satellites." Astrodynamics Conference. American Institute of Aeronautics and Astronautics, 1988. */
Expand Down Expand Up @@ -174,7 +175,7 @@ class SecondDegreeZonalPeriodicSurfacePropertyDistributionSettings : public Surf
const double referenceEpoch,
const double period) :
SurfacePropertyDistributionSettings(SurfacePropertyDistributionType::second_degree_zonal_periodic),
model_(SecondDegreeZonalPeriodicSurfacePropertyDistributionModel::custom),
model_(KnockeTypeSurfacePropertyDistributionModel::custom),
a0(a0),
c0(c0),
c1(c1),
Expand All @@ -189,7 +190,7 @@ class SecondDegreeZonalPeriodicSurfacePropertyDistributionSettings : public Surf
* @param model Model to be used
*/
explicit SecondDegreeZonalPeriodicSurfacePropertyDistributionSettings(
SecondDegreeZonalPeriodicSurfacePropertyDistributionModel model);
KnockeTypeSurfacePropertyDistributionModel model);

double getA0() const
{
Expand Down Expand Up @@ -227,7 +228,7 @@ class SecondDegreeZonalPeriodicSurfacePropertyDistributionSettings : public Surf
}

private:
SecondDegreeZonalPeriodicSurfacePropertyDistributionModel model_;
KnockeTypeSurfacePropertyDistributionModel model_;

double a0;
double c0;
Expand All @@ -238,6 +239,24 @@ class SecondDegreeZonalPeriodicSurfacePropertyDistributionSettings : public Surf
double period;
};


class CustomSurfacePropertyDistributionSettings : public SurfacePropertyDistributionSettings
{
public:
explicit CustomSurfacePropertyDistributionSettings(
const std::function< double( const double, const double, const double ) > customFunction ) :
SurfacePropertyDistributionSettings(SurfacePropertyDistributionType::custom_surface_distribution),
customFunction_( customFunction ){ }

std::function< double( const double, const double, const double ) > getCustomFunction( )
{
return customFunction_;
}

private:
std::function< double( const double, const double, const double ) > customFunction_;

};
/*!
* Create settings for constant surface property distribution.
*
Expand Down Expand Up @@ -287,7 +306,7 @@ inline std::shared_ptr<SurfacePropertyDistributionSettings>
*/
inline std::shared_ptr<SurfacePropertyDistributionSettings>
secondDegreeZonalPeriodicSurfacePropertyDistributionSettings(
SecondDegreeZonalPeriodicSurfacePropertyDistributionModel model)
KnockeTypeSurfacePropertyDistributionModel model)
{
return std::make_shared< SecondDegreeZonalPeriodicSurfacePropertyDistributionSettings >(model);
}
Expand All @@ -307,6 +326,12 @@ manualSecondDegreeZonalPeriodicSurfacePropertyDistributionSettings(
);
}

inline std::shared_ptr<SurfacePropertyDistributionSettings>
customSurfacePropertyDistributionSettings(
const std::function< double( const double, const double, const double ) > customFunction )
{
return std::make_shared< CustomSurfacePropertyDistributionSettings >(customFunction);
}

/*!
* Create surface property distribution from its settings.
Expand Down
18 changes: 5 additions & 13 deletions src/astro/electromagnetism/luminosityModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ namespace tudat
namespace electromagnetism
{

double computeLuminosityFromIrradiance( const double irradiance, const double distance )
{
return 4.0 * mathematical_constants::PI * distance * distance * irradiance;
}

void LuminosityModel::updateMembers(double currentTime)
{
if(currentTime_ != currentTime)
Expand All @@ -30,18 +35,5 @@ void LuminosityModel::updateMembers(double currentTime)
}
}

double IrradianceBasedLuminosityModel::getLuminosity() const
{
// The source is assumed to be isotropic
auto sphereArea = 4 * mathematical_constants::PI * distance_ * distance_;
auto luminosity = irradianceAtDistance_ * sphereArea;
return luminosity;
}

void IrradianceBasedLuminosityModel::updateMembers_(const double currentTime)
{
// Evaluate only once per timestep since irradiance function could be expensive to evaluate
irradianceAtDistance_ = irradianceAtDistanceFunction_(currentTime);
}
} // tudat
} // electromagnetism
15 changes: 7 additions & 8 deletions src/simulation/environment_setup/createRadiationSourceModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,18 @@ std::shared_ptr<electromagnetism::LuminosityModel> createLuminosityModel(
);
break;
}
case LuminosityModelType::irradiance_based_radiant_power:
case LuminosityModelType::time_variable_isotropic_radiant_power :
{
auto irradianceBasedLuminosityModelSettings =
std::dynamic_pointer_cast< IrradianceBasedLuminosityModelSettings >(modelSettings);
if(irradianceBasedLuminosityModelSettings == nullptr)
auto variableLuminosityModelSettings =
std::dynamic_pointer_cast< TimeVariableLuminosityModelSettings >(modelSettings);
if(variableLuminosityModelSettings == nullptr)
{
throw std::runtime_error(
"Error, expected irradiance-based luminosity model for body " + body );
"Error, expected time-variable luminosity model for body " + body );
}

luminosityModel = std::make_shared<IrradianceBasedLuminosityModel>(
irradianceBasedLuminosityModelSettings->getIrradianceAtDistanceFunction(),
irradianceBasedLuminosityModelSettings->getDistance()
luminosityModel = std::make_shared<VariableLuminosityModel>(
variableLuminosityModelSettings->getLuminosityFuntion( )
);
break;
}
Expand Down
Loading

0 comments on commit f148afd

Please sign in to comment.