Skip to content

Commit

Permalink
Change day_of_week_for_start_day to start_day_of_year
Browse files Browse the repository at this point in the history
  • Loading branch information
kbenne committed Aug 30, 2024
1 parent c10e8c6 commit ad740fa
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 19 deletions.
2 changes: 1 addition & 1 deletion energyplus_coroutine/create_fmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void energyplus::CreateFMU::operator()() const
spawn_fs::create_directories(fmuEPFMIPath.parent_path());

auto idfjson = idf_to_json(input.idfInputPath());
auto start_time = StartTime(day_from_string(input.runPeriod.day_of_week_for_start_day), 0.0);
auto start_time = StartTime(day_from_string(input.runPeriod.start_day_of_year), 0.0);
prepare_idf(idfjson, input, start_time);
copyIDFResourceFiles(idfjson, input.idfInputPath().parent_path(), fmuResourcesPath);
json_to_idf(idfjson, fmuidfPath);
Expand Down
2 changes: 1 addition & 1 deletion energyplus_coroutine/idfprep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ json &addRunPeriod(json &jsonidf, [[maybe_unused]] const Input &input, const Sta
{"begin_day_of_month", int(start_time.EnergyPlusEpoch().day())},
{"begin_month", int(start_time.EnergyPlusEpoch().month())},
{"begin_year", int(start_time.EnergyPlusEpoch().year())},
{"day_of_week_for_start_day", input.runPeriod.day_of_week_for_start_day},
{"start_day_of_year", input.runPeriod.start_day_of_year},
{"end_day_of_month", 31},
{"end_month", 12},
{"end_year", 2217},
Expand Down
3 changes: 1 addition & 2 deletions energyplus_coroutine/input/runperiod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ RunPeriod RunPeriod::create_run_period([[maybe_unused]] const nlohmann::json &sp

const auto run_period_json = spawnjson.value("RunPeriod", nlohmann::json::object());

result.day_of_week_for_start_day =
run_period_json.value("day_of_week_for_start_day", result.day_of_week_for_start_day);
result.start_day_of_year = run_period_json.value("start_day_of_year", result.start_day_of_year);

result.apply_weekend_holiday_rule =
run_period_json.value("apply_weekend_holiday_rule", result.apply_weekend_holiday_rule);
Expand Down
2 changes: 1 addition & 1 deletion energyplus_coroutine/input/runperiod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class RunPeriod

[[nodiscard]] static RunPeriod create_run_period(const nlohmann::json &spawnjson);

std::string day_of_week_for_start_day{"Sunday"};
std::string start_day_of_year{"Sunday"};
std::string apply_weekend_holiday_rule{"No"};
std::string use_weather_file_daylight_saving_period{"No"};
std::string use_weather_file_holidays_and_special_days{"No"};
Expand Down
2 changes: 1 addition & 1 deletion energyplus_coroutine/spawn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ double Spawn::startTime() const noexcept

void Spawn::setStartTime(const double &time) noexcept
{
start_time_ = StartTime(day_from_string(input.runPeriod.day_of_week_for_start_day), time);
start_time_ = StartTime(day_from_string(input.runPeriod.start_day_of_year), time);
}

void Spawn::setTime(const double &time)
Expand Down
8 changes: 4 additions & 4 deletions energyplus_coroutine/start_time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ namespace spawn {
class StartTime
{
public:
explicit StartTime(const boost::date_time::weekdays &day_of_week_for_start_day = boost::date_time::weekdays::Sunday,
explicit StartTime(const boost::date_time::weekdays &start_day_of_year = boost::date_time::weekdays::Sunday,
const double &seconds = 0.0)
: day_of_week_for_start_day_(day_of_week_for_start_day), seconds_(seconds)
: start_day_of_year_(start_day_of_year), seconds_(seconds)
{
}

Expand Down Expand Up @@ -54,7 +54,7 @@ class StartTime

private:
// Day of the week for Jan 1 of the start year.
boost::date_time::weekdays day_of_week_for_start_day_;
boost::date_time::weekdays start_day_of_year_;

// Is the start year a leap year?
bool is_leap_year_{false};
Expand All @@ -65,7 +65,7 @@ class StartTime

// Description of the spawn epoch year.
// This is used to find an assumed year, given the criteria.
YearDescription start_year_description_{day_of_week_for_start_day_, is_leap_year_};
YearDescription start_year_description_{start_day_of_year_, is_leap_year_};

// The date, Jan 1, and time 00:00, of the start year.
boost::gregorian::date spawn_epoch_{start_year_description_.AssumedYear(), boost::date_time::Jan, 1};
Expand Down
4 changes: 2 additions & 2 deletions test/test_run_period.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ TEST_CASE("Test SingleFamilyHouse with Custom RunPeriod")
"kind" : "ME"
}},
"RunPeriod": {{
"day_of_week_for_start_day": "Monday",
"start_day_of_year": "Monday",
"apply_weekend_holiday_rule": "Yes",
"use_weather_file_daylight_saving_period": "Yes",
"use_weather_file_holidays_and_special_days": "Yes",
Expand All @@ -50,7 +50,7 @@ TEST_CASE("Test SingleFamilyHouse with Custom RunPeriod")
const auto idf_json = spawn::idf_to_json(idf_path);
const auto runperiod_json = idf_json["RunPeriod"]["Spawn-RunPeriod"];

CHECK(runperiod_json["day_of_week_for_start_day"] == "Monday");
CHECK(runperiod_json["start_day_of_year"] == "Monday");
CHECK(runperiod_json["apply_weekend_holiday_rule"] == "Yes");
CHECK(runperiod_json["use_weather_file_daylight_saving_period"] == "Yes");
CHECK(runperiod_json["use_weather_file_holidays_and_special_days"] == "Yes");
Expand Down
2 changes: 1 addition & 1 deletion util/datetime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

// start incrementing or decrementing assumedYear until we match *yearStartsOn and assumedLeapYear
while ((boost::gregorian::gregorian_calendar::is_leap_year(year) != is_leap_year_) ||
(boost::gregorian::date(year, boost::date_time::Jan, 1).day_of_week() != day_of_week_for_start_day_)) {
(boost::gregorian::date(year, boost::date_time::Jan, 1).day_of_week() != start_day_of_year_)) {
if (look_in_future_) {
++year;
} else {
Expand Down
9 changes: 3 additions & 6 deletions util/datetime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@ class YearDescription
public:
explicit YearDescription() = default;

explicit YearDescription(boost::date_time::weekdays day_of_week_for_start_day,
bool is_leap_year,
bool look_in_future = false)
: day_of_week_for_start_day_(day_of_week_for_start_day), is_leap_year_(is_leap_year),
look_in_future_(look_in_future)
explicit YearDescription(boost::date_time::weekdays start_day_of_year, bool is_leap_year, bool look_in_future = false)
: start_day_of_year_(start_day_of_year), is_leap_year_(is_leap_year), look_in_future_(look_in_future)
{
}

[[nodiscard]] unsigned short AssumedYear() const noexcept;

boost::date_time::weekdays day_of_week_for_start_day_{boost::date_time::Thursday};
boost::date_time::weekdays start_day_of_year_{boost::date_time::Thursday};
bool is_leap_year_{false};
bool look_in_future_{true};
};
Expand Down

0 comments on commit ad740fa

Please sign in to comment.