예제 #1
0
		public void Equals()
		{
			double[] values={1.0,2.0,3.0};
			ScalarSet scalarSet2 = new ScalarSet(values);
			Assert.IsTrue(scalarSet.Equals(scalarSet2));
			scalarSet2.data[1] = 2.5;
			Assert.IsFalse(scalarSet.Equals(scalarSet2));
		}
예제 #2
0
	  /// <summary>
	  /// Retrieves data from the providing LinkableComponent as defined 
	  /// in the Link and sets this data in the engine
	  /// </summary>
	  public virtual void UpdateInput()
	  { 
		  ITime inputTime = this._engine.GetInputTime(link.TargetQuantity.ID, link.TargetElementSet.ID);

		  if (inputTime != null) 
		  {
              SendEvent(EventType.TargetBeforeGetValuesCall, this.link.TargetComponent);
              IScalarSet sourceValueSet = (IScalarSet)link.SourceComponent.GetValues(inputTime, link.ID);

              //The input values set is copied in ordet to avoid the risk that it is changed be the provider.

              double targetMissValDef = this._engine.GetMissingValueDefinition();
              ScalarSet targetValueSet = new ScalarSet(sourceValueSet);

              for (int i = 0; i < sourceValueSet.Count; i++)
              {
                  if (!sourceValueSet.IsValid(i))
                  {
                      targetValueSet.data[i] = targetMissValDef;
                  }
              }

              targetValueSet.MissingValueDefinition = targetMissValDef;
              targetValueSet.CompareDoublesEpsilon = targetMissValDef / 1.0e+10;
              if (link.TargetComponent is LinkableRunEngine && ((LinkableRunEngine)link.TargetComponent).SendExtendedEventInfo)
              {
                  string msg = " Quantity: " + link.TargetQuantity.ID + "  Recieved values:";
                  if (sourceValueSet is IScalarSet)
                  {
                      for (int i = 0; i < ((IScalarSet)sourceValueSet).Count; i++)
                      {
                          msg += (((IScalarSet)sourceValueSet).GetScalar(i).ToString() + ", ");
                      }
                  }
                  SendEvent(EventType.TargetAfterGetValuesReturn, this.link.TargetComponent, msg);
              }
              else
              {
                  SendEvent(EventType.TargetAfterGetValuesReturn, this.link.TargetComponent);
              }
              this.Engine.SetValues(link.TargetQuantity.ID, link.TargetElementSet.ID, targetValueSet);
          }
	  }
예제 #3
0
        ///<summary>
        /// Check if the current instance equals another instance of this class.
        ///</summary>
        ///<param name="obj">The instance to compare the current instance with.</param>
        ///<returns><code>true</code> if the instances are the same instance or have the same content.</returns>
        public override bool Equals(Object obj)
        {
            if (obj is ScalarSet)
            {
                ScalarSet sourceSet = (ScalarSet)obj;
                if (sourceSet.Count != Count)
                {
                    return(false);
                }
                for (int i = 0; i < Count; i++)
                {
                    if (sourceSet.GetScalar(i) != GetScalar(i))
                    {
                        return(false);
                    }
                }
                return(true);
            }

            return(base.Equals(obj));
        }
예제 #4
0
		public void AddValues_01()
		{
			try
			{
				SmartBuffer smartBuffer = new SmartBuffer();
				smartBuffer.DoExtendedDataVerification = true;
				
				ScalarSet scalarSet = new ScalarSet(new double[3] { 0, 1, 2 });
				TimeStamp timeStamp = new TimeStamp(1);

				smartBuffer.AddValues(timeStamp, scalarSet);

				timeStamp.ModifiedJulianDay = 2;
				scalarSet.data[0] = 10;
				scalarSet.data[1] = 11;
				scalarSet.data[2] = 12;

				smartBuffer.AddValues(timeStamp, scalarSet);

				smartBuffer.AddValues(new TimeStamp(3), new ScalarSet(new double[3] { 110, 111, 112 }));
				smartBuffer.AddValues(new TimeStamp(4), new ScalarSet(new double[3] { 1110, 1111, 1112 }));

				Assert.AreEqual(0,((IScalarSet) smartBuffer.GetValuesAt(0)).GetScalar(0));
				Assert.AreEqual(1,((IScalarSet) smartBuffer.GetValuesAt(0)).GetScalar(1));
				Assert.AreEqual(2,((IScalarSet) smartBuffer.GetValuesAt(0)).GetScalar(2));

				Assert.AreEqual(10,((IScalarSet) smartBuffer.GetValuesAt(1)).GetScalar(0));
				Assert.AreEqual(11,((IScalarSet) smartBuffer.GetValuesAt(1)).GetScalar(1));
				Assert.AreEqual(12,((IScalarSet) smartBuffer.GetValuesAt(1)).GetScalar(2));

				Assert.AreEqual(110,((IScalarSet) smartBuffer.GetValuesAt(2)).GetScalar(0));
				Assert.AreEqual(111,((IScalarSet) smartBuffer.GetValuesAt(2)).GetScalar(1));
				Assert.AreEqual(112,((IScalarSet) smartBuffer.GetValuesAt(2)).GetScalar(2));

				Assert.AreEqual(1110,((IScalarSet) smartBuffer.GetValuesAt(3)).GetScalar(0));
				Assert.AreEqual(1111,((IScalarSet) smartBuffer.GetValuesAt(3)).GetScalar(1));
				Assert.AreEqual(1112,((IScalarSet) smartBuffer.GetValuesAt(3)).GetScalar(2));

				Assert.AreEqual(4,smartBuffer.TimesCount);
				Assert.AreEqual(3,smartBuffer.ValuesCount);
			}
			catch (System.Exception e)
			{
                //WriteException(e);
				throw (e);
			}
		}
예제 #5
0
		public void Constructor()
		{
			ScalarSet scalarSet2 = new ScalarSet(scalarSet);
			Assert.AreEqual(scalarSet,scalarSet2);
		}
예제 #6
0
		public void Init()
		{
			double[] values = {1.0,2.0,3.0};
			scalarSet = new ScalarSet(values);
		}
