Skip to content

Commit

Permalink
Fix boolean check, rename variables to rotation angle, apply rotation
Browse files Browse the repository at this point in the history
limits
  • Loading branch information
mjprilliman committed Oct 25, 2023
1 parent 96138f7 commit f061325
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 50 deletions.
29 changes: 17 additions & 12 deletions shared/lib_irradproc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,12 @@ void incidence(int mode, double tilt, double sazm, double rlim, double zen,

/*Check if custom tilt angles enabled, apply timeseries value*/
if (useCustomAngle) {
rot = customAngle * DTOR; //overwrite rotation angle with input from array
if (rot < -rlim) /* Do not let rotation exceed physical constraints */
rot = -rlim;
else if (rot > rlim)
rot = rlim;
else
rot = customAngle * DTOR; //overwrite rotation angle with input from array
}

/* Find tilt angle for the tracking surface */
Expand Down Expand Up @@ -1756,7 +1761,7 @@ void irrad::setup() {
poaRearDirectDiffuse = 0.;
poaRearRowReflections = 0.;
poaRearSelfShaded = 0.;
useCustomTiltAngles = 0.;
useCustomRotAngles = 0.;

}

Expand All @@ -1772,7 +1777,7 @@ irrad::irrad(weather_record wf, weather_header hdr,
double groundCoverageRatioIn, double slopeTiltIn, double slopeAzmIn, std::vector<double> monthlyTiltDegrees,
std::vector<double> userSpecifiedAlbedo,
poaDecompReq *poaAllIn,
bool useSpatialAlbedos, const util::matrix_t<double>* userSpecifiedSpatialAlbedos, bool enableSubhourlyClipping, bool useCustomTiltAngles, double customTiltAngle) :
bool useSpatialAlbedos, const util::matrix_t<double>* userSpecifiedSpatialAlbedos, bool enableSubhourlyClipping, bool useCustomRotAngles, double customRotAngle) :
skyModel(skyModelIn), radiationMode(radiationModeIn), trackingMode(trackModeIn),
enableBacktrack(backtrackingEnabled), forceToStow(forceToStowIn),
delt(dtHour), tiltDegrees(tiltDegreesIn), surfaceAzimuthDegrees(azimuthDegreesIn),
Expand Down Expand Up @@ -1801,7 +1806,7 @@ irrad::irrad(weather_record wf, weather_header hdr,

set_subhourly_clipping(enableSubhourlyClipping);

set_custom_tilt_angles(useCustomTiltAngles, customTiltAngle);
set_custom_rot_angles(useCustomRotAngles, customRotAngle);

if (radiationMode == irrad::DN_DF) set_beam_diffuse(wf.dn, wf.df);
else if (radiationMode == irrad::DN_GH) set_global_beam(wf.gh, wf.dn);
Expand Down Expand Up @@ -1996,10 +2001,10 @@ void irrad::set_subhourly_clipping(bool enable)
if (enable) this->enableSubhourlyClipping = true;
}

void irrad::set_custom_tilt_angles(bool enable, double angle)
void irrad::set_custom_rot_angles(bool enable, double angle)
{
this->useCustomTiltAngles = enable;
this->customTiltAngle = angle;
this->useCustomRotAngles = enable;
this->customRotAngle = angle;
}

