Example 1, using a separate input items for x, y, z, t and 1 output item for f
Unknown macro: {graphviz}
digraph flow {
rankdir=LR;
node [shape = circle, len=1.00]; x y z t f;
node [shape = rectangle]; function;
x -> function;
y -> function;
z -> function;
t -> function;
function -> f;
}
[Test] public void AnalyticalFunction() { AnalyticalFunctionComponent function = new AnalyticalFunctionComponent(); function.Initialize(null); IInputItem x = function.InputItems[0]; IInputItem y = function.InputItems[1]; IInputItem z = function.InputItems[2]; IInputItem t = function.InputItems[3]; IOutputItem f = function.OutputItems[0]; Assert.AreEqual(1, x.Values.Count); Assert.AreEqual(1, y.Values.Count); Assert.AreEqual(1, z.Values.Count); Assert.AreEqual(1, t.Values.Count); Assert.AreEqual(1, f.Values.Count); x.Values[0] = 1.0; y.Values[0] = 0.0; z.Values[0] = 10.0; t.Values[0] = new System.TimeSpan(20, 10, 0, 0); function.Update(); // computes f(x,y,z,t) = sin(x + y) + z * t log.DebugFormat("Computed analytical function value f({0}, {1}, {2}, {3}) = {4}", x.Values[0], y.Values[0], z.Values[0], t.Values[0], f.Values[0]); Assert.AreEqual(17640000.841470987d, (double)f.Values[0], 0.00001); }
Example 2, using an input items containing element set with 1 point for x, y, z and one time for t which is connected as input of the function and computing values in the output item for f
Unknown macro: {graphviz}
digraph flow {
rankdir=LR;
node [shape = circle, len=1.00]; src xyzt f;
node [shape = rectangle]; function;
src -> xyzt -> function -> f;
}
[Test] public void AnalyticalFunction2() { AnalyticalFunctionComponent2 function = new AnalyticalFunctionComponent2(); function.Initialize(null); Assert.AreEqual(1, function.InputItems.Count); Assert.AreEqual(1, function.OutputItems.Count); OutputItem source = new OutputItem(); FillItem(source, 0.1, 0.1, 0.5, DateTime.Now); source.AddConsumer(function.InputItems[0]); Assert.AreEqual(default(double), function.OutputItems[0].Values[0]); function.Update(); Assert.AreNotEqual(default(double), function.OutputItems[0].Values[0]); }
Example 3, using input item which has element set with 1 point for x, y, z and one time for t. Then it is connected to the 1st output item of the function. When values in the function are computed - they are passed to that input item.
Unknown macro: {graphviz}
digraph flow {
rankdir=LR;
node [shape = circle, len=1.00]; xyzt f;
node [shape = rectangle]; function;
function -> f -> xyzt;
}
/// <summary> /// This is the way (conceptually) how it worked in v1. /// </summary> [Test] public void AnalyticalFunction3() { AnalyticalFunctionComponent3 function = new AnalyticalFunctionComponent3(); function.Initialize(null); Assert.AreEqual(0, function.InputItems.Count); Assert.AreEqual(1, function.OutputItems.Count); // create an element set InputItem requiredInput = new InputItem(); FillItem(requiredInput, 0.1, 0.1, 0.5, DateTime.Now); function.OutputItems[0].Consumers.Add(requiredInput); Assert.AreEqual(default(double), function.OutputItems[0].Values[0]); // compute function.Update(); Assert.AreNotEqual(default(double), requiredInput.Values[0], "value in the input item must be changed"); }
Helper method to fill element set and time into exchange item
// TODO: we have to make construction of such thing simpler private void FillItem(ExchangeItem item, double x, double y, double z, DateTime t) { ElementSet elementSet = new ElementSet("1 point element set"); elementSet.ElementType = ElementType.XYZPoint; Element point = new Element(string.Empty); point.AddVertex(new Coordinate(x, y, z)); elementSet.AddElement(point); // set required elements and times item.ElementSet = elementSet; item.Temporal = new Temporal(); item.Temporal.Times.Add(new TimeStamp(CalendarConverter.Gregorian2ModifiedJulian(t))); } } }