Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update gbXML schema to v7.03 #4995

Merged
merged 16 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions resources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ SET(gbxml_resources_src
gbxml/gbXMLStandard_Single_Family_Residential_2016.xml
gbxml/TropicBird_BEM_4_2018.xml
gbxml/TropicBird.xml
gbxml/11_Jay_St.xml
gbxml/A00.xml
gbxml/Building_Central_Conceptual_Model.xml
Comment on lines +338 to +340
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Add a few files (v7.03) from autodesk's test suite.

)

# update the resources
Expand Down
23,980 changes: 23,980 additions & 0 deletions resources/gbxml/11_Jay_St.xml

Large diffs are not rendered by default.

780 changes: 780 additions & 0 deletions resources/gbxml/A00.xml

Large diffs are not rendered by default.

118,954 changes: 118,954 additions & 0 deletions resources/gbxml/Building_Central_Conceptual_Model.xml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/gbxml/ForwardTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,13 @@ namespace gbxml {
gbXMLElement.append_attribute("xmlns:xhtml") = "http://www.w3.org/1999/xhtml";
gbXMLElement.append_attribute("xmlns:xsi") = "http://www.w3.org/2001/XMLSchema-instance";
gbXMLElement.append_attribute("xmlns:xsd") = "http://www.w3.org/2001/XMLSchema";
gbXMLElement.append_attribute("xsi:schemaLocation") = "http://www.gbxml.org/schema http://gbxml.org/schema/6-01/GreenBuildingXML_Ver6.01.xsd";
gbXMLElement.append_attribute("xsi:schemaLocation") = "http://www.gbxml.org/schema http://gbxml.org/schema/7-03/GreenBuildingXML_Ver7.03.xsd";
gbXMLElement.append_attribute("temperatureUnit") = "C";
gbXMLElement.append_attribute("lengthUnit") = "Meters";
gbXMLElement.append_attribute("areaUnit") = "SquareMeters";
gbXMLElement.append_attribute("volumeUnit") = "CubicMeters";
gbXMLElement.append_attribute("useSIUnitsForResults") = "true";
gbXMLElement.append_attribute("version") = "6.01";
gbXMLElement.append_attribute("version") = "7.03";
Comment on lines +185 to +191
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Forward translate with v7.03 header attributes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Naively would expect some stuff to change in there.
I do realize we only handle geometry (and thermostat), so perhaps it's expected that nothing changes there.

But from a cursory diff of the v6 and v7 schemas, I think we could perhaps handle the new DesignCoolRH and DesignHeatRH by inspecting a potential ZoneControlHumidistat in the ForwardTranslator::translateThermalZone method. Maybe worth an enhancement request, not sure.

gbXMLElement.append_attribute("SurfaceReferenceLocation") = "Centerline";

// translateFacility is responsible to translate Surfaces, and calls translateBuilding, which is responsible to translate spaces
Expand Down
44 changes: 38 additions & 6 deletions src/gbxml/Test/ReverseTranslator_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@
#include "../../model/YearDescription.hpp"
#include "../../model/YearDescription_Impl.hpp"

#include "../../utilities/idf/Workspace.hpp"
#include "../../utilities/core/Optional.hpp"
#include "../../utilities/geometry/Plane.hpp"
#include "../../utilities/time/Date.hpp"
#include "utilities/idf/Workspace.hpp"
#include "utilities/core/Optional.hpp"
#include "utilities/geometry/Plane.hpp"
#include "utilities/time/Date.hpp"
#include "utilities/xml/XMLValidator.hpp"
#include <resources.hxx>

#include <utilities/idd/OS_Surface_FieldEnums.hxx>
#include <utilities/idd/OS_SubSurface_FieldEnums.hxx>

#include <resources.hxx>

#include <sstream>
#include <utility>

Expand Down Expand Up @@ -968,3 +968,35 @@ TEST_F(gbXMLFixture, ReverseTranslator_Absorptance) {
EXPECT_EQ(0.7, _material2->visibleAbsorptance()); // default
}
}

TEST_P(RoundTripGbXMLParametrizedFixture, RoundTripped_v703_GbXMLs_AreStillValid) {
const openstudio::path xmlPath = resourcesPath() / openstudio::toPath("gbxml") / GetParam();

openstudio::gbxml::ReverseTranslator reverseTranslator;
openstudio::gbxml::ForwardTranslator forwardTranslator;

boost::optional<openstudio::model::Model> model = reverseTranslator.loadModel(xmlPath);
ASSERT_TRUE(model);

const openstudio::path outputPath = xmlPath.parent_path() / toPath(xmlPath.stem().string() + "_RoundTripped" + xmlPath.extension().string());
ASSERT_TRUE(forwardTranslator.modelToGbXML(*model, outputPath));

auto xmlValidator = XMLValidator::gbxmlValidator();

EXPECT_TRUE(xmlValidator.validate(outputPath));
EXPECT_TRUE(xmlValidator.isValid());
EXPECT_EQ(0, xmlValidator.warnings().size());

auto errors = xmlValidator.errors();
EXPECT_EQ(0, errors.size());
}