void irrad::set_sky_model(int sm, double alb, const std::vector<double> &albSpatial) {
Expand Down Expand Up @@ -2190,7 +2195,7 @@ int irrad::calc() {
// compute incidence angles onto fixed or tracking surface
incidence(trackingMode, tiltDegrees, surfaceAzimuthDegrees, rotationLimitDegrees, sunAnglesRadians[1],
sunAnglesRadians[0],
enableBacktrack, groundCoverageRatio, slopeTilt, slopeAzm, forceToStow, stowAngleDegrees, useCustomTiltAngles, customTiltAngle, surfaceAnglesRadians);
enableBacktrack, groundCoverageRatio, slopeTilt, slopeAzm, forceToStow, stowAngleDegrees, useCustomRotAngles, customRotAngle, surfaceAnglesRadians);
if (radiationMode < irrad::POA_R) {
double hextra = sunAnglesRadians[8];
double hbeam = directNormal *
Expand Down Expand Up @@ -2590,7 +2595,7 @@ void irrad::getFrontSurfaceIrradiances(double pvFrontShadeFraction, double rowTo
// Calculate irradiance components for a 90 degree tilt to get horizon brightening
double angleTmp[5] = {0, 0, 0, 0, 0}; // ([0] = incidence angle, [1] = tilt)
incidence(0, 90.0, 180.0, 45.0, solarZenithRadians, solarAzimuthRadians, this->enableBacktrack,
this->groundCoverageRatio, this->slopeTilt, this->slopeAzm, this->forceToStow, this->stowAngleDegrees, this->useCustomTiltAngles, this->customTiltAngle, angleTmp);
this->groundCoverageRatio, this->slopeTilt, this->slopeAzm, this->forceToStow, this->stowAngleDegrees, this->useCustomRotAngles, this->customRotAngle, angleTmp);
perez(0, calculatedDirectNormal, calculatedDiffuseHorizontal, albedo, angleTmp[0], angleTmp[1], solarZenithRadians,
poa, diffc);
double horizonDiffuse = diffc[2];
Expand Down Expand Up @@ -2726,7 +2731,7 @@ void irrad::getFrontSurfaceIrradiances(double pvFrontShadeFraction, double rowTo
// Calculate and add direct and circumsolar irradiance components
incidence(0, tiltRadians * RTOD, surfaceAzimuthRadians * RTOD, 45.0, solarZenithRadians, solarAzimuthRadians,
this->enableBacktrack, this->groundCoverageRatio, this->slopeTilt, this->slopeAzm,
this->forceToStow, this->stowAngleDegrees, this->useCustomTiltAngles, this->customTiltAngle, surfaceAnglesRadians);
this->forceToStow, this->stowAngleDegrees, this->useCustomRotAngles, this->customRotAngle, surfaceAnglesRadians);
perez(0, calculatedDirectNormal, calculatedDiffuseHorizontal, albedo, surfaceAnglesRadians[0],
surfaceAnglesRadians[1], solarZenithRadians, poa, diffc);

Expand Down Expand Up @@ -2771,7 +2776,7 @@ void irrad::getBackSurfaceIrradiances(double pvBackShadeFraction, double rowToRo
// Calculate components for a 90 degree tilt to get horizon brightening
double surfaceAnglesRadians90[5] = {0, 0, 0, 0, 0};
incidence(0, 90.0, 180.0, 45.0, solarZenithRadians, solarAzimuthRadians, this->enableBacktrack,
this->groundCoverageRatio, this->slopeTilt, this->slopeAzm, this->forceToStow, this->stowAngleDegrees, this->useCustomTiltAngles, this->customTiltAngle, surfaceAnglesRadians90);
this->groundCoverageRatio, this->slopeTilt, this->slopeAzm, this->forceToStow, this->stowAngleDegrees, this->useCustomRotAngles, this->customRotAngle, surfaceAnglesRadians90);
perez(0, calculatedDirectNormal, calculatedDiffuseHorizontal, albedo, surfaceAnglesRadians90[0],
surfaceAnglesRadians90[1], solarZenithRadians, planeOfArrayIrradianceRear, diffuseIrradianceRear);
double horizonDiffuse = diffuseIrradianceRear[2];
Expand Down Expand Up @@ -2971,7 +2976,7 @@ void irrad::getBackSurfaceIrradiances(double pvBackShadeFraction, double rowToRo
// Calculate and add direct and circumsolar irradiance components
incidence(0, 180.0 - tiltRadians * RTOD, (surfaceAzimuthRadians * RTOD - 180.0), 45.0, solarZenithRadians,
solarAzimuthRadians, this->enableBacktrack,
this->groundCoverageRatio, this->slopeTilt, this->slopeAzm, this->forceToStow, this->stowAngleDegrees, this->useCustomTiltAngles, this->customTiltAngle, surfaceAnglesRadians);
this->groundCoverageRatio, this->slopeTilt, this->slopeAzm, this->forceToStow, this->stowAngleDegrees, this->useCustomRotAngles, this->customRotAngle, surfaceAnglesRadians);
perez(0, calculatedDirectNormal, calculatedDiffuseHorizontal, albedo, surfaceAnglesRadians[0],
surfaceAnglesRadians[1], solarZenithRadians, planeOfArrayIrradianceRear, diffuseIrradianceRear);

Expand Down
8 changes: 4 additions & 4 deletions shared/lib_irradproc.h
Original file line number Diff line number Diff line change
Expand Up @@ -994,8 +994,8 @@ class irrad
bool enableSubhourlyClipping;

//Custom rotation angles for single-axis trackers
bool useCustomTiltAngles;
double customTiltAngle; // custom tracker rotation angle in degrees
bool useCustomRotAngles;
double customRotAngle; // custom tracker rotation angle in degrees

// Subarray properties
double tiltDegrees; ///< Surface tilt of subarray in degrees
Expand Down Expand Up @@ -1061,7 +1061,7 @@ class irrad
double dtHour, double tiltDegrees, double azimuthDegrees, double trackerRotationLimitDegrees, double stowAngleDegreesIn,
double groundCoverageRatio, double slopeTilt, double slopeAzm, std::vector<double> monthlyTiltDegrees, std::vector<double> userSpecifiedAlbedo,
poaDecompReq* poaAllIn,
bool useSpatialAlbedos = false, const util::matrix_t<double>* userSpecifiedSpatialAlbedos = nullptr, bool enableSubhourlyClipping = false, bool useCustomTiltAngles = false, double customTiltAngle = 0);
bool useSpatialAlbedos = false, const util::matrix_t<double>* userSpecifiedSpatialAlbedos = nullptr, bool enableSubhourlyClipping = false, bool useCustomRotAngles = false, double customRotAngle = 0);

