openstudio::analysis::Analysis AnalysisFixture::analysis2(bool simulate) { // Create problem and analysis Problem problem("My Problem"); BCLMeasure bclMeasure(resourcesPath() / toPath("utilities/BCL/Measures/v2/SetWindowToWallRatioByFacade")); RubyMeasure measure(bclMeasure); StringVector choices; choices.push_back("North"); choices.push_back("South"); choices.push_back("East"); choices.push_back("West"); OSArgument facade = OSArgument::makeChoiceArgument("facade",choices); OSArgument wwr = OSArgument::makeDoubleArgument("wwr"); // RubyContinuousVariable for South Facade measure = measure.clone().cast<RubyMeasure>(); OSArgument arg = facade.clone(); arg.setValue("South"); measure.setArgument(arg); arg = wwr.clone(); RubyContinuousVariable southWWR("South Window to Wall Ratio",arg,measure); problem.push(southWWR); // RubyContinuousVariable for North Facade measure = measure.clone().cast<RubyMeasure>(); arg = facade.clone(); arg.setValue("North"); measure.setArgument(arg); arg = wwr.clone(); RubyContinuousVariable northWWR("North Window to Wall Ratio",arg,measure); problem.push(northWWR); if (simulate) { problem.push(WorkItem(JobType::ModelToIdf)); problem.push(WorkItem(JobType::EnergyPlusPreProcess)); problem.push(WorkItem(JobType::EnergyPlus)); problem.push(WorkItem(JobType::OpenStudioPostProcess)); } Analysis analysis("My Analysis",problem,FileReferenceType::OSM); return analysis; }
openstudio::analysis::Analysis AnalysisFixture::analysis1(AnalysisState state) { // Create problem and analysis Problem problem("My Problem"); BCLMeasure bclMeasure(resourcesPath() / toPath("utilities/BCL/Measures/SetWindowToWallRatioByFacade")); RubyMeasure measure(bclMeasure); // Measure Group StringVector choices; choices.push_back("North"); choices.push_back("South"); choices.push_back("East"); choices.push_back("West"); OSArgument facade = OSArgument::makeChoiceArgument("facade",choices); OSArgument arg = facade.clone(); arg.setValue("South"); measure.setArgument(arg); OSArgument wwr = OSArgument::makeDoubleArgument("wwr"); MeasureVector measures(1u,NullMeasure()); measures.push_back(measure.clone().cast<Measure>()); arg = wwr.clone(); arg.setValue(0.1); measures.back().cast<RubyMeasure>().setArgument(arg); measures.push_back(measure.clone().cast<Measure>()); arg = wwr.clone(); arg.setValue(0.2); measures.back().cast<RubyMeasure>().setArgument(arg); measures.push_back(measure.clone().cast<Measure>()); arg = wwr.clone(); arg.setValue(0.3); measures.back().cast<RubyMeasure>().setArgument(arg); problem.push(MeasureGroup("South Windows",measures)); // Continuous Variables Attached to Arguments arg = facade.clone(); arg.setValue("North"); measure.setArgument(arg); arg = wwr.clone(); RubyContinuousVariable wwrCV("Window to Wall Ratio",arg,measure); wwrCV.setMinimum(0.0); wwrCV.setMaximum(1.0); TriangularDistribution td(0.2,0.0,0.5); wwrCV.setUncertaintyDescription(td); problem.push(wwrCV); OSArgument offset = OSArgument::makeDoubleArgument("offset"); RubyContinuousVariable offsetCV("Offset",offset,measure); offsetCV.setMinimum(0.0); offsetCV.setMaximum(1.5); NormalDistribution nd(0.9,0.05); offsetCV.setUncertaintyDescription(nd); problem.push(offsetCV); // Simulation problem.push(WorkItem(JobType::ModelToIdf)); problem.push(WorkItem(JobType::EnergyPlusPreProcess)); problem.push(WorkItem(JobType::EnergyPlus)); problem.push(WorkItem(JobType::OpenStudioPostProcess)); // Responses LinearFunction response1("Energy Use Intensity", VariableVector(1u,OutputAttributeVariable("EUI","site.eui"))); problem.pushResponse(response1); VariableVector vars; vars.push_back(OutputAttributeVariable("Heating Energy","heating.energy.gas")); vars.push_back(OutputAttributeVariable("Cooling Energy","cooling.energy.elec")); DoubleVector coeffs; coeffs.push_back(1.0); // approx. source factor coeffs.push_back(2.5); // approx. source factor LinearFunction response2("Approximate Source Energy",vars,coeffs); problem.pushResponse(response2); LinearFunction response3("North WWR",VariableVector(1u,wwrCV)); // input variable as output problem.pushResponse(response3); Analysis analysis("My Analysis",problem,FileReferenceType::OSM); if (state == PreRun) { // Add three DataPoints std::vector<QVariant> values; values.push_back(0); values.push_back(0.2); values.push_back(0.9); OptionalDataPoint dataPoint = problem.createDataPoint(values); analysis.addDataPoint(*dataPoint); values[0] = 1; values[1] = 0.21851789; values[2] = 1.1681938; dataPoint = problem.createDataPoint(values); analysis.addDataPoint(*dataPoint); values[0] = 2; values[1] = 0.0; values[2] = 0.581563892; dataPoint = problem.createDataPoint(values); analysis.addDataPoint(*dataPoint); } else { // state == PostRun // Add one complete DataPoint std::vector<QVariant> values; values.push_back(1); values.push_back(0.3); values.push_back(0.9); DoubleVector responseValues; responseValues.push_back(58.281967); responseValues.push_back(718952.281); responseValues.push_back(0.3); TagVector tags; tags.push_back(Tag("custom")); tags.push_back(Tag("faked")); // attributes AttributeVector attributes; attributes.push_back(Attribute("electricity.Cooling",281.281567,"kWh")); attributes.push_back(Attribute("electricity.Lighting",19206.291876,"kWh")); attributes.push_back(Attribute("electricity.Equipment",5112.125718,"kWh")); attributes = AttributeVector(1u,Attribute("enduses.electric",attributes)); attributes.push_back(Attribute("eui",createQuantity(128.21689,"kBtu/ft^2").get())); // complete job // 1. get vector of work items std::vector<WorkItem> workItems; // 0 workItems.push_back(problem.variables()[0].cast<MeasureGroup>().createWorkItem(QVariant(1), toPath(rubyOpenStudioDir()))); RubyContinuousVariable rcv = problem.variables()[1].cast<RubyContinuousVariable>(); RubyMeasure rm = rcv.measure(); OSArgument arg = rcv.argument().clone(); arg.setValue(values[1].toDouble()); rm.setArgument(arg); rcv = problem.variables()[2].cast<RubyContinuousVariable>(); arg = rcv.argument().clone(); arg.setValue(values[2].toDouble()); rm.setArgument(arg); // 1 workItems.push_back(rm.createWorkItem(toPath(rubyOpenStudioDir()))); // 2 workItems.push_back(WorkItem(JobType::ModelToIdf)); // 3 workItems.push_back(WorkItem(JobType::EnergyPlusPreProcess)); // 4 workItems.push_back(WorkItem(JobType::EnergyPlus)); // 5 workItems.push_back(WorkItem(JobType::OpenStudioPostProcess)); // 2. step through work items and create jobs with results WorkItem wi = workItems[5]; std::vector<FileInfo> inFiles = wi.files.files(); inFiles.push_back(FileInfo("eplusout.sql", DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,33,32)), "", toPath("myProject/fakeDataPoint/75-OpenStudioPostProcess-0/eplusout.sql"))); Files inFilesObject(inFiles); std::vector<std::pair<ErrorType, std::string> > errors; errors.push_back(std::make_pair(ErrorType::Info,"Post-process completed successfully.")); JobErrors errorsObject(OSResultValue::Success,errors); std::vector<FileInfo> outFiles; outFiles.push_back(FileInfo("report.xml", DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,34,21)), "", toPath("myProject/fakeDataPoint/75-OpenStudioPostProcess-0/report.xml"))); Files outFilesObject(outFiles); Job job = JobFactory::createJob( wi.type, wi.tools, wi.params, inFilesObject, std::vector<openstudio::URLSearchPath>(), false, createUUID(), JobState( DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,34,21)), errorsObject, outFilesObject, AdvancedStatus(), openstudio::path()) ); // OpenStudioPostProcess Job jobLast = job; wi = workItems[4]; inFiles = wi.files.files(); inFiles.push_back(FileInfo("in.idf", DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,23,05)), "", toPath("myProject/fakeDataPoint/74-EnergyPlus-0/in.idf"))); inFilesObject = Files(inFiles); errors.clear(); errors.push_back(std::make_pair(ErrorType::Warning,"ENERGYPLUS WARNING: ...")); errors.push_back(std::make_pair(ErrorType::Warning,"ENERGYPLUS WARNING: ...")); errors.push_back(std::make_pair(ErrorType::Warning,"ENERGYPLUS WARNING: ...")); errorsObject = JobErrors(OSResultValue::Success,errors); outFiles.clear(); outFiles.push_back(FileInfo("eplusout.sql", DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,33,32)), "", toPath("myProject/fakeDataPoint/74-EnergyPlus-0/eplusout.sql"))); outFiles.push_back(FileInfo("eplusout.err", DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,33,34)), "", toPath("myProject/fakeDataPoint/74-EnergyPlus-0/eplusout.err"))); outFilesObject = Files(outFiles); job = JobFactory::createJob( wi.type, wi.tools, wi.params, inFilesObject, std::vector<openstudio::URLSearchPath>(), false, createUUID(), JobState( DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,33,42)), errorsObject, outFilesObject, AdvancedStatus(), openstudio::path()) ); // EnergyPlus job.addChild(jobLast); jobLast = job; wi = workItems[3]; inFiles = wi.files.files(); inFiles.push_back(FileInfo("in.idf", DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,22,30)), "", toPath("myProject/fakeDataPoint/73-EnergyPlusPreProcess-0/in.idf"))); inFilesObject = Files(inFiles); errors.clear(); errorsObject = JobErrors(OSResultValue::Success,errors); outFiles.clear(); outFiles.push_back(FileInfo("out.idf", DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,23,05)), "", toPath("myProject/fakeDataPoint/73-EnergyPlusPreProcess-0/out.idf"))); outFilesObject = Files(outFiles); job = JobFactory::createJob( wi.type, wi.tools, wi.params, inFilesObject, std::vector<openstudio::URLSearchPath>(), false, createUUID(), JobState( DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,23,12)), errorsObject, outFilesObject, AdvancedStatus(), openstudio::path()) ); // EnergyPlusPreProcess job.addChild(jobLast); jobLast = job; wi = workItems[2]; inFiles = wi.files.files(); inFiles.push_back(FileInfo("in.osm", DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,22,01)), "", toPath("myProject/fakeDataPoint/72-ModelToIdf-0/in.osm"))); inFilesObject = Files(inFiles); errors.clear(); errors.push_back(std::make_pair(ErrorType::Info,"Did not find ScheduleTypeLimits for Schedule ...")); errors.push_back(std::make_pair(ErrorType::Warning,"Unexpectedly did not find a child object of a certain type, replaced with a default one.")); errorsObject = JobErrors(OSResultValue::Success,errors); outFiles.clear(); outFiles.push_back(FileInfo("out.idf", DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,22,30)), "", toPath("myProject/fakeDataPoint/72-ModelToIdf-0/out.idf"))); outFilesObject = Files(outFiles); job = JobFactory::createJob( wi.type, wi.tools, wi.params, inFilesObject, std::vector<openstudio::URLSearchPath>(), false, createUUID(), JobState( DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,22,32)), errorsObject, outFilesObject, AdvancedStatus(), openstudio::path()) ); // ModelToIdf job.addChild(jobLast); jobLast = job; wi = workItems[1]; errors.clear(); errors.push_back(std::make_pair(ErrorType::InitialCondition,"Started with a window to wall ratio of ...")); errors.push_back(std::make_pair(ErrorType::FinalCondition,"Set the window to wall ratio ...")); errorsObject = JobErrors(OSResultValue::Success,errors); outFiles.clear(); outFilesObject = Files(outFiles); wi.params.append("outdir","myProject/fakeDataPoint/"); job = JobFactory::createJob( wi.type, wi.tools, wi.params, wi.files, std::vector<openstudio::URLSearchPath>(), false, createUUID(), JobState( DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,21,52)), errorsObject, outFilesObject, AdvancedStatus(), openstudio::path()) ); // Variables 2 & 3 job.addChild(jobLast); jobLast = job; wi = workItems[0]; errors.clear(); errors.push_back(std::make_pair(ErrorType::InitialCondition,"Started with a window to wall ratio of ...")); errors.push_back(std::make_pair(ErrorType::FinalCondition,"Set the window to wall ratio ...")); errorsObject = JobErrors(OSResultValue::Success,errors); outFiles.clear(); outFilesObject = Files(outFiles); // add outdir job param JobParams params = wi.params; params.append("outdir","myProject/fakeDataPoint"); job = JobFactory::createJob( wi.type, wi.tools, params, wi.files, std::vector<openstudio::URLSearchPath>(), false, createUUID(), JobState( DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,21,10)), errorsObject, outFilesObject, AdvancedStatus(), openstudio::path()) ); // Variable 1 job.addChild(jobLast); DataPoint dataPoint(createUUID(), createUUID(), "fakeDataPoint", "Fake Data Point", "Demonstrating json serialization of complete DataPoint.", problem, true, false, true, DataPointRunType::Local, values, responseValues, toPath("myProject/fakeDataPoint/"), FileReference(toPath("myProject/fakeDataPoint/71-Ruby-0/out.osm")), FileReference(toPath("myProject/fakeDataPoint/72-ModelToIdf-0/out.idf")), FileReference(toPath("myProject/fakeDataPoint/74-EnergyPlus-0/eplusout.sql")), FileReferenceVector(1u,FileReference(toPath("myProject/fakeDataPoint/75-OpenStudioPostProcess-0/report.xml"))), job, std::vector<openstudio::path>(), tags, attributes); EXPECT_TRUE(analysis.addDataPoint(dataPoint)); } return analysis; }
TEST_F(RulesetFixture, OSArgument_Clone) { std::vector<std::string> choices; choices.push_back("On"); choices.push_back("Off"); OSArgument boolArgument = OSArgument::makeBoolArgument("bool"); OSArgument doubleArgument = OSArgument::makeDoubleArgument("double"); OSArgument integerArgument = OSArgument::makeIntegerArgument("integer"); OSArgument stringArgument = OSArgument::makeStringArgument("string"); OSArgument choiceArgument = OSArgument::makeChoiceArgument("choice", choices); EXPECT_FALSE(boolArgument.hasValue()); EXPECT_FALSE(doubleArgument.hasValue()); EXPECT_FALSE(integerArgument.hasValue()); EXPECT_FALSE(stringArgument.hasValue()); EXPECT_FALSE(choiceArgument.hasValue()); EXPECT_TRUE(boolArgument.setValue(true)); EXPECT_TRUE(doubleArgument.setValue(1.0)); EXPECT_TRUE(doubleArgument.setValue((int)1)); // can also set double arg using int EXPECT_TRUE(integerArgument.setValue((int)1)); EXPECT_TRUE(stringArgument.setValue(std::string("value"))); EXPECT_TRUE(choiceArgument.setValue(std::string("On"))); ASSERT_TRUE(boolArgument.hasValue()); ASSERT_TRUE(doubleArgument.hasValue()); ASSERT_TRUE(integerArgument.hasValue()); ASSERT_TRUE(stringArgument.hasValue()); ASSERT_TRUE(choiceArgument.hasValue()); EXPECT_EQ(true, boolArgument.valueAsBool()); EXPECT_EQ(1.0, doubleArgument.valueAsDouble()); EXPECT_EQ(1, integerArgument.valueAsInteger()); EXPECT_EQ("value", stringArgument.valueAsString()); EXPECT_EQ("On", choiceArgument.valueAsString()); OSArgument boolArgument2 = boolArgument.clone(); OSArgument doubleArgument2 = doubleArgument.clone(); OSArgument integerArgument2 = integerArgument.clone(); OSArgument stringArgument2 = stringArgument.clone(); OSArgument choiceArgument2 = choiceArgument.clone(); ASSERT_TRUE(boolArgument2.hasValue()); ASSERT_TRUE(doubleArgument2.hasValue()); ASSERT_TRUE(integerArgument2.hasValue()); ASSERT_TRUE(stringArgument2.hasValue()); ASSERT_TRUE(choiceArgument2.hasValue()); EXPECT_EQ(true, boolArgument2.valueAsBool()); EXPECT_EQ(1.0, doubleArgument2.valueAsDouble()); EXPECT_EQ(1, integerArgument2.valueAsInteger()); EXPECT_EQ("value", stringArgument2.valueAsString()); EXPECT_EQ("On", choiceArgument2.valueAsString()); std::vector<OSArgument> argumentVector; argumentVector.push_back(boolArgument); argumentVector.push_back(doubleArgument); argumentVector.push_back(integerArgument); argumentVector.push_back(stringArgument); argumentVector.push_back(choiceArgument); std::map<std::string,OSArgument> argumentMap = convertOSArgumentVectorToMap(argumentVector); ASSERT_FALSE(argumentMap.find("bool") == argumentMap.end()); ASSERT_FALSE(argumentMap.find("double") == argumentMap.end()); ASSERT_FALSE(argumentMap.find("integer") == argumentMap.end()); ASSERT_FALSE(argumentMap.find("string") == argumentMap.end()); ASSERT_FALSE(argumentMap.find("choice") == argumentMap.end()); ASSERT_TRUE(argumentMap.find("bool")->second.hasValue()); ASSERT_TRUE(argumentMap.find("double")->second.hasValue()); ASSERT_TRUE(argumentMap.find("integer")->second.hasValue()); ASSERT_TRUE(argumentMap.find("string")->second.hasValue()); ASSERT_TRUE(argumentMap.find("choice")->second.hasValue()); EXPECT_EQ(true, argumentMap.find("bool")->second.valueAsBool()); EXPECT_EQ(1.0, argumentMap.find("double")->second.valueAsDouble()); EXPECT_EQ(1, argumentMap.find("integer")->second.valueAsInteger()); EXPECT_EQ("value", argumentMap.find("string")->second.valueAsString()); EXPECT_EQ("On", argumentMap.find("choice")->second.valueAsString()); }