Exemplo n.º 1
0
		public void Init()
		{
			Vector vector1 = new Vector(1.0,2.0,3.0);
			Vector vector2 = new Vector(4.0,5.0,6.0);
			Vector vector3 = new Vector(7.0,8.0,9.0);

			Vector[] data = {vector1,vector2,vector3};

			vectorSet = new VectorSet(data);
		}
Exemplo n.º 2
0
		public void Equals()
		{
			Vector vector1 = new Vector(1.0,2.0,3.0);
			Vector vector2 = new Vector(4.0,5.0,6.0);
			Vector vector3 = new Vector(7.0,8.0,9.0);

			Vector[] data = {vector1,vector2,vector3};

			VectorSet vectorSet2 = new VectorSet(data);

			Assert.IsTrue(vectorSet.Equals(vectorSet2));
		}
Exemplo n.º 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 VectorSet)
            {
                VectorSet sourceSet = (VectorSet)obj;
                if (sourceSet.Count != Count)
                {
                    return(false);
                }
                for (int i = 0; i < Count; i++)
                {
                    if (!sourceSet.GetVector(i).Equals(GetVector(i)))
                    {
                        return(false);
                    }
                }
                return(true);
            }

            return(base.Equals(obj));
        }
Exemplo n.º 4
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++)
     {
       outValues[i].XComponent = 0;
       outValues[i].YComponent = 0;
       outValues[i].ZComponent = 0;
       for (int n = 0; n < _numberOfColumns; n++)
       {
         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");
   }
 }
Exemplo n.º 5
0
		public void Constructor()
		{
			VectorSet vectorSet2 = new VectorSet(vectorSet);
			Assert.AreEqual(vectorSet,vectorSet2);
		}
Exemplo n.º 6
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);
      }
		}
Exemplo n.º 7
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);
      }
		}
Exemplo n.º 8
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;
			}
		}
Exemplo n.º 9
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);
      }
		}
Exemplo n.º 10
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);
      }
		}
Exemplo n.º 11
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);

				Backbone.TimeSpan newTimeSpan = new 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();
			}
		}
Exemplo n.º 12
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 virtual IValueSet MapValues(IValueSet inputValues)
        {
            if (!isInitialised)
            {
                throw new Exception(
                    "ElementMapper objects needs to be initialised before the MapValue method can be used");
            }

            if (!inputValues.Count.Equals(ColumnsCount))
            {
                throw new Exception("Dimension mismatch between inputValues and mapping matrix");
            }

            if (inputValues is IScalarSet)
            {
                return MappingMatrix.Product((IScalarSet)inputValues);
            }
            else if (inputValues is IVectorSet)
            {
                Vector[] outValues = new Vector[RowsCount];
                //--- Multiply the Values vector with the MappingMatrix ---
                for (int i = 0; i < RowsCount; i++)
                {
                    for (int n = 0; n < ColumnsCount; 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 Exception("Invalid datatype used for inputValues parameter. MapValues failed");
            }
        }