Skip to content

Commit

Permalink
Continue updating naming convention.
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-okeefe committed Nov 1, 2024
1 parent e0db36c commit e91a399
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 123 deletions.
15 changes: 9 additions & 6 deletions include/erin/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace erin
{

// Clojure program to calculate the below:
// > (def days-per-month [31 28 31 30 31 30 31 31 30 31 30 31])
// > (count days-per-month) ;=> 12
Expand Down Expand Up @@ -43,6 +44,7 @@ std::vector<flow_t> const days_per_month {// January
30,
// December
31};

std::vector<flow_t> const day_of_year_to_month {// January is doy <= 31 days
31,
// February (non-leap year) is doy <= 59
Expand All @@ -67,6 +69,7 @@ std::vector<flow_t> const day_of_year_to_month {// January is doy <= 31 days
334,
// December
365};

flow_t const num_months {12};
int const max_month_idx = 11;
int const min_month_idx = 0;
Expand All @@ -93,19 +96,19 @@ struct Months_days_elapsed
flow_t days;
};

Months_days_elapsed DayOfYearToMonthsDaysElapsed(uint64_t day_of_year);
Months_days_elapsed day_of_year_to_months_days_elapsed(uint64_t day_of_year);

std::string TimeToISO8601Period(uint64_t time_seconds);
std::string time_to_ISO8601_period(uint64_t time_seconds);

double TimeInSecondsToHours(uint64_t time_seconds);
double time_in_seconds_to_hours(uint64_t time_seconds);

void WriteTaggedCategoryMessage(std::string const& category,
void write_tagged_category_message(std::string const& category,
std::string const& tag,
std::string const& message);

void WriteWarningMessage(std::string const& tag, std::string const& message);
void write_warning_message(std::string const& tag, std::string const& message);

void WriteErrorMessage(std::string const& tag, std::string const& message);
void write_error_message(std::string const& tag, std::string const& message);

std::string WriteTaggedCategoryToString(std::string const& category,
std::string const& tag,
Expand Down
44 changes: 22 additions & 22 deletions src/erin-component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Result ParseSingleComponent(Simulation& s,
break;
default:
{
WriteErrorMessage(fullTableName, "unhandled component type: " + ToString(ct));
write_error_message(fullTableName, "unhandled component type: " + ToString(ct));
std::exit(1);
}
break;
Expand Down Expand Up @@ -209,15 +209,15 @@ Result ParseSingleComponent(Simulation& s,
std::optional<PowerUnit> maybePowerUnit = tag_to_power_unit(localRateUnit);
if (!maybePowerUnit.has_value())
{
WriteErrorMessage(fullTableName,
write_error_message(fullTableName,
"unhandled rate_unit value: '" + localRateUnit + "'");
return Result::Failure;
}
localPowerUnit = maybePowerUnit.value();
}
if (!input.contains("constant_request"))
{
WriteErrorMessage(fullTableName, "required field 'constant_request' not found");
write_error_message(fullTableName, "required field 'constant_request' not found");
return Result::Failure;
}
double loadRequest = std::get<double>(input.at("constant_request").Value);
Expand Down Expand Up @@ -320,19 +320,19 @@ Result ParseSingleComponent(Simulation& s,
auto numOutflowsTemp = std::get<int64_t>(input.at("num_outflows").Value);
if (numInflowsTemp <= 0)
{
WriteErrorMessage(fullTableName, "num_inflows must be a positive integer");
write_error_message(fullTableName, "num_inflows must be a positive integer");
return Result::Failure;
}
if (numOutflowsTemp <= 0)
{
WriteErrorMessage(fullTableName, "num_outflows must be a positive integer");
write_error_message(fullTableName, "num_outflows must be a positive integer");
return Result::Failure;
}
size_t numInflows = static_cast<size_t>(numInflowsTemp);
size_t numOutflows = static_cast<size_t>(numOutflowsTemp);
if (inflowId != outflowId)
{
WriteErrorMessage(fullTableName,
write_error_message(fullTableName,
"a mux component must have the same inflow type "
"as outflow type; we have inflow = '" +
s.FlowTypeMap.Type[inflowId] + "'; outflow = '" +
Expand Down Expand Up @@ -496,7 +496,7 @@ Result ParseSingleComponent(Simulation& s,
{
if (inflowId != outflowId)
{
WriteErrorMessage(fullTableName,
write_error_message(fullTableName,
"inflow type must equal outflow type for pass-through");
return Result::Failure;
}
Expand All @@ -513,7 +513,7 @@ Result ParseSingleComponent(Simulation& s,
{
if (inflowId != outflowId)
{
WriteErrorMessage(fullTableName, "inflow type must equal outflow type for store");
write_error_message(fullTableName, "inflow type must equal outflow type for store");
return Result::Failure;
}
EnergyUnit capacityUnit = EnergyUnit::Joule;
Expand All @@ -523,7 +523,7 @@ Result ParseSingleComponent(Simulation& s,
auto maybeCapacityUnit = tag_to_energy_unit(capacityUnitStr);
if (!maybeCapacityUnit.has_value())
{
WriteErrorMessage(fullTableName,
write_error_message(fullTableName,
"unhandled capacity unit '" + capacityUnitStr + "'");
return Result::Failure;
}
Expand All @@ -533,7 +533,7 @@ Result ParseSingleComponent(Simulation& s,
energy_to_joules(std::get<double>(input.at("capacity").Value), capacityUnit));
if (capacity_J == 0)
{
WriteErrorMessage(fullTableName, "capacity must be greater than 0");
write_error_message(fullTableName, "capacity must be greater than 0");
return Result::Failure;
}
flow_t maxCharge_W = static_cast<flow_t>(
Expand All @@ -543,7 +543,7 @@ Result ParseSingleComponent(Simulation& s,
double chargeAtSoc = std::get<double>(input.at("charge_at_soc").Value);
if (chargeAtSoc < 0.0 || chargeAtSoc > 1.0)
{
WriteErrorMessage(fullTableName, "charge_at_soc must be in range [0.0, 1.0]");
write_error_message(fullTableName, "charge_at_soc must be in range [0.0, 1.0]");
return Result::Failure;
}
flow_t noChargeAmount_J = static_cast<flow_t>(chargeAtSoc * capacity_J);
Expand All @@ -556,7 +556,7 @@ Result ParseSingleComponent(Simulation& s,
double initSoc = std::get<double>(input.at("init_soc").Value);
if (initSoc < 0.0 || initSoc > 1.0)
{
WriteErrorMessage(fullTableName, "init_soc must be in range [0.0, 1.0]");
write_error_message(fullTableName, "init_soc must be in range [0.0, 1.0]");
return Result::Failure;
}
flow_t initialStorage_J = static_cast<flow_t>(capacity_J * initSoc);
Expand All @@ -566,7 +566,7 @@ Result ParseSingleComponent(Simulation& s,
rtEff = std::get<double>(input.at("roundtrip_efficiency").Value);
if (rtEff <= 0.0 || rtEff > 1.0)
{
WriteErrorMessage(fullTableName, "roundtrip efficiency must be (0.0, 1.0]");
write_error_message(fullTableName, "roundtrip efficiency must be (0.0, 1.0]");
return Result::Failure;
}
}
Expand Down Expand Up @@ -722,7 +722,7 @@ Result ParseSingleComponent(Simulation& s,
break;
default:
{
WriteErrorMessage(fullTableName, "unhandled component type: " + ToString(ct));
write_error_message(fullTableName, "unhandled component type: " + ToString(ct));
std::exit(1);
}
}
Expand All @@ -731,15 +731,15 @@ Result ParseSingleComponent(Simulation& s,
{
if (!table.at("failure_modes").is_array())
{
WriteErrorMessage(fullTableName, "failure_modes must be an array of string");
write_error_message(fullTableName, "failure_modes must be an array of string");
return Result::Failure;
}
std::vector<toml::value> const& fms = table.at("failure_modes").as_array();
for (size_t fmIdx = 0; fmIdx < fms.size(); ++fmIdx)
{
if (!fms[fmIdx].is_string())
{
WriteErrorMessage(fullTableName,
write_error_message(fullTableName,
"failure_modes[" + std::to_string(fmIdx) + "] must be string");
return Result::Failure;
}
Expand Down Expand Up @@ -770,15 +770,15 @@ Result ParseSingleComponent(Simulation& s,
{
if (!table.at("fragility_modes").is_array())
{
WriteErrorMessage(fullTableName, "fragility_modes must be an array of string");
write_error_message(fullTableName, "fragility_modes must be an array of string");
return Result::Failure;
}
std::vector<toml::value> const& fms = table.at("fragility_modes").as_array();
for (size_t fmIdx = 0; fmIdx < fms.size(); ++fmIdx)
{
if (!fms[fmIdx].is_string())
{
WriteErrorMessage(fullTableName,
write_error_message(fullTableName,
"fragility_modes[" + std::to_string(fmIdx) + "] must be string");
return Result::Failure;
}
Expand Down Expand Up @@ -813,13 +813,13 @@ Result ParseSingleComponent(Simulation& s,
auto maybeTimeUnitStr = TOMLTable_parse_string(table, "time_unit", fullTableName);
if (!maybeTimeUnitStr.has_value())
{
WriteErrorMessage(fullTableName, "unable to parse 'time_unit' as string");
write_error_message(fullTableName, "unable to parse 'time_unit' as string");
return Result::Failure;
}
auto maybeTimeUnit = tag_to_time_unit(maybeTimeUnitStr.value());
if (!maybeTimeUnit.has_value())
{
WriteErrorMessage(fullTableName,
write_error_message(fullTableName,
"could not interpret '" + maybeTimeUnitStr.value() +
"' as time unit");
return Result::Failure;
Expand All @@ -829,7 +829,7 @@ Result ParseSingleComponent(Simulation& s,
auto maybeInitialAge = TOMLTable_parse_double(table, "initial_age", fullTableName);
if (!maybeInitialAge.has_value())
{
WriteErrorMessage(fullTableName, "unable to parse initial age as a number");
write_error_message(fullTableName, "unable to parse initial age as a number");
return Result::Failure;
}
double initialAge_s = time_to_seconds(maybeInitialAge.value(), timeUnit);
Expand All @@ -840,7 +840,7 @@ Result ParseSingleComponent(Simulation& s,
auto maybeGroup = TOMLTable_parse_string(table, "group", fullTableName);
if (!maybeGroup.has_value())
{
WriteErrorMessage(fullTableName, "unable to parse 'group' as a string");
write_error_message(fullTableName, "unable to parse 'group' as a string");
return Result::Failure;
}
std::string group = maybeGroup.value();
Expand Down
22 changes: 11 additions & 11 deletions src/erin-distribution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ double DistributionSystem::next_time_advance(size_t dist_id, double fraction) co
break;
default:
{
WriteErrorMessage("distribution", "unhandled cumulative density function");
write_error_message("distribution", "unhandled cumulative density function");
std::exit(1);
}
}
Expand All @@ -518,18 +518,18 @@ void DistributionSystem::print_distributions() const
case DistType::Fixed:
{
double v = fixed_dist.value[dist.subtype_id[i]];
std::cout << "-- value: " << TimeInSecondsToHours(static_cast<uint64_t>(v)) << " h"
std::cout << "-- value: " << time_in_seconds_to_hours(static_cast<uint64_t>(v)) << " h"
<< std::endl;
}
break;
case DistType::Normal:
{
double avg = normal_dist.average[dist.subtype_id[i]];
double sd = normal_dist.stddev[dist.subtype_id[i]];
std::cout << "-- average: " << TimeInSecondsToHours(static_cast<uint64_t>(avg)) << " h"
std::cout << "-- average: " << time_in_seconds_to_hours(static_cast<uint64_t>(avg)) << " h"
<< std::endl;
std::cout << "-- standard deviation: "
<< TimeInSecondsToHours(static_cast<uint64_t>(sd)) << " h" << std::endl;
<< time_in_seconds_to_hours(static_cast<uint64_t>(sd)) << " h" << std::endl;
}
break;
case DistType::QuantileTable:
Expand All @@ -541,7 +541,7 @@ void DistributionSystem::print_distributions() const
double t = quantile_table_dist.times[qIdx];
double v = quantile_table_dist.variates[qIdx];
std::cout << "-- [" << qIdx - q0
<< "] time: " << TimeInSecondsToHours(static_cast<uint64_t>(t))
<< "] time: " << time_in_seconds_to_hours(static_cast<uint64_t>(t))
<< " h => variate: " << v << std::endl;
}
}
Expand All @@ -550,9 +550,9 @@ void DistributionSystem::print_distributions() const
{
double lb = uniform_dist.lower_bound[dist.subtype_id[i]];
double ub = uniform_dist.upper_bound[dist.subtype_id[i]];
std::cout << "-- lower bound: " << TimeInSecondsToHours(static_cast<uint64_t>(lb))
std::cout << "-- lower bound: " << time_in_seconds_to_hours(static_cast<uint64_t>(lb))
<< " h" << std::endl;
std::cout << "-- upper bound: " << TimeInSecondsToHours(static_cast<uint64_t>(ub))
std::cout << "-- upper bound: " << time_in_seconds_to_hours(static_cast<uint64_t>(ub))
<< " h" << std::endl;
}
break;
Expand All @@ -563,7 +563,7 @@ void DistributionSystem::print_distributions() const
double loc = weibull_dist.location_params[dist.subtype_id[i]];
std::cout << "-- shape parameter: " << shape << std::endl;
std::cout << "-- scale parameter: " << scale << std::endl;
std::cout << "-- location: " << TimeInSecondsToHours(static_cast<uint64_t>(loc)) << " h"
std::cout << "-- location: " << time_in_seconds_to_hours(static_cast<uint64_t>(loc)) << " h"
<< std::endl;
}
break;
Expand Down Expand Up @@ -722,7 +722,7 @@ Result ParseDistributions(DistributionSystem& ds,
inputDataFile.open(csvFileName);
if (!inputDataFile.good())
{
WriteErrorMessage(fullTableName,
write_error_message(fullTableName,
"unable to load input csv file '" + csvFileName + "'");
return {};
}
Expand All @@ -733,7 +733,7 @@ Result ParseDistributions(DistributionSystem& ds,
std::optional<TimeUnit> maybeTimeUnit = tag_to_time_unit(timeUnitStr);
if (!maybeTimeUnit.has_value())
{
WriteErrorMessage(fullTableName, "unhandled time unit: " + timeUnitStr);
write_error_message(fullTableName, "unhandled time unit: " + timeUnitStr);
return {};
}
TimeUnit timeUnitForRead = maybeTimeUnit.value();
Expand All @@ -748,7 +748,7 @@ Result ParseDistributions(DistributionSystem& ds,
++rowIdx;
if (pair.size() != 2)
{
WriteErrorMessage(fullTableName,
write_error_message(fullTableName,
"csv file '" + csvFileName +
"'"
" row: " +
Expand Down
Loading

0 comments on commit e91a399

Please sign in to comment.