Skip to content

Commit

Permalink
now with forward translator that doesn't quite work
Browse files Browse the repository at this point in the history
  • Loading branch information
nmerket authored and macumber committed Feb 6, 2017
1 parent 9a13e82 commit 62071c6
Show file tree
Hide file tree
Showing 6 changed files with 275 additions and 8 deletions.
2 changes: 2 additions & 0 deletions openstudiocore/src/energyplus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ set(${target_name}_src
ForwardTranslator/ForwardTranslateSteamEquipment.cpp
ForwardTranslator/ForwardTranslateSubSurface.cpp
ForwardTranslator/ForwardTranslateSurface.cpp
ForwardTranslator/ForwardTranslateSurfacePropertyConvectionCoefficients.cpp
ForwardTranslator/ForwardTranslateSurfacePropertyConvectionCoefficientsMultipleSurface.cpp
ForwardTranslator/ForwardTranslateSurfacePropertyOtherSideCoefficients.cpp
ForwardTranslator/ForwardTranslateSurfacePropertyOtherSideConditionsModel.cpp
Expand Down Expand Up @@ -509,6 +510,7 @@ set(${target_name}_test_src
Test/SpaceInfiltrationEffectiveLeakageArea_GTest.cpp
Test/SubSurface_GTest.cpp
Test/Surface_GTest.cpp
Test/SurfacePropertyConvectionCoefficients.cpp
Test/TableMultiVariableLookup_GTest.cpp
Test/ThermalZone_GTest.cpp
Test/WindowPropertyFrameAndDivider_GTest.cpp
Expand Down
11 changes: 11 additions & 0 deletions openstudiocore/src/energyplus/ForwardTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ Workspace ForwardTranslator::translateModelObject( ModelObject & modelObject )
Model modelCopy;
modelObject.clone(modelCopy);

std::cout << "------------------------------------------------" << std::endl;
std::cout << modelCopy << std::endl;
std::cout << "------------------------------------------------" << std::endl;

m_progressBar = nullptr;

return translateModelPrivate(modelCopy, false);
Expand Down Expand Up @@ -2474,6 +2478,12 @@ boost::optional<IdfObject> ForwardTranslator::translateAndMapModelObject(ModelOb
retVal = translateOutsideSurfaceConvectionAlgorithm(mo);
break;
}
case openstudio::IddObjectType::OS_SurfaceProperty_ConvectionCoefficients:
{
model::SurfacePropertyConvectionCoefficients obj = modelObject.cast<SurfacePropertyConvectionCoefficients>();
retVal = translateSurfacePropertyConvectionCoefficients(obj);
break;
}
case openstudio::IddObjectType::OS_SurfaceProperty_ConvectionCoefficients_MultipleSurface:
{
model::SurfacePropertyConvectionCoefficientsMultipleSurface obj = modelObject.cast<SurfacePropertyConvectionCoefficientsMultipleSurface>();
Expand Down Expand Up @@ -3115,6 +3125,7 @@ void ForwardTranslator::translateConstructions(const model::Model & model)

iddObjectTypes.push_back(IddObjectType::OS_SurfaceProperty_OtherSideCoefficients);
iddObjectTypes.push_back(IddObjectType::OS_SurfaceProperty_OtherSideConditionsModel);
iddObjectTypes.push_back(IddObjectType::OS_SurfaceProperty_ConvectionCoefficients);

for (const IddObjectType& iddObjectType : iddObjectTypes){

Expand Down
3 changes: 3 additions & 0 deletions openstudiocore/src/energyplus/ForwardTranslator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ class SpaceType;
class SteamEquipment;
class SubSurface;
class Surface;
class SurfacePropertyConvectionCoefficients;
class SurfacePropertyConvectionCoefficientsMultipleSurface;
class SurfacePropertyOtherSideCoefficients;
class SurfacePropertyOtherSideConditionsModel;
Expand Down Expand Up @@ -1006,6 +1007,8 @@ class ENERGYPLUS_API ForwardTranslator {

boost::optional<IdfObject> translateSurface( model::Surface & modelObject );

boost::optional<IdfObject> translateSurfacePropertyConvectionCoefficients(model::SurfacePropertyConvectionCoefficients & modelObject);

boost::optional<IdfObject> translateSurfacePropertyConvectionCoefficientsMultipleSurface(model::SurfacePropertyConvectionCoefficientsMultipleSurface & modelObject);

boost::optional<IdfObject> translateSurfacePropertyOtherSideCoefficients(model::SurfacePropertyOtherSideCoefficients & modelObject);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/***********************************************************************************************************************
* OpenStudio(R), Copyright (c) 2008-2016, Alliance for Sustainable Energy, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following
* disclaimer.
*
* (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other materials provided with the distribution.
*
* (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote
* products derived from this software without specific prior written permission from the respective party.
*
* (4) Other than as required in clauses (1) and (2), distributions in any form of modifications or other derivative
* works may not use the "OpenStudio" trademark, "OS", "os", or any other confusingly similar designation without
* specific prior written permission from Alliance for Sustainable Energy, LLC.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES GOVERNMENT, OR ANY CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**********************************************************************************************************************/

#include "../ForwardTranslator.hpp"

#include "../../model/Model.hpp"
#include "../../model/SurfacePropertyConvectionCoefficients.hpp"
#include "../../model/SurfacePropertyConvectionCoefficients_Impl.hpp"
#include "../../model/Schedule.hpp"
#include "../../model/ModelObject.hpp"

#include <utilities/idd/SurfaceProperty_ConvectionCoefficients_FieldEnums.hxx>

#include "../../utilities/idd/IddEnums.hpp"
#include <utilities/idd/IddEnums.hxx>
#include <utilities/idd/IddFactory.hxx>

#include "../../utilities/core/Assert.hpp"

using namespace openstudio::model;

using namespace std;

namespace openstudio {

namespace energyplus {

boost::optional<IdfObject> ForwardTranslator::translateSurfacePropertyConvectionCoefficients(model::SurfacePropertyConvectionCoefficients & modelObject)
{
std::cout << modelObject.model() << std::endl;
boost::optional<ModelObject> convectionCoefficientSurface = modelObject.surfaceAsModelObject();
boost::optional<std::string> convectionCoefficient1Location = modelObject.convectionCoefficient1Location();
boost::optional<std::string> convectionCoefficient1Type = modelObject.convectionCoefficient1Type();
boost::optional<double> convectionCoefficient1 = modelObject.convectionCoefficient1();
boost::optional<Schedule> convectionCoefficient1Schedule = modelObject.convectionCoefficient1Schedule();
boost::optional<std::string> convectionCoefficient2Location = modelObject.convectionCoefficient2Location();
boost::optional<std::string> convectionCoefficient2Type = modelObject.convectionCoefficient2Type();
boost::optional<double> convectionCoefficient2 = modelObject.convectionCoefficient2();
boost::optional<Schedule> convectionCoefficient2Schedule = modelObject.convectionCoefficient2Schedule();

if (!(convectionCoefficientSurface && convectionCoefficient1Location && convectionCoefficient1Type)){
LOG(Error, "SurfacePropertyConvectionCoefficients '" << modelObject.name().get() << "' missing required fields, will not be translated");
return boost::none;
}

IdfObject idfObject = createRegisterAndNameIdfObject(openstudio::IddObjectType::SurfaceProperty_ConvectionCoefficients,
modelObject);

if (convectionCoefficientSurface) {
boost::optional<IdfObject> surface = translateAndMapModelObject(*convectionCoefficientSurface);
if (surface && surface->name()) {
idfObject.setString(SurfaceProperty_ConvectionCoefficientsFields::SurfaceName, surface->name().get());
}
}

if (convectionCoefficient1Location){
idfObject.setString(SurfaceProperty_ConvectionCoefficientsFields::ConvectionCoefficient1Location, *convectionCoefficient1Location);
}

if (convectionCoefficient1Type){
idfObject.setString(SurfaceProperty_ConvectionCoefficientsFields::ConvectionCoefficient1Type, *convectionCoefficient1Type);
}

if (convectionCoefficient1){
idfObject.setDouble(SurfaceProperty_ConvectionCoefficientsFields::ConvectionCoefficient1, *convectionCoefficient1);
}

if (convectionCoefficient1Schedule){
boost::optional<IdfObject> sch = translateAndMapModelObject(*convectionCoefficient1Schedule);
if (sch && sch->name()){
idfObject.setString(SurfaceProperty_ConvectionCoefficientsFields::ConvectionCoefficient1ScheduleName, sch->name().get());
}
}

if (convectionCoefficient2Location){
idfObject.setString(SurfaceProperty_ConvectionCoefficientsFields::ConvectionCoefficient2Location, *convectionCoefficient2Location);
}

if (convectionCoefficient2Type){
idfObject.setString(SurfaceProperty_ConvectionCoefficientsFields::ConvectionCoefficient2Type, *convectionCoefficient2Type);
}

if (convectionCoefficient2){
idfObject.setDouble(SurfaceProperty_ConvectionCoefficientsFields::ConvectionCoefficient2, *convectionCoefficient2);
}

if (convectionCoefficient2Schedule){
boost::optional<IdfObject> sch = translateAndMapModelObject(*convectionCoefficient2Schedule);
if (sch && sch->name()){
idfObject.setString(SurfaceProperty_ConvectionCoefficientsFields::ConvectionCoefficient2ScheduleName, sch->name().get());
}
}

return idfObject;
}

} // energyplus

} // openstudio

Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/***********************************************************************************************************************
* OpenStudio(R), Copyright (c) 2008-2016, Alliance for Sustainable Energy, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following
* disclaimer.
*
* (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other materials provided with the distribution.
*
* (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote
* products derived from this software without specific prior written permission from the respective party.
*
* (4) Other than as required in clauses (1) and (2), distributions in any form of modifications or other derivative
* works may not use the "OpenStudio" trademark, "OS", "os", or any other confusingly similar designation without
* specific prior written permission from Alliance for Sustainable Energy, LLC.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES GOVERNMENT, OR ANY CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**********************************************************************************************************************/

#include <gtest/gtest.h>
#include "EnergyPlusFixture.hpp"

#include "../ErrorFile.hpp"
#include "../ForwardTranslator.hpp"
#include "../ReverseTranslator.hpp"

#include "../../model/Model.hpp"
#include "../../model/Space.hpp"
#include "../../model/Space_Impl.hpp"
#include "../../model/SurfacePropertyConvectionCoefficients.hpp"
#include "../../model/SurfacePropertyConvectionCoefficients_Impl.hpp"
#include "../../model/ScheduleConstant.hpp"
#include "../../model/ScheduleConstant_Impl.hpp"
#include "../../model/Surface.hpp"
#include "../../model/Surface_Impl.hpp"
#include "../../model/InternalMass.hpp"
#include "../../model/InternalMass_Impl.hpp"
#include "../../model/InternalMassDefinition.hpp"
#include "../../model/InternalMassDefinition_Impl.hpp"
#include "../../model/ThermalZone.hpp"
#include "../../model/ThermalZone_Impl.hpp"

#include "../../utilities/idf/IdfFile.hpp"
#include "../../utilities/idf/IdfObject.hpp"

#include <utilities/idd/IddEnums.hxx>
#include <utilities/idd/IddFactory.hxx>
#include <utilities/idd/SurfaceProperty_ConvectionCoefficients_FieldEnums.hxx>

#include <vector>

using namespace openstudio::energyplus;
using namespace openstudio::model;
using namespace openstudio;

TEST_F(EnergyPlusFixture, ForwardTranslator_SurfacePropertyConvectionCoefficients_InternalMass) {
openstudio::Logger::instance().standardOutLogger().enable();
openstudio::Logger::instance().standardOutLogger().setLogLevel(Debug);
Model model;
ThermalZone zone(model);
Space space(model);
space.setThermalZone(zone);
InternalMassDefinition intMassDefn(model);
intMassDefn.setSurfaceArea(20);
InternalMass intMass(intMassDefn);
intMass.setSpace(space);
openstudio::model::SurfacePropertyConvectionCoefficients cc(intMass);
EXPECT_EQ(intMass.handle(), cc.surfaceAsModelObject().handle());

cc.setConvectionCoefficient1Location("Inside");
cc.setConvectionCoefficient1Type("Value");
cc.setConvectionCoefficient2Location("Outside");
cc.setConvectionCoefficient2Type("Schedule");
ScheduleConstant sched(model);
sched.setName("Constant Schedule");
sched.setValue(1.0);
cc.setConvectionCoefficient2Schedule(sched);

ForwardTranslator trans;
Workspace workspace = trans.translateModelObject(cc);

ASSERT_EQ(1u, workspace.numObjectsOfType(IddObjectType::SurfaceProperty_ConvectionCoefficients));
}

TEST_F(EnergyPlusFixture, ForwardTranslator_SurfacePropertyConvectionCoefficients_Surface) {
openstudio::Logger::instance().standardOutLogger().enable();
openstudio::Logger::instance().standardOutLogger().setLogLevel(Debug);
Model model;
ThermalZone zone(model);
Space space(model);
space.setThermalZone(zone);

std::vector<Point3d> vertices;
vertices.push_back(Point3d());
vertices.push_back(Point3d(1, 0, 0));
vertices.push_back(Point3d(1, 1, 0));
vertices.push_back(Point3d(0, 1, 0));

Surface surface(vertices, model);
surface.setSurfaceType("Floor");
surface.setSpace(space);
surface.setOutsideBoundaryCondition("Outdoors");


openstudio::model::SurfacePropertyConvectionCoefficients cc(surface);
EXPECT_EQ(surface.handle(), cc.surfaceAsModelObject().handle());

cc.setConvectionCoefficient1Location("Inside");
cc.setConvectionCoefficient1Type("Value");
cc.setConvectionCoefficient1(3.0);
cc.setConvectionCoefficient2Location("Outside");
cc.setConvectionCoefficient2Type("Schedule");
ScheduleConstant sched(model);
sched.setName("Constant Schedule");
sched.setValue(1.0);
cc.setConvectionCoefficient2Schedule(sched);

std::cout << model << std::endl;
std::cout << "------------------------------------------------------" << std::endl;
ForwardTranslator trans;
Workspace workspace = trans.translateModelObject(cc);

ASSERT_EQ(1u, workspace.numObjectsOfType(IddObjectType::SurfaceProperty_ConvectionCoefficients));
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,7 @@ namespace detail {
}

bool SurfacePropertyConvectionCoefficients_Impl::setSurface(const ModelObject &surface) {
IddObjectType iddType(surface.iddObjectType());
if (iddType == IddObjectType::OS_InternalMass || iddType == IddObjectType::OS_Surface || iddType == IddObjectType::OS_SubSurface) {
const boost::optional<std::string> surfaceName(surface.name());
OS_ASSERT(surfaceName);
return setString(OS_SurfaceProperty_ConvectionCoefficientsFields::SurfaceName, *surfaceName);
} else {
return false;
}
return setPointer(OS_SurfaceProperty_ConvectionCoefficientsFields::SurfaceName, surface.handle());
}

ModelObject SurfacePropertyConvectionCoefficients_Impl::surfaceAsModelObject() const {
Expand Down

0 comments on commit 62071c6

Please sign in to comment.