/// <summary>
        /// Update the associated buffer with the last values calculated by the engine
        /// </summary>
        public virtual void UpdateBuffer()
        {
            if ((link.SourceQuantity != null) && (link.SourceElementSet != null))
            {
                if (this.Engine is Oatc.OpenMI.Sdk.Wrapper.IAdvancedEngine)
                {
                    TimeValueSet timeValueSet = ((IAdvancedEngine)this.Engine).GetValues(link.SourceQuantity.ID, link.SourceElementSet.ID);

                    if (timeValueSet.Time != null)
                    {
                        if (_useSpatialMapping)
                        {
                            this.smartBuffer.AddValues(timeValueSet.Time, elementMapper.MapValues(timeValueSet.ValueSet));
                        }
                        else
                        {
                            this.smartBuffer.AddValues(timeValueSet.Time, timeValueSet.ValueSet);
                        }
                    }
                }
                else // the engine is IEngine or IRunEngine
                {
                    ITime time = this.Engine.GetCurrentTime();


                    IValueSet valueSet = this.Engine.GetValues(link.SourceQuantity.ID, link.SourceElementSet.ID);


                    if (_useSpatialMapping)
                    {
                        this.smartBuffer.AddValues(time, elementMapper.MapValues(valueSet));
                    }
                    else
                    {
                        this.smartBuffer.AddValues(time, valueSet);
                    }
                }
            }

            SmartBuffer.ClearBefore(link.TargetComponent.EarliestInputTime);
        }
Пример #2
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));
        }