public void GetValuesFromTimeSeries() { ITimeSpaceComponent timeSeries = new TimeSeriesComponent(); // initialize model timeSeries.Initialize(); ITimeSpaceOutput output = (ITimeSpaceOutput)timeSeries.Outputs[0]; // specify query times Time startTime = new Time(new DateTime(2005, 1, 1, 0, 0, 0)); double firstTriggerGetValuesTime = startTime.StampAsModifiedJulianDay; double secondTriggerGetValuesTime = firstTriggerGetValuesTime + 12.1; double thirdTriggerGetValuesTime = firstTriggerGetValuesTime + 16.7; // get values for specified query times - initial time, will return initial value queryItem1.TimeSet.SetSingleTimeStamp(firstTriggerGetValuesTime); ITimeSpaceValueSet values = output.GetValues(queryItem1); Assert.AreEqual(1, values.GetValue(0, 0), "value for first query time"); // 12.1 days from 01-01 queryItem1.TimeSet.SetSingleTimeStamp(secondTriggerGetValuesTime); values = output.GetValues(queryItem1); Assert.AreEqual(13, values.GetValue(0, 0), "value for second query time"); // 16.7 days from 01-01 queryItem1.TimeSet.SetSingleTimeStamp(thirdTriggerGetValuesTime); values = output.GetValues(queryItem1); Assert.AreEqual(17, values.GetValue(0, 0), "value for third query time"); }
public void Polygon2PointAdaptedOutputGetValues2Consumers() { Output adaptee = new Output(xyPolygon.Caption + ".Flow") { SpatialDefinition = xyPolygon, ValueDefinition = waterLevelQuantity }; ITimeSpaceInput consumerA = new Input(xyPointA.Caption + ".Flow") { SpatialDefinition = xyPointA, ValueDefinition = waterLevelQuantity }; IIdentifiable selectedAvailableAdaptedOutputId = adaptedOutputFactory.GetAvailableAdaptedOutputIds(adaptee, consumerA)[1]; ITimeSpaceAdaptedOutput adaptedOutput = (ITimeSpaceAdaptedOutput)adaptedOutputFactory.CreateAdaptedOutput(selectedAvailableAdaptedOutputId, adaptee, consumerA); adaptedOutput.AddConsumer(consumerA); IList <IList> values2D = new List <IList>(); values2D.Add(new List <double> { 0.444 }); adaptee.Values = new ValueSet(values2D); ITimeSpaceValueSet adaptedValuesA = adaptedOutput.GetValues(consumerA); Assert.AreEqual(1, ValueSet.GetTimesCount(adaptedValuesA), "adaptedValuesA.TimesCount"); Assert.AreEqual(consumerA.ElementSet().ElementCount, ValueSet.GetElementCount(adaptedValuesA), "adaptedValuesA.ElementCount"); }
public void GetValuesOnTimeExtrapolator() { // create the component // connect query and output item // take care that component becomes valid and produces initial output for connected items ITimeSpaceComponent cf = RainRrCfComponents.CreateChannelFlowInstance("CF-2"); ITimeSpaceOutput selectedOutput = RainRrCfCompositions.FindOutputItem(cf, "node-2.waterlevel"); cf.Validate(); ITimeSpaceAdaptedOutput timeExtrapolator = (ITimeSpaceAdaptedOutput)RainRrCfCompositions.ConnectItemsUsingAdaptedOutput(cf, selectedOutput, _waterlevQueryItem, RainRrCfCompositions.timeExtrapolatorId); // set query time for getting values _dischargeQueryItem.TimeSet.SetSingleTimeStamp(new DateTime(2009, 3, 28, 12, 0, 0)); ITimeSpaceValueSet values = timeExtrapolator.GetValues(_dischargeQueryItem); Assert.IsNotNull(values, "values != null"); Assert.AreEqual(4001.5, (double)values.Values2D[0][0], "value[0] from GetValues 1"); _dischargeQueryItem.TimeSet.SetSingleTimeStamp(new DateTime(2009, 3, 29, 0, 0, 0)); values = timeExtrapolator.GetValues(_dischargeQueryItem); Assert.IsNotNull(values, "values != null"); Assert.AreEqual(4002.0, (double)values.Values2D[0][0], "value[0] from GetValues 1"); _dischargeQueryItem.TimeSet.SetSingleTimeStamp(new DateTime(2009, 3, 30, 0, 0, 0)); timeExtrapolator.GetValues(_dischargeQueryItem); Assert.AreEqual(4002.0, (double)values.Values2D[0][0], "value[0] from GetValues 1"); }
/// <summary> /// Returns an array of T's from the <paramref name="values"/>, extracting /// data from the <paramref name="timeIndex"/> - in principle a typed version /// of <see cref="ITimeSpaceValueSet.GetElementValuesForTime"/> returning /// an array. /// </summary> /// <example> /// <code> /// ITimeSpaceValueSet values = ... /// double[] doubleArray = values.GetElementValuesForTime<double>(0); /// </code> /// </example> /// <param name="values">Values to retrieve</param> /// <param name="timeIndex">Index to retrieve data from.</param> /// <returns>Array of T</returns> public static T[] GetElementValuesForTime <T>(this ITimeSpaceValueSet values, int timeIndex) { IList elmtValues = values.GetElementValuesForTime(timeIndex); // Check if it is already an array T[] tArray = elmtValues as T[]; if (tArray != null) { return(tArray); } // Check if it is a generic list, and use C# build in extension method IList <T> tList = elmtValues as IList <T>; if (tList != null) { return(tList.ToArray()); } // Do a manual copy (an IList which is not an IList<T>) tArray = new T[elmtValues.Count]; for (int i = 0; i < elmtValues.Count; i++) { tArray[i] = (T)elmtValues[i]; } return(tArray); }
/// <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 static void CheckValueSizes(ITimeSpaceExchangeItem exchangeItem, ITimeSpaceValueSet valueSet) { int timesCount = 1; if (exchangeItem.TimeSet != null) { if (exchangeItem.TimeSet.Times != null) { timesCount = exchangeItem.TimeSet.Times.Count; } else { timesCount = 0; } } if (ValueSet.GetTimesCount(valueSet) != timesCount) { throw new Exception("ExchangeItem \"" + exchangeItem.Caption + "\": Wrong #times in valueSet (" + ValueSet.GetTimesCount(valueSet) + "), expected #times (" + timesCount + ")"); } int elementCount = 1; if (exchangeItem.ElementSet() != null) { elementCount = exchangeItem.ElementSet().ElementCount; } if (ValueSet.GetElementCount(valueSet) != elementCount) { throw new Exception("ExchangeItem \"" + exchangeItem.Caption + "\": Wrong #times in valueSet (" + ValueSet.GetElementCount(valueSet) + "), expected #times (" + elementCount + ")"); } }
/// <summary> /// Compared to <see cref="GetValues(IBaseExchangeItem)"/>, /// this version adds the values to the targetSet (for reuse or adding to a targetSet) /// </summary> public void GetValues(ITimeSpaceValueSet <double> targetSet, IBaseExchangeItem querySpecifier2) { ITimeSpaceExchangeItem timeSpaceQuery = querySpecifier2 as ITimeSpaceExchangeItem; if (timeSpaceQuery == null) { throw new ArgumentException("querySpecifier must be an ITimeSpaceExchangeItem - add an adaptor"); } if (!(timeSpaceQuery is ITimeSpaceInput)) { throw new OpenMIException("Get Values can only be called with an Input as argument") { Component = Adaptee.Component, Output = this }; } // Set query time to internal query item _query.TimeSet = timeSpaceQuery.TimeSet; ITimeSpaceValueSet incomingValues = _adaptee.GetValues(_query); // Transform the values from the adaptee _elementMapper.MapValues(targetSet, incomingValues); }
public ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier) { ITimeSpaceExchangeItem timeSpaceQuery = querySpecifier as ITimeSpaceExchangeItem; if (timeSpaceQuery == null) { throw new ArgumentException("Must be an ITimeSpaceExchangeItem, add an adaptor", "querySpecifier"); } if (_children.Count == 0) { return(null); // TODO: Or throw an exception? } TimeSpaceValueSet <double> resultSet = ElementMapper.CreateResultValueSet(timeSpaceQuery.TimeSet.Times.Count, this.ElementSet().ElementCount); // Get values from all adaptees/children, and add them together for (int i = 0; i < _children.Count; i++) { ITimeSpaceOutputAdder addingChild = _children[i] as ITimeSpaceOutputAdder; if (addingChild != null) { addingChild.GetValues(resultSet, querySpecifier); } else { ITimeSpaceValueSet values = _children[i].GetValues(querySpecifier); AddSourceToTarget(resultSet, values); } } return(resultSet); }
/// <summary> /// MapValues calculates for each set of timestep data /// a resulting IValueSet through multiplication of an inputValues IValueSet /// vector with the mapping maprix. /// <para> /// This version can be used if the output value set is to be reused (performance or for /// adding up) /// </para> /// </summary> /// <param name="outputValues">IValueset of mapped values, of the correct size</param> /// <param name="inputValues">IValueSet of values to be mapped.</param> public void MapValues(ref ITimeSpaceValueSet <double> outputValues, ref ITimeSpaceValueSet inputValues) { for (int i = 0; i < inputValues.Values2D.Count; i++) { _mappingMatrix.Product(outputValues.Values2D[i], inputValues.GetElementValuesForTime <double>(i)); } }
public void GetValuesExtrapolateTest() { string dataFileRoot = @"..\..\..\..\..\Examples\AsciiFileReader\Data\"; AsciiFileDataComponent ascii = new AsciiFileDataComponent(); IArgument[] arguments = new IArgument[2]; arguments[0] = Argument.Create("File1", dataFileRoot + "FlowDataId.txt", false, "Name of first file to load"); arguments[1] = Argument.Create("File2", dataFileRoot + "WaterlevelDataPoints.txt", false, "Name of second file to load"); ascii.ApplyArguments(arguments); ascii.Initialize(); Assert.AreEqual(2, ascii.Outputs.Count); ITimeSpaceOutput flowOutput = (ITimeSpaceOutput)ascii.Outputs[0]; ITimeSpaceOutput levelOutput = (ITimeSpaceOutput)ascii.Outputs[1]; Time startTime = new Time(new DateTime(2005, 1, 1, 0, 0, 0)); double startTimeMjd = startTime.StampAsModifiedJulianDay; double afterEndTimeMjd = startTimeMjd + 4; double[] expectedFlows = new double[] { 11, 15.6, 21.3 }; double[] expectedLevels = new double[] { 1, 5.6, 8.3 }; // TODO: Make it extrapolate instead! _queryItem1.TimeSet.SetSingleTimeStamp(afterEndTimeMjd); ITimeSpaceValueSet flows = flowOutput.GetValues(_queryItem1); ITimeSpaceValueSet levels = levelOutput.GetValues(_queryItem1); Assert.AreEqual(expectedFlows, flows.Values2D[0]); Assert.AreEqual(expectedLevels, levels.Values2D[0]); }
public override ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier) { // Note (SH): shouldn't a copy be made here? // Reply (ADH): In EngineWrapper2 I effectivly clone via the Values attribute // Suggest that standard should require GetValues to return // cloned IValueSet. // Maybe, more simply, IVAlueSet should implement IClonable ITimeSpaceValueSet values = base.GetValues(querySpecifier); if (values == null) { return(values); } if (!_initialisedFromArgs) { InitialiseFromArgs(); } for (int m = 0; m < values.Values2D.Count; ++m) { for (int n = 0; n < values.Values2D[m].Count; ++n) { if (values.Values2D[m][n] is double) { values.Values2D[m][n] = _a * (double)values.Values2D[m][n] + _b; } } } return(values); }
public override void SetValuesToEngine(ITimeSpaceValueSet values) { throw new OpenMIException("Internal LinkableEngine error: Values are stored in the input item," + " so SetValuesToEngine should not be called") { Component = Component, Input = this }; }
public void GetValues1A() { LinkableEngine riverModelLE = CreateRiverModel(); ITimeSpaceComponent riverModelLC = riverModelLE; // initialize model List <IArgument> riverArguments = CreateRiverModelArguments(riverModelLC); riverArguments.Add(Argument.Create("ModelID", "RiverModel", true, "argument")); riverArguments.Add(Argument.Create("TimeStepLength", 3600)); riverModelLC.Arguments.ApplyArguments(riverArguments); riverModelLC.Initialize(); // Link output and trigger with a time buffer ITimeSpaceOutput output = (ITimeSpaceOutput)riverModelLC.Outputs[2]; IAdaptedOutputFactory adaptedOutputFactory = riverModelLC.AdaptedOutputFactories[0]; IIdentifiable[] adaptedOutputIds = adaptedOutputFactory.GetAvailableAdaptedOutputIds(output, _queryItem1); ITimeSpaceAdaptedOutput adaptedOutput = (ITimeSpaceAdaptedOutput) adaptedOutputFactory.CreateAdaptedOutput(adaptedOutputIds[0], output, _queryItem1); adaptedOutput.AddConsumer(_queryItem1); riverModelLC.Validate(); Assert.IsTrue(riverModelLC.Status == LinkableComponentStatus.Valid); riverModelLC.Prepare(); Assert.IsTrue(riverModelLC.Status == LinkableComponentStatus.Updated); // specify query times double firstTriggerGetValuesTime = riverModelLE.CurrentTime.StampAsModifiedJulianDay; double secondTriggerGetValuesTime = firstTriggerGetValuesTime + 2; double thirdTriggerGetValuesTime = firstTriggerGetValuesTime + 4.3; // check initial values Assert.AreEqual(1, output.Values.Values2D[0].Count, "#values for " + output.Id); Assert.AreEqual(7.0, (double)output.Values.GetValue(0, 0), "Value[0] as property"); // get values for specified query times _queryItem1.TimeSet.SetSingleTimeStamp(firstTriggerGetValuesTime); ITimeSpaceValueSet values = adaptedOutput.GetValues(_queryItem1); Assert.AreEqual(7.0, values.GetValue(0, 0), "value for first query time"); // only runoff inflow, 10 L/s _queryItem1.TimeSet.SetSingleTimeStamp(secondTriggerGetValuesTime); values = adaptedOutput.GetValues(_queryItem1); Assert.AreEqual(35.0 / 4.0, values.GetValue(0, 0), "value for second query time"); // still only runoff inflow, 10 L/s _queryItem1.TimeSet.SetSingleTimeStamp(thirdTriggerGetValuesTime); values = adaptedOutput.GetValues(_queryItem1); Assert.AreEqual(35.0 / 4.0, values.GetValue(0, 0), "value for third query time"); riverModelLC.Finish(); }
public void SetValues(ITimeSpaceValueSet values) { // Assuming elsewhere is taken care of that the sizes are correct. // i.e. one time step and same number of elements IList elementValues = values.GetElementValuesForTime(0); for (int i = 0; i < _vector.Count; i++) { _vector[i] = (T)elementValues[i]; } }
public void SetValues(ITimeSpaceValueSet values) { double invScaleFactor = 1.0 / _scaleFactor; // Assuming elsewhere is taken care of that the sizes are correct. IList elementValues = values.GetElementValuesForTime(0); for (int i = 0; i < _vector.Count; i++) { _vector[i] = ((double)elementValues[i]) * invScaleFactor; } }
private void AddInflow(ITimeSpaceValueSet values) { // values are numberOfNodes-1 long (input for each branch. // Put inflow at "upstream" node/storage IList elementValues = values.GetElementValuesForTime(0); for (int i = 0; i < _inflowStorage.Length - 1; i++) { _inflowStorage[i] += ((double)elementValues[i]) * _timeStepLengthInSeconds; } }
private static double SumTimeStep(ITimeSpaceValueSet values, int timestepIndex) { IList <double> vals = (IList <double>)values.GetElementValuesForTime(timestepIndex); double sum = 0; foreach (double d in vals) { sum += d; } return(sum); }
/// <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 static void CheckTimeIndex(ITimeSpaceValueSet valueSet, int timeIndex) { if (timeIndex < 0) { throw new Exception("Invalid timeindex (" + timeIndex + "), negative index not allowed"); } if (timeIndex >= GetTimesCount(valueSet)) { throw new Exception("Invalid timeindex (" + timeIndex + "), only " + GetTimesCount(valueSet) + " times available"); } }
public static void CheckElementIndex(ITimeSpaceValueSet valueSet, int elementIndex) { if (elementIndex < 0) { throw new Exception("Invalid elementindex (" + elementIndex + "), negative index nog allowed"); } if (elementIndex >= GetElementCount(valueSet)) { throw new Exception("Invalid elementindex (" + elementIndex + "), only " + GetElementCount(valueSet) + " elements available"); } }
private void FillLocalValues() { if (_Values == null) { ITimeSpaceValueSet temp = _openMIOutputItem.Values; int nVals = temp.Values2D[0].Count; _Values = new double[nVals]; for (int i = 0; i < temp.Values2D[0].Count; i++) { _Values[i] = (double)temp.GetValue(0, i); } } }
public override void SetEngineValues(EngineInputItem inputItem, ITimeSpaceValueSet values) { int elementCount = ValueSet.GetElementCount(values); double[] avalues = new double[elementCount]; for (int i = 0; i < elementCount; i++) { avalues[i] = (double)values.GetValue(0, i); } ScalarSet scalarSet = new ScalarSet(avalues); _engineApiAccess.SetValues(inputItem.ValueDefinition.Caption, inputItem.SpatialDefinition.Caption, scalarSet); }
public override ITimeSpaceValueSet GetEngineValues(ExchangeItem exchangeItem) { if (exchangeItem is EngineInputItem) { // Input item, provide current internal values for this item // NOT supported by this computational core throw new ArgumentException("Unknown Exchange Item Id: \"" + exchangeItem.Id + "\"", "exchangeItem"); } ITimeSpaceValueSet values = GetOutputValuesFromComputationalCore(exchangeItem); return(values); }
public List <double> ApxyLinearly(ITimeSpaceValueSet data, double[] apxValue) { int size = data.Values2D[0].Count; double incrementV = apxValue[0] / size; List <double> dvalues = new List <double>(); for (int i = 0; i < size; i++) { dvalues.Add((double)data.GetValue(0, i) + incrementV * i); } return(dvalues); }
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]; } } }
private void CheckBuffer() { if (_buffer == null) { _buffer = new SmartBuffer(); ITimeSpaceValueSet outputItemValues = _adaptee.Values; IList <ITime> outputItemTimes = _adaptee.TimeSet.Times; for (int t = 0; t < outputItemTimes.Count; t++) { ITime time = outputItemTimes[t]; _buffer.AddValues(time, outputItemValues.GetElementValuesForTime(0)); } } }
protected virtual void UpdateLoopVersion(ICollection <EngineOutputItem> requiredOutputItems) { Status = LinkableComponentStatus.Updating; foreach (ITimeSpaceInput inputItem in Inputs) { if (inputItem.Provider != null) { if (!ExchangeItemHelper.OutputAndInputFit((ITimeSpaceOutput)inputItem.Provider, inputItem)) { Status = LinkableComponentStatus.WaitingForData; return; } } } // All data available, get all values // TODO JGr: Check if we can reuse the ProcessActiveInputItems(); foreach (ITimeSpaceInput inputItem in Inputs) { if (inputItem.Provider != null) { // get and store input ITimeSpaceValueSet incomingValues = (ITimeSpaceValueSet)inputItem.Provider.Values; inputItem.Values = incomingValues; } } // compute and produce output PerformTimestep(requiredOutputItems); ProcessActiveOutputItems(); // Assuming the time step was successfull, then we can update the time horizon // start time of all input items, to indicate that we are never going to ask // data before this time. Done here in order to support redoing of time steps // to the horizon start time should only be updated on a successfull performTimestep foreach (EngineInputItem inputItem in ActiveInputItems) { // Assuming this input item is never (ever again) going to ask // for data before the current inputTime inputItem.TimeSet.SetTimeHorizonStart(inputItem.TimeSet.Times[0]); } // indicate that Update is done Status = CurrentTime.StampAsModifiedJulianDay >= EndTime.StampAsModifiedJulianDay ? LinkableComponentStatus.Done : LinkableComponentStatus.Updated; }
private void LogIncomingValues(ITimeSpaceInput inputItem, ITimeSpaceValueSet providedValues) { string message = Caption + " " + inputItem.Caption + " values:"; foreach (IList valuesArray in providedValues.Values2D) { foreach (object value in valuesArray) { message += " " + value; } } message += " <= " + inputItem.Provider.Caption + " from " + inputItem.Provider.Component.Caption + ")"; log.Info(message); }
private ValueSetArray <double> Convert(ITimeSpaceValueSet values) { ValueSetArray <double> res = new ValueSetArray <double>(); for (int n = 0; n < values.Values2D.Count; ++n) { double[] elmtValues = new double[values.Values2D[n].Count]; res.Values2DArray.Add(elmtValues); for (int m = 0; m < values.Values2D[n].Count; m++) { elmtValues[m] = _a * (double)values.Values2D[n][m] + _b; } } return(res); }
public SWMMTimeSpaceValueSet(ITimeSpaceValueSet timeSpaceValueSet) { values = new ListIList <T>(); for (int i = 0; i < timeSpaceValueSet.Values2D.Count; i++) { IList <T> temp = new List <T>(); IList value = timeSpaceValueSet.Values2D[i]; for (int j = 0; j < value.Count; j++) { temp.Add((T)value[j]); } values.Add(temp); } }
public static int GetElementCount(ITimeSpaceValueSet valueSet) { return (valueSet.Values2D.Count > 0) ? valueSet.Values2D[0].Count : 0; }
protected override void SetValuesTimeImplementation(ITimeSpaceValueSet values) { Contract.Requires(false, "Orphaned Input, does not implement get values calls"); }
protected override void SetValuesTimeImplementation(ITimeSpaceValueSet values) { _valuesExplicitOverride = values; SendItemChangedEvent(string.Format("InputSpaceTime({0}).Values.set, explicit override {1}", Caption, values == null ? "deactivated" : "activated")); }
public static int GetTimesCount(ITimeSpaceValueSet valueSet) { return valueSet.Values2D.Count; }
protected override void SetValuesTimeImplementation(ITimeSpaceValueSet values) { throw new NotImplementedException("Not meant to be used at runtime, composition building tool only"); }
/// <summary> /// MapValues calculates for each set of timestep data /// a resulting IValueSet through multiplication of an inputValues IValueSet /// vector with the mapping maprix. /// <para> /// This version can be used if the output value set is to be reused (performance or for /// adding up) /// </para> /// </summary> /// <param name="outputValues">IValueset of mapped values, of the correct size</param> /// <param name="inputValues">IValueSet of values to be mapped.</param> public void MapValues(ITimeSpaceValueSet<double> outputValues, ITimeSpaceValueSet inputValues) { for (int i = 0; i < inputValues.Values2D.Count; i++) { _mappingMatrix.Product(outputValues.Values2D[i], inputValues.GetElementValuesForTime<double>(i)); } }
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]; } } }
/// <summary> /// MapValues calculates for each set of timestep data /// a resulting IValueSet through multiplication of an inputValues IValueSet /// vector with the mapping maprix. /// </summary> /// <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 TimeSpaceValueSet<double> MapValues(ITimeSpaceValueSet inputValues) { if (!_isInitialised) { throw new Exception( "ElementMapper objects needs to be initialised before the MapValue method can be used"); } if (!ValueSet.GetElementCount(inputValues).Equals(_numberOfColumns)) { throw new Exception("Dimension mismatch between inputValues and mapping matrix"); } // Make a time-space value set of the correct size TimeSpaceValueSet<double> result = CreateResultValueSet(inputValues.TimesCount(), _numberOfRows); MapValues(result, inputValues); return result; }