public ITimeSpan GetTimeHorizon()
		{
			TimeStamp startTime = new TimeStamp(HydroNumerics.OpenMI.Sdk.DevelopmentSupport.CalendarConverter.Gregorian2ModifiedJulian(_simulationStart));
			TimeStamp endTime   = new TimeStamp(HydroNumerics.OpenMI.Sdk.DevelopmentSupport.CalendarConverter.Gregorian2ModifiedJulian(_simulationEnd));
			HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan timeHorizon = new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(startTime,endTime);
			return timeHorizon;
		}
		public void IsBefore()
		{
			TimeStamp t_4 = new TimeStamp(4);
			TimeStamp t_7 = new TimeStamp(7);
            Assert.AreEqual(true, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_4, t_7));
            Assert.AreEqual(false, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_7, t_4));
            Assert.AreEqual(false, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_4, t_4));

            HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan t_3_5 = new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(3), new TimeStamp(5));
            HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan t_4_6 = new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(4), new TimeStamp(6));
            HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan t_5_7 = new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(5), new TimeStamp(7));
            HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan t_6_8 = new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(6), new TimeStamp(8));

            Assert.AreEqual(true, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_3_5, t_6_8));
            Assert.AreEqual(false, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_6_8, t_3_5));
            Assert.AreEqual(false, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_3_5, t_4_6));
            Assert.AreEqual(false, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_3_5, t_5_7));
            Assert.AreEqual(false, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_3_5, t_3_5));

            Assert.AreEqual(true, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_4, t_5_7));
            Assert.AreEqual(false, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_4, t_3_5));
            Assert.AreEqual(false, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_7, t_3_5));
            Assert.AreEqual(false, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_4, t_4_6));
            Assert.AreEqual(false, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_7, t_5_7));

            Assert.AreEqual(true, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_3_5, t_7));
            Assert.AreEqual(false, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_3_5, t_4));
            Assert.AreEqual(false, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_6_8, t_4));
            Assert.AreEqual(false, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_5_7, t_7));

		}
Exemple #3
0
        public void IsBefore()
        {
            TimeStamp t_4 = new TimeStamp(4);
            TimeStamp t_7 = new TimeStamp(7);

            Assert.AreEqual(true, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_4, t_7));
            Assert.AreEqual(false, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_7, t_4));
            Assert.AreEqual(false, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_4, t_4));

            HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan t_3_5 = new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(3), new TimeStamp(5));
            HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan t_4_6 = new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(4), new TimeStamp(6));
            HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan t_5_7 = new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(5), new TimeStamp(7));
            HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan t_6_8 = new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(6), new TimeStamp(8));

            Assert.AreEqual(true, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_3_5, t_6_8));
            Assert.AreEqual(false, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_6_8, t_3_5));
            Assert.AreEqual(false, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_3_5, t_4_6));
            Assert.AreEqual(false, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_3_5, t_5_7));
            Assert.AreEqual(false, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_3_5, t_3_5));

            Assert.AreEqual(true, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_4, t_5_7));
            Assert.AreEqual(false, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_4, t_3_5));
            Assert.AreEqual(false, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_7, t_3_5));
            Assert.AreEqual(false, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_4, t_4_6));
            Assert.AreEqual(false, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_7, t_5_7));

            Assert.AreEqual(true, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_3_5, t_7));
            Assert.AreEqual(false, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_3_5, t_4));
            Assert.AreEqual(false, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_6_8, t_4));
            Assert.AreEqual(false, global::HydroNumerics.OpenMI.Sdk.Buffer.Support.IsBefore(t_5_7, t_7));
        }
Exemple #4
0
        public ITimeSpan GetTimeHorizon()
        {
            TimeStamp startTime = new TimeStamp(HydroNumerics.OpenMI.Sdk.DevelopmentSupport.CalendarConverter.Gregorian2ModifiedJulian(_simulationStart));
            TimeStamp endTime   = new TimeStamp(HydroNumerics.OpenMI.Sdk.DevelopmentSupport.CalendarConverter.Gregorian2ModifiedJulian(_simulationEnd));

            HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan timeHorizon = new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(startTime, endTime);
            return(timeHorizon);
        }
