/// <summary>
        /// Compared to <see cref="GetValues(IBaseExchangeItem)"/>,
        /// this version adds the values to the targetSet (for reuse or adding to a targetSet)
        /// </summary>
        public void GetValues(ITimeSpaceValueSet <double> targetSet, IBaseExchangeItem querySpecifier2)
        {
            ITimeSpaceExchangeItem timeSpaceQuery = querySpecifier2 as ITimeSpaceExchangeItem;

            if (timeSpaceQuery == null)
            {
                throw new ArgumentException("querySpecifier must be an ITimeSpaceExchangeItem - add an adaptor");
            }

            if (!(timeSpaceQuery is ITimeSpaceInput))
            {
                throw new OpenMIException("Get Values can only be called with an Input as argument")
                      {
                          Component = Adaptee.Component, Output = this
                      };
            }

            // Set query time to internal query item
            _query.TimeSet = timeSpaceQuery.TimeSet;

            ITimeSpaceValueSet incomingValues = _adaptee.GetValues(_query);

            // Transform the values from the adaptee
            _elementMapper.MapValues(targetSet, incomingValues);
        }
Ejemplo n.º 2
0
 public ExchangeItem(ITimeSpaceExchangeItem item)
     : base(item)
 {
     _id = item.Id;
     if (item.ValueDefinition != null)
     {
         if (item.ValueDefinition is IQuality)
         {
             _valueDefinition = new Quality((IQuality)item.ValueDefinition);
         }
         else
         {
             _valueDefinition = new Quantity((IQuantity)item.ValueDefinition);
         }
     }
     if (item.ElementSet() != null)
     {
         _elementSet = new ElementSet(item.ElementSet());
     }
     if (item.TimeSet != null)
     {
         _timeSet = new TimeSet(item.TimeSet);
     }
     if (item.Component != null)
     {
         _component = new Component(item.Component);
     }
 }
Ejemplo n.º 3
0
 public void AddOut(IBaseExchangeItem openMIo)
 {
     if (openMIo is ITimeSpaceOutput)
     {
         _openMIItem = _openMIOutputItem = (ITimeSpaceOutput)openMIo;
     }
 }
Ejemplo n.º 4
0
        public ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier)
        {
            ITimeSpaceExchangeItem timeSpaceQuery = querySpecifier as ITimeSpaceExchangeItem;

            if (timeSpaceQuery == null)
            {
                throw new ArgumentException("Must be an ITimeSpaceExchangeItem, add an adaptor", "querySpecifier");
            }

            if (_children.Count == 0)
            {
                return(null); // TODO: Or throw an exception?
            }
            TimeSpaceValueSet <double> resultSet = ElementMapper.CreateResultValueSet(timeSpaceQuery.TimeSet.Times.Count, this.ElementSet().ElementCount);

            // Get values from all adaptees/children, and add them together
            for (int i = 0; i < _children.Count; i++)
            {
                ITimeSpaceOutputAdder addingChild = _children[i] as ITimeSpaceOutputAdder;
                if (addingChild != null)
                {
                    addingChild.GetValues(resultSet, querySpecifier);
                }
                else
                {
                    ITimeSpaceValueSet values = _children[i].GetValues(querySpecifier);
                    AddSourceToTarget(resultSet, values);
                }
            }
            return(resultSet);
        }
Ejemplo n.º 5
0
 public void AddIn(IBaseExchangeItem openMIo)
 {
     if (openMIo is ITimeSpaceInput)
     {
         _openMIItem = _openMIInputItem = (ITimeSpaceInput)openMIo;
     }
 }
Ejemplo n.º 6
0
        public static void CheckValueSizes(ITimeSpaceExchangeItem exchangeItem, ITimeSpaceValueSet valueSet)
        {
            int timesCount = 1;

            if (exchangeItem.TimeSet != null)
            {
                if (exchangeItem.TimeSet.Times != null)
                {
                    timesCount = exchangeItem.TimeSet.Times.Count;
                }
                else
                {
                    timesCount = 0;
                }
            }

            if (ValueSet.GetTimesCount(valueSet) != timesCount)
            {
                throw new Exception("ExchangeItem \"" + exchangeItem.Caption +
                                    "\": Wrong #times in valueSet (" + ValueSet.GetTimesCount(valueSet) + "), expected #times (" + timesCount + ")");
            }

            int elementCount = 1;

            if (exchangeItem.ElementSet() != null)
            {
                elementCount = exchangeItem.ElementSet().ElementCount;
            }
            if (ValueSet.GetElementCount(valueSet) != elementCount)
            {
                throw new Exception("ExchangeItem \"" + exchangeItem.Caption +
                                    "\": Wrong #times in valueSet (" + ValueSet.GetElementCount(valueSet) + "), expected #times (" + elementCount + ")");
            }
        }