/// Construct the irrad class with an Irradiance_IO() object and Subarray_IO() object
irrad();
Expand All @@ -1084,7 +1084,7 @@ class irrad
//Set whether to use subhourly clipping model
void set_subhourly_clipping(bool enable = false);

void set_custom_tilt_angles(bool enable = false, double angle = 0);
void set_custom_rot_angles(bool enable = false, double angle = 0);

/// Set the sky model for the irradiance processor, using \link Irradiance_IO::SKYMODEL
void set_sky_model(int skymodel, double albedo, const std::vector<double> &albedoSpatial = std::vector<double>());
Expand Down
14 changes: 7 additions & 7 deletions shared/lib_pv_io_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ Subarray_IO::Subarray_IO(compute_module* cm, const std::string& cmName, size_t s
nModulesPerString = cm->as_integer(prefix + "modules_per_string");
mpptInput = cm->as_integer(prefix + "mppt_input");
trackMode = cm->as_integer(prefix + "track_mode");
useCustomTiltAngles = cm->as_integer(prefix + "use_custom_tilt_angles");
useMeasuredTemp = cm->as_integer(prefix + "use_measured_temp");
useCustomRotAngles = cm->as_boolean(prefix + "use_custom_rot_angles");
useMeasuredTemp = cm->as_boolean(prefix + "use_measured_temp");
tiltEqualLatitude = 0;
if (cm->is_assigned(prefix + "tilt_eq_lat")) tiltEqualLatitude = cm->as_boolean(prefix + "tilt_eq_lat");

Expand All @@ -380,11 +380,11 @@ Subarray_IO::Subarray_IO(compute_module* cm, const std::string& cmName, size_t s
}

/* Insert checks for custom tilt angles here*/
if (useCustomTiltAngles == 1) {
if (cm->is_assigned(prefix + "custom_tilt_angles_array")) {
customTiltAngles = cm->as_vector_double(prefix + "custom_tilt_angles_array");
for (int i = 0; i < customTiltAngles.size(); i++) {
if (customTiltAngles[i] > 90.0 || customTiltAngles[i] < -90.0) throw exec_error(cmName, "Subarray " + util::to_string((int)subarrayNumber) + "custom tilt angles cannot be outside of 90deg.");
if (useCustomRotAngles == 1) {
if (cm->is_assigned(prefix + "custom_rot_angles_array")) {
customRotAngles = cm->as_vector_double(prefix + "custom_rot_angles_array");
for (int i = 0; i < customRotAngles.size(); i++) {
if (customRotAngles[i] > 90.0 || customRotAngles[i] < -90.0) throw exec_error(cmName, "Subarray " + util::to_string((int)subarrayNumber) + "custom tilt angles cannot be outside of 90deg.");
}
}
else {
Expand Down
4 changes: 2 additions & 2 deletions shared/lib_pv_io_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,8 @@ struct Subarray_IO
double slopeTilt; // Angle of sloped terrain [degrees]
double slopeAzm; // azimuth of sloped terrain relative to tracker azimuth [degrees]
double tiltDegrees; // The surface tilt [degrees]
flag useCustomTiltAngles; // Use custom timeseries rotation angles
std::vector<double> customTiltAngles; //Custom timeseries rotation angles [degrees]
flag useCustomRotAngles; // Use custom timeseries rotation angles
std::vector<double> customRotAngles; //Custom timeseries rotation angles [degrees]
flag useMeasuredTemp;
std::vector<double> measuredTempArray;
double azimuthDegrees; // The surface azimuth [degrees]
Expand Down
Loading

0 comments on commit f061325

Please sign in to comment.