public override ITimeSpaceValueSet GetValues(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
                      };
            }


            /// Using a _query item in the
            ///     _adaptee.GetValues(_query)
            /// instead of
            ///     _adaptee.GetValues(this)
            ///
            /// Reason:
            /// The latter would need to set internal
            ///     TimeSet = timeSpaceQuery.TimeSet;
            /// but then internal Values does not match TimeSet
            /// (and also the TimeSet is set to override and return _adaptee.TimeSet)

            // Before uncommenting this, comment out the overidden TimeSet property above
            //TimeSet = timeSpaceQuery.TimeSet;

            // Set query time to internal query item
            _query.TimeSet = timeSpaceQuery.TimeSet;

            ITimeSpaceValueSet         incomingValues = _adaptee.GetValues(_query);
            TimeSpaceValueSet <double> resultValues   = ElementMapper.CreateResultValueSet(incomingValues.TimesCount(), SpatialDefinition.ElementCount);

            // Transform the values from the adaptee
            _elementMapper.MapValues(resultValues, incomingValues);
            return(resultValues);
        }
        /// <summary>
        /// Update the associated buffer with the last values calculated by the engine
        /// </summary>
        public virtual void UpdateBuffer()
        {
            if ((link.SourceQuantity != null) && (link.SourceElementSet != null))
            {
                if (this.Engine is Oatc.OpenMI.Sdk.Wrapper.IAdvancedEngine)
                {
                    TimeValueSet timeValueSet = ((IAdvancedEngine)this.Engine).GetValues(link.SourceQuantity.ID, link.SourceElementSet.ID);

                    if (timeValueSet.Time != null)
                    {
                        if (_useSpatialMapping)
                        {
                            this.smartBuffer.AddValues(timeValueSet.Time, elementMapper.MapValues(timeValueSet.ValueSet));
                        }
                        else
                        {
                            this.smartBuffer.AddValues(timeValueSet.Time, timeValueSet.ValueSet);
                        }
                    }
                }
                else // the engine is IEngine or IRunEngine
                {
                    ITime time = this.Engine.GetCurrentTime();


                    IValueSet valueSet = this.Engine.GetValues(link.SourceQuantity.ID, link.SourceElementSet.ID);


                    if (_useSpatialMapping)
                    {
                        this.smartBuffer.AddValues(time, elementMapper.MapValues(valueSet));
                    }
                    else
                    {
                        this.smartBuffer.AddValues(time, valueSet);
                    }
                }
            }

            SmartBuffer.ClearBefore(link.TargetComponent.EarliestInputTime);
        }
        [Test]         // testing the Initialise method
        public void MapValues()
        {
            ElementSet gridElementSet       = new ElementSet("RegularGrid", "RegularGrid", ElementType.XYPolygon, new SpatialReference("ref"));
            ElementSet fourPointsElementSet = new ElementSet("4 points", "4P", ElementType.XYPoint, new SpatialReference("DummyID"));

            Vertex v_0_20  = new Vertex(0, 20, 0);
            Vertex v_0_10  = new Vertex(0, 10, 0);
            Vertex v_0_0   = new Vertex(0, 0, 0);
            Vertex v_0_15  = new Vertex(0, 15, 0);
            Vertex v_5_15  = new Vertex(5, 15, 0);
            Vertex v_10_20 = new Vertex(10, 20, 0);
            Vertex v_10_15 = new Vertex(10, 15, 0);
            Vertex v_10_10 = new Vertex(10, 10, 0);
            Vertex v_10_0  = new Vertex(10, 0, 0);
            Vertex v_15_15 = new Vertex(15, 15, 0);
            Vertex v_15_5  = new Vertex(15, 5, 0);
            Vertex v_20_20 = new Vertex(20, 20, 0);
            Vertex v_20_10 = new Vertex(20, 10, 0);

            Element square1 = new Element("square1");
            Element square2 = new Element("square2");
            Element square3 = new Element("square3");

            square1.AddVertex(v_0_20);
            square1.AddVertex(v_0_10);
            square1.AddVertex(v_10_10);
            square1.AddVertex(v_10_20);

            square2.AddVertex(v_10_20);
            square2.AddVertex(v_10_10);
            square2.AddVertex(v_20_10);
            square2.AddVertex(v_20_20);

            square3.AddVertex(v_0_10);
            square3.AddVertex(v_0_0);
            square3.AddVertex(v_10_0);
            square3.AddVertex(v_10_10);

            gridElementSet.AddElement(square1);
            gridElementSet.AddElement(square2);
            gridElementSet.AddElement(square3);

            Element point_5_15  = new Element("point 5, 15");
            Element point_10_15 = new Element("point 10, 15");
            Element point_15_15 = new Element("point 15, 15");
            Element point_15_5  = new Element("point 15, 5");

            point_5_15.AddVertex(v_5_15);
            point_10_15.AddVertex(v_10_15);
            point_15_15.AddVertex(v_15_15);
            point_15_5.AddVertex(v_15_5);

            fourPointsElementSet.AddElement(point_5_15);
            fourPointsElementSet.AddElement(point_10_15);
            fourPointsElementSet.AddElement(point_15_15);
            fourPointsElementSet.AddElement(point_15_5);
            ScalarSet fourPointsScalarSet = new ScalarSet();
            ScalarSet gridScalarSet       = new ScalarSet();

            ElementMapper elementMapper = new ElementMapper();

            // point to polygon

            ArrayList methodDescriptions = elementMapper.GetAvailableMethods(fourPointsElementSet.ElementType, gridElementSet.ElementType);

            elementMapper.Initialise(methodDescriptions[0].ToString(), fourPointsElementSet, gridElementSet);
            fourPointsScalarSet.data = new double[4] {
                0, 10, 20, 30
            };
            gridScalarSet = (ScalarSet)elementMapper.MapValues(fourPointsScalarSet);
            Assert.AreEqual(5, gridScalarSet.data[0]);
            Assert.AreEqual(20, gridScalarSet.data[1]);
            Assert.AreEqual(0, gridScalarSet.data[2]);
            // polygon to point
            methodDescriptions = elementMapper.GetAvailableMethods(gridElementSet.ElementType, fourPointsElementSet.ElementType);
            elementMapper.Initialise(methodDescriptions[0].ToString(), gridElementSet, fourPointsElementSet);
            fourPointsScalarSet = (ScalarSet)elementMapper.MapValues(gridScalarSet);
            Assert.AreEqual(5, fourPointsScalarSet.data[0]);
            Assert.AreEqual(5, fourPointsScalarSet.data[1]);
            Assert.AreEqual(20, fourPointsScalarSet.data[2]);
            Assert.AreEqual(0, fourPointsScalarSet.data[3]);
        }