Ejemplo n.º 7
0
 public ExchangeItem(IBaseExchangeItem openMIItem, bool useBufferedValues)
 {
     if (openMIItem is ITimeSpaceOutput)
     {
         _openMIItem = _openMIOutputItem = (ITimeSpaceOutput)openMIItem;
     }
     else if (openMIItem is ITimeSpaceInput)
     {
         _openMIItem = _openMIInputItem = (ITimeSpaceInput)openMIItem;
     }
     else
     {
         throw new Exception("Unknown exchange item type: " + openMIItem.GetType());
     }
     if (_openMIItem.TimeSet != null && _openMIItem.TimeSet.HasDurations)
     {
         throw new Exception("\"" + Id + ": OpenDA Time Spans not covered by OpenDA Exchange items");
     }
     _useBufferedValues = useBufferedValues;
     if (_useBufferedValues)
     {
         _bufferedValues = new List <List <double> > {
             new List <double>()
         };
         _bufferedTimes = new List <double>();
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Get the <see cref="IElementSet"/> from the <paramref name="baseitem"/>,
        /// assuming it is a <see cref="ITimeSpaceExchangeItem"/> with an <see cref="IElementSet"/>
        /// as its <see cref="ITimeSpaceExchangeItem.SpatialDefinition"/>. If not, exceptions
        /// are thrown.
        /// </summary>
        public static IElementSet ElementSet(this IBaseExchangeItem baseitem)
        {
            ITimeSpaceExchangeItem item = baseitem as ITimeSpaceExchangeItem;

            if (item == null)
            {
                throw new Exception("base item is not an ITimeSpaceExchangeItem");
            }
            return(item.ElementSet());
        }
Ejemplo n.º 9
0
 public static bool OutputAndInputValuesFit(ITimeSpaceExchangeItem sourceItem, ITimeSpaceExchangeItem targetItem)
 {
     bool timeFits = OutputAndInputTimeSetsFit(sourceItem, targetItem);
     bool elementSetFits = true;
     if (timeFits)
     {
         elementSetFits = OutputAndInputElementSetsFit(sourceItem, targetItem);
     }            
     return timeFits && elementSetFits;
 }
Ejemplo n.º 10
0
        public static bool OutputAndInputValuesFit(ITimeSpaceExchangeItem sourceItem, ITimeSpaceExchangeItem targetItem)
        {
            bool timeFits       = OutputAndInputTimeSetsFit(sourceItem, targetItem);
            bool elementSetFits = true;

            if (timeFits)
            {
                elementSetFits = OutputAndInputElementSetsFit(sourceItem, targetItem);
            }
            return(timeFits && elementSetFits);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Check if the element set and the time set of a provider fit accoring to what the consumer
        /// requires. This method can be used to check of the providing component yet needs to do another Update() step.
        /// </summary>
        /// <param name="provider">The provider</param>
        /// <param name="consumer">The consumer</param>
        /// <returns>True if both element set and the time set fit</returns>
        public static bool OutputAndInputFit(ITimeSpaceExchangeItem provider, ITimeSpaceExchangeItem consumer)
        {
            bool timeFits       = OutputAndInputTimeSetsFit(provider, consumer);
            bool elementSetFits = true;

            if (timeFits)
            {
                elementSetFits = OutputAndInputElementSetsFit(provider, consumer);
            }
            return(timeFits && elementSetFits);
        }
Ejemplo n.º 12
0
        public ValueSet(ITimeSpaceExchangeItem item, IEnumerable <T> value)
        {
            if (item.TimeSet != null && item.TimeSet.Times.Count > 1)
            {
                throw new Exception("Can not handle more than one time step");
            }
            List <T> elementValues = new List <T>();

            elementValues.AddRange(value);
            _values = new List <List <T> >();
            _values.Add(elementValues);
        }
Ejemplo n.º 13
0
        public override ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier)
        {
            ITimeSpaceExchangeItem timeSpaceQuery = querySpecifier as ITimeSpaceExchangeItem;

            if (timeSpaceQuery == null)
            {
                throw new ArgumentException("querySpecifier must be an ITimeSpaceExchangeItem - add an adaptor");
            }

            CheckSpecificationAndTryUpdateIfRequired(timeSpaceQuery);
            return(Values);
        }
Ejemplo n.º 14
0
        public static bool Update(ITimeSpaceOutput output, IBaseExchangeItem basequerySpecifier)
        {
            ITimeSpaceExchangeItem querySpecifier = basequerySpecifier as ITimeSpaceExchangeItem;

            if (querySpecifier == null)
            {
                throw new ArgumentException("querySpecifier must be an ITimeSpaceExchangeItem - add an adaptor");
            }

            // Time set of query must be defined and have at least 1 time
            if (querySpecifier.TimeSet == null ||
                querySpecifier.TimeSet.Times == null ||
                querySpecifier.TimeSet.Times.Count == 0)
            {
                throw new Exception("Given the TimeSet of output item \"" + output.Id +
                                    "\", it can not produce one set of values for \"" + querySpecifier.Id + "\"");
            }

            // Output time set must be defined
            if (output.TimeSet == null || output.TimeSet.Times == null)
            {
                throw new Exception("Invalid time specifier in output item \"" + output.Id +
                                    "\" for in updating according to a time specification" + querySpecifier.Id);
            }

            // Compute until this time is available
            double queryTimeMjd = querySpecifier.TimeSet.Times[0].End().StampAsModifiedJulianDay;

            // The current available time from the output item
            double availableTimeMjd = Double.NegativeInfinity;

            if (output.TimeSet.Times.Count > 0)
            {
                availableTimeMjd = output.TimeSet.Times[output.TimeSet.Times.Count - 1].End().StampAsModifiedJulianDay;
            }

            // Update component until querytime is available
            // If component is "busy" (LinkableComponentStatus.Updating), the
            // component will not be updated.
            IBaseLinkableComponent component = output.Component;

            while ((component.Status == LinkableComponentStatus.Valid ||
                    component.Status == LinkableComponentStatus.Updated) &&
                   availableTimeMjd + Time.EpsilonForTimeCompare < queryTimeMjd)
            {
                component.Update();
                availableTimeMjd = output.TimeSet.Times[output.TimeSet.Times.Count - 1].End().StampAsModifiedJulianDay;
            }

            // Return true if component was updated up until queryTimeMjd
            return(availableTimeMjd + Time.EpsilonForTimeCompare >= queryTimeMjd);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Get the <see cref="IElementSet"/> from the <paramref name="item"/>,
        /// assuming the <see cref="ITimeSpaceExchangeItem.SpatialDefinition"/> is
        /// an <see cref="IElementSet"/>. If not, an exception is thrown.
        /// </summary>
        public static IElementSet ElementSet(this ITimeSpaceExchangeItem item)
        {
            if (item.SpatialDefinition == null)
            {
                return(null);
            }
            IElementSet elmtSet = item.SpatialDefinition as IElementSet;

            if (elmtSet != null)
            {
                return(elmtSet);
            }
            throw new NotSupportedException("The SpatialDefinition needs currently to be an IElementSet");
        }
Ejemplo n.º 16
0
        public static bool OutputAndInputElementSetsFit(ITimeSpaceExchangeItem sourceItem, ITimeSpaceExchangeItem targetItem)
        {
            if (sourceItem == null)
            {
                throw new ArgumentNullException("sourceItem");
            }

            if (targetItem == null)
            {
                throw new ArgumentNullException("targetItem");
            }

            bool        elementSetFits   = true;
            IElementSet sourceElementSet = sourceItem.ElementSet();
            IElementSet targetElementSet = targetItem.ElementSet();

            if (sourceElementSet == null)
            {
                if (targetElementSet != null)
                {
                    // NOTE: Source has no elementset specification, source has.
                    // Source fits target if target requires only one element.
                    elementSetFits = targetElementSet.ElementCount == 1;
                }
            }
            else
            {
                if (targetElementSet == null)
                {
                    // NOTE: Target has no elementset specification, source has.
                    // Source fits target if source has values for only one element available.
                    elementSetFits = sourceElementSet.ElementCount == 1;
                }
                else
                {
                    // Both source and target have an element set specification
                    // If the source is a regular exchange item, the #elements will fit
                    // (has been checked configuration time)

                    // If it is a spatial extension, we need to check if valeus on the newly required
                    // element set can be delivered
                    if (sourceItem is ITimeSpaceAdaptedOutput)
                    {
                        // TODO: Check how we can find out that it is a spatial adaptedOutput.
                        // TODO: If it is, how do we check whether the values on the target element set can be delivered
                    }
                }
            }
            return(elementSetFits);
        }
Ejemplo n.º 17
0
            public override ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier)
            {
                ITimeSpaceExchangeItem timeSpaceQuery = querySpecifier as ITimeSpaceExchangeItem;

                if (timeSpaceQuery == null)
                {
                    throw new ArgumentException("Query is not an ITimeSpaceExchangeItem - you may need to add an adaptor");
                }
                if (timeSpaceQuery.TimeSet != null && timeSpaceQuery.TimeSet.Times.Count == 1)
                {
                    double[] valuesForTimeStep = _timeSeriesComponent.Buffer.GetValues(timeSpaceQuery.TimeSet.Times[0]);
                    return(new ValueSet(new List <IList> {
                        valuesForTimeStep
                    }));
                }
                throw new Exception("Invalid time specification in querying exchange item \"" + querySpecifier.Id + "\"");
            }
        public override ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier2)
        {
            ITimeSpaceExchangeItem timeSpaceQuery = querySpecifier2 as ITimeSpaceExchangeItem;

            if (timeSpaceQuery == null)
            {
                throw new ArgumentException("querySpecifier must be an ITimeSpaceExchangeItem - add an adaptor");
            }

            if (!(timeSpaceQuery is ITimeSpaceInput))
            {
                throw new OpenMIException("Get Values can only be called with an Input as argument")
                      {
                          Component = Adaptee.Component, Output = this
                      };
            }


            /// Using a _query item in the
            ///     _adaptee.GetValues(_query)
            /// instead of
            ///     _adaptee.GetValues(this)
            ///
            /// Reason:
            /// If using the latter, it would be required to set the internal
            ///     TimeSet = timeSpaceQuery.TimeSet;
            /// but then internal Values (retrieved from adaptee) does not match TimeSet.
            /// And also:
            /// - the TimeSet is set to override and return _adaptee.TimeSet
            /// - the spatial definition would not match the adaptee

            // If uncommenting this, comment out also the overidden TimeSet property above
            //TimeSet = timeSpaceQuery.TimeSet;

            // Set query time to internal query item
            _query.TimeSet = timeSpaceQuery.TimeSet;

            ITimeSpaceValueSet          incomingValues = _adaptee.GetValues(_query);
            ITimeSpaceValueSet <double> resultValues   = ElementMapper.CreateResultValueSet(incomingValues.TimesCount(), SpatialDefinition.ElementCount);

            // Transform the values from the adaptee
            _elementMapper.MapValues(ref resultValues, ref incomingValues);

            return(resultValues);
        }
Ejemplo n.º 19
0
      public override ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier)
      {
        ITimeSpaceExchangeItem item = (ITimeSpaceExchangeItem)querySpecifier;

        TimeSet.SetSingleTime(item.TimeSet.Times[0]);

        int count = item.ElementSet().ElementCount;

        double[] vals = new double[count];
        for (int i = 0; i < count; i++)
        {
          vals[i] = ConstOutput;
        }

        ValueSetArray<double> valueset = new ValueSetArray<double>(vals);

        return valueset;

      }