예제 #7
0
		/// <summary>
		/// Returns the ValueSet that corresponds to requestTime. The ValueSet may be found by 
		/// interpolation, extrapolation and/or aggregation.
		/// </summary>
		/// <param name="requestedTime">time for which the value is requested</param>
		/// <returns>valueSet that corresponds to requestTime</returns>
		public IValueSet GetValues(ITime requestedTime)
		{
			if (_doExtendedDataVerification)
			{
				CheckTime(requestedTime);
				CheckBuffer();
			}
			IValueSet returnValueSet;
			if (_values.Count == 0)
			{
				returnValueSet = new ScalarSet(); 
			}
			else if (_values.Count == 1)
			{
				returnValueSet = MakeCopyOfValues();
			}
			else if (requestedTime is ITimeStamp && _times[0] is ITimeStamp)
			{
				returnValueSet = MapFromTimeStampsToTimeStamp((ITimeStamp) requestedTime);
			}
			else if (requestedTime is ITimeSpan && _times[0] is ITimeSpan)
			{
				returnValueSet = MapFromTimeSpansToTimeSpan((ITimeSpan) requestedTime);
			}
			else if (requestedTime is ITimeSpan && _times[0] is ITimeStamp)
			{
				returnValueSet = MapFromTimeStampsToTimeSpan((ITimeSpan) requestedTime);
			}
			else if (requestedTime is ITimeStamp && _times[0] is ITimeSpan)
			{
				returnValueSet = MapFromTimeSpansToTimeStamp((ITimeStamp) requestedTime);
			}
			else
			{
				throw new Exception("Requested TimeMapping not available in SmartWrapper Class");
			}
			return returnValueSet;
		}
예제 #8
0
 /// <summary>
 /// MapValues calculates a IValueSet through multiplication of an inputValues IValueSet
 /// vector or matrix (ScalarSet or VectorSet) on to the mapping maprix. IScalarSets maps
 /// to IScalarSets and IVectorSets maps to IVectorSets.
 /// </summary>
 /// 
 /// <remarks>
 /// Mapvalues is called every time a georeferenced link is evaluated.
 /// </remarks>
 /// 
 /// <param name="inputValues">IValueSet of values to be mapped.</param>
 /// 
 /// <returns>
 /// A IValueSet found by mapping of the inputValues on to the toElementSet.
 /// </returns>
 public IValueSet MapValues(IValueSet inputValues)
 {
   if (!_isInitialised)
   {
     throw new System.Exception("ElementMapper objects needs to be initialised before the MapValue method can be used");
   }
   if (!inputValues.Count.Equals(_numberOfColumns))
   {
     throw new System.Exception("Dimension mismatch between inputValues and mapping matrix");
   }
   if (inputValues is IScalarSet)
   {
     double[] outValues = new double[_numberOfRows];
     //--- Multiply the Values vector with the MappingMatrix ---
     for (int i = 0; i < _numberOfRows; i++)
     {
       outValues[i] = 0;
       for (int n = 0; n < _numberOfColumns; n++)
       {
         outValues[i] += _mappingMatrix[i,n] * ((IScalarSet) inputValues).GetScalar(n); //(remove)inValues[n];
       }
     }
     ScalarSet outputValues = new ScalarSet(outValues);
     return outputValues;
   }
   else if (inputValues is IVectorSet)
   {
     Vector[] outValues = new Vector[_numberOfRows];
     //--- Multiply the Values vector with the MappingMatrix ---
     for (int i = 0; i < _numberOfRows; i++)
     {            
       for (int n = 0; n < _numberOfColumns; n++)
       {
         outValues[i] = new Vector(); // Need this as Initialisation only valid for value types!
       
         outValues[i].XComponent += _mappingMatrix[i,n] * ((IVectorSet) inputValues).GetVector(n).XComponent;
         outValues[i].YComponent += _mappingMatrix[i,n] * ((IVectorSet) inputValues).GetVector(n).YComponent;
         outValues[i].ZComponent += _mappingMatrix[i,n] * ((IVectorSet) inputValues).GetVector(n).ZComponent;
       }
     }
     VectorSet outputValues = new VectorSet(outValues);
     return outputValues;
   }
   else
   {
     throw new System.Exception("Invalid datatype used for inputValues parameter. MapValues failed");
   }
 }
예제 #9
0
		/// <summary>
		/// Implementation of the same method in
		/// OpenMI.Standard.ILInkableComponent
		/// </summary>
		/// <param name="time">Time (ITimeSpan or ITimeStamp) for which values are requested</param>
		/// <param name="LinkID">LinkID associated to the requested values</param>
		/// <returns>The values</returns>
		public override IValueSet GetValues(ITime time, string LinkID)
		{
			try
			{
				CheckTimeArgumentInGetvaluesMethod(time);
				SendSourceAfterGetValuesCallEvent(time, LinkID);
				IValueSet engineResult = new ScalarSet();
 
                int outputLinkIndex = -999;
                for (int i = 0; i < _smartOutputLinks.Count; i++)
                {
                    if ( ((SmartOutputLink) _smartOutputLinks[i]).link.ID == LinkID)
                    {
                        outputLinkIndex = i;
                        break;
                    }
                }
			
				if (_isBusy==false)
				{
					//while(IsLater(time,_engineApiAccess.GetCurrentTime()))
                    while(IsLater(time, ((SmartOutputLink) _smartOutputLinks[outputLinkIndex]).GetLastBufferedTime()))
					{
						_isBusy=true;

						//Update input links
                        foreach(SmartInputLink smartInputLink in _smartInputLinks)
                        {
                            smartInputLink.UpdateInput();
                        }
						_isBusy=false; 

						//Perform Timestep
						if(_engineApiAccess.PerformTimeStep()) 
						{
							//Update buffer with engine values, Time is timestamp
                            foreach (SmartOutputLink smartOutputLink in _smartOutputLinks)
                            {
                                smartOutputLink.UpdateBuffer();
                            }

							SendEvent(EventType.DataChanged);
						}
					}
				}

                engineResult = ((SmartOutputLink)_smartOutputLinks[outputLinkIndex]).GetValue(time);

                if (sendExtendedEventInfo)
                {
                    string msg = " Quantity: " + ((SmartOutputLink)_smartOutputLinks[outputLinkIndex]).link.SourceQuantity.ID + "  Returned values:";
                    if (engineResult is IScalarSet)
                    {
                        for (int i = 0; i < ((IScalarSet)engineResult).Count; i++)
                        {
                            msg += (((IScalarSet)engineResult).GetScalar(i).ToString() + ", ");
                        }
                    }
                    SendEvent(EventType.SourceBeforeGetValuesReturn, msg);
                }
                else
                {
                    SendEvent(EventType.SourceBeforeGetValuesReturn);
                }
				return engineResult;
		
			}
			catch (System.Exception e)
			{
				string message = "Exception in LinkableComponent. ComponentID: ";
				message += this.ComponentID;
				throw new System.Exception(message,e);
			}
		}
