/// <summary>
 /// Adds the content of the source values to the target values. Assumes the two
 /// are equally big.
 /// </summary>
 /// <param name="targetValues">Target set, where values are added to</param>
 /// <param name="sourceValues">Source set, containing values to add</param>
 private static void AddSourceToTarget(ITimeSpaceValueSet <double> targetValues, ITimeSpaceValueSet sourceValues)
 {
     for (int i = 0; i < targetValues.TimesCount(); i++)
     {
         double[]       sourceTimeValues = sourceValues.GetElementValuesForTime <double>(i);
         IList <double> targetTimeValues = targetValues.Values2D[i];
         for (int j = 0; j < targetValues.ElementCount(); j++)
         {
             targetTimeValues[j] += sourceTimeValues[j];
         }
     }
 }
            public void GetValues(ITimeSpaceValueSet <double> targetSet, IBaseExchangeItem querySpecifier)
            {
                // Copy values from the adaptee to the targetSet
                ITimeSpaceValueSet sourceValues = _adaptee.GetValues(querySpecifier);

                for (int i = 0; i < targetSet.TimesCount(); i++)
                {
                    double[] sourceTimeValues = sourceValues.GetElementValuesForTime <double>(i);
                    for (int j = 0; j < targetSet.ElementCount(); j++)
                    {
                        targetSet.Values2D[i][j] += sourceTimeValues[j];
                    }
                }
            }
      public void GetValues(ITimeSpaceValueSet<double> targetSet, IBaseExchangeItem querySpecifier)
      {
        // Copy values from the adaptee to the targetSet
        ITimeSpaceValueSet sourceValues = _adaptee.GetValues(querySpecifier);

        for (int i = 0; i < targetSet.TimesCount(); i++)
        {
          double[] sourceTimeValues = sourceValues.GetElementValuesForTime<double>(i);
          for (int j = 0; j < targetSet.ElementCount(); j++)
          {
            targetSet.Values2D[i][j] += sourceTimeValues[j];
          }
        }
      }
Beispiel #4
0
        protected internal override void Update()
        {
            if (_providers.Count > 0)
            {
                ITime inputTime = GetInputTime();
                if (inputTime == null)
                {
                    return;
                }

                TimeSet.SetSingleTime(inputTime);

                // the set of values that is set to the engine
                ITimeSpaceValueSet values = null;

                // Loop through all providers
                for (int i = 0; i < _providers.Count; i++)
                {
                    ITimeSpaceOutput provider = _providers[i];

                    // Create the values variable for the first provider
                    // and add the result from the remaining providers to this
                    if (i == 0)
                    {
                        values = provider.GetValues(this);
                    }
                    else
                    {
                        ITimeSpaceValueSet addValues = provider.GetValues(this);

                        // Add the addValues to the values
                        int times = values.TimesCount();
                        int elmts = values.ElementCount();

                        if (addValues.TimesCount() != times ||
                            addValues.ElementCount() != elmts)
                        {
                            throw new Exception("Size of inputs differs, valuesets can not be added");
                        }

                        for (int j = 0; j < times; j++)
                        {
                            for (int k = 0; k < elmts; k++)
                            {
                                // would be really nice if the value set was templated (to avoid casting)
                                values.Values2D[j][k] = ((double)values.Values2D[j][k]) + ((double)addValues.Values2D[j][k]);
                            }
                        }
                    }
                }
                ITimeSpaceValueSet incomingValues = values;


                if (StoreValuesInExchangeItem)
                {
                    _values = incomingValues;
                    _linkableEngine.InputItemsToBeProcessed.Add(this);
                    HasBeenProcessed = false;
                }
                else
                {
                    // Here we do not add this input item to the list of InputItemsToBeProcessed, we process immediately
                    SetValuesToEngine(incomingValues);
                    HasBeenProcessed = true;
                }
            }
            else
            {
                throw new Exception("Trying to update an input item without a provider.");
            }
        }