...
Example
...
1,
...
using
...
a
...
separate
...
input
...
items
...
for
...
x,
...
y,
...
z,
...
t
...
and
...
1
...
output
...
item
...
for f
Wiki Markup |
---|
f
{graphviz}
digraph flow {
rankdir=LR;
node [shape = circle, len=1.00, color=lightblue2, style=filled]; x y z t f;
node [shape = rectangle, color=lightblue2, style=filled]; function;
x -> function;
y -> function;
z -> function;
t -> function;
function -> f;
}
{graphviz} |
Code Block | ||||
---|---|---|---|---|
| ||||
{code:java} [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); } {code} h4. Example |
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
Wiki Markup |
---|
f
{graphviz}
digraph flow {
rankdir=LR;
node [shape = circle, len=1.00]; src;
node [shape = circle, len=1.00, color=lightblue2, style=filled]; xyzt f;
node [shape = rectangle, color=lightblue2, style=filled]; function;
src -> xyzt-> function -> f;
}
{graphviz} |
Code Block | ||||
---|---|---|---|---|
| ||||
{code:java} [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]); } {code} h4. Example |
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.
Wiki Markup |
---|
{graphviz}
digraph flow {
rankdir=LR;
node [shape = circle, len=1.00]; xyzt;
node [shape = circle, len=1.00, color=lightblue2, style=filled]; f;
node [shape = rectangle , color=lightblue2, style=filled]; function;
function -> f -> xyzt;
}
{graphviz} |
Code Block | ||||
---|---|---|---|---|
| ||||
{code:java}
/// <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
Code Block | ||||
---|---|---|---|---|
| ||||
{code} h4. Helper method to fill element set and time into exchange item {code:java} // 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))); } } } {code} |