예제 #10
0
    /// <summary>
    /// A ValueSet corresponding to a TimeStamp is calculated using interpolation or
    /// extrapolation in corresponding lists of ValueSets and TimeStamps.
    /// </summary>
		/// <param name="requestedTimeStamp">TimeStamp for which the values are requested</param>
    /// <returns>ValueSet that corresponds to the requested time stamp</returns>
		private IValueSet MapFromTimeStampsToTimeStamp(ITimeStamp requestedTimeStamp)
		{
      try
      {
        int	     m  = ((IValueSet)_values[0]).Count;
        double[][] xr = new double[m][];                             // Values to return
        double   tr = requestedTimeStamp.ModifiedJulianDay;		     // Requested TimeStamp

        int nk; // number of components (scalars has only 1 and vectors has 3 (3 axis))

        if (_values[0] is IVectorSet)
        {
          nk = 3;
        }
        else
        {
          nk = 1;
        }

        for (int i = 0; i < m; i++)
        {
          xr[i] = new double[nk];
        }

        //---------------------------------------------------------------------------
        //  Buffered TimesStamps: |          >tb0<   >tb1<   >tb2<  >tbN<
        //  Requested TimeStamp:  |    >tr<
        //                         -----------------------------------------> t
        // --------------------------------------------------------------------------
        if (tr <= ((ITimeStamp)_times[0]).ModifiedJulianDay )
        {
          double tb0 = ((ITimeStamp) _times[0]).ModifiedJulianDay;
          double tb1 = ((ITimeStamp) _times[1]).ModifiedJulianDay;

          for (int k = 1; k <= nk; k++)
          {
            for (int i = 0; i < m ; i++) //For each Vector in buffered VectorSet [0]
            {
              double sbi0 = Support.GetVal((IValueSet)_values[0], i, k);
              double sbi1       = Support.GetVal((IValueSet)_values[1], i, k);
              xr[i][k-1] = ((sbi0 - sbi1)/(tb0 - tb1))*(tr - tb0) * (1 - _relaxationFactor) + sbi0;
            }
          }
        }

          //---------------------------------------------------------------------------
          //  Buffered TimesStamps: |    >tb0<   >tb1<   >tb2<  >tbN_2<  >tbN_1<
          //  Requested TimeStamp:  |                                             >tr<
          //                         ---------------------------------------------------> t
          // --------------------------------------------------------------------------
        else if (tr > ((ITimeStamp) _times[_times.Count - 1]).ModifiedJulianDay)
        {
          double tbN_2 = ((ITimeStamp) _times[_times.Count - 2]).ModifiedJulianDay;
          double tbN_1 = ((ITimeStamp) _times[_times.Count - 1]).ModifiedJulianDay;

          for (int k = 1; k <= nk; k++)
          {
            for (int i = 0; i < m; i++) //For each Vector in buffered VectorSet [N-1]
            {
              double sbiN_2     = Support.GetVal((IValueSet)_values[_times.Count-2], i, k);
              double sbiN_1     = Support.GetVal((IValueSet)_values[_times.Count-1], i, k);

              xr[i][k-1] = ((sbiN_1 - sbiN_2)/(tbN_1 - tbN_2))*(tr - tbN_1)*(1 - _relaxationFactor) + sbiN_1;
            }
          }
        }

          //---------------------------------------------------------------------------
          //  Availeble TimesStamps: |    >tb0<   >tb1<  >tbna<       >tnb<   >tbN_1<  >tbN_2<
          //  Requested TimeStamp:   |                          >tr<
          //                         -------------------------------------------------> t
          // --------------------------------------------------------------------------
        else
        {
          for (int n = _times.Count - 2; n >= 0 ; n--)
          {
            double tbn1 = ((ITimeStamp) _times[n]).ModifiedJulianDay;
            double tbn2 = ((ITimeStamp) _times[n+1]).ModifiedJulianDay;

            if ( tbn1 <= tr && tr <= tbn2)
            {
              for (int k = 1; k <= nk; k++)
              {
                for (int i = 0; i < m; i++) //For each Vector in buffered VectorSet [n]
                {
					IValueSet valueSet_n = (IValueSet)_values[n];
					double sbin1 = Support.GetVal(valueSet_n, i, k);

					IValueSet valueSet_nPlus1 = (IValueSet)_values[n+1];
                	double sbin2 = Support.GetVal(valueSet_nPlus1, i, k);;

					if ( valueSet_n.IsValid(i) && valueSet_nPlus1.IsValid(i))
					{
						xr[i][k-1]     = ((sbin2 - sbin1)/(tbn2 - tbn1)) * (tr - tbn1) + sbin1;
					}
					else if ( valueSet_n.IsValid(i) ) 
					{
						xr[i][k-1] = sbin1;
					}
					else if ( valueSet_nPlus1.IsValid(i) ) 
					{
						xr[i][k-1] = sbin2;
					}
					else
					{
						// both invalid, set to one of the (==invalid) values
						xr[i][k-1] = sbin1;
					}
                }
              }
              break;
            }
          }
        }
        //----------------------------------------------------------------------------------------------
        if (_values[0] is IVectorSet)
        {
          Vector [] vectors = new Vector[m]; 

          for (int i = 0; i < m; i++)
          {
            vectors[i] = new Vector(xr[i][0],xr[i][1],xr[i][2]);
          }

          VectorSet vectorSet = new VectorSet(vectors);

          return vectorSet;
        }
        else
        {
          double[] xx = new double[m];

          for (int i = 0; i < m; i++)
          {
            xx[i] = xr[i][0];
          }
				
          ScalarSet scalarSet = new ScalarSet(xx);

          return scalarSet;
        }
      }
      catch (Exception e)
      {
        throw new Exception("MapFromTimeStampsToTimeStamp Failed",e);
      }
		}