예제 #4
0
        [Test] // testing the Initialise method
        public void MapValues()
        {
            ElementSet gridElementSet       = new ElementSet("RegularGrid", "RegularGrid", ElementType.Polygon);
            ElementSet fourPointsElementSet = new ElementSet("4 points", "4P", ElementType.Point);

            Coordinate v_0_20  = new Coordinate(0, 20, 0);
            Coordinate v_0_10  = new Coordinate(0, 10, 0);
            Coordinate v_0_0   = new Coordinate(0, 0, 0);
            Coordinate v_5_15  = new Coordinate(5, 15, 0);
            Coordinate v_10_20 = new Coordinate(10, 20, 0);
            Coordinate v_10_15 = new Coordinate(10, 15, 0);
            Coordinate v_10_10 = new Coordinate(10, 10, 0);
            Coordinate v_10_0  = new Coordinate(10, 0, 0);
            Coordinate v_15_15 = new Coordinate(15, 15, 0);
            Coordinate v_15_5  = new Coordinate(15, 5, 0);
            Coordinate v_20_20 = new Coordinate(20, 20, 0);
            Coordinate v_20_10 = new Coordinate(20, 10, 0);

            Element square1 = new Element("square1");
            Element square2 = new Element("square2");
            Element square3 = new Element("square3");

            square1.AddVertex(v_0_20);
            square1.AddVertex(v_0_10);
            square1.AddVertex(v_10_10);
            square1.AddVertex(v_10_20);

            square2.AddVertex(v_10_20);
            square2.AddVertex(v_10_10);
            square2.AddVertex(v_20_10);
            square2.AddVertex(v_20_20);

            square3.AddVertex(v_0_10);
            square3.AddVertex(v_0_0);
            square3.AddVertex(v_10_0);
            square3.AddVertex(v_10_10);

            gridElementSet.AddElement(square1);
            gridElementSet.AddElement(square2);
            gridElementSet.AddElement(square3);

            Element point_5_15  = new Element("point 5, 15");
            Element point_10_15 = new Element("point 10, 15");
            Element point_15_15 = new Element("point 15, 15");
            Element point_15_5  = new Element("point 15, 5");

            point_5_15.AddVertex(v_5_15);
            point_10_15.AddVertex(v_10_15);
            point_15_15.AddVertex(v_15_15);
            point_15_5.AddVertex(v_15_5);

            fourPointsElementSet.AddElement(point_5_15);
            fourPointsElementSet.AddElement(point_10_15);
            fourPointsElementSet.AddElement(point_15_15);
            fourPointsElementSet.AddElement(point_15_5);

            ElementMapper elementMapper = new ElementMapper();

            // point to polygon

            IIdentifiable[] methods = SpatialAdaptedOutputFactory.GetAvailableMethods(fourPointsElementSet.ElementType, gridElementSet.ElementType);
            elementMapper.Initialise(methods[0], fourPointsElementSet, gridElementSet);
            IList values = new List <double>();

            values.Add(0d);
            values.Add(10d);
            values.Add(20d);
            values.Add(30d);
            ITimeSpaceValueSet fourPointsScalarSet = new ValueSet(new List <IList> {
                values
            });

            ITimeSpaceValueSet gridScalarSet = elementMapper.MapValues(fourPointsScalarSet);
            IList elementValuesForTime       = gridScalarSet.GetElementValuesForTime(0);

            Assert.AreEqual(5, elementValuesForTime[0]);
            Assert.AreEqual(20, elementValuesForTime[1]);
            Assert.AreEqual(0, elementValuesForTime[2]);

            // polygon to point
            methods = SpatialAdaptedOutputFactory.GetAvailableMethods(gridElementSet.ElementType, fourPointsElementSet.ElementType);
            elementMapper.Initialise(methods[0], gridElementSet, fourPointsElementSet);
            fourPointsScalarSet  = elementMapper.MapValues(gridScalarSet);
            elementValuesForTime = fourPointsScalarSet.GetElementValuesForTime(0);
            Assert.AreEqual(5, elementValuesForTime[0]);
            Assert.AreEqual(5, elementValuesForTime[1]);
            Assert.AreEqual(20, elementValuesForTime[2]);
            Assert.AreEqual(0, elementValuesForTime[3]);
        }
