Skip to content

Commit

Permalink
Fix EMS issues and several others
Browse files Browse the repository at this point in the history
  • Loading branch information
amirroth committed Dec 8, 2024
1 parent d0b7ff9 commit 1272641
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 86 deletions.
2 changes: 1 addition & 1 deletion src/EnergyPlus/DataRuntimeLanguage.hh
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ struct RuntimeLanguageData : BaseGlobalStruct
DataRuntimeLanguage::ErlValueType True = DataRuntimeLanguage::ErlValueType(
DataRuntimeLanguage::Value::Null, 0.0, "", 0, 0, false, 0, "", true); // special "True" Erl variable value instance, gets reset

std::map<std::tuple<std::string_view, std::string_view, std::string_view>, int> EMSActuatorAvailableMap;
std::map<std::tuple<std::string, std::string, std::string>, int> EMSActuatorAvailableMap;

void init_constant_state([[maybe_unused]] EnergyPlusData &state) override
{
Expand Down
52 changes: 25 additions & 27 deletions src/EnergyPlus/EMSManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1958,9 +1958,9 @@ namespace EMSManager {
// ScheduleManager and OutputProcessor. Followed pattern used for SetupOutputVariable

void SetupEMSActuator(EnergyPlusData &state,
std::string_view cComponentTypeName,
std::string_view cUniqueIDName,
std::string_view cControlTypeName,
std::string_view objType,
std::string_view objName,
std::string_view controlTypeName,
std::string_view cUnits,
bool &lEMSActuated,
Real64 &rValue)
Expand All @@ -1981,34 +1981,32 @@ void SetupEMSActuator(EnergyPlusData &state,

auto &s_lang = state.dataRuntimeLang;

std::string const objType = Util::makeUPPER(cComponentTypeName);
std::string const objName = Util::makeUPPER(cUniqueIDName);
std::string const actuatorName = Util::makeUPPER(cControlTypeName);
auto tup = std::make_tuple(std::move(Util::makeUPPER(objType)), std::move(Util::makeUPPER(objName)), std::move(Util::makeUPPER(controlTypeName)));

// DataRuntimeLanguage::EMSActuatorKey const key(UpperCaseObjectType, UpperCaseObjectName, UpperCaseActuatorName);
auto found = s_lang->EMSActuatorAvailableMap.find(std::make_tuple(objType, objName, actuatorName));
if (found == s_lang->EMSActuatorAvailableMap.end()) {
if (s_lang->numEMSActuatorsAvailable == 0) {
s_lang->EMSActuatorAvailable.allocate(s_lang->varsAvailableAllocInc);
s_lang->numEMSActuatorsAvailable = 1;
s_lang->maxEMSActuatorsAvailable = s_lang->varsAvailableAllocInc;
} else {
if (s_lang->numEMSActuatorsAvailable + 1 > s_lang->maxEMSActuatorsAvailable) {
s_lang->EMSActuatorAvailable.redimension(s_lang->maxEMSActuatorsAvailable *= 2);
}
++s_lang->numEMSActuatorsAvailable;
if (s_lang->EMSActuatorAvailableMap.find(tup) != s_lang->EMSActuatorAvailableMap.end())
return;

if (s_lang->numEMSActuatorsAvailable == 0) {
s_lang->EMSActuatorAvailable.allocate(s_lang->varsAvailableAllocInc);
s_lang->numEMSActuatorsAvailable = 1;
s_lang->maxEMSActuatorsAvailable = s_lang->varsAvailableAllocInc;
} else {
if (s_lang->numEMSActuatorsAvailable + 1 > s_lang->maxEMSActuatorsAvailable) {
s_lang->EMSActuatorAvailable.redimension(s_lang->maxEMSActuatorsAvailable *= 2);
}

auto &actuator = s_lang->EMSActuatorAvailable(s_lang->numEMSActuatorsAvailable);
actuator.ComponentTypeName = cComponentTypeName;
actuator.UniqueIDName = cUniqueIDName;
actuator.ControlTypeName = cControlTypeName;
actuator.Units = cUnits;
actuator.Actuated = &lEMSActuated; // Pointer assigment
actuator.RealValue = &rValue; // Pointer assigment
actuator.PntrVarTypeUsed = DataRuntimeLanguage::PtrDataType::Real;
s_lang->EMSActuatorAvailableMap.insert_or_assign(std::make_tuple(objType, objName, actuatorName), s_lang->numEMSActuatorsAvailable);
++s_lang->numEMSActuatorsAvailable;
}

auto &actuator = s_lang->EMSActuatorAvailable(s_lang->numEMSActuatorsAvailable);
actuator.ComponentTypeName = objType;
actuator.UniqueIDName = objName;
actuator.ControlTypeName = controlTypeName;
actuator.Units = cUnits;
actuator.Actuated = &lEMSActuated; // Pointer assigment
actuator.RealValue = &rValue; // Pointer assigment
actuator.PntrVarTypeUsed = DataRuntimeLanguage::PtrDataType::Real;
s_lang->EMSActuatorAvailableMap.insert_or_assign(std::move(tup), s_lang->numEMSActuatorsAvailable);
}

void SetupEMSActuator(EnergyPlusData &state,
Expand Down
1 change: 1 addition & 0 deletions src/EnergyPlus/PlantCentralGSHP.cc
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ void GetWrapperInput(EnergyPlusData &state)

state.dataPlantCentralGSHP->Wrapper(WrapperNum).AncillaryPower = state.dataIPShortCut->rNumericArgs(1);
if (state.dataIPShortCut->lAlphaFieldBlanks(9)) {
state.dataPlantCentralGSHP->Wrapper(WrapperNum).ancillaryPowerSched = Sched::GetScheduleAlwaysOff(state);
} else if ((state.dataPlantCentralGSHP->Wrapper(WrapperNum).ancillaryPowerSched = Sched::GetSchedule(state, state.dataIPShortCut->cAlphaArgs(9))) == nullptr) {
ShowSevereItemNotFound(state, eoh, state.dataIPShortCut->cAlphaFieldNames(9), state.dataIPShortCut->cAlphaArgs(9));
}
Expand Down
96 changes: 50 additions & 46 deletions src/EnergyPlus/ScheduleManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,15 @@ namespace Sched {
auto &s_glob = state.dataGlobal;
if (this->interpolation == Interpolation::Average) {
for (int hr = 0; hr < Constant::iHoursInDay; ++hr) {
int begMinute = 0;
int endMinute = s_glob->MinutesInTimeStep - 1;
int begMin = 0;
int endMin = s_glob->MinutesInTimeStep - 1;
for (int ts = 0; ts < s_glob->TimeStepsInHour; ++ts) {
this->tsVals[hr * s_glob->TimeStepsInHour + ts] =
std::accumulate(minuteVals.begin() + (hr * Constant::iMinutesInHour + begMinute),
minuteVals.begin() + (hr * Constant::iMinutesInHour + endMinute),
0) / double(s_glob->MinutesInTimeStep);
std::accumulate(&minuteVals[hr * Constant::iMinutesInHour + begMin], &minuteVals[hr * Constant::iMinutesInHour + endMin + 1], 0) /
double(s_glob->MinutesInTimeStep);
this->sumTsVals += this->tsVals[hr * s_glob->TimeStepsInHour + ts];
begMinute = endMinute + 1;
endMinute += s_glob->MinutesInTimeStep;
begMin = endMin + 1;
endMin += s_glob->MinutesInTimeStep;
}
}
} else {
Expand All @@ -230,7 +229,7 @@ namespace Sched {
sched->Name = name;
sched->Num = (int)s_sched->schedules.size();
s_sched->schedules.push_back(sched);
s_sched->scheduleMap.insert_or_assign(Util::makeUPPER(sched->Name), sched->Num);
s_sched->scheduleMap.insert_or_assign(std::move(Util::makeUPPER(sched->Name)), sched->Num);

sched->type = SchedType::Constant;
return sched;
Expand All @@ -245,7 +244,7 @@ namespace Sched {

sched->Num = (int)s_sched->schedules.size();
s_sched->schedules.push_back(sched);
s_sched->scheduleMap.insert_or_assign(Util::makeUPPER(sched->Name), sched->Num);
s_sched->scheduleMap.insert_or_assign(std::move(Util::makeUPPER(sched->Name)), sched->Num);

sched->type = SchedType::Year;
return sched;
Expand All @@ -261,7 +260,7 @@ namespace Sched {

daySched->Num = (int)s_sched->daySchedules.size();
s_sched->daySchedules.push_back(daySched);
s_sched->dayScheduleMap.insert_or_assign(Util::makeUPPER(daySched->Name), daySched->Num);
s_sched->dayScheduleMap.insert_or_assign(std::move(Util::makeUPPER(daySched->Name)), daySched->Num);

daySched->tsVals.resize(Constant::iHoursInDay * s_glob->TimeStepsInHour);

Expand All @@ -277,7 +276,7 @@ namespace Sched {

weekSched->Num = (int)s_sched->weekSchedules.size();
s_sched->weekSchedules.push_back(weekSched);
s_sched->weekScheduleMap.insert_or_assign(Util::makeUPPER(weekSched->Name), weekSched->Num);
s_sched->weekScheduleMap.insert_or_assign(std::move(Util::makeUPPER(weekSched->Name)), weekSched->Num);

return weekSched;
} // AddWeekSchedule()
Expand Down Expand Up @@ -1375,16 +1374,16 @@ namespace Sched {
}
} else {
for (int hr = 0; hr < Constant::iHoursInDay; ++hr) {
int begMinute = 0;
int endMinute = s_glob->MinutesInTimeStep - 1;
int begMin = 0;
int endMin = s_glob->MinutesInTimeStep - 1;
for (int ts = 0; ts < s_glob->TimeStepsInHour; ++ts) {
daySched->tsVals[hr * s_glob->TimeStepsInHour + ts] =
std::accumulate(minuteVals.begin() + (hr * Constant::iMinutesInHour + begMinute),
minuteVals.begin() + (hr * Constant::iMinutesInHour + endMinute),
std::accumulate(&minuteVals[hr * Constant::iMinutesInHour + begMin],
&minuteVals[hr * Constant::iMinutesInHour + endMin + 1],
0) / double(s_glob->MinutesInTimeStep);
daySched->sumTsVals += daySched->tsVals[hr * s_glob->TimeStepsInHour + ts];
begMinute = endMinute + 1;
endMinute += s_glob->MinutesInTimeStep;
begMin = endMin + 1;
endMin += s_glob->MinutesInTimeStep;
}
}
}
Expand Down Expand Up @@ -1499,7 +1498,7 @@ namespace Sched {
cNumericFields);

ErrorObjectHeader eoh{routineName, CurrentModuleObject, Alphas(1)};

if (s_sched->scheduleMap.find(Alphas(1)) != s_sched->scheduleMap.end()) {
ShowSevereDuplicateName(state, eoh);
ErrorsFound = true;
Expand Down Expand Up @@ -1564,20 +1563,20 @@ namespace Sched {
}

// is it a sub-hourly schedule or not?
int MinutesPerItem = 60;
int MinutesPerItem = Constant::iMinutesInHour;
if (NumNumbers > 3) {
MinutesPerItem = int(Numbers(4));
// int NumExpectedItems = 1440 / MinutesPerItem;
if (mod(60, MinutesPerItem) != 0) {
if (mod(Constant::iMinutesInHour, MinutesPerItem) != 0) {
ShowSevereCustom(state, eoh, format("Requested {} field value ({}) not evenly divisible into 60", cNumericFields(4), MinutesPerItem));
ErrorsFound = true;
continue;
}
}

int numHourlyValues = Numbers(3);
int rowLimitCount = (Numbers(3) * 60.0) / MinutesPerItem;
int hrLimitCount = 60 / MinutesPerItem;
int rowLimitCount = (Numbers(3) * Constant::rMinutesInHour) / MinutesPerItem;
int hrLimitCount = Constant::iMinutesInHour / MinutesPerItem;

std::string contextString = format("{}=\"{}\", {}: ", CurrentModuleObject, Alphas(1), cAlphaFields(3));

Expand Down Expand Up @@ -1630,7 +1629,7 @@ namespace Sched {

if (rowCnt < rowLimitCount) {
ShowWarningCustom(state, eoh, format("less than {} hourly values read from file."
"..Number read={}.", numHourlyValues, (rowCnt * 60) / MinutesPerItem));
"..Number read={}.", numHourlyValues, (rowCnt * Constant::iMinutesInHour) / MinutesPerItem));
}

// process the data into the normal schedule data structures
Expand Down Expand Up @@ -1672,38 +1671,38 @@ namespace Sched {
}
} else { // Minutes Per Item < 60
for (int hr = 0; hr < Constant::iHoursInDay; ++hr) {
int endMinute = MinutesPerItem - 1;
int begMinute = 0;
int endMin = MinutesPerItem - 1;
int begMin = 0;
for (int NumFields = 1; NumFields <= hrLimitCount; ++NumFields) {
std::fill(&minuteVals[hr * Constant::iMinutesInHour + begMinute],
&minuteVals[hr * Constant::iMinutesInHour + endMinute],
std::fill(&minuteVals[hr * Constant::iMinutesInHour + begMin],
&minuteVals[hr * Constant::iMinutesInHour + endMin + 1],
column_values[ifld]);
++ifld;
begMinute = endMinute + 1;
endMinute += MinutesPerItem;
begMin = endMin + 1;
endMin += MinutesPerItem;
}
}
if (FileIntervalInterpolated) {
for (int hr = 0; hr < Constant::iHoursInDay; ++hr) {
int begMinute = 0;
int endMinute = s_glob->MinutesInTimeStep - 1;
int begMin = 0;
int endMin = s_glob->MinutesInTimeStep - 1;
for (int ts = 0; ts < s_glob->TimeStepsInHour; ++ts) {
daySched->tsVals[hr * s_glob->TimeStepsInHour + ts] =
std::accumulate(minuteVals.begin() + (hr * Constant::iMinutesInHour + begMinute),
minuteVals.begin() + (hr * Constant::iMinutesInHour + endMinute),
std::accumulate(&minuteVals[hr * Constant::iMinutesInHour + begMin],
&minuteVals[hr * Constant::iMinutesInHour + endMin + 1],
0) / double(s_glob->MinutesInTimeStep);
daySched->sumTsVals += daySched->tsVals[hr * s_glob->TimeStepsInHour + ts];
begMinute = endMinute + 1;
endMinute += s_glob->MinutesInTimeStep;
begMin = endMin + 1;
endMin += s_glob->MinutesInTimeStep;
}
}
} else {
for (int hr = 0; hr < Constant::iHoursInDay; ++hr) {
int curMinute = s_glob->MinutesInTimeStep - 1;
int curMin = s_glob->MinutesInTimeStep - 1;
for (int ts = 0; ts < s_glob->TimeStepsInHour; ++ts) {
daySched->tsVals[hr * s_glob->TimeStepsInHour + ts] = minuteVals[hr * Constant::iMinutesInHour + curMinute];
daySched->tsVals[hr * s_glob->TimeStepsInHour + ts] = minuteVals[hr * Constant::iMinutesInHour + curMin];
daySched->sumTsVals += daySched->tsVals[hr * s_glob->TimeStepsInHour + ts];
curMinute += s_glob->MinutesInTimeStep;
curMin += s_glob->MinutesInTimeStep;
}
}
}
Expand Down Expand Up @@ -2777,7 +2776,19 @@ namespace Sched {
curValue = StartValue + incrementPerMinute;
}

if (begHr == endHr) {
if (begHr > endHr) {
if (begHr == endHr + 1 && begMin == 0 && endMin == Constant::iMinutesInHour - 1) {
ShowWarningError(state, format("ProcessScheduleInput: ProcessIntervalFields, Processing time fields, zero time interval detected, {}={}",
ErrContext, DayScheduleName));
} else {
ShowSevereError(state,
format("ProcessScheduleInput: ProcessIntervalFields, Processing time fields, overlapping times detected, {}={}",
ErrContext,
DayScheduleName));
ErrorsFound = true;
}

} else if (begHr == endHr) {
if (std::find(&setMinuteVals[begHr * Constant::iMinutesInHour + begMin],
&setMinuteVals[begHr * Constant::iMinutesInHour + endMin + 1],
true) != &setMinuteVals[begHr * Constant::iMinutesInHour + endMin + 1]) {
Expand Down Expand Up @@ -2809,13 +2820,6 @@ namespace Sched {
begMin = 0;
}

} else if (endHr < begHr) {
ShowSevereError(state,
format("ProcessScheduleInput: ProcessIntervalFields, Processing time fields, overlapping times detected, {}={}",
ErrContext,
DayScheduleName));
ErrorsFound = true;

} else { // begHr < endHr
if (interpolation == Interpolation::Linear) {
for (int iMin = begMin; iMin < Constant::iMinutesInHour; ++iMin) { // for portion of starting hour
Expand Down
2 changes: 1 addition & 1 deletion src/EnergyPlus/WeatherManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6005,7 +6005,7 @@ namespace Weather {
std::vector<Real64> const &dayVals = desDayInput.tempRangeSched->getDayVals(state);
auto &desDayModEnvrn = state.dataWeather->desDayMods(EnvrnNum);
for (int hr = 0; hr < Constant::iHoursInDay; ++hr) {
for (int ts = 0; ts <= state.dataGlobal->TimeStepsInHour; ++ts) {
for (int ts = 0; ts < state.dataGlobal->TimeStepsInHour; ++ts) {
desDayModEnvrn(ts+1, hr+1).OutDryBulbTemp = dayVals[hr * state.dataGlobal->TimeStepsInHour + ts];
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/EnergyPlus/ZoneContaminantPredictorCorrector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ void GetZoneContaminanSetPoints(EnergyPlusData &state)
if (state.dataIPShortCut->lAlphaFieldBlanks(5)) {
controlledZone.zoneMinCO2Sched = Sched::GetScheduleAlwaysOff(state);
} else if ((controlledZone.zoneMinCO2Sched = Sched::GetSchedule(state, state.dataIPShortCut->cAlphaArgs(5))) == nullptr) {
ShowSevereEmptyField(state, eoh, state.dataIPShortCut->cAlphaFieldNames(5), state.dataIPShortCut->cAlphaArgs(5));
ShowSevereItemNotFound(state, eoh, state.dataIPShortCut->cAlphaFieldNames(5), state.dataIPShortCut->cAlphaArgs(5));
ErrorsFound = true;
} else if (!controlledZone.zoneMinCO2Sched->checkMinMaxVals(state, Clusive::In, 0.0, Clusive::In, 2000.0)) {
Sched::ShowSevereBadMinMax(state, eoh, state.dataIPShortCut->cAlphaFieldNames(5), state.dataIPShortCut->cAlphaArgs(5),
Expand All @@ -1121,7 +1121,7 @@ void GetZoneContaminanSetPoints(EnergyPlusData &state)
if (state.dataIPShortCut->lAlphaFieldBlanks(6)) {
controlledZone.zoneMaxCO2Sched = Sched::GetScheduleAlwaysOff(state);
} else if ((controlledZone.zoneMaxCO2Sched = Sched::GetSchedule(state, state.dataIPShortCut->cAlphaArgs(6))) == nullptr) {
ShowSevereEmptyField(state, eoh, state.dataIPShortCut->cAlphaFieldNames(6), state.dataIPShortCut->cAlphaArgs(6));
ShowSevereItemNotFound(state, eoh, state.dataIPShortCut->cAlphaFieldNames(6), state.dataIPShortCut->cAlphaArgs(6));
ErrorsFound = true;
} else if (!controlledZone.zoneMaxCO2Sched->checkMinMaxVals(state, Clusive::In, 0.0, Clusive::In, 2000.0)) {
Sched::ShowSevereBadMinMax(state, eoh, state.dataIPShortCut->cAlphaFieldNames(6), state.dataIPShortCut->cAlphaArgs(6),
Expand Down
Loading

3 comments on commit 1272641

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ScheduleAPI (amirroth) - x86_64-Linux-Ubuntu-24.04-gcc-13.2: OK (2858 of 2918 tests passed, 0 test warnings)

Failures:\n

API Test Summary

  • Passed: 14
  • Subprocess aborted: 2

EnergyPlusFixture Test Summary

  • Passed: 1602
  • Subprocess aborted: 3

integration Test Summary

  • Passed: 747
  • Failed: 54

performance Test Summary

  • Passed: 16
  • Failed: 1

Build Badge Test Badge

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ScheduleAPI (amirroth) - x86_64-Linux-Ubuntu-24.04-gcc-13.2-UnitTestsCoverage-RelWithDebInfo: OK (2095 of 2100 tests passed, 0 test warnings)

Failures:\n

API Test Summary

  • Passed: 14
  • Subprocess aborted: 2

EnergyPlusFixture Test Summary

  • Passed: 1602
  • Subprocess aborted: 3

Build Badge Test Badge Coverage Badge

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ScheduleAPI (amirroth) - x86_64-Linux-Ubuntu-24.04-gcc-13.2-IntegrationCoverage-RelWithDebInfo: OK (747 of 801 tests passed, 0 test warnings)

Failures:\n

integration Test Summary

  • Passed: 747
  • Failed: 54

Build Badge Test Badge Coverage Badge

Please sign in to comment.