예제 #11
0
    /// <summary>
    /// A ValueSet corresponding to a TimeSpan is calculated using interpolation or
    /// extrapolation in corresponding lists of ValueSets and TimeSpans.
    /// </summary>
    /// <param name="requestedTimeStamp">Time for which the ValueSet is requested</param>
    /// <returns>ValueSet that corresponds to requestedTime</returns>
		private IValueSet MapFromTimeSpansToTimeStamp(ITimeStamp requestedTimeStamp)
		{
      try
      {
        int	     m  = ((IValueSet)_values[0]).Count;
        double[][] xr = new double[m][];                             // Values to return
        double   tr = requestedTimeStamp.ModifiedJulianDay; 	     // Requested TimeStamp

        int nk; // number of components (scalars has only 1 and vectors has 3 (3 axis))

        if (_values[0] is IVectorSet)
        {
          nk = 3;
        }
        else
        {
          nk = 1;
        }

        for (int i = 0; i < m; i++)
        {
          xr[i] = new double[nk];
        }

        //---------------------------------------------------------------------------
        //  Buffered TimesSpans:  |          >tbb0<  ..........  >tbbN<
        //  Requested TimeStamp:  |    >tr<
        //                         -----------------------------------------> t
        // --------------------------------------------------------------------------
        if (tr <= ((ITimeSpan)_times[0]).Start.ModifiedJulianDay )
        {
          double tbb0 = ((ITimeSpan) _times[0]).Start.ModifiedJulianDay;
          double tbb1 = ((ITimeSpan) _times[1]).Start.ModifiedJulianDay;
				
          for (int k = 1; k <= nk; k++)
          {
            for (int i = 0; i < m ; i++) //For each Vector in buffered VectorSet [0]
            {
              double sbi0       = Support.GetVal((IValueSet)_values[0], i, k);
              double sbi1       = Support.GetVal((IValueSet)_values[1], i, k);
              xr[i][k-1] = ((sbi0 - sbi1)/(tbb0 - tbb1))*(tr - tbb0) * (1 - _relaxationFactor) + sbi0;
            }
          }
        }

          //---------------------------------------------------------------------------
          //  Buffered TimesSpans:  |    >tbb0<   .................  >tbbN_1<
          //  Requested TimeStamp:  |                                             >tr<
          //                         ---------------------------------------------------> t
          // --------------------------------------------------------------------------
        else if (tr >= ((ITimeSpan) _times[_times.Count - 1]).End.ModifiedJulianDay)
        {
          double tbeN_2 = ((ITimeSpan) _times[_times.Count - 2]).End.ModifiedJulianDay;
          double tbeN_1 = ((ITimeSpan) _times[_times.Count - 1]).End.ModifiedJulianDay;

          for (int k = 1; k <= nk; k++)
          {
            for (int i = 0; i < m; i++) //For each Vector in buffered VectorSet [N-1]
            {
              double sbiN_2 = Support.GetVal((IValueSet)_values[_times.Count-2], i, k);
              double sbiN_1 = Support.GetVal((IValueSet)_values[_times.Count-1], i, k);

              xr[i][k-1] = ((sbiN_1 - sbiN_2)/(tbeN_1 - tbeN_2))*(tr - tbeN_1)*(1 - _relaxationFactor) + sbiN_1;
            }
          }
        }

          //---------------------------------------------------------------------------
          //  Availeble TimesSpans:  |    >tbb0<   ......................  >tbbN_1<
          //  Requested TimeStamp:   |                          >tr<
          //                         -------------------------------------------------> t
          // --------------------------------------------------------------------------
        else
        {
          for (int n = _times.Count - 1; n >= 0 ; n--)
          {
            double tbbn = ((ITimeSpan) _times[n]).Start.ModifiedJulianDay;
            double tben = ((ITimeSpan) _times[n]).End.ModifiedJulianDay;

            if ( tbbn <= tr && tr < tben)
            {
              for (int k = 1; k <= nk; k++)
              {
                for (int i = 0; i < m; i++) //For each Vector in buffered VectorSet [n]
                {
                  xr[i][k-1]     = Support.GetVal((IValueSet)_values[n], i, k);
                }
              }
              break;
            }
          }
        }

        //----------------------------------------------------------------------------------------------
	
		
        if (_values[0] is IVectorSet)
        {
          Vector [] vectors = new Vector[m]; 

          for (int i = 0; i < m; i++)
          {
            vectors[i] = new Vector(xr[i][0],xr[i][1],xr[i][2]);
          }

          VectorSet vectorSet = new VectorSet(vectors);

          return vectorSet;
        }
        else
        {
          double[] xx = new double[m];

          for (int i = 0; i < m; i++)
          {
            xx[i] = xr[i][0];
          }
				
          ScalarSet scalarSet = new ScalarSet(xx);

          return scalarSet;
        }
      }
      catch (Exception e)
      {
        throw new Exception("MapFromTimeSpansToTimeStamp Failed",e);
      }
		}
예제 #12
0
		/// <summary>
		/// Makes a copy of the first ValueSet in the list of valueSets
		/// </summary>
		/// <returns></returns>
		private IValueSet MakeCopyOfValues()
		{

			if (_values[0] is IScalarSet)
			{
				int NumberOfScalarsInEachScalarSet = ((IScalarSet) _values[0]).Count;
				double[] x = new Double[NumberOfScalarsInEachScalarSet];
				for (int i = 0; i < NumberOfScalarsInEachScalarSet; i++)
				{
					x[i] = ((IScalarSet) _values[0]).GetScalar(i);
				}
				ScalarSet scalarSet = new ScalarSet(x);
				return scalarSet;
			}

			else // _values[0] is VectorSet
			{
				
				int NumberOfVectorsInEachVectorSet = ((IVectorSet) _values[0]).Count;

				Vector[] vectors = new Vector[NumberOfVectorsInEachVectorSet];

				for (int i = 0; i < NumberOfVectorsInEachVectorSet; i++)
				{
          Vector vector;         
          double x = ((IVectorSet)_values[0]).GetVector(i).XComponent;
					double y = ((IVectorSet) _values[0]).GetVector(i).YComponent;
					double z = ((IVectorSet) _values[0]).GetVector(i).ZComponent;
					vector = new Vector(x, y, z);
					vectors[i] = vector;

				}
				VectorSet vectorSet = new VectorSet(vectors);
							
				return vectorSet;
			}
		}