Ejemplo n.º 20
0
        /// <summary>
        /// Checks the <paramref name="querySpecifier"/> if it matches the current values. If not,
        /// try and update the component and the item.
        ///
        /// If failing, this will throw an exception
        /// </summary>
        protected void CheckSpecificationAndTryUpdateIfRequired(ITimeSpaceExchangeItem querySpecifier)
        {
            if (!ExchangeItemHelper.OutputAndInputElementSetsFit(this, querySpecifier))
            {
                throw new Exception("ElementSet of output item \"" + Id +
                                    "\" does not fit the ElementSet of requesting item \"" + querySpecifier.Id);
            }

            if (!ExchangeItemHelper.OutputAndInputTimeSetsFit(this, querySpecifier))
            {
                TimeComponentUpdater.Update(this, querySpecifier);

                // TODO JGR: Remove commented code when tested properly
                //if (querySpecifier.TimeSet == null ||
                //    querySpecifier.TimeSet.Times == null ||
                //    querySpecifier.TimeSet.Times.Count != 1)
                //{
                //  // Time independent target item, but for some reason this output item's time set does
                //  // not fit (most probably because is has either 0 or more then 1 timesteps).
                //  throw new Exception("Given the TimeSet of output item \"" + Id +
                //                      "\", it can not produce one set of values for \"" + querySpecifier.Id + "\"");
                //}

                //// Compute until the value are available indeed
                //// Check the max #of steps, to avoid an eternal loop
                //double targetTimeAsMJD = querySpecifier.TimeSet.Times[0].End().StampAsModifiedJulianDay;

                //while ((_linkableEngine.Status == LinkableComponentStatus.Valid ||
                //    _linkableEngine.Status == LinkableComponentStatus.Updated) &&
                //    _linkableEngine.CurrentTime.StampAsModifiedJulianDay + Time.EpsilonForTimeCompare < targetTimeAsMJD)
                //{
                //  _linkableEngine.Update();
                //}
            }

            if (!ExchangeItemHelper.OutputAndInputTimeSetsFit(this, querySpecifier))
            {
                throw new Exception("Could not update engine \"" + _linkableEngine.Id + "\" to required time for output item \"" + Id +
                                    "\" (requiring input item \"" + querySpecifier.Id + "\"). Use a Time Extrapolator.");
            }
        }