INSTANTIATE_TEST_SUITE_P(gbXMLFixture, RoundTripGbXMLParametrizedFixture,
::testing::Values( //
"11_Jay_St.xml", //
"A00.xml" //
// "Building_Central_Conceptual_Model.xml" // TODO: disabled because it throws in Debug
),
[](const testing::TestParamInfo<RoundTripGbXMLParametrizedFixture::ParamType>& info) {
return info.param.stem().generic_string();
});
7 changes: 7 additions & 0 deletions src/gbxml/Test/gbXMLFixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,11 @@ class gbXMLFixture : public ::testing::Test
REGISTER_LOGGER("gbXML");
};

/** A fixture that RTs a gbXML to a Model, then FT's it back to a gbXML, and asserts that the final gbXML is still valid per the gbXML schema */
class RoundTripGbXMLParametrizedFixture
: public gbXMLFixture
, public ::testing::WithParamInterface<openstudio::path>
{
};

#endif // GBXML_TEST_GBXMLFIXTURE_HPP
4 changes: 3 additions & 1 deletion src/utilities/xml/Test/XMLValidator_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ INSTANTIATE_TEST_SUITE_P(XMLValidatorFixture, GbXMLValidatorParametrizedFixture,
std::make_tuple("gbxml/seb.xml", 0, 16), std::make_tuple("gbxml/simpleBox_vasari.xml", 0, 27),
std::make_tuple("gbxml/TestCube.xml", 0, 8), std::make_tuple("gbxml/TestCubeAlternateUnits.xml", 0, 8),
std::make_tuple("gbxml/TestSchedules.xml", 0, 16), std::make_tuple("gbxml/TropicBird.xml", 0, 110),
std::make_tuple("gbxml/TwoStoryOffice_Trane.xml", 0, 236), std::make_tuple("gbxml/ZNETH.xml", 0, 204)),
std::make_tuple("gbxml/TwoStoryOffice_Trane.xml", 0, 236), std::make_tuple("gbxml/ZNETH.xml", 0, 204),
std::make_tuple("gbxml/11_Jay_St.xml", 0, 0), std::make_tuple("gbxml/A00.xml", 0, 0),
std::make_tuple("gbxml/Building_Central_Conceptual_Model.xml", 0, 3)),
Comment on lines +193 to +195
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Test XML validation on the new v7.03 files.

[](const testing::TestParamInfo<GbXMLValidatorParametrizedFixture::ParamType>& info) {
auto filename = std::get<0>(info.param);
std::replace_if(
Expand Down
4 changes: 2 additions & 2 deletions src/utilities/xml/XMLValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,8 @@ XMLValidator XMLValidator::gbxmlValidator() {
LOG_AND_THROW("Failed to create a temporary directory for extracting the embedded path");
}
const bool quiet = true;
::openstudio::embedded_files::extractFile(":/xml/resources/GreenBuildingXML_Ver6.01.xsd", openstudio::toString(tmpDir), quiet);
return XMLValidator(tmpDir / "GreenBuildingXML_Ver6.01.xsd");
::openstudio::embedded_files::extractFile(":/xml/resources/GreenBuildingXML_Ver7.03.xsd", openstudio::toString(tmpDir), quiet);
return XMLValidator(tmpDir / "GreenBuildingXML_Ver7.03.xsd");
Comment on lines +480 to +481
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Validate all gbXML files against the v7.03 schema. This is called prior to RT, and after FT.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I had noted on the first PR that Matt opened that maybe we should add an enum #4980 (comment)

Quoting myself:

Maybe we should use an enum (or a string with validation... ) and modifying the gbxmlValidator signature to take en optional gbxmlVersion parameter?

enum class GbxmlVersion { Ver601, Ver703 };
XMLValidator gbxmlValidator(GbxmlVersion gbxmlVersion = GbxmlVersion::Ver601);

Otherwise perhaps we should delete the GreenBuildingXML_Ver6.01.xsd altogether.

}

XMLValidator XMLValidator::bclXMLValidator(openstudio::BCLXMLType bclXMLType, const VersionString& schemaVersion) {
Expand Down
Loading