예제 #1
0
  double ScheduleDay_Impl::getValue(const openstudio::Time& time) const
  {
    if (time.totalMinutes() < 0.0 || time.totalDays() > 1.0){
      return 0.0;
    }

    std::vector<double> values = this->values(); // these are already sorted
    std::vector<openstudio::Time> times = this->times(); // these are already sorted

    unsigned N = times.size();
    OS_ASSERT(values.size() == N);

    if (N == 0){
      return 0.0;
    }

    openstudio::Vector x(N + 2);
    openstudio::Vector y(N + 2);

    x[0] = -0.000001;
    y[0] = 0.0;

    for (unsigned i = 0; i < N; ++i){
      x[i + 1] = times[i].totalDays();
      y[i + 1] = values[i];
    }

    x[N + 1] = 1.000001;
    y[N + 1] = 0.0;

    InterpMethod interpMethod;
    if (this->interpolatetoTimestep()){
      interpMethod = LinearInterp;
    }else{
      interpMethod = HoldNextInterp;
    }

    double result = interp(x, y, time.totalDays(), interpMethod, NoneExtrap);

    return result;
  }
예제 #2
0
  bool ScheduleDay_Impl::addValue(const openstudio::Time& untilTime, double value) {
    if (untilTime.totalMinutes() <= 0.5 || untilTime.totalDays() > 1.0) {
      return false;
    }

    int untilHours = untilTime.hours() + 24*untilTime.days();
    int untilMinutes = untilTime.minutes() + floor((untilTime.seconds()/60.0) + 0.5);

    if (untilMinutes >= 60){
      untilHours += 1;
      untilMinutes += -60;
    }

    // use set to determine whether to overwrite or insert, and where
    std::set<openstudio::Time> times;
    std::pair<std::set<openstudio::Time>::const_iterator,bool> insertResult;
    for (const openstudio::Time& time : this->times()) {
      insertResult = times.insert(time);
      OS_ASSERT(insertResult.second);
    }

    insertResult = times.insert(untilTime);
    unsigned index = std::distance<std::set<openstudio::Time>::const_iterator>(times.begin(),insertResult.first);
    OS_ASSERT(index <= numExtensibleGroups());
    bool result(true);
    if (insertResult.second) {
      // new time--insert an extensible group
      std::vector<std::string> groupValues;
      groupValues.push_back(boost::lexical_cast<std::string>(untilHours));
      groupValues.push_back(boost::lexical_cast<std::string>(untilMinutes));
      groupValues.push_back(toString(value));

      IdfExtensibleGroup group = insertExtensibleGroup(index, groupValues);
      OS_ASSERT(!group.empty());
    }
    else {
      // time already exists, overwrite value
      IdfExtensibleGroup group = getExtensibleGroup(index);
      result = group.setDouble(OS_Schedule_DayExtensibleFields::ValueUntilTime,value);
    }

    return result;
  }
 bool RefrigerationDefrostCycleParameters_Impl::setDefrost8StartTime(const openstudio::Time& defrost8StartTime) {
   bool hours = setInt(OS_Refrigeration_DefrostCycleParametersFields::Defrost8HourStartTime, defrost8StartTime.hours());
   bool minutes = setInt(OS_Refrigeration_DefrostCycleParametersFields::Defrost8MinuteStartTime, defrost8StartTime.minutes());
   if ( !hours || !minutes ) {
     resetDefrost8StartTime();
   }
   return hours && minutes;
 }