예제 #5
0
        public void MapValues()
        {
            ElementSet gridElementSet = new ElementSet("RegularGrid","RegularGrid",ElementType.XYPolygon, new SpatialReference("ref"));
            ElementSet fourPointsElementSet = new ElementSet("4 points","4P",ElementType.XYPoint,new SpatialReference("DummyID"));

            Vertex v_0_20  = new Vertex(0,20,0);
            Vertex v_0_10  = new Vertex(0,10,0);
            Vertex v_0_0   = new Vertex(0, 0,0);
            Vertex v_0_15  = new Vertex(0,15,0);
            Vertex v_5_15  = new Vertex(5,15,0);
            Vertex v_10_20 = new Vertex(10,20,0);
            Vertex v_10_15 = new Vertex(10,15,0);
            Vertex v_10_10 = new Vertex(10,10,0);
            Vertex v_10_0  = new Vertex(10, 0,0);
            Vertex v_15_15 = new Vertex(15,15,0);
            Vertex v_15_5  = new Vertex(15,5,0);
            Vertex v_20_20 = new Vertex(20,20,0);
            Vertex v_20_10 = new Vertex(20,10,0);

            Element square1 = new Element("square1");
            Element square2 = new Element("square2");
            Element square3 = new Element("square3");

            square1.AddVertex(v_0_20);
            square1.AddVertex(v_0_10);
            square1.AddVertex(v_10_10);
            square1.AddVertex(v_10_20);

            square2.AddVertex(v_10_20);
            square2.AddVertex(v_10_10);
            square2.AddVertex(v_20_10);
            square2.AddVertex(v_20_20);

            square3.AddVertex(v_0_10);
            square3.AddVertex(v_0_0);
            square3.AddVertex(v_10_0);
            square3.AddVertex(v_10_10);

            gridElementSet.AddElement(square1);
            gridElementSet.AddElement(square2);
            gridElementSet.AddElement(square3);

            Element point_5_15  = new Element("point 5, 15");
            Element point_10_15 = new Element("point 10, 15");
            Element point_15_15 = new Element("point 15, 15");
            Element point_15_5  = new Element("point 15, 5");

            point_5_15.AddVertex(v_5_15);
            point_10_15.AddVertex(v_10_15);
            point_15_15.AddVertex(v_15_15);
            point_15_5.AddVertex(v_15_5);

            fourPointsElementSet.AddElement(point_5_15);
            fourPointsElementSet.AddElement(point_10_15);
            fourPointsElementSet.AddElement(point_15_15);
            fourPointsElementSet.AddElement(point_15_5);
            ScalarSet fourPointsScalarSet = new ScalarSet();
            ScalarSet gridScalarSet = new ScalarSet();

            ElementMapper elementMapper = new ElementMapper();

            // point to polygon

            ArrayList methodDescriptions = elementMapper.GetAvailableMethods(fourPointsElementSet.ElementType, gridElementSet.ElementType);
            elementMapper.Initialise(methodDescriptions[0].ToString(), fourPointsElementSet, gridElementSet);
            fourPointsScalarSet.data = new double[4] { 0, 10, 20, 30 };
            gridScalarSet = (ScalarSet)elementMapper.MapValues(fourPointsScalarSet);
            Assert.AreEqual(5, gridScalarSet.data[0]);
            Assert.AreEqual(20, gridScalarSet.data[1]);
            Assert.AreEqual(0, gridScalarSet.data[2]);
            // polygon to point
            methodDescriptions = elementMapper.GetAvailableMethods(gridElementSet.ElementType, fourPointsElementSet.ElementType);
            elementMapper.Initialise(methodDescriptions[0].ToString(), gridElementSet, fourPointsElementSet);
            fourPointsScalarSet = (ScalarSet)elementMapper.MapValues(gridScalarSet);
            Assert.AreEqual(5, fourPointsScalarSet.data[0]);
            Assert.AreEqual(5, fourPointsScalarSet.data[1]);
            Assert.AreEqual(20, fourPointsScalarSet.data[2]);
            Assert.AreEqual(0, fourPointsScalarSet.data[3]);
        }