예제 #13
0
		/// <summary>
		/// A ValueSet corresponding to a TimeSpan is calculated using interpolation or
		/// extrapolation in corresponding lists of ValueSets and TimeStamps.
		/// </summary>
		/// <param name="requestedTime">Time for which the ValueSet is requested</param>
		/// <returns>ValueSet that corresponds to requestedTime</returns>
		private IValueSet MapFromTimeStampsToTimeSpan(ITimeSpan requestedTime)
		{
			try
      {
        int	       m  = ((IValueSet)_values[0]).Count;
			//int        N  = _times.Count;								   	      // Number of time steps in buffer
			double[][] xr = new double[m][];                                      // Values to return
			double trb    = requestedTime.Start.ModifiedJulianDay;   // Begin time in requester time interval
			double tre    = requestedTime.End.ModifiedJulianDay;    // End time in requester time interval

			int nk; // number of components (scalars has only 1 and vectors has 3 (3 axis))

			if (_values[0] is IVectorSet)
			{
				nk = 3;
			}
			else
			{
				nk = 1;
			}
				
			for (int i = 0; i < m; i++)
			{
				xr[i] = new double[nk];
			}

			for (int i = 0; i < m; i++)
			{
				for (int k = 0; k < nk; k++)
				{
					xr[i][k] = 0;
				}
			}


			for (int n = 0; n < _times.Count-1; n++)
			{
				double tbn   = ((ITimeStamp) _times[n]).ModifiedJulianDay;
				double tbnp1 = ((ITimeStamp) _times[n+1]).ModifiedJulianDay;
				

				//---------------------------------------------------------------------------
				//    B:           <-------------------------->
				//    R:        <------------------------------------->
				// --------------------------------------------------------------------------
				if (trb <= tbn && tre >= tbnp1 )
				{
					for (int k = 1; k <= nk; k++)
					{
						for (int i = 0; i < m; i++) // for all values coorsponding to the same time interval
						{
							double sbin   = Support.GetVal((IValueSet)_values[n], i, k);
							double sbinp1 = Support.GetVal((IValueSet)_values[n+1], i, k);
							xr[i][k-1] += 0.5 * (sbin + sbinp1) * (tbnp1 - tbn)/(tre - trb);
						}
					}
				}

				//---------------------------------------------------------------------------
				//           Times[i] Interval:        t1|-----------------------|t2
				//           Requested Interval:          rt1|--------------|rt2
				// --------------------------------------------------------------------------
				else if (tbn <= trb && tre <= tbnp1) //cover all
				{
					for (int k = 1; k <= nk; k++)
					{
						for (int i = 0; i < m; i++) // for all values coorsponding to the same time interval
						{
							double sbin   = Support.GetVal((IValueSet)_values[n], i, k);
							double sbinp1 = Support.GetVal((IValueSet)_values[n+1], i, k);
							xr[i][k-1] += sbin + ((sbinp1 - sbin)/(tbnp1 - tbn))*((tre + trb)/2 - tbn);
						}
					}
				}

				//---------------------------------------------------------------------------
				//           Times[i] Interval:       t1|-----------------|t2
				//           Requested Interval:                 rt1|--------------|rt2
				// --------------------------------------------------------------------------
				else if (tbn < trb && trb < tbnp1 && tre > tbnp1)
				{
					for (int k = 1; k <= nk; k++)
					{
						for (int i = 0; i < m; i++) // for all values coorsponding to the same time interval
						{
							double sbin   = Support.GetVal((IValueSet)_values[n], i, k);
							double sbinp1 = Support.GetVal((IValueSet)_values[n+1], i, k);
							xr[i][k-1] +=  (sbinp1 - (sbinp1 - sbin)/(tbnp1 - tbn)*((tbnp1 - trb)/2))* (tbnp1 - trb)/(tre - trb);
						}
					}
				}

				//---------------------------------------------------------------------------
				//           Times[i] Interval:             t1|-----------------|t2
				//           Requested Interval:      rt1|--------------|rt2
				// --------------------------------------------------------------------------
				else if (trb < tbn && tre > tbn && tre < tbnp1)
				{
					for (int k = 1; k <= nk; k++)
					{
						for (int i = 0; i < m; i++) // for all values coorsponding to the same time interval
						{
							double sbin   = Support.GetVal((IValueSet)_values[n], i, k);
							double sbinp1 = Support.GetVal((IValueSet)_values[n+1], i, k);
							xr[i][k-1] += (sbin + (sbinp1 - sbin)/(tbnp1 - tbn)*((tre - tbn)/2)) * (tre - tbn)/(tre - trb);
						}
					}
				}
			}
			//--------------------------------------------------------------------------
			//              |--------|---------|--------| B
			//        |----------------|                  R
			//---------------------------------------------------------------------------
			double tb0   = ((ITimeStamp) _times[0]).ModifiedJulianDay;
			//double tb1   = ((ITimeStamp) _times[0]).ModifiedJulianDay;
			double tb1   = ((ITimeStamp) _times[1]).ModifiedJulianDay; // line above was corrected to this Gregersen Sep 15 2004
			double tbN_1 = ((ITimeStamp) _times[_times.Count-1]).ModifiedJulianDay;
			double tbN_2 = ((ITimeStamp) _times[_times.Count-2]).ModifiedJulianDay;
			
			if (trb < tb0 && tre > tb0)
			{
				for (int k = 1; k <= nk; k++)
				{
					for (int i = 0; i < m; i++)
					{
						double sbi0 = Support.GetVal((IValueSet)_values[0], i, k);
						double sbi1 = Support.GetVal((IValueSet)_values[1], i, k);
						xr[i][k-1] += ((tb0 - trb)/(tre - trb)) * (sbi0 - (1 - _relaxationFactor) * 0.5 * ((tb0 - trb)*(sbi1 - sbi0)/(tb1 - tb0)));
					}
				}
			}
			//-------------------------------------------------------------------------------------
			//              |--------|---------|--------| B
			//                                    |----------------|                  R
			//-------------------------------------------------------------------------------------
			if (tre > tbN_1 && trb < tbN_1)
			{
				for (int k = 1; k <= nk; k++)
				{
					for (int i = 0; i < m; i++)
					{
						double sbiN_1 = Support.GetVal((IValueSet)_values[_times.Count-1], i, k);
						double sbiN_2 = Support.GetVal((IValueSet)_values[_times.Count-2], i, k);
						xr[i][k-1] += ((tre - tbN_1)/(tre - trb)) * (sbiN_1 + (1 - _relaxationFactor) * 0.5 * ((tre - tbN_1)*(sbiN_1 - sbiN_2)/(tbN_1 - tbN_2)));
					}
				}
			}
			//-------------------------------------------------------------------------------------
			//              |--------|---------|--------| B
			//                                              |----------------|   R
			//-------------------------------------------------------------------------------------
			if (trb >= tbN_1)
			{
				
				for (int k = 1; k <= nk; k++)
				{
					for (int i = 0; i < m; i++)
					{
						double sbiN_1 = Support.GetVal((IValueSet)_values[_times.Count-1], i, k);
						double sbiN_2 = Support.GetVal((IValueSet)_values[_times.Count-2], i, k);
					
						xr[i][k-1] = sbiN_1 + (1 - _relaxationFactor) * ((sbiN_1 - sbiN_2)/(tbN_1 - tbN_2)) * ( 0.5 * (trb + tre) - tbN_1);
					}
				}
			}
			//-------------------------------------------------------------------------------------
			//                           |--------|---------|--------| B
			//        |----------------|   R
			//-------------------------------------------------------------------------------------
			if (tre <= tb0)
			{
				for (int k = 1; k <= nk; k++)
				{
					for (int i = 0; i < m; i++)
					{
						double sbi0 = Support.GetVal((IValueSet)_values[0], i, k);
						double sbi1 = Support.GetVal((IValueSet)_values[1], i, k);
						xr[i][k-1] = sbi0 - (1 - _relaxationFactor) * ((sbi1 - sbi0)/(tb1- tb0))*(tb0 - 0.5 * (trb + tre));
					}
				}
			}
			//-------------------------------------------------------------------------------------
        if (_values[0] is IVectorSet)
        {
          Vector [] vectors = new Vector[m]; 

          for (int i = 0; i < m; i++)
          {
            vectors[i] = new Vector(xr[i][0],xr[i][1],xr[i][2]);
          }

          VectorSet vectorSet = new VectorSet(vectors);

          return vectorSet;
        }
        else
        {
          double[] xx = new double[m];

          for (int i = 0; i < m; i++)
          {
            xx[i] = xr[i][0];
          }
				
          ScalarSet scalarSet = new ScalarSet(xx);

          return scalarSet;
        }
      }
      catch (Exception e)
      {
        throw new Exception("MapFromTimeStampsToTimeSpan Failed",e);
      }
		}