Exemple #5
0
        public ITime GetCurrentTime()
        {
            double t = HydroNumerics.OpenMI.Sdk.DevelopmentSupport.CalendarConverter.Gregorian2ModifiedJulian(_simulationStart);

            t += _currentTimeStepNumber * _timeStepLength / (24.0 * 3600.0);
            HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan currentTime = new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(t - _timeStepLength / (24.0 * 3600.0)), new TimeStamp(t));
            return(currentTime);
        }
 public global::OpenMI.Standard.ITimeSpan GetTimeHorizon()
 {
     //HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp startTime = new HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp(model.CurrentTime);
     //HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp endTime = new HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp(model.EndTime);
     //OpenMI times cannot handle the DateTime.MinValue and the DateTime.MaxValue so the timehorizon is simply made large (see below).
     HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp startTime   = new HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp(new DateTime(1900, 1, 1));
     HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp endTime     = new HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp(new DateTime(2100, 1, 1));
     HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan  timeHorizon = new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(startTime, endTime);
     return(timeHorizon);
 }
Exemple #7
0
        /// <summary>
        /// Creates a new instance of <see cref="Trigger">Trigger</see> class.
        /// </summary>
        public Trigger()
        {
            _link = null;
            _inputExchangeItem = new TriggerExchangeItem();

            HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp
                start = new TimeStamp(CalendarConverter.Gregorian2ModifiedJulian(new DateTime(1800, 1, 1))),
                end   = new TimeStamp(CalendarConverter.Gregorian2ModifiedJulian(new DateTime(2200, 1, 1)));
            _timeHorizon = new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(start, end);

            _earliestInputTime = end;
        }
        public override IValueSet GetValues(ITime time, string LinkID)
        {
            if (!initializeWasInvoked)
            {
                throw new Exception("Method \"GetValues\" in LinkableTimeSeriesGroup class was invoked before the Initialize method was invoked");
            }

            ILink link = this.GetLink(LinkID);
            SendSourceAfterGetValuesCallEvent(time, link);

            // -- handle incoming links (where this component is the target)
            if (!isBusy) //avoiding deadlocks 
            {
                isBusy = true;
                foreach (ILink acceptingLink in _acceptingLinks)
                {
                    if (((TsQuantity)acceptingLink.TargetQuantity).BaseTimeSeries is TimestampSeries)
                    {
                        TimestampSeries timestampSeries = (TimestampSeries)((TsQuantity)acceptingLink.TargetQuantity).BaseTimeSeries;
                        foreach (TimestampValue timestampValue in timestampSeries.Items)
                        {
                            TimeStamp getValuesTime = new TimeStamp(timestampValue.Time);
                            SendTargetBeforeGetValuesCall(getValuesTime, acceptingLink);
                            IValueSet valueSet = acceptingLink.SourceComponent.GetValues(getValuesTime, acceptingLink.ID);
                            timestampValue.Value = ((IScalarSet)valueSet).GetScalar(0);
                            SendTargetAfterGetValuesReturn(timestampValue.Value, acceptingLink);
                        }
                    }
                    else if (((TsQuantity)acceptingLink.TargetQuantity).BaseTimeSeries is TimespanSeries)
                    {
                        TimespanSeries timespanSeries = (TimespanSeries)((TsQuantity)acceptingLink.TargetQuantity).BaseTimeSeries;
                        foreach (TimespanValue timespanValue in timespanSeries.Items)
                        {
                            HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan timeSpan = new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp(timespanValue.StartTime), new HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp(timespanValue.EndTime));
                            SendTargetBeforeGetValuesCall(timeSpan, acceptingLink);
                            IValueSet valueSet = acceptingLink.SourceComponent.GetValues(timeSpan, acceptingLink.ID);
                            timespanValue.Value = ((IScalarSet)valueSet).GetScalar(0);
                            SendTargetAfterGetValuesReturn(timespanValue.Value, acceptingLink);
                        }
                    }
                    else
                    {
                        throw new Exception("Unexpected exception : Undefined timeseries type (occured in HydroNumerics.Time.OpenMI.LinkableTimeSeriesGroup class)");
                    }
                }
                isBusy = false;
            }

            // -- handle outgoing links (where this component is the source)
            HydroNumerics.Core.Unit toUnit = new HydroNumerics.Core.Unit();
            toUnit.ConversionFactorToSI = link.TargetQuantity.Unit.ConversionFactorToSI;
            toUnit.OffSetToSI = link.TargetQuantity.Unit.OffSetToSI;

            if (time is ITimeStamp)
            {
                HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp t = new TimeStamp((ITimeStamp)time);

                double x = ((TsQuantity)link.SourceQuantity).BaseTimeSeries.GetValue(t.ToDateTime(), toUnit);
                ScalarSet scalarSet = new ScalarSet(new double[] { x });
                SendSourceBeforeGetValuesReturn(x, link);
                return scalarSet;
            }
            else
            {
                HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp start = new TimeStamp(((ITimeSpan)time).Start);
                HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp end = new TimeStamp(((ITimeSpan)time).End);

                double x = ((TsQuantity)link.SourceQuantity).BaseTimeSeries.GetValue(start.ToDateTime(), end.ToDateTime(), toUnit);
                ScalarSet scalarSet = new ScalarSet(new double[] { x });
                SendSourceBeforeGetValuesReturn(x, link);
                return scalarSet;
            }
        }
        public override IValueSet GetValues(ITime time, string LinkID)
        {
            if (!initializeWasInvoked)
            {
                throw new Exception("Method \"GetValues\" in LinkableTimeSeriesGroup class was invoked before the Initialize method was invoked");
            }

            ILink link = this.GetLink(LinkID);

            SendSourceAfterGetValuesCallEvent(time, link);

            // -- handle incoming links (where this component is the target)
            if (!isBusy) //avoiding deadlocks
            {
                isBusy = true;
                foreach (ILink acceptingLink in _acceptingLinks)
                {
                    if (((TsQuantity)acceptingLink.TargetQuantity).BaseTimeSeries is TimestampSeries)
                    {
                        TimestampSeries timestampSeries = (TimestampSeries)((TsQuantity)acceptingLink.TargetQuantity).BaseTimeSeries;
                        foreach (TimestampValue timestampValue in timestampSeries.Items)
                        {
                            TimeStamp getValuesTime = new TimeStamp(timestampValue.Time);
                            SendTargetBeforeGetValuesCall(getValuesTime, acceptingLink);
                            IValueSet valueSet = acceptingLink.SourceComponent.GetValues(getValuesTime, acceptingLink.ID);
                            timestampValue.Value = ((IScalarSet)valueSet).GetScalar(0);
                            SendTargetAfterGetValuesReturn(timestampValue.Value, acceptingLink);
                        }
                    }
                    else if (((TsQuantity)acceptingLink.TargetQuantity).BaseTimeSeries is TimespanSeries)
                    {
                        TimespanSeries timespanSeries = (TimespanSeries)((TsQuantity)acceptingLink.TargetQuantity).BaseTimeSeries;
                        foreach (TimespanValue timespanValue in timespanSeries.Items)
                        {
                            HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan timeSpan = new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp(timespanValue.StartTime), new HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp(timespanValue.EndTime));
                            SendTargetBeforeGetValuesCall(timeSpan, acceptingLink);
                            IValueSet valueSet = acceptingLink.SourceComponent.GetValues(timeSpan, acceptingLink.ID);
                            timespanValue.Value = ((IScalarSet)valueSet).GetScalar(0);
                            SendTargetAfterGetValuesReturn(timespanValue.Value, acceptingLink);
                        }
                    }
                    else
                    {
                        throw new Exception("Unexpected exception : Undefined timeseries type (occured in HydroNumerics.Time.OpenMI.LinkableTimeSeriesGroup class)");
                    }
                }
                isBusy = false;
            }

            // -- handle outgoing links (where this component is the source)
            HydroNumerics.Core.Unit toUnit = new HydroNumerics.Core.Unit();
            toUnit.ConversionFactorToSI = link.TargetQuantity.Unit.ConversionFactorToSI;
            toUnit.OffSetToSI           = link.TargetQuantity.Unit.OffSetToSI;

            if (time is ITimeStamp)
            {
                HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp t = new TimeStamp((ITimeStamp)time);

                double    x         = ((TsQuantity)link.SourceQuantity).BaseTimeSeries.GetValue(t.ToDateTime(), toUnit);
                ScalarSet scalarSet = new ScalarSet(new double[] { x });
                SendSourceBeforeGetValuesReturn(x, link);
                return(scalarSet);
            }
            else
            {
                HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp start = new TimeStamp(((ITimeSpan)time).Start);
                HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp end   = new TimeStamp(((ITimeSpan)time).End);

                double    x         = ((TsQuantity)link.SourceQuantity).BaseTimeSeries.GetValue(start.ToDateTime(), end.ToDateTime(), toUnit);
                ScalarSet scalarSet = new ScalarSet(new double[] { x });
                SendSourceBeforeGetValuesReturn(x, link);
                return(scalarSet);
            }
        }
		public void ClearAfter()
		{
			SmartBuffer smartBuffer = new SmartBuffer();
			smartBuffer.DoExtendedDataVerification = true;

			// --Populate the SmartBuffer --
			smartBuffer.AddValues(new TimeStamp(10), new ScalarSet(new double[2] {11, 21}));
			smartBuffer.AddValues(new TimeStamp(13), new ScalarSet(new double[2] {12 ,22}));
			smartBuffer.AddValues(new TimeStamp(16), new ScalarSet(new double[2] {13 ,23}));
			smartBuffer.AddValues(new TimeStamp(20), new ScalarSet(new double[2] {14 ,24}));
			smartBuffer.AddValues(new TimeStamp(27), new ScalarSet(new double[2] {15 ,25}));
			smartBuffer.AddValues(new TimeStamp(30), new ScalarSet(new double[2] {16, 26}));
			smartBuffer.AddValues(new TimeStamp(48), new ScalarSet(new double[2] {17, 27}));

            HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp time = new HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp();

			time.ModifiedJulianDay = 50; // this time is after the last time in buffer
			smartBuffer.ClearAfter(time);
			Assert.AreEqual(7,smartBuffer.TimesCount);  //nothing removed
			Assert.AreEqual(11,((IScalarSet) smartBuffer.GetValuesAt(0)).GetScalar(0));
			Assert.AreEqual(27,((IScalarSet) smartBuffer.GetValuesAt(6)).GetScalar(1));

			time.ModifiedJulianDay = 30;
			smartBuffer.ClearAfter(time);
			Assert.AreEqual(5,smartBuffer.TimesCount);
			Assert.AreEqual(11,((IScalarSet) smartBuffer.GetValuesAt(0)).GetScalar(0));
			Assert.AreEqual(25,((IScalarSet) smartBuffer.GetValuesAt(4)).GetScalar(1));

			time.ModifiedJulianDay = 16.5;
			smartBuffer.ClearAfter(time);
			Assert.AreEqual(3,smartBuffer.TimesCount);
			Assert.AreEqual(11,((IScalarSet) smartBuffer.GetValuesAt(0)).GetScalar(0));
			Assert.AreEqual(23,((IScalarSet) smartBuffer.GetValuesAt(2)).GetScalar(1));

			time.ModifiedJulianDay = 9;
			smartBuffer.ClearAfter(time);
			Assert.AreEqual(0,smartBuffer.TimesCount);

			time.ModifiedJulianDay = 9;
			smartBuffer.ClearAfter(time);
			Assert.AreEqual(0,smartBuffer.TimesCount);

			smartBuffer.AddValues(new TimeStamp(10), new ScalarSet(new double[2] {11, 21}));
			smartBuffer.AddValues(new TimeStamp(13), new ScalarSet(new double[2] {12 ,22}));
			smartBuffer.AddValues(new TimeStamp(16), new ScalarSet(new double[2] {13 ,23}));
			smartBuffer.AddValues(new TimeStamp(20), new ScalarSet(new double[2] {14 ,24}));
			smartBuffer.AddValues(new TimeStamp(27), new ScalarSet(new double[2] {15 ,25}));
			smartBuffer.AddValues(new TimeStamp(30), new ScalarSet(new double[2] {16, 26}));
			smartBuffer.AddValues(new TimeStamp(48), new ScalarSet(new double[2] {17, 27}));

			HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp start   = new HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp(50);
			HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp end     = new HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp(55);
			HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan timeSpan = new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(start,end);

			start.ModifiedJulianDay = 50; // this time is after the last time in buffer
			smartBuffer.ClearAfter(timeSpan);
			Assert.AreEqual(7,smartBuffer.TimesCount);  //nothing removed
			Assert.AreEqual(11,((IScalarSet) smartBuffer.GetValuesAt(0)).GetScalar(0));
			Assert.AreEqual(27,((IScalarSet) smartBuffer.GetValuesAt(6)).GetScalar(1));

			start.ModifiedJulianDay = 30;
			smartBuffer.ClearAfter(timeSpan);
			Assert.AreEqual(5,smartBuffer.TimesCount);
			Assert.AreEqual(11,((IScalarSet) smartBuffer.GetValuesAt(0)).GetScalar(0));
			Assert.AreEqual(25,((IScalarSet) smartBuffer.GetValuesAt(4)).GetScalar(1));

			start.ModifiedJulianDay = 16.5;
			smartBuffer.ClearAfter(timeSpan);
			Assert.AreEqual(3,smartBuffer.TimesCount);
			Assert.AreEqual(11,((IScalarSet) smartBuffer.GetValuesAt(0)).GetScalar(0));
			Assert.AreEqual(23,((IScalarSet) smartBuffer.GetValuesAt(2)).GetScalar(1));

			start.ModifiedJulianDay = 9;
			smartBuffer.ClearAfter(timeSpan);
			Assert.AreEqual(0,smartBuffer.TimesCount);

			start.ModifiedJulianDay = 9;
			smartBuffer.ClearAfter(timeSpan);
			Assert.AreEqual(0,smartBuffer.TimesCount);

			smartBuffer.AddValues(new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(10),new TimeStamp(13)), new ScalarSet(new double[2] {11, 21}));
			smartBuffer.AddValues(new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(13),new TimeStamp(16)), new ScalarSet(new double[2] {12, 22}));
			smartBuffer.AddValues(new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(16),new TimeStamp(20)), new ScalarSet(new double[2] {13, 23}));
			smartBuffer.AddValues(new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(20),new TimeStamp(27)), new ScalarSet(new double[2] {14, 24}));
			smartBuffer.AddValues(new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(27),new TimeStamp(30)), new ScalarSet(new double[2] {15, 25}));
			smartBuffer.AddValues(new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(30),new TimeStamp(48)), new ScalarSet(new double[2] {16, 26}));
			smartBuffer.AddValues(new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(48),new TimeStamp(55)), new ScalarSet(new double[2] {17, 27}));

			
			time.ModifiedJulianDay = 50; // this time is after the last time in buffer
			smartBuffer.ClearAfter(time);
			Assert.AreEqual(7,smartBuffer.TimesCount);  //nothing removed
			Assert.AreEqual(11,((IScalarSet) smartBuffer.GetValuesAt(0)).GetScalar(0));
			Assert.AreEqual(27,((IScalarSet) smartBuffer.GetValuesAt(6)).GetScalar(1));

			time.ModifiedJulianDay = 30;
			smartBuffer.ClearAfter(time);
			Assert.AreEqual(5,smartBuffer.TimesCount);
			Assert.AreEqual(11,((IScalarSet) smartBuffer.GetValuesAt(0)).GetScalar(0));
			Assert.AreEqual(25,((IScalarSet) smartBuffer.GetValuesAt(4)).GetScalar(1));

			time.ModifiedJulianDay = 16.5;
			smartBuffer.ClearAfter(time);
			Assert.AreEqual(3,smartBuffer.TimesCount);
			Assert.AreEqual(11,((IScalarSet) smartBuffer.GetValuesAt(0)).GetScalar(0));
			Assert.AreEqual(23,((IScalarSet) smartBuffer.GetValuesAt(2)).GetScalar(1));

			time.ModifiedJulianDay = 9;
			smartBuffer.ClearAfter(time);
			Assert.AreEqual(0,smartBuffer.TimesCount);

			time.ModifiedJulianDay = 9;
			smartBuffer.ClearAfter(time);
			Assert.AreEqual(0,smartBuffer.TimesCount);

			smartBuffer.AddValues(new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(10),new TimeStamp(13)), new ScalarSet(new double[2] {11, 21}));
			smartBuffer.AddValues(new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(13),new TimeStamp(16)), new ScalarSet(new double[2] {12, 22}));
			smartBuffer.AddValues(new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(16),new TimeStamp(20)), new ScalarSet(new double[2] {13, 23}));
			smartBuffer.AddValues(new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(20),new TimeStamp(27)), new ScalarSet(new double[2] {14, 24}));
			smartBuffer.AddValues(new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(27),new TimeStamp(30)), new ScalarSet(new double[2] {15, 25}));
			smartBuffer.AddValues(new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(30),new TimeStamp(48)), new ScalarSet(new double[2] {16, 26}));
			smartBuffer.AddValues(new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(48),new TimeStamp(55)), new ScalarSet(new double[2] {17, 27}));

			start.ModifiedJulianDay = 50; // this time is after the last time in buffer
			smartBuffer.ClearAfter(timeSpan);
			Assert.AreEqual(7,smartBuffer.TimesCount);  //nothing removed
			Assert.AreEqual(11,((IScalarSet) smartBuffer.GetValuesAt(0)).GetScalar(0));
			Assert.AreEqual(27,((IScalarSet) smartBuffer.GetValuesAt(6)).GetScalar(1));

			start.ModifiedJulianDay = 30;
			smartBuffer.ClearAfter(timeSpan);
			Assert.AreEqual(5,smartBuffer.TimesCount);
			Assert.AreEqual(11,((IScalarSet) smartBuffer.GetValuesAt(0)).GetScalar(0));
			Assert.AreEqual(25,((IScalarSet) smartBuffer.GetValuesAt(4)).GetScalar(1));

			start.ModifiedJulianDay = 16.5;
			smartBuffer.ClearAfter(timeSpan);
			Assert.AreEqual(3,smartBuffer.TimesCount);
			Assert.AreEqual(11,((IScalarSet) smartBuffer.GetValuesAt(0)).GetScalar(0));
			Assert.AreEqual(23,((IScalarSet) smartBuffer.GetValuesAt(2)).GetScalar(1));

			start.ModifiedJulianDay = 9;
			smartBuffer.ClearAfter(timeSpan);
			Assert.AreEqual(0,smartBuffer.TimesCount);

			start.ModifiedJulianDay = 9;
			smartBuffer.ClearAfter(timeSpan);
			Assert.AreEqual(0,smartBuffer.TimesCount);
		}
		public ITime GetCurrentTime()
		{
			double t = HydroNumerics.OpenMI.Sdk.DevelopmentSupport.CalendarConverter.Gregorian2ModifiedJulian(_simulationStart);
			t += _currentTimeStepNumber * _timeStepLength / (24.0*3600.0);
			HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan currentTime = new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(t - _timeStepLength / (24.0*3600.0)),new TimeStamp(t));
			return currentTime;
		}
