MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / addSimulation

Method addSimulation

src/utilities/sql/SqlFile_Impl.cpp:330–403  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

328 }
329
330 void SqlFile_Impl::addSimulation(const openstudio::EpwFile& t_epwFile, const openstudio::DateTime& t_simulationTime,
331 const openstudio::Calendar& t_calendar) {
332 int nextSimulationIndex = getNextIndex("simulations", "SimulationIndex");
333
334 std::stringstream timeStamp;
335 timeStamp << t_simulationTime.date().year() << "." << t_simulationTime.date().monthOfYear().value() << "." << t_simulationTime.date().dayOfMonth()
336 << " " << t_simulationTime.time().toString();
337
338 std::stringstream version;
339 version << "EnergyPlus, VERSION " << energyPlusVersionMajor() << "." << energyPlusVersionMinor() << ", (OpenStudio) YMD=" << timeStamp.str();
340
341 std::string insertSimulation = R"(INSERT INTO Simulations (SimulationIndex, EnergyPlusVersion, TimeStamp,
342 NumTimestepsPerHour, Completed, CompletedSuccessfully)
343 VALUES (?, ?, ?, ?, ?, ?);)";
344
345 execAndThrowOnError(insertSimulation,
346 // bindArgs
347 nextSimulationIndex, version.str(), timeStamp.str(), 6, 6, 1);
348
349 int nextEnvironmentPeriodIndex = getNextIndex("EnvironmentPeriods", "EnvironmentPeriodIndex");
350
351 std::stringstream envName;
352 envName << t_epwFile.stateProvinceRegion() << " WMO#=" << t_epwFile.wmoNumber();
353
354 std::string insertEnvironment = R"(INSERT INTO EnvironmentPeriods (EnvironmentPeriodIndex, SimulationIndex,
355 EnvironmentName, EnvironmentType) VALUES (?, ?, ?, ?);)";
356 execAndThrowOnError(insertEnvironment,
357 // bindArgs
358 nextEnvironmentPeriodIndex, nextSimulationIndex, envName.str(), 3);
359
360 int nextTimeIndex = getNextIndex("time", "TimeIndex");
361
362 std::shared_ptr<PreparedStatement> stmt;
363 if (hasYear()) {
364 stmt = std::make_shared<PreparedStatement>(
365 "insert into time (TimeIndex, Year, Month, Day, Hour, Minute, Dst, Interval, IntervalType, SimulationDays, DayType, EnvironmentPeriodIndex, "
366 "WarmupFlag) values (?, ?, ?, ?, ?, 0, 0, 60, 1, ?, ?, ?, null)",
367 m_db, true);
368 } else {
369 stmt =
370 std::make_shared<PreparedStatement>("insert into time (TimeIndex, Month, Day, Hour, Minute, Dst, Interval, IntervalType, SimulationDays, "
371 "DayType, EnvironmentPeriodIndex, WarmupFlag) values (?, ?, ?, ?, 0, 0, 60, 1, ?, ?, ?, null)",
372 m_db, true);
373 }
374
375 int simulationDay = 1;
376 for (openstudio::Date d = t_calendar.startDate(); d <= t_calendar.endDate(); d += openstudio::Time(1, 0)) {
377 for (int i = 1; i <= 24; ++i) {
378 int b = 0;
379 stmt->bind(++b, nextTimeIndex);
380 if (hasYear()) {
381 stmt->bind(++b, d.year());
382 }
383 stmt->bind(++b, d.monthOfYear().value());
384 stmt->bind(++b, d.dayOfMonth());
385 stmt->bind(++b, i);
386 stmt->bind(++b, simulationDay);
387

Callers

nothing calls this directly

Calls 15

monthOfYearMethod · 0.80
wmoNumberMethod · 0.80
isHolidayMethod · 0.80
valueNameMethod · 0.80
dayOfWeekMethod · 0.80
execAndThrowOnErrorMethod · 0.80
execAndThrowOnErrorFunction · 0.70
TimeClass · 0.50
yearMethod · 0.45
dateMethod · 0.45
valueMethod · 0.45
dayOfMonthMethod · 0.45

Tested by

no test coverage detected