public void GetYCoordinate() { Assert.AreEqual(2.0, elementSet.GetYCoordinate(0, 0)); Assert.AreEqual(3.0, elementSet.GetYCoordinate(0, 1)); Assert.AreEqual(5.0, elementSet.GetYCoordinate(0, 2)); Assert.AreEqual(7.0, elementSet.GetYCoordinate(1, 0)); Assert.AreEqual(10.0, elementSet.GetYCoordinate(1, 1)); Assert.AreEqual(13.0, elementSet.GetYCoordinate(1, 2)); }
public override void AddLink(ILink link) { base.AddLink(link); //save the link // //get the id of the target element set string id = link.TargetElementSet.ID; //get the corresponding input and output exchange item index int inIndex = 0; int outIndex = 0; for (int i = 0; i <= _inputExchangeItems.Count - 1; i++) { if (_inputExchangeItems[i].ElementSet.ID == id) { inIndex = i; break; } } for (int i = 0; i <= _outputExchangeItems.Count - 1; i++) { if (_outputExchangeItems[i].ElementSet.ID == id) { outIndex = i; break; } } //update input and output exchange item elementsets and quantities //Unit u = new Unit(); //u.Description = link.SourceQuantity.Unit.Description; //u.ID = link.SourceQuantity.Unit.ID; Quantity q = new Quantity(); q = (Quantity)link.SourceQuantity; //q.Description = link.SourceQuantity.Description; //q.ID = link.SourceQuantity.ID; //q.ValueType = link.SourceQuantity.ValueType; //q.Unit = link.SourceQuantity.Unit; ElementSet eset = new ElementSet(); //eset.Description = link.SourceElementSet.Description; //eset.ID = link.SourceElementSet.ID; //eset.ElementType = link.SourceElementSet.ElementType; eset = (ElementSet)link.SourceElementSet; //HACK: Right now this assumes there is only one outputexchangeitem! //HACK: Also assumes that the output elementset will contain the same elements as the element set of the first link //check to see if the output exchange item has been defined yet if (_outputExchangeItems[0].ElementSet.GetElementID(0) == "Empty") { OutputExchangeItem Output = (OutputExchangeItem)_outputExchangeItems[0]; //Quantity OutputQ = (Quantity)Output.Quantity; ElementSet OutputE = (ElementSet)Output.ElementSet; OutputE.ElementType = eset.ElementType; //int min = 100000; //int index = 0; //for (int o = 0; o <= _inputExchangeItems.Count - 1; o++) // if (_inputExchangeItems[o].ElementSet != OutputE) // if (_inputExchangeItems[o].ElementSet.ElementCount < min) // { // min = _inputExchangeItems[o].ElementSet.ElementCount; // index = o; // } Element e = OutputE.GetElement(0); e.ID = eset.GetElementID(0); Vertex v = new Vertex(); e.Vertices[0].x = eset.GetXCoordinate(0, 0); e.Vertices[0].y = eset.GetYCoordinate(0, 0); //e.AddVertex(v); for (int o = 1; o <= eset.Elements.Length - 1; o++) { e = new Element(eset.GetElementID(o)); v = new Vertex(); v.x = eset.GetXCoordinate(o, 0); v.y = eset.GetYCoordinate(o, 0); e.AddVertex(v); OutputE.AddElement(e); } Output.ElementSet = OutputE; //_outputExchangeItems.Add(output); } //generate an output exchange item based on the input its getting OutputExchangeItem output = new OutputExchangeItem(); output.Quantity = q; output.ElementSet = eset; if (!_outputExchangeItems.Contains(output)) { eset.Description = "Time Matched: " + output.Quantity.ID; output.ElementSet = eset; _outputExchangeItems.Add(output); } //create a link to reflect the info we're getting from the source component Link l = new Link(); l.ID = link.ID; l.SourceComponent = link.SourceComponent; l.SourceElementSet = link.SourceElementSet; l.SourceQuantity = link.SourceQuantity; l.TargetComponent = link.TargetComponent; l.TargetElementSet = eset; l.TargetQuantity = q; //get the earliest time (this will determine a start time based on source component, unless one is provided in the omi) if (this.start == -999) { if (_currentTime < l.SourceComponent.TimeHorizon.Start.ModifiedJulianDay) { _currentTime = l.SourceComponent.TimeHorizon.Start.ModifiedJulianDay; } } //add updated link instead of the placeholder one _links.Add(link.ID, l); //Subscribe to events System.Collections.Hashtable hashtable = new Hashtable(); if (link.SourceComponent != this) { ////get the exchange item info //string value = link.SourceQuantity.ID + "," + link.SourceElementSet.ID; //hashtable.Add("OutputExchangeItem", value); string value = link.TargetQuantity.ID + "," + link.TargetElementSet.ID; hashtable.Add("InputExchangeItem", value); //add the time horizon info hashtable.Add("TimeHorizon", link.SourceComponent.TimeHorizon); //add the link info hashtable.Add("Link", link); //pass this info to the IRunEngine, via Intitialize _engineApiAccess.Initialize(hashtable); //set the time horizon for the LinkableRunEngine Oatc.OpenMI.Sdk.Backbone.TimeSpan timehorizon = (Oatc.OpenMI.Sdk.Backbone.TimeSpan)link.SourceComponent.TimeHorizon; if (timehorizon.Start.ModifiedJulianDay > start) { start = timehorizon.Start.ModifiedJulianDay; } if (timehorizon.End.ModifiedJulianDay < end) { end = timehorizon.End.ModifiedJulianDay; } } else { //get the exchange item info string value = link.SourceQuantity.ID + "," + link.SourceElementSet.ID; hashtable.Add("OutputExchangeItem", value); //add the link info hashtable.Add("Link", link); //pass this info to the IRunEngine, via Intitialize _engineApiAccess.Initialize(hashtable); //lc = link.TargetComponent; } }