Ejemplo n.º 21
0
        public virtual ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier)
        {
            ITimeSpaceExchangeItem timeSpaceQuery = querySpecifier as ITimeSpaceExchangeItem;

            if (timeSpaceQuery == null)
            {
                throw new ArgumentException("Must be an ITimeSpaceExchangeItem - an adaptor may be required");
            }
            if (!ExchangeItemHelper.OutputAndInputElementSetsFit(this, timeSpaceQuery))
            {
                throw new Exception("ElementSet of output item \"" + Id +
                                    "\" does not fit the ElementSet of requesting item \"" + querySpecifier.Id);
            }

            if (!ExchangeItemHelper.OutputAndInputTimeSetsFit(this, timeSpaceQuery))
            {
                throw new Exception("TimeSet of output item \"" + Id +
                                    "\" does not fit the TimeSet of requesting item \"" + querySpecifier.Id);
            }

            return(Values);
        }
Ejemplo n.º 22
0
        public static void CheckValueSizes(ITimeSpaceExchangeItem exchangeItem, ITimeSpaceValueSet valueSet)
        {
            int timesCount = 1;
            if (exchangeItem.TimeSet != null)
            {
                if (exchangeItem.TimeSet.Times != null)
                {
                    timesCount = exchangeItem.TimeSet.Times.Count;
                }
                else
                {
                    timesCount = 0;
                }
            }

            if (ValueSet.GetTimesCount(valueSet) != timesCount)
            {
                throw new Exception("ExchangeItem \"" + exchangeItem.Caption +
                    "\": Wrong #times in valueSet (" + ValueSet.GetTimesCount(valueSet) + "), expected #times (" + timesCount + ")");
            }

            int elementCount = 1;
            if (exchangeItem.ElementSet() != null)
            {
                elementCount = exchangeItem.ElementSet().ElementCount;
            }
            if (ValueSet.GetElementCount(valueSet) != elementCount)
            {
                throw new Exception("ExchangeItem \"" + exchangeItem.Caption +
                    "\": Wrong #times in valueSet (" + ValueSet.GetElementCount(valueSet) + "), expected #times (" + elementCount + ")");
            }

        }
