/// <summary> /// Updates the input item, retrieves values from the provider and /// sets the values to the engine. /// <para> /// Is called just before <see cref="LinkableEngine.PerformTimestep"/> /// </para> /// <para> /// The input time is retrieved from <see cref="GetInputTime"/>. Updating /// this input can be "disabled" by letting <see cref="GetInputTime"/> /// return null. /// </para> /// </summary> protected internal virtual void Update() { if (_provider != null) { ITime inputTime = GetInputTime(); if (inputTime == null) { return; // can not update input item if time is null } TimeSet.SetSingleTime(inputTime); ITimeSpaceValueSet incomingValues = _provider.GetValues(this); 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."); } }
public override ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier) { ITimeSpaceExchangeItem item = (ITimeSpaceExchangeItem)querySpecifier; TimeSet.SetSingleTime(item.TimeSet.Times[0]); int count = item.ElementSet().ElementCount; double[] vals = new double[count]; for (int i = 0; i < count; i++) { vals[i] = ConstOutput; } ValueSetArray<double> valueset = new ValueSetArray<double>(vals); return valueset; }
/// <summary> /// Updates the values in the exchange item and the times in the time set. /// <para> /// This method is called just after the <see cref="LinkableEngine.PerformTimestep"/> /// of the <see cref="LinkableEngine"/>. If it returns true, all its output adaptors /// are refreshed. /// </para> /// <para> /// If a particular output item is not updated by a performed time step, /// override this method and let it return false when not updated. /// </para> /// </summary> /// <returns>true if output item was updated, false if not</returns> public virtual bool Update() { ITime time = GetOutputTime(); if (time == null) { return(false); } TimeSet.SetSingleTime(time); if (_storeValuesInExchangeItem) { _values = GetValueFromEngine(); } else { // no action needed, engine update call has fill exchange item } return(true); }
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."); } }