Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into load-profile-plant
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarrec committed Sep 11, 2023
2 parents 22d61f1 + cc9652f commit 20a4618
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 53 deletions.
21 changes: 11 additions & 10 deletions src/energyplus/ForwardTranslator/ForwardTranslateSubSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,17 @@ namespace energyplus {

idfObject.setString(FenestrationSurface_DetailedFields::Name, modelObject.name().get());

openstudio::Vector3d offset(0, 0, 0);
idfObject.clearExtensibleGroups();

openstudio::Vector3d offset(0, 0, 0);
boost::optional<WindowPropertyFrameAndDivider> frameAndDivider = modelObject.windowPropertyFrameAndDivider();
if (frameAndDivider) {
if (!frameAndDivider->isOutsideRevealDepthDefaulted()) {
offset = -frameAndDivider->outsideRevealDepth() * modelObject.outwardNormal();
}
idfObject.setString(FenestrationSurface_DetailedFields::FrameandDividerName, frameAndDivider->name().get());
}

for (const Point3d& point : modelObject.vertices()) {
IdfExtensibleGroup group = idfObject.pushExtensibleGroup();
if (group.empty()) {
Expand All @@ -53,7 +62,7 @@ namespace energyplus {
return boost::none;
}

Point3d newPoint = point + offset;
const Point3d newPoint = point + offset;

group.setDouble(0, newPoint.x());
group.setDouble(1, newPoint.y());
Expand Down Expand Up @@ -137,14 +146,6 @@ namespace energyplus {
idfObject.setDouble(FenestrationSurface_DetailedFields::ViewFactortoGround, *viewFactortoGround);
}

boost::optional<WindowPropertyFrameAndDivider> frameAndDivider = modelObject.windowPropertyFrameAndDivider();
if (frameAndDivider) {
if (!frameAndDivider->isOutsideRevealDepthDefaulted()) {
offset = -frameAndDivider->outsideRevealDepth() * modelObject.outwardNormal();
}
idfObject.setString(FenestrationSurface_DetailedFields::FrameandDividerName, frameAndDivider->name().get());
}

if (!modelObject.isMultiplierDefaulted()) {
idfObject.setDouble(FenestrationSurface_DetailedFields::Multiplier, modelObject.multiplier());
}
Expand Down
49 changes: 44 additions & 5 deletions src/energyplus/Test/WindowPropertyFrameAndDivider_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "../ErrorFile.hpp"
#include "../ForwardTranslator.hpp"
#include "../ReverseTranslator.hpp"
#include "../GeometryTranslator.hpp"

#include "../../model/Model.hpp"
#include "../../model/Space.hpp"
Expand All @@ -30,6 +31,8 @@
#include "../../utilities/idf/IdfFile.hpp"

#include <resources.hxx>
#include <utilities/idd/IddEnums.hxx>
#include <utilities/idd/FenestrationSurface_Detailed_FieldEnums.hxx>

#include <sstream>

Expand Down Expand Up @@ -76,8 +79,9 @@ TEST_F(EnergyPlusFixture, WindowPropertyFrameAndDivider) {
EXPECT_DOUBLE_EQ(-1.0, normal.y());
EXPECT_DOUBLE_EQ(0.0, normal.z());

static constexpr double outsideRevealDepth = 1.75;
WindowPropertyFrameAndDivider frameAndDivider(model);
frameAndDivider.setOutsideRevealDepth(1.0);
frameAndDivider.setOutsideRevealDepth(outsideRevealDepth);

EXPECT_FALSE(subSurface2.allowWindowPropertyFrameAndDivider());
EXPECT_TRUE(subSurface2.setSubSurfaceType("GlassDoor"));
Expand All @@ -86,12 +90,47 @@ TEST_F(EnergyPlusFixture, WindowPropertyFrameAndDivider) {
EXPECT_TRUE(subSurface2.setWindowPropertyFrameAndDivider(frameAndDivider));
ASSERT_TRUE(subSurface2.windowPropertyFrameAndDivider());


ForwardTranslator forwardTranslator;
OptionalWorkspace outWorkspace = forwardTranslator.translateModel(model);
ASSERT_TRUE(outWorkspace);
auto workspace = forwardTranslator.translateModel(model);

EXPECT_EQ(2u, workspace.getObjectsByType(IddObjectType::FenestrationSurface_Detailed).size());
ASSERT_EQ(1u, workspace.getObjectsByType(IddObjectType::WindowProperty_FrameAndDivider).size());

auto pointEqual = [](const Point3d& a, const Point3d& b) {
static constexpr double tol = 1.0e-6;
EXPECT_NEAR(a.x(), b.x(), tol);
EXPECT_NEAR(a.y(), b.y(), tol);
EXPECT_NEAR(a.z(), b.z(), tol);
};

{
auto ss_ = workspace.getObjectByTypeAndName(IddObjectType::FenestrationSurface_Detailed, subSurface1.nameString());
ASSERT_TRUE(ss_);
EXPECT_TRUE(ss_->isEmpty(FenestrationSurface_DetailedFields::FrameandDividerName));
auto idf_vertices = getVertices(FenestrationSurface_DetailedFields::NumberofVertices + 1, *ss_);
ASSERT_EQ(vertices.size(), idf_vertices.size());
for (size_t i = 0; i < vertices.size(); ++i) {
pointEqual(vertices[i], idf_vertices[i]);
}
}

{
auto ss_ = workspace.getObjectByTypeAndName(IddObjectType::FenestrationSurface_Detailed, subSurface2.nameString());
ASSERT_TRUE(ss_);
auto frame_ = ss_->getTarget(FenestrationSurface_DetailedFields::FrameandDividerName);
ASSERT_TRUE(frame_);

auto idf_vertices = getVertices(FenestrationSurface_DetailedFields::NumberofVertices + 1, *ss_);
ASSERT_EQ(vertices.size(), idf_vertices.size());
for (size_t i = 0; i < vertices.size(); ++i) {
auto pt = vertices[i] + Vector3d(0.0, outsideRevealDepth, 0.0);
pointEqual(pt, idf_vertices[i]);
}
}

ReverseTranslator reverseTranslator;
OptionalModel outModel = reverseTranslator.translateWorkspace(*outWorkspace);
OptionalModel outModel = reverseTranslator.translateWorkspace(workspace);
ASSERT_TRUE(outModel);

EXPECT_EQ(1u, outModel->getConcreteModelObjects<WindowPropertyFrameAndDivider>().size());
Expand All @@ -102,7 +141,7 @@ TEST_F(EnergyPlusFixture, WindowPropertyFrameAndDivider) {
vertices = testSubSurface->vertices();
ASSERT_EQ(4u, vertices.size());
EXPECT_DOUBLE_EQ(0.0, vertices[0].x());
EXPECT_DOUBLE_EQ(0.0, vertices[0].y());
EXPECT_DOUBLE_EQ(outsideRevealDepth, vertices[0].y());
EXPECT_DOUBLE_EQ(1.0, vertices[0].z());

testSubSurface = outModel->getConcreteModelObjectByName<SubSurface>("No Offset");
Expand Down
10 changes: 4 additions & 6 deletions src/utilities/core/FilesystemHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,14 @@ namespace filesystem {
}

openstudio::path create_temporary_directory(const openstudio::path& basename) {
// making this count static/atomic so that we reduce the chance of collisions
// on each run of the binary. This is threadsafe, with the atomic
static std::atomic<unsigned int> count = 0;
constexpr unsigned int allowed_attempts = 1000;

const auto base_temp_dir = openstudio::filesystem::temp_directory_path();
// std::filesystem::unique_path doesn't exist, if moving to std::filesystem, use emoveBraces(createUUID)
// std::filesystem::unique_path doesn't exist, if moving to std::filesystem, use removeBraces(createUUID())
auto upath = boost::filesystem::unique_path();
const auto temp_dir = base_temp_dir / fmt::format("{}-{}-{}-", basename.string(), upath.string(), std::time(nullptr));

// unique_path is supposed to be unique already...
unsigned int count = 0;
constexpr unsigned int allowed_attempts = 1000;
while (count < allowed_attempts) {
// concat number to path basename, without adding a new path element
auto full_pathname = temp_dir;
Expand Down
8 changes: 8 additions & 0 deletions src/utilities/geometry/Geometry.i
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@
}
}

%extend openstudio::Surface3d {
std::string __str__() const {
std::ostringstream os;
os << *self;
return os.str();
}
}

%extend openstudio::Transformation {

std::string __str__() const {
Expand Down
10 changes: 5 additions & 5 deletions src/utilities/geometry/Plane.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ class UTILITIES_API Plane
/// throws openstudio::Exception if cannot compute plane for these points.
Plane(const std::vector<Point3d>& points);

// Copy and move operators are implicitly declared (Rule of 1)
// Copy and move operators are implicitly declared (Rule of 1), but we want the copy ctor for SWIG so we have to define all of them
// There's no need to check if the length of the normal is zero since we never allow another plane to not satisfy this condition
// Plane(const Plane& other) = default;
// Plane(Plane&& other) = default;
// Plane& operator=(const Plane&) = default;
// Plane& operator=(Plane&&) = default;
Plane(const Plane& other) = default;
Plane(Plane&& other) noexcept = default;
Plane& operator=(const Plane&) = default;
Plane& operator=(Plane&&) noexcept = default;
// ~Plane() noexcept = default;

/// get the outward normal of this plane
Expand Down
10 changes: 5 additions & 5 deletions src/utilities/geometry/Point3d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class UTILITIES_API Point3d
/// constructor with x, y, z
Point3d(double x, double y, double z);

// Copy and move operators are implicitly declared
// Point3d(const Point3d& other) = default;
// Point3d(Point3d&& other) = default;
// Point3d& operator=(const Point3d&) = default;
// Point3d& operator=(Point3d&&) = default;
// Copy and move operators are implicitly declared, but we want the copy ctor for SWIG so we have to define all of them
Point3d(const Point3d& other) = default;
Point3d(Point3d&& other) noexcept = default;
Point3d& operator=(const Point3d&) = default;
Point3d& operator=(Point3d&&) noexcept = default;
// ~Point3d() noexcept = default;

/// get x
Expand Down
10 changes: 5 additions & 5 deletions src/utilities/geometry/Polygon3d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class UTILITIES_API Polygon3d
// Constructs a polygon with an outer path and one or more inner paths
Polygon3d(const Point3dVector& outerPath, const Point3dVectorVector& innerPaths);

// Copy and move operators are implicitly declared (Rule of 1)
// Polygon3d(const Polygon3d& other) = default;
// Polygon3d(Polygon3d&& other) = default;
// Polygon3d& operator=(const Polygon3d&) = default;
// Polygon3d& operator=(Polygon3d&&) = default;
// Copy and move operators are implicitly declared (Rule of 1), but we want the copy ctor for SWIG so we have to define all of them
Polygon3d(const Polygon3d& other) = default;
Polygon3d(Polygon3d&& other) noexcept = default;
Polygon3d& operator=(const Polygon3d&) = default;
Polygon3d& operator=(Polygon3d&&) noexcept = default;
// ~Polygon3d() noexcept = default;

// Assigns an outer path for the polygon
Expand Down
23 changes: 20 additions & 3 deletions src/utilities/geometry/Polyhedron.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ Vector3d Surface3dEdge::asVector() const {
}

std::ostream& operator<<(std::ostream& os, const Surface3dEdge& edge) {
os << "Surface3dEdge: start=" << edge.start() << ", end=" << edge.end() << ", count=" << edge.count()
<< ", firstSurface=" << edge.firstSurfaceName();
os << "Surface3dEdge: start=" << edge.start() << ", end=" << edge.end() << ", count=" << edge.count() << ", firstSurface='"
<< edge.firstSurfaceName() << "'";
return os;
}

Expand All @@ -118,10 +118,23 @@ Surface3d::Surface3d(std::vector<Point3d> t_vertices, std::string t_name, size_t
itnext = std::begin(vertices);
}

edges.emplace_back(*it, *itnext, t_name, t_surfNum);
edges.emplace_back(*it, *itnext, name, surfNum);
}
}

std::ostream& operator<<(std::ostream& os, const Surface3d& surface3d) {
os << "Surface3d ";
if (!surface3d.name.empty()) {
os << "'" << surface3d.name << "' ";
}
os << "= [\n";
for (const auto& pt : surface3d.vertices) {
os << " " << pt << ",\n";
}
os << "]";
return os;
}

bool Surface3d::operator<(const Surface3d& rhs) const {
return this->name < rhs.name;
}
Expand Down Expand Up @@ -492,4 +505,8 @@ double Polyhedron::calcDivergenceTheoremVolume() const {
return volume;
}

std::vector<Surface3d> Polyhedron::surface3ds() const {
return m_surfaces;
}

} // namespace openstudio
3 changes: 3 additions & 0 deletions src/utilities/geometry/Polyhedron.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ class UTILITIES_API Polyhedron
* proportion of conflicted edges / total number of edges */
std::vector<Surface3d> findSurfacesWithIncorrectOrientation() const;

std::vector<Surface3d> surface3ds() const;

protected:
void performEdgeMatching();
void resetEdgeMatching();
Expand All @@ -164,6 +166,7 @@ using PolyhedronVector = std::vector<Polyhedron>;

/// ostream operator
UTILITIES_API std::ostream& operator<<(std::ostream& os, const Surface3dEdge& edge);
UTILITIES_API std::ostream& operator<<(std::ostream& os, const Surface3d& surface3d);

} // namespace openstudio

Expand Down
10 changes: 5 additions & 5 deletions src/utilities/geometry/Transformation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class UTILITIES_API Transformation
/// constructor from storage, asserts vector is size 16
Transformation(const Vector& vector);

// Copy and move operators are implicitly declared (Rule of 1)
// Transformation(const Transformation& other) = default;
// Transformation(Transformation&& other) = default;
// Transformation& operator=(const Transformation&) = default;
// Transformation& operator=(Transformation&&) = default;
// Copy and move operators are implicitly declared (Rule of 1), but we want the copy ctor for SWIG so we have to define all of them
Transformation(const Transformation& other) = default;
Transformation(Transformation&& other) noexcept = default;
Transformation& operator=(const Transformation&) = default;
Transformation& operator=(Transformation&&) noexcept = default;
// ~Transformation() noexcept = default;

/// rotation about origin defined by axis and angle (radians)
Expand Down
10 changes: 5 additions & 5 deletions src/utilities/geometry/Vector3d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ class UTILITIES_API Vector3d
/// constructor with x, y, z
Vector3d(double x, double y, double z);

// Copy and move operators are implicitly declared (Rule of 1)
// Vector3d(const Vector3d& other) = default;
// Vector3d(Vector3d&& other) = default;
// Vector3d& operator=(const Vector3d&) = default;
// Vector3d& operator=(Vector3d&&) = default;
// Copy and move operators are implicitly declared (Rule of 1), but we want the copy ctor for SWIG so we have to define all of them
Vector3d(const Vector3d& other) = default;
Vector3d(Vector3d&& other) noexcept = default;
Vector3d& operator=(const Vector3d&) = default;
Vector3d& operator=(Vector3d&&) noexcept = default;
// ~Vector3d() noexcept = default;

/// get x
Expand Down
11 changes: 7 additions & 4 deletions src/utilities/mainpage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ namespace openstudio {
*
* \section data_sec Data
*
* Structures for storing data such as \link Vector.hpp vectors\endlink,
* \link Matrix.hpp matrices\endlink, and \link TimeSeries time series\endlink. The Attribute
* class is used for reporting measures in particular; class EndUses and the enumeration classes in
* DataEnums.hpp are also of interest.
* Structures for storing data such as \link Vector vectors\endlink,
* \link Matrix matrices\endlink, and \link TimeSeries time series\endlink. The Attribute
* class provides a way for storing data additional values attached to objects,
* and is useful for reporting measures in particular. EndUses and associated enumeration
* classes EndUseType, EndUseCategoryType, and EndUseFuelType are helpful to break out energy use in reporting.
* FuelType, AppGFuelType, and ComponentType are useful to determine fuel and component sources
* for standards code. These and other enumerations are listed in DataEnums.hpp.
*
* \section filetypes_sec Filetypes
*
Expand Down

0 comments on commit 20a4618

Please sign in to comment.