Exemple #12
0
		/// <summary>
		/// Creates a new instance of <see cref="Trigger">Trigger</see> class.
		/// </summary>
		public Trigger()
		{
			_link = null;
			_inputExchangeItem = new TriggerExchangeItem();

			HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp
				start = new TimeStamp( CalendarConverter.Gregorian2ModifiedJulian(new DateTime(1800,1,1)) ),
				end = new TimeStamp( CalendarConverter.Gregorian2ModifiedJulian(new DateTime(2200,1,1)) );
			_timeHorizon = new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(start, end);

			_earliestInputTime = end;
		}
		public void ITimeToString()
		{
			System.DateTime t1 = new DateTime(2004,7,12,10,25,34);
			System.DateTime t2 = new DateTime(2004,8,15,13,15,14);
			TimeStamp timeStamp1 = new TimeStamp(HydroNumerics.OpenMI.Sdk.DevelopmentSupport.CalendarConverter.Gregorian2ModifiedJulian(t1));
			TimeStamp timeStamp2 = new TimeStamp(HydroNumerics.OpenMI.Sdk.DevelopmentSupport.CalendarConverter.Gregorian2ModifiedJulian(t2));
			HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan timeSpan = new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(timeStamp1,timeStamp2);

			Assert.AreEqual(t1.ToString(),LinkableRunEngine.ITimeToString(timeStamp1));
			string str = "[" + t1.ToString()+", "+t2.ToString()+"]";
			Assert.AreEqual(str, LinkableRunEngine.ITimeToString(timeSpan));

		}
		public void TimeToTimeStamp()
		{
			HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan timeSpan = new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(10.0),new TimeStamp(20.0));
			HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp timeStamp = new TimeStamp(15.0);

			Assert.AreEqual(20.0, LinkableRunEngine.TimeToTimeStamp(timeSpan).ModifiedJulianDay);
			Assert.AreEqual(15.0, LinkableRunEngine.TimeToTimeStamp(timeStamp).ModifiedJulianDay);
		}
 public global::OpenMI.Standard.ITimeSpan GetTimeHorizon()
 {
     //HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp startTime = new HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp(model.CurrentTime);
     //HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp endTime = new HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp(model.EndTime);
     //OpenMI times cannot handle the DateTime.MinValue and the DateTime.MaxValue so the timehorizon is simply made large (see below).
     HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp startTime = new HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp(new DateTime(1900,1,1));
     HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp endTime = new HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp(new DateTime(2100,1,1));
     HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan timeHorizon = new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(startTime, endTime);
     return timeHorizon;
 }