예제 #14
0
		/// <summary>
		/// A ValueSet corresponding to a TimeSpan is calculated using interpolation or
		/// extrapolation in corresponding lists of ValueSets and TimeSpans.
		/// </summary>
		/// <param name="requestedTime">Time for which the ValueSet is requested</param>
		/// <returns>ValueSet that corresponds to requestedTime</returns>
		private IValueSet MapFromTimeSpansToTimeSpan(ITimeSpan requestedTime)

		{
      try
      {
        int	       m  = ((IValueSet)_values[0]).Count;
        double[][] xr = new double[m][];                                       // Values to return
        double trb    = requestedTime.Start.ModifiedJulianDay;   // Begin time in requester time interval
        double tre    = requestedTime.End.ModifiedJulianDay;     // End time in requester time interval

        int nk; // number of components (scalars has only 1 and vectors has 3 (3 axis))

        if (_values[0] is IVectorSet)
        {
          nk = 3;
        }
        else
        {
          nk = 1;
        }
				
        for (int i = 0; i < m; i++)
        {
          xr[i] = new double[nk];
        }

        for (int i = 0; i < m; i++)
        {
          for (int k = 0; k < nk; k++)
          {
            xr[i][k] = 0;
          }
        }

        for (int n = 0; n < _times.Count; n++)
        {
          double tbbn = ((ITimeSpan) _times[n]).Start.ModifiedJulianDay;
          double tben = ((ITimeSpan) _times[n]).End.ModifiedJulianDay;

          //---------------------------------------------------------------------------
          //    B:           <-------------------------->
          //    R:        <------------------------------------->
          // --------------------------------------------------------------------------
          if (trb <= tbbn && tre >= tben ) //Buffered TimeSpan fully included in requested TimeSpan
          {
            for (int k = 1; k <= nk; k++)
            {
              for (int i = 0; i < m; i++) // for all values coorsponding to the same time interval
              {
                double sbin = Support.GetVal((IValueSet)_values[n], i, k);
                xr[i][k-1] += sbin * (tben - tbbn)/(tre - trb);
              }
            }
          }

            //---------------------------------------------------------------------------
            //           Times[i] Interval:        t1|-----------------------|t2
            //           Requested Interval:          rt1|--------------|rt2
            // --------------------------------------------------------------------------
          else if (tbbn <= trb && tre <= tben) //cover all
          {
            for (int k = 1; k <= nk; k++)
            {
              for (int i = 0; i < m; i++) // for all values coorsponding to the same time interval
              {
                xr[i][k-1] += Support.GetVal((IValueSet)_values[n], i, k);
              }
            }
          }

            //---------------------------------------------------------------------------
            //           Times[i] Interval:       t1|-----------------|t2
            //           Requested Interval:                 rt1|--------------|rt2
            // --------------------------------------------------------------------------
          else if (tbbn < trb && trb < tben && tre > tben)
          {
            for (int k = 1; k <= nk; k++)
            {
              for (int i = 0; i < m; i++) // for all values coorsponding to the same time interval
              {
                double sbin = Support.GetVal((IValueSet)_values[n], i, k);
                xr[i][k-1] += sbin * (tben - trb)/(tre - trb);
              }
            }
          }

            //---------------------------------------------------------------------------
            //           Times[i] Interval:             t1|-----------------|t2
            //           Requested Interval:      rt1|--------------|rt2
            // --------------------------------------------------------------------------
          else if (trb < tbbn && tre > tbbn && tre < tben)
          {
            for (int k = 1; k <= nk; k++)
            {
              for (int i = 0; i < m; i++) // for all values coorsponding to the same time interval
              {
                double sbin = Support.GetVal((IValueSet)_values[n], i, k);
                xr[i][k-1] += sbin * (tre - tbbn)/(tre - trb);
              }
            }
          }
        }

        //--------------------------------------------------------------------------
        //              |--------|---------|--------| B
        //        |----------------|                  R
        //---------------------------------------------------------------------------
        double tbb0 = ((ITimeSpan) _times[0]).Start.ModifiedJulianDay;
        double tbe0 = ((ITimeSpan) _times[0]).End.ModifiedJulianDay;
        //double tbb1 = ((ITimeSpan) _times[1]).Start.ModifiedJulianDay;
        double tbe1 = ((ITimeSpan) _times[1]).End.ModifiedJulianDay;

        if (trb < tbb0 && tre > tbb0)
        {
          for (int k = 1; k <= nk; k++)
          {
            for (int i = 0; i < m; i++)
            {
              double sbi0 = Support.GetVal((IValueSet)_values[0], i, k);
              double sbi1 = Support.GetVal((IValueSet)_values[1], i, k); 
              xr[i][k-1] += ((tbb0 - trb)/(tre - trb)) * (sbi0 - (1 - _relaxationFactor) * ((tbb0 - trb)*(sbi1 - sbi0)/(tbe1 - tbe0)));
            }
          }
        }

        //-------------------------------------------------------------------------------------
        //              |--------|---------|--------| B
        //                                    |----------------|                  R
        //-------------------------------------------------------------------------------------

        double tbeN_1 = ((ITimeSpan) _times[_times.Count-1]).End.ModifiedJulianDay;
        double tbbN_2 = ((ITimeSpan) _times[_times.Count-2]).Start.ModifiedJulianDay;

        if (tre > tbeN_1 && trb < tbeN_1)
        {
          //double tbeN_2 = ((ITimeSpan) _times[_times.Count-2]).End.ModifiedJulianDay;
          double tbbN_1 = ((ITimeSpan) _times[_times.Count-1]).Start.ModifiedJulianDay;

          for (int k = 1; k <= nk; k++)
          {
            for (int i = 0; i < m; i++)
            {
              double sbiN_1 = Support.GetVal((IValueSet)_values[_times.Count-1], i, k);
              double sbiN_2 = Support.GetVal((IValueSet)_values[_times.Count-2], i,k);
              xr[i][k-1] += ((tre - tbeN_1)/(tre - trb)) * (sbiN_1 + (1 - _relaxationFactor) * ((tre - tbbN_1)*(sbiN_1 - sbiN_2)/(tbeN_1 - tbbN_2)));
            }
          }
        }
        //-------------------------------------------------------------------------------------
        //              |--------|---------|--------| B
        //                                              |----------------|   R
        //-------------------------------------------------------------------------------------

        if (trb >= tbeN_1)
        {
          double tbeN_2 = ((ITimeSpan) _times[_times.Count-2]).End.ModifiedJulianDay;
          //double tbbN_1 = ((ITimeSpan) _times[_times.Count-1]).Start.ModifiedJulianDay;
			
          for (int k = 1; k <= nk; k++)
          {
            for (int i = 0; i < m; i++)
            {
              double sbiN_1 = Support.GetVal((IValueSet)_values[_times.Count-1], i, k);
              double sbiN_2 = Support.GetVal((IValueSet)_values[_times.Count-2], i, k);
              xr[i][k-1] = sbiN_1 + (1 - _relaxationFactor) * ((sbiN_1 - sbiN_2)/(tbeN_1 - tbbN_2)) * (trb + tre - tbeN_1 - tbeN_2);
            }
          }
        }

        //-------------------------------------------------------------------------------------
        //                           |--------|---------|--------| B
        //        |----------------|   R
        //-------------------------------------------------------------------------------------

        if (tre <= tbb0)
        {
          for (int k = 1; k <= nk; k++)
          {
            for (int i = 0; i < m; i++)
            {
              double sbi0 = Support.GetVal((IValueSet)_values[0], i, k);
              double sbi1 = Support.GetVal((IValueSet)_values[1], i, k);
              xr[i][k-1] = sbi0 - (1 - _relaxationFactor) * ((sbi1 - sbi0)/(tbe1- tbb0))*(tbe0 + tbb0 - tre - trb);
            }
          }
        }

        //-------------------------------------------------------------------------------------
        if (_values[0] is IVectorSet)
        {
          Vector [] vectors = new Vector[m]; 

          for (int i = 0; i < m; i++)
          {
            vectors[i] = new Vector(xr[i][0],xr[i][1],xr[i][2]);
          }

          VectorSet vectorSet = new VectorSet(vectors);

          return vectorSet;
        }
        else
        {
          double[] xx = new double[m];

          for (int i = 0; i < m; i++)
          {
            xx[i] = xr[i][0];
          }
				
          ScalarSet scalarSet = new ScalarSet(xx);

          return scalarSet;
        }
      }
      catch (Exception e)
      {
        throw new Exception("MapFromTimeSpansToTimeSpan Failed",e);
      }
		}