Ejemplo n.º 23
0
        public static bool OutputAndInputTimeSetsFit(ITimeSpaceExchangeItem sourceItem, ITimeSpaceExchangeItem targetItem)
        {
            if (sourceItem == null)
            {
                throw new ArgumentNullException("sourceItem");
            }

            if (targetItem == null)
            {
                throw new ArgumentNullException("targetItem");
            }

            bool timeFits = true;
            ITimeSet sourceTimeSet = sourceItem.TimeSet;
            ITimeSet targetTimeSet = targetItem.TimeSet;
            if (sourceTimeSet == null)
            {
                if (targetTimeSet != null)
                {
                    // NOTE: Source has no timeset specification, source has.
                    // Source fits target if target requires only one time step.
                    timeFits = targetTimeSet.Times.Count == 1;
                }
            }
            else
            {
                if (targetTimeSet == null)
                {
                    // NOTE: Target has no timeset specification, source has.
                    // Source fits target if source has values for only one time step available.
                    timeFits = sourceTimeSet.Times.Count == 1;
                }
                else
                {
                    /*
                     * SH/AM: TODO I Think this code is wrong, IOutput and IAdaptedOutput should be treated the same
                     * (SH: reactivated (if (sourceItem is IAdaptedOutput) code
                     * to make things work for time extrapolators again.
                     */
                    // Both source and target have time set specification
                    if (sourceItem is ITimeSpaceAdaptedOutput)
                    {
                        // NOTE: Source is an adaptedOutput that has a time set.
                        // Most probably a timeinterpolator, but:
                        // TODO: Check how we can find out that it is a time interpolator.
                        // For now: check if the target's last required time is included in the source's time horizon
                        if (sourceTimeSet.TimeHorizon == null)
                        {
                            throw new Exception("Error when checking if the times of AdaptedOutput \"" + sourceItem.Id +
                                                " fits the times required by inputItem \"" + targetItem.Id +
                                                "\": no time horizon available in the adaptedOutput");
                        }
                        ITime lastRequiredTime = targetTimeSet.Times[targetTimeSet.Times.Count - 1];
                        double lastRequiredTimeAsMJD = lastRequiredTime.StampAsModifiedJulianDay +
                                                       lastRequiredTime.DurationInDays;
                        double endOfSourceTimeHorizon = sourceTimeSet.TimeHorizon.StampAsModifiedJulianDay +
                                                        sourceTimeSet.TimeHorizon.DurationInDays;
                        timeFits = lastRequiredTimeAsMJD <= (endOfSourceTimeHorizon + Time.EpsilonForTimeCompare);
                    }
                    else
                    {
                        timeFits = false;
                        // regular (output) exchange item, check if all times fit
                        IList<ITime> sourceTimes = sourceTimeSet.Times;
                        IList<ITime> requiredTimes = targetTimeSet.Times;
                        if (sourceTimes.Count == requiredTimes.Count)
                        {
                            timeFits = true;
                            for (int timeIndex = 0; timeIndex < requiredTimes.Count; timeIndex++)
                            {
                                if ( (requiredTimes[timeIndex].DurationInDays > 0 && !(sourceTimes[timeIndex].DurationInDays>0)) ||
                                     (sourceTimes[timeIndex].DurationInDays > 0 && !(requiredTimes[timeIndex].DurationInDays>0)) )
                                {
                                    throw new Exception("Incompatible times (stamp versus span) between outputItem \"" + sourceItem.Id +
                                                        " and inputItem \"" + targetItem.Id + "\"");
                                }
                                if (requiredTimes[timeIndex].Equals(sourceTimes[timeIndex])) continue;
                                timeFits = false;
                                break;
                            }
                        }
                    }
                }
            }
            return timeFits;
        }
