Skip to content

Commit

Permalink
Updates to cpp and stub new epwfile test.
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-robertson committed Dec 17, 2024
1 parent d297b4c commit 83f36cc
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 53 deletions.
98 changes: 49 additions & 49 deletions src/utilities/filetypes/EpwFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,25 +559,25 @@ EpwGroundTemperatureDepth::EpwGroundTemperatureDepth()
m_novGroundTemperature(),
m_decGroundTemperature() {}

EpwGroundTemperatureDepth::EpwGroundTemperatureDepth(
double groundTemperatureDepth, double soilConductivity, double soilDensity, double soilSpecificHeat,
double jan, double feb, double mar, double apr, double may, double jun, double jul, double aug, double sep, double oct, double nov, double dec) {
void setGroundTemperatureDepth(groundTemperatureDepth);
void setSoilConductivity(soilConductivity);
void setSoilDensity(soilDensity);
void setSoilSpecificHeat(soilSpecificHeat);
void setJanGroundTemperature(janGroundTemperature);
void setFebGroundTemperature(febGroundTemperature);
void setMarGroundTemperature(marGroundTemperature);
void setAprGroundTemperature(aprGroundTemperature);
void setMayGroundTemperature(mayGroundTemperature);
void setJunGroundTemperature(junGroundTemperature);
void setJulGroundTemperature(julGroundTemperature);
void setAugGroundTemperature(augGroundTemperature);
void setSepGroundTemperature(sepGroundTemperature);
void setOctGroundTemperature(octGroundTemperature);
void setNovGroundTemperature(novGroundTemperature);
void setDecGroundTemperature(decGroundTemperature);
EpwGroundTemperatureDepth::EpwGroundTemperatureDepth(double groundTemperatureDepth, double soilConductivity, double soilDensity,
double soilSpecificHeat, double jan, double feb, double mar, double apr, double may, double jun,
double jul, double aug, double sep, double oct, double nov, double dec) {
setGroundTemperatureDepth(groundTemperatureDepth);
setSoilConductivity(soilConductivity);
setSoilDensity(soilDensity);
setSoilSpecificHeat(soilSpecificHeat);
setJanGroundTemperature(janGroundTemperature);
setFebGroundTemperature(febGroundTemperature);
setMarGroundTemperature(marGroundTemperature);
setAprGroundTemperature(aprGroundTemperature);
setMayGroundTemperature(mayGroundTemperature);
setJunGroundTemperature(junGroundTemperature);
setJulGroundTemperature(julGroundTemperature);
setAugGroundTemperature(augGroundTemperature);
setSepGroundTemperature(sepGroundTemperature);
setOctGroundTemperature(octGroundTemperature);
setNovGroundTemperature(novGroundTemperature);
setDecGroundTemperature(decGroundTemperature);
}

boost::optional<EpwDataPoint> EpwDataPoint::fromEpwString(const std::string& line) {
Expand Down Expand Up @@ -792,35 +792,35 @@ boost::optional<EpwDesignCondition> EpwDesignCondition::fromDesignConditionsStri
return boost::optional<EpwDesignCondition>(dc);
}

boost::optional<EpwGroundTemperatureDepth> EpwGroundTemperatureDepth::fromEpwGroundTemperatureDepthsString(const std::string& line) {
boost::optional<EpwGroundTemperatureDepth> EpwGroundTemperatureDepth::fromGroundTemperatureDepthsString(const std::string& line) {
std::vector<std::string> list = splitString(line, ',');
return fromEpwGroundTemperatureDepthsStrings(list);
return fromGroundTemperatureDepthsStrings(list);
}

boost::optional<EpwGroundTemperatureDepth> EpwGroundTemperatureDepth::fromEpwGroundTemperatureDepthsStrings(const std::vector<std::string>& list) {
boost::optional<EpwGroundTemperatureDepth> EpwGroundTemperatureDepth::fromGroundTemperatureDepthsStrings(const std::vector<std::string>& list) {
EpwGroundTemperatureDepth gtd;
// Expect 68 items in the list
if (list.size() < 68) {
LOG_FREE(Error, "openstudio.EpwFile", "Expected 68 fields in EPW ground temperature depth instead of the " << list.size() << " received");
// Expect 48 items in the list
if (list.size() < 48) {
LOG_FREE(Error, "openstudio.EpwFile", "Expected 48 fields in EPW ground temperature depth instead of the " << list.size() << " received");
return boost::none;
}
// Use the appropriate setter on each field
gtd.setGroundTemperatureDepth(list[EpwDepthField::TitleOfDesignCondition]);
gtd.setSoilConductivity(list[EpwDepthField::HeatingColdestMonth]);
gtd.setSoilDensity(list[EpwDepthField::HeatingDryBulb99pt6]);
gtd.setSoilSpecificHeat(list[EpwDepthField::HeatingDryBulb99]);
gtd.setJanGroundTemperature(list[EpwDepthField::HeatingHumidificationDewPoint99pt6]);
gtd.setFebGroundTemperature(list[EpwDepthField::HeatingHumidificationHumidityRatio99pt6]);
gtd.setMarGroundTemperature(list[EpwDepthField::HeatingHumidificationMeanCoincidentDryBulb99pt6]);
gtd.setAprGroundTemperature(list[EpwDepthField::HeatingHumidificationDewPoint99]);
gtd.setMarGroundTemperature(list[EpwDepthField::HeatingHumidificationHumidityRatio99]);
gtd.setJunGroundTemperature(list[EpwDepthField::HeatingHumidificationMeanCoincidentDryBulb99]);
gtd.setJulGroundTemperature(list[EpwDepthField::HeatingColdestMonthWindSpeed0pt4]);
gtd.setAugGroundTemperature(list[EpwDepthField::HeatingColdestMonthMeanCoincidentDryBulb0pt4]);
gtd.setSepGroundTemperature(list[EpwDepthField::HeatingColdestMonthWindSpeed1]);
gtd.setOctGroundTemperature(list[EpwDepthField::HeatingColdestMonthMeanCoincidentDryBulb1]);
gtd.setNovGroundTemperature(list[EpwDepthField::HeatingMeanCoincidentWindSpeed99pt6]);
gtd.setDecGroundTemperature(list[EpwDepthField::HeatingPrevailingCoincidentWindDirection99pt6]);
gtd.setGroundTemperatureDepth(list[EpwDepthField::GroundTemperatureDepth]);
gtd.setSoilConductivity(list[EpwDepthField::SoilConductivity]);
gtd.setSoilDensity(list[EpwDepthField::SoilDensity]);
gtd.setSoilSpecificHeat(list[EpwDepthField::SoilSpecificHeat]);
gtd.setJanGroundTemperature(list[EpwDepthField::JanGroundTemperature]);
gtd.setFebGroundTemperature(list[EpwDepthField::FebGroundTemperature]);
gtd.setMarGroundTemperature(list[EpwDepthField::MarGroundTemperature]);
gtd.setAprGroundTemperature(list[EpwDepthField::AprGroundTemperature]);
gtd.setMarGroundTemperature(list[EpwDepthField::MayGroundTemperature]);
gtd.setJunGroundTemperature(list[EpwDepthField::JunGroundTemperature]);
gtd.setJulGroundTemperature(list[EpwDepthField::JulGroundTemperature]);
gtd.setAugGroundTemperature(list[EpwDepthField::AugGroundTemperature]);
gtd.setSepGroundTemperature(list[EpwDepthField::SepGroundTemperature]);
gtd.setOctGroundTemperature(list[EpwDepthField::OctGroundTemperature]);
gtd.setNovGroundTemperature(list[EpwDepthField::NovGroundTemperature]);
gtd.setDecGroundTemperature(list[EpwDepthField::DecGroundTemperature]);
return boost::optional<EpwGroundTemperatureDepth>(gtd);
}

Expand Down Expand Up @@ -4646,8 +4646,8 @@ bool EpwFile::parseGroundTemperatures(const std::string& line) {

int nGroundTemperatureDepths = std::stoi(split[1]);

double expected_split_size = 70;
expected_split_size += (nGroundTemperatureDepths - 1) * 68;
double expected_split_size = 50;
expected_split_size += (nGroundTemperatureDepths - 1) * 48;

if (split.size() != expected_split_size) {
LOG(Warn, "Expected " << expected_split_size << " ground temperature depth fields rather than the " << split.size() << " fields in the EPW file '"
Expand All @@ -4658,13 +4658,13 @@ bool EpwFile::parseGroundTemperatures(const std::string& line) {
}

for (int j = 0; j < nGroundTemperatureDepths; j++) {
std::vector<std::string> ground_temperature_depth(68);
for (int k = 0; k < 68; k++) {
ground_temperature_depth[k] = split[k + 2 + (68 * j)];
std::vector<std::string> ground_temperature_depth(48);
for (int k = 0; k < 48; k++) {
ground_temperature_depth[k] = split[k + 2 + (48 * j)];
}
boost::optional<EpwGroundTemperatureDepth> dc = EpwGroundTemperatureDepth::fromGroundTemperatureDepthsStrings(ground_temperature_depth);
if (dc) {
m_depths.push_back(dc.get());
boost::optional<EpwGroundTemperatureDepth> gtd = EpwGroundTemperatureDepth::fromGroundTemperatureDepthsStrings(ground_temperature_depth);
if (gtd) {
m_depths.push_back(gtd.get());
} else {
LOG(Error, "Failed to parse ground temperature depth " << j + 1 << " of EPW file '" << m_path << "'");
return false;
Expand Down
7 changes: 3 additions & 4 deletions src/utilities/filetypes/EpwFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,6 @@ class UTILITIES_API EpwDesignCondition
double m_extremeN50YearsMaxDryBulb;
};


/** EpwGroundTemperatureDepth is one line from the EPW file. All floating point numbers are stored as strings,
* but are checked as numbers.
*/
Expand All @@ -872,9 +871,9 @@ class UTILITIES_API EpwGroundTemperatureDepth
/** Create an empty EpwGroundTemperatureDepth object */
EpwGroundTemperatureDepth();
/** Create an EpwGroundTemperatureDepth object with specified properties */
EpwGroundTemperatureDepth(
double groundTemperatureDepth, double soilConductivity, double soilDensity, double soilSpecificHeat,
double jan, double feb, double mar, double apr, double may, double jun, double jul, double aug, double sep, double oct, double nov, double dec);
EpwGroundTemperatureDepth(double groundTemperatureDepth, double soilConductivity, double soilDensity, double soilSpecificHeat, double jan,
double feb, double mar, double apr, double may, double jun, double jul, double aug, double sep, double oct, double nov,
double dec);
// Static
/** Returns the units of the named field */
static boost::optional<std::string> getUnitsByName(const std::string& name);
Expand Down
76 changes: 76 additions & 0 deletions src/utilities/filetypes/test/EpwFile_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,82 @@ TEST(Filetypes, EpwFile_Design) {
}
}

TEST(Filetypes, EpwFile_Ground) {
try {
path p = resourcesPath() / toPath("utilities/Filetypes/USA_CO_Golden-NREL.724666_TMY3.epw");
EpwFile epwFile(p);
EXPECT_EQ(p, epwFile.path());
EXPECT_EQ("BDF687C1", epwFile.checksum());
EXPECT_EQ(openstudio::checksum(epwFile.path()), epwFile.checksum());
EXPECT_EQ("Denver Centennial Golden Nr", epwFile.city());
EXPECT_EQ("CO", epwFile.stateProvinceRegion());
EXPECT_EQ("USA", epwFile.country());
EXPECT_EQ("TMY3", epwFile.dataSource());
EXPECT_EQ("724666", epwFile.wmoNumber());
EXPECT_EQ(39.74, epwFile.latitude());
EXPECT_EQ(-105.18, epwFile.longitude());
EXPECT_EQ(-7, epwFile.timeZone());
EXPECT_EQ(1829, epwFile.elevation());
EXPECT_EQ(Time(0, 1, 0, 0), epwFile.timeStep());
EXPECT_EQ(DayOfWeek(DayOfWeek::Sunday), epwFile.startDayOfWeek());
EXPECT_EQ(Date(MonthOfYear::Jan, 1), epwFile.startDate());
EXPECT_EQ(Date(MonthOfYear::Dec, 31), epwFile.endDate());
// Up to here, everything should be the same as the first test. Now ask for the design conditions
std::vector<EpwGroundTemperatureDepth> depths = epwFile.groundTemperatureDepths();
EXPECT_EQ(3, depths.size());
EXPECT_EQ(0.5, depths[0].groundTemperatureDepth());
EXPECT_EQ(0, depths[0].soilConductivity());
EXPECT_EQ(0, depths[0].soilDensity());
EXPECT_EQ(0, depths[0].soilSpecificHeat());
EXPECT_EQ(0, depths[0].janGroundTemperature());
EXPECT_EQ(0, depths[0].febGroundTemperature());
EXPECT_EQ(0, depths[0].marGroundTemperature());
EXPECT_EQ(0, depths[0].aprGroundTemperature());
EXPECT_EQ(0, depths[0].mayGroundTemperature());
EXPECT_EQ(0, depths[0].junGroundTemperature());
EXPECT_EQ(0, depths[0].julGroundTemperature());
EXPECT_EQ(0, depths[0].augGroundTemperature());
EXPECT_EQ(0, depths[0].sepGroundTemperature());
EXPECT_EQ(0, depths[0].octGroundTemperature());
EXPECT_EQ(0, depths[0].novGroundTemperature());
EXPECT_EQ(0, depths[0].decGroundTemperature());
EXPECT_EQ(2, depths[1].groundTemperatureDepth());
EXPECT_EQ(0, depths[1].soilConductivity());
EXPECT_EQ(0, depths[1].soilDensity());
EXPECT_EQ(0, depths[1].soilSpecificHeat());
EXPECT_EQ(0, depths[1].janGroundTemperature());
EXPECT_EQ(0, depths[1].febGroundTemperature());
EXPECT_EQ(0, depths[1].marGroundTemperature());
EXPECT_EQ(0, depths[1].aprGroundTemperature());
EXPECT_EQ(0, depths[1].mayGroundTemperature());
EXPECT_EQ(0, depths[1].junGroundTemperature());
EXPECT_EQ(0, depths[1].julGroundTemperature());
EXPECT_EQ(0, depths[1].augGroundTemperature());
EXPECT_EQ(0, depths[1].sepGroundTemperature());
EXPECT_EQ(0, depths[1].octGroundTemperature());
EXPECT_EQ(0, depths[1].novGroundTemperature());
EXPECT_EQ(0, depths[1].decGroundTemperature());
EXPECT_EQ(4, depths[2].groundTemperatureDepth());
EXPECT_EQ(0, depths[2].soilConductivity());
EXPECT_EQ(0, depths[2].soilDensity());
EXPECT_EQ(0, depths[2].soilSpecificHeat());
EXPECT_EQ(0, depths[2].janGroundTemperature());
EXPECT_EQ(0, depths[2].febGroundTemperature());
EXPECT_EQ(0, depths[2].marGroundTemperature());
EXPECT_EQ(0, depths[2].aprGroundTemperature());
EXPECT_EQ(0, depths[2].mayGroundTemperature());
EXPECT_EQ(0, depths[2].junGroundTemperature());
EXPECT_EQ(0, depths[2].julGroundTemperature());
EXPECT_EQ(0, depths[2].augGroundTemperature());
EXPECT_EQ(0, depths[2].sepGroundTemperature());
EXPECT_EQ(0, depths[2].octGroundTemperature());
EXPECT_EQ(0, depths[2].novGroundTemperature());
EXPECT_EQ(0, depths[2].decGroundTemperature());
} catch (...) {
ASSERT_TRUE(false);
}
}

TEST(Filetypes, EpwFile_Design_DoubleRead) {
try {
path p = resourcesPath() / toPath("utilities/Filetypes/USA_CO_Golden-NREL.724666_TMY3.epw");
Expand Down

0 comments on commit 83f36cc

Please sign in to comment.