예제 #15
0
        [TestMethod()] // testing the Initialise method
		public void MapValues()
		{
			ElementSet gridElementSet = new ElementSet("RegularGrid","RegularGrid",ElementType.XYPolygon, new SpatialReference("ref"));
			ElementSet fourPointsElementSet = new ElementSet("4 points","4P",ElementType.XYPoint,new SpatialReference("DummyID")); 

			Vertex v_0_20  = new Vertex(0,20,0);
			Vertex v_0_10  = new Vertex(0,10,0);
			Vertex v_0_0   = new Vertex(0, 0,0);
			Vertex v_0_15  = new Vertex(0,15,0);
			Vertex v_5_15  = new Vertex(5,15,0);
			Vertex v_10_20 = new Vertex(10,20,0);
			Vertex v_10_15 = new Vertex(10,15,0);
			Vertex v_10_10 = new Vertex(10,10,0);
			Vertex v_10_0  = new Vertex(10, 0,0);
			Vertex v_15_15 = new Vertex(15,15,0);
			Vertex v_15_5  = new Vertex(15,5,0);
			Vertex v_20_20 = new Vertex(20,20,0);
			Vertex v_20_10 = new Vertex(20,10,0);

			Element square1 = new Element("square1");
			Element square2 = new Element("square2");
			Element square3 = new Element("square3");

			square1.AddVertex(v_0_20);
			square1.AddVertex(v_0_10);
			square1.AddVertex(v_10_10);
			square1.AddVertex(v_10_20);

			square2.AddVertex(v_10_20);
			square2.AddVertex(v_10_10);
			square2.AddVertex(v_20_10);
			square2.AddVertex(v_20_20);

			square3.AddVertex(v_0_10);
			square3.AddVertex(v_0_0);
			square3.AddVertex(v_10_0);
			square3.AddVertex(v_10_10);

			gridElementSet.AddElement(square1);
			gridElementSet.AddElement(square2);
			gridElementSet.AddElement(square3);

			Element point_5_15  = new Element("point 5, 15");
			Element point_10_15 = new Element("point 10, 15");
			Element point_15_15 = new Element("point 15, 15");
			Element point_15_5  = new Element("point 15, 5");

			point_5_15.AddVertex(v_5_15);
			point_10_15.AddVertex(v_10_15);
			point_15_15.AddVertex(v_15_15);
			point_15_5.AddVertex(v_15_5);

			fourPointsElementSet.AddElement(point_5_15);
			fourPointsElementSet.AddElement(point_10_15);
			fourPointsElementSet.AddElement(point_15_15);
			fourPointsElementSet.AddElement(point_15_5);
			ScalarSet fourPointsScalarSet = new ScalarSet();
			ScalarSet gridScalarSet = new ScalarSet();      
      
			ElementMapper elementMapper = new ElementMapper();
      
			// point to polygon  
      
			ArrayList methodDescriptions = elementMapper.GetAvailableMethods(fourPointsElementSet.ElementType, gridElementSet.ElementType);
			elementMapper.Initialise(methodDescriptions[0].ToString(), fourPointsElementSet, gridElementSet);
			fourPointsScalarSet.data = new double[4] { 0, 10, 20, 30 };
			gridScalarSet = (ScalarSet)elementMapper.MapValues(fourPointsScalarSet);
			Assert.AreEqual(5, gridScalarSet.data[0]);
			Assert.AreEqual(20, gridScalarSet.data[1]);
			Assert.AreEqual(0, gridScalarSet.data[2]);
			// polygon to point
			methodDescriptions = elementMapper.GetAvailableMethods(gridElementSet.ElementType, fourPointsElementSet.ElementType);
			elementMapper.Initialise(methodDescriptions[0].ToString(), gridElementSet, fourPointsElementSet);
			fourPointsScalarSet = (ScalarSet)elementMapper.MapValues(gridScalarSet);
			Assert.AreEqual(5, fourPointsScalarSet.data[0]);
			Assert.AreEqual(5, fourPointsScalarSet.data[1]);
			Assert.AreEqual(20, fourPointsScalarSet.data[2]);
			Assert.AreEqual(0, fourPointsScalarSet.data[3]);
		}
 public global::OpenMI.Standard.IValueSet GetValues(string QuantityID, string ElementSetID)
 {
     ScalarSet scalarSet = new ScalarSet(nx * ny, 0);
     for (int i = 0; i < nx * ny; i++)
     {
         scalarSet.data[i] = ((TimestampSeries)groundwaterHeads.Items[i]).Items[currentTimestep].Value;
     }
     return scalarSet;
 }