Ejemplo n.º 24
0
        public override ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier)
        {
            ITimeSpaceExchangeItem timeSpaceQuery = querySpecifier as ITimeSpaceExchangeItem;

            if (timeSpaceQuery == null)
            {
                throw new ArgumentException("querySpecifier must be an ITimeSpaceExchangeItem - add an adaptor");
            }

            if (timeSpaceQuery.TimeSet == null || timeSpaceQuery.TimeSet.Times == null ||
                timeSpaceQuery.TimeSet.Times.Count == 0)
            {
                throw new Exception("Invalid query specifier \"" + timeSpaceQuery.Id +
                                    "\" for in GetValues() call to time decorater " + Id);
            }

            // Determinee query time and currently available time
            double queryTimeAsMJD =
                timeSpaceQuery.TimeSet.Times[timeSpaceQuery.TimeSet.Times.Count - 1].StampAsModifiedJulianDay +
                timeSpaceQuery.TimeSet.Times[timeSpaceQuery.TimeSet.Times.Count - 1].DurationInDays;

            double        availableTimeAsMJD = Double.NegativeInfinity;
            IList <ITime> currentTimes       = TimeSet.Times;

            if (currentTimes.Count > 0)
            {
                availableTimeAsMJD =
                    currentTimes[currentTimes.Count - 1].StampAsModifiedJulianDay +
                    currentTimes[currentTimes.Count - 1].DurationInDays;
            }

            // Check if we need to update
            if (availableTimeAsMJD < queryTimeAsMJD)
            {
                // TODO (JGr): output item should not do the actual update of the component?
                if (Adaptee == null)
                {
                    throw new Exception("Can not update, no parent output defined, calling GetValues() of time bufferer " + Id);
                }
                if (_adaptee.TimeSet == null || _adaptee.TimeSet.Times == null)
                {
                    throw new Exception("Invalid time specifier in decorated output item \"" + Adaptee.Id +
                                        "\" for in GetValues() call to time decorater " + Id);
                }

                // Update as far as needed.
                IBaseLinkableComponent linkableComponent = Adaptee.Component;
                while ((linkableComponent.Status == LinkableComponentStatus.Valid ||
                        linkableComponent.Status == LinkableComponentStatus.Updated) &&
                       availableTimeAsMJD < queryTimeAsMJD)
                {
                    linkableComponent.Update();
                    // Determine newly available time
                    IList <ITime> parentTimes = _adaptee.TimeSet.Times;
                    availableTimeAsMJD =
                        parentTimes[parentTimes.Count - 1].StampAsModifiedJulianDay +
                        parentTimes[parentTimes.Count - 1].DurationInDays;
                }
            }

            // Return the values for the required time(s)
            IList <IList <double> > resultValues = new List <IList <double> >();

            if (timeSpaceQuery.TimeSet != null && timeSpaceQuery.TimeSet.Times != null)
            {
                for (int t = 0; t < timeSpaceQuery.TimeSet.Times.Count; t++)
                {
                    resultValues.Add(new List <double>());
                    ITime         queryTime         = timeSpaceQuery.TimeSet.Times[t];
                    List <double> valuesForTimeStep = _buffer.GetValues(queryTime);
                    foreach (double d in valuesForTimeStep)
                    {
                        resultValues[t].Add(d);
                    }
                }
            }
            return(new TimeSpaceValueSet <double>(resultValues));
        }
Ejemplo n.º 25
0
        public static bool OutputAndInputTimeSetsFit(ITimeSpaceExchangeItem sourceItem, ITimeSpaceExchangeItem targetItem)
        {
            if (sourceItem == null)
            {
                throw new ArgumentNullException("sourceItem");
            }

            if (targetItem == null)
            {
                throw new ArgumentNullException("targetItem");
            }

            bool     timeFits      = true;
            ITimeSet sourceTimeSet = sourceItem.TimeSet;
            ITimeSet targetTimeSet = targetItem.TimeSet;

            if (sourceTimeSet == null)
            {
                if (targetTimeSet != null)
                {
                    // NOTE: Source has no timeset specification, source has.
                    // Source fits target if target requires only one time step.
                    timeFits = targetTimeSet.Times.Count == 1;
                }
            }
            else
            {
                if (targetTimeSet == null)
                {
                    // NOTE: Target has no timeset specification, source has.
                    // Source fits target if source has values for only one time step available.
                    timeFits = sourceTimeSet.Times.Count == 1;
                }
                else
                {
                    /*
                     * SH/AM: TODO I Think this code is wrong, IOutput and IAdaptedOutput should be treated the same
                     * (SH: reactivated (if (sourceItem is IAdaptedOutput) code
                     * to make things work for time extrapolators again.
                     */
                    // Both source and target have time set specification
                    if (sourceItem is ITimeSpaceAdaptedOutput)
                    {
                        // NOTE: Source is an adaptedOutput that has a time set.
                        // Most probably a timeinterpolator, but:
                        // TODO: Check how we can find out that it is a time interpolator.
                        // For now: check if the target's last required time is included in the source's time horizon
                        if (sourceTimeSet.TimeHorizon == null)
                        {
                            throw new Exception("Error when checking if the times of AdaptedOutput \"" + sourceItem.Id +
                                                " fits the times required by inputItem \"" + targetItem.Id +
                                                "\": no time horizon available in the adaptedOutput");
                        }
                        ITime  lastRequiredTime      = targetTimeSet.Times[targetTimeSet.Times.Count - 1];
                        double lastRequiredTimeAsMJD = lastRequiredTime.StampAsModifiedJulianDay +
                                                       lastRequiredTime.DurationInDays;
                        double endOfSourceTimeHorizon = sourceTimeSet.TimeHorizon.StampAsModifiedJulianDay +
                                                        sourceTimeSet.TimeHorizon.DurationInDays;
                        timeFits = lastRequiredTimeAsMJD <= (endOfSourceTimeHorizon + Time.EpsilonForTimeCompare);
                    }
                    else
                    {
                        timeFits = false;
                        // regular (output) exchange item, check if all times fit
                        IList <ITime> sourceTimes   = sourceTimeSet.Times;
                        IList <ITime> requiredTimes = targetTimeSet.Times;
                        if (sourceTimes.Count == requiredTimes.Count)
                        {
                            timeFits = true;
                            for (int timeIndex = 0; timeIndex < requiredTimes.Count; timeIndex++)
                            {
                                if ((requiredTimes[timeIndex].DurationInDays > 0 && !(sourceTimes[timeIndex].DurationInDays > 0)) ||
                                    (sourceTimes[timeIndex].DurationInDays > 0 && !(requiredTimes[timeIndex].DurationInDays > 0)))
                                {
                                    throw new Exception("Incompatible times (stamp versus span) between outputItem \"" + sourceItem.Id +
                                                        " and inputItem \"" + targetItem.Id + "\"");
                                }
                                if (requiredTimes[timeIndex].Equals(sourceTimes[timeIndex]))
                                {
                                    continue;
                                }
                                timeFits = false;
                                break;
                            }
                        }
                    }
                }
            }
            return(timeFits);
        }
Ejemplo n.º 26
0
 public UIExchangeItem(ITimeSpaceExchangeItem item)
 {
     _item = item;
 }
Ejemplo n.º 27
0
        public static bool OutputAndInputElementSetsFit(ITimeSpaceExchangeItem sourceItem, ITimeSpaceExchangeItem targetItem)
        {
            if (sourceItem == null)
            {
                throw new ArgumentNullException("sourceItem");
            }

            if (targetItem == null)
            {
                throw new ArgumentNullException("targetItem");
            }

            bool elementSetFits = true;
            IElementSet sourceElementSet = sourceItem.ElementSet();
            IElementSet targetElementSet = targetItem.ElementSet();
            if (sourceElementSet == null)
            {
                if (targetElementSet != null)
                {
                    // NOTE: Source has no elementset specification, source has.
                    // Source fits target if target requires only one element.
                    elementSetFits = targetElementSet.ElementCount == 1;
                }
            }
            else
            {
                if (targetElementSet == null)
                {
                    // NOTE: Target has no elementset specification, source has.
                    // Source fits target if source has values for only one element available.
                    elementSetFits = sourceElementSet.ElementCount == 1;
                }
                else
                {
                    // Both source and target have an element set specification
                    // If the source is a regular exchange item, the #elements will fit
                    // (has been checked configuration time)

                    // If it is a spatial extension, we need to check if valeus on the newly required
                    // element set can be delivered
                    if (sourceItem is ITimeSpaceAdaptedOutput)
                    {
                        // TODO: Check how we can find out that it is a spatial adaptedOutput.
                        // TODO: If it is, how do we check whether the values on the target element set can be delivered
                    }
                }
            }
            return elementSetFits;
        }
Ejemplo n.º 28
0
        public override ITimeSpaceValueSet GetValues(IBaseExchangeItem basequerySpecifier)
        {
            ITimeSpaceExchangeItem querySpecifier = basequerySpecifier as ITimeSpaceExchangeItem;

            if (querySpecifier == null)
            {
                throw new ArgumentException("querySpecifier must be an ITimeSpaceExchangeItem - add an adaptor");
            }

            //------------------------------------------------------
            // Check if we need to update the output component

            // Time set of query must be defined and have at least 1 time
            if (querySpecifier.TimeSet == null ||
                querySpecifier.TimeSet.Times == null ||
                querySpecifier.TimeSet.Times.Count == 0)
            {
                throw new Exception("Invalid query specifier \"" + querySpecifier.Id +
                                    "\" for in GetValues() call to time decorater " + Id);
            }

            // Determine query time
            double queryTimeMjd = querySpecifier.TimeSet.Times[querySpecifier.TimeSet.Times.Count - 1].End().StampAsModifiedJulianDay;

            // Determine the times available in the buffer
            double        availableTimeMjd = Double.NegativeInfinity;
            IList <ITime> currentTimes     = TimeSet.Times;

            if (currentTimes.Count > 0)
            {
                availableTimeMjd = currentTimes[currentTimes.Count - 1].End().StampAsModifiedJulianDay;
            }

            // Check if we need to update
            // In case the output component is "busy", this may not actually update values
            // up to queryTimeMjd, in which case the _buffer.GetValues below will extrapolate.
            if (availableTimeMjd < queryTimeMjd)
            {
                if (ComponentUpdater == null)
                {
                    throw new Exception("Failed when trying to update time buffer (no updater is specified)");
                }
                ComponentUpdater.Update(querySpecifier);
            }

            //------------------------------------------------------
            // Retrieve values from the buffer

            // Return the values for the required time(s)
            IList <IList <double> > resultValues = new List <IList <double> >();

            if (querySpecifier.TimeSet != null && querySpecifier.TimeSet.Times != null)
            {
                for (int t = 0; t < querySpecifier.TimeSet.Times.Count; t++)
                {
                    ITime    queryTime         = querySpecifier.TimeSet.Times[t];
                    double[] valuesForTimeStep = _buffer.GetValues(queryTime);
                    resultValues.Add(valuesForTimeStep);
                }
            }
            ITime earliestConsumerTime = ExchangeItemHelper.GetEarliestConsumerTime(this);

            if (earliestConsumerTime != null)
            {
                _buffer.ClearBefore(earliestConsumerTime);
            }
            return(new TimeSpaceValueSet <double>(resultValues));
        }