예제 #17
0
		public void Run(ITimeStamp time)
		{
			//IScalarSet scalarSet = new ScalarSet();
			
			ScalarSet scalarSet = new ScalarSet((IScalarSet) _link.SourceComponent.GetValues(time,_link.ID));
			_earliestInputTime.ModifiedJulianDay = time.ModifiedJulianDay;
			_resultsBuffer.AddValues(time,scalarSet);
		}
예제 #18
0
		public IValueSet GetValues(string QuantityID, string ElementSetID)
		{
			char[] separator = new char[]{':'};
			double[] x;
			
			if(ElementSetID.Split(separator)[0] == "Branch")
			{
				 x = new double[1];
				int branchIndex = Convert.ToInt32(ElementSetID.Split(separator)[1]);
				if (QuantityID == "Flow")
				{
					x[0] = _flow[branchIndex];
				}
				else if (QuantityID == "Leakage")
				{
					x[0] = _leakage[branchIndex];
				}
				else 
				{
					throw new Exception("Quanity ID not recognized in GetValues method");
				}

			}
			else if(ElementSetID.Split(separator)[0] == "WholeRiver")
			{
				x = new double[_leakage.Length];
				for (int i = 0; i < _leakage.Length; i++)
				{
					x[i] = _leakage[i];
				}
			}
			else 
			{
				throw new Exception("Failed to recognize ElementSetID in method GetValues");
			}

			ScalarSet scalarSet = new ScalarSet(x);
			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;
            }
        }
예제 #20
0
		/// <summary>
		///	Add corresponding values for time and values to the SmartBuffer.
		/// </summary>
		/// <param name="time"> Description of the time parameter</param>
		/// <param name="valueSet">Description of the values parameter</param>
		/// <remarks>
		/// The AddValues method will internally make a copy of the added times and values. The reason for
		/// doing this is that the times and values arguments are references, and the correspondign values 
		/// could be changed by the owner of the classes
		/// </remarks>
		public void AddValues(ITime time, IValueSet valueSet)
		{
			if (time is ITimeStamp)
			{
				_times.Add(new TimeStamp( ((ITimeStamp) time).ModifiedJulianDay ));
			}
			else if(time is ITimeSpan)
			{
				TimeStamp newStartTime = new TimeStamp(((ITimeSpan) time).Start.ModifiedJulianDay);
				TimeStamp newEndTime = new TimeStamp(((ITimeSpan) time).End.ModifiedJulianDay);

                global::HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan newTimeSpan = new global::HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(newStartTime, newEndTime);
				_times.Add(newTimeSpan);
			}
			else
			{
				throw new Exception("Invalid datatype used for time argument in method AddValues");
			}

			if (valueSet is IScalarSet)
			{
				double[] x = new double[(valueSet).Count];
				for (int i = 0; i < x.Length; i++)
				{
					x[i] = ((IScalarSet) valueSet).GetScalar(i);
				}

				ScalarSet newScalarSet = new ScalarSet(x);

                if (valueSet is ScalarSet)
                {
                    newScalarSet.MissingValueDefinition =
                        ((ScalarSet)valueSet).MissingValueDefinition;
                    newScalarSet.CompareDoublesEpsilon =
                        ((ScalarSet)valueSet).CompareDoublesEpsilon;
                }

                _values.Add(newScalarSet);
			}
			else if (valueSet is IVectorSet)
			{			
				Vector[] vectors = new Vector[valueSet.Count];
				for (int i = 0; i < vectors.Length; i++)
				{
					vectors[i] = new Vector(((IVectorSet) valueSet).GetVector(i).XComponent, ((IVectorSet) valueSet).GetVector(i).YComponent, ((IVectorSet) valueSet).GetVector(i).ZComponent);
				}
			  VectorSet newVectorSet = new VectorSet(vectors);
				_values.Add(newVectorSet);
			}
			else
			{
				throw new Exception("Invalid datatype used for values argument in method AddValues");
			}
	
			if (_doExtendedDataVerification)
			{
				CheckBuffer();
			}
		}