예제 #1
0
        public void LineStringElmtBasedWrapperTest()
        {
            ICoordinate[] coordinates = new ICoordinate[4];
            coordinates[0] = new CoordinateM(1, 2, 0, 0);
            coordinates[1] = new CoordinateM(3, 4, 0, 1);
            coordinates[2] = new CoordinateM(5, 6, -5, 2);
            coordinates[3] = new CoordinateM(7, 8, 0, 3.5);

            LineString lineString = new LineString()
            {
                Coordinates = coordinates,
                HasZ        = false,
                IsNodeBased = false,
            };

            LineStringWrapper wrapper = new LineStringWrapper(lineString);

            Assert.AreEqual(ElementType.PolyLine, wrapper.ElementType);
            Assert.AreEqual(3, wrapper.ElementCount);

            Assert.AreEqual(2, wrapper.GetVertexCount(0));
            Assert.AreEqual(2, wrapper.GetVertexCount(1));
            Assert.AreEqual(2, wrapper.GetVertexCount(2));

            Assert.AreEqual(1, wrapper.GetVertexXCoordinate(0, 0));
            Assert.AreEqual(2, wrapper.GetVertexYCoordinate(0, 0));
            Assert.AreEqual(0, wrapper.GetVertexMCoordinate(0, 0));
            Assert.AreEqual(3, wrapper.GetVertexXCoordinate(0, 1));
            Assert.AreEqual(4, wrapper.GetVertexYCoordinate(0, 1));
            Assert.AreEqual(1, wrapper.GetVertexMCoordinate(0, 1));

            Assert.AreEqual(3, wrapper.GetVertexXCoordinate(1, 0));
            Assert.AreEqual(4, wrapper.GetVertexYCoordinate(1, 0));
            Assert.AreEqual(1, wrapper.GetVertexMCoordinate(1, 0));
            Assert.AreEqual(5, wrapper.GetVertexXCoordinate(1, 1));
            Assert.AreEqual(6, wrapper.GetVertexYCoordinate(1, 1));
            Assert.AreEqual(2, wrapper.GetVertexMCoordinate(1, 1));

            Assert.AreEqual(5, wrapper.GetVertexXCoordinate(2, 0));
            Assert.AreEqual(6, wrapper.GetVertexYCoordinate(2, 0));
            Assert.AreEqual(2, wrapper.GetVertexMCoordinate(2, 0));
            Assert.AreEqual(7, wrapper.GetVertexXCoordinate(2, 1));
            Assert.AreEqual(8, wrapper.GetVertexYCoordinate(2, 1));
            Assert.AreEqual(3.5, wrapper.GetVertexMCoordinate(2, 1));
        }
예제 #2
0
        public override void Initialize()
        {
            Status = LinkableComponentStatus.Initializing;

            // Handle arguments
            IDictionary <string, IArgument> argDict = Arguments.Dictionary();

            Id           = argDict.GetValue <string>("ModelId");
            this.Caption = "RiverModel Default Model";

            _flowItemsAsSpan         = argDict.GetValue <bool>("FlowItemsAsSpan");
            _storeValuesInItem       = argDict.GetValue <bool>("StoreValuesInExchangeitems");
            _timeStepLengthInSeconds = argDict.GetValue <double>("TimestepLength");
            _timeStepLengthInDays    = _timeStepLengthInSeconds / (24.0 * 3600.0);

            double xyscale = argDict.GetValue <double>("xyscale");
            double xOffset = argDict.GetValue <double>("xoffset");
            double yOffset = argDict.GetValue <double>("yoffset");

            for (int i = 0; i < _numberOfNodes; i++)
            {
                _xCoordinate[i] = xyscale * _xCoordinate[i] + xOffset;
                _yCoordinate[i] = xyscale * _yCoordinate[i] + yOffset;
            }

            // -- create a flow quantity --
            Dimension flowDimension = new Dimension();

            flowDimension.SetPower(DimensionBase.Length, 3);
            flowDimension.SetPower(DimensionBase.Time, -1);

            Unit literPrSecUnit = new Unit("LiterPrSecond", 0.001, 0, "Liters pr Second");

            Quantity flowQuantity    = new Quantity(literPrSecUnit, "Flow", "Flow");
            Quantity leakageQuantity = new Quantity(literPrSecUnit, "Leakage", "Leakage");

            // -- create a ground water level quantity --
            Dimension levelDimension = new Dimension();

            levelDimension.SetPower(DimensionBase.Length, 1);

            Unit levelUnit = new Unit("GroundWaterLevel", 1, 0, "Ground water level");

            levelUnit.Dimension = levelDimension;

            Quantity levelQuantity = new Quantity(levelUnit, "Ground water level", "Ground Water level");

            // -- Time settings for input and output exchange items --
            ITime timeHorizon = new Time(StartTime, EndTime);

            // -- create and populate elementset to represent all branches, links betwen nodes in the river network --
            LineString fullRiverLineString =
                new LineString
            {
                Coordinates = GeometryFactory.CreateCoordinateList(_xCoordinate, _yCoordinate),
                Caption     = "WholeRiver",
                Description = "WholeRiver",
                IsClosed    = false,
                IsNodeBased = false,
            };
            IElementSet fullRiverElementSet = new LineStringWrapper(fullRiverLineString);

            // --- populate input exchange items for flow to individual nodes, id-based ---
            for (int i = 0; i < _numberOfNodes; i++)
            {
                string     id         = "Node:" + i;
                ElementSet elementSet = new ElementSet(id, id, ElementType.IdBased);
                elementSet.AddElement(new Element(id));

                EngineInputItem inputExchangeItem = CreateInputInflowToOneNode(i, id, flowQuantity, elementSet);
                inputExchangeItem.StoreValuesInExchangeItem = true; // Item is adding up, therefor store in item
                inputExchangeItem.TimeSet.SetTimeHorizon(timeHorizon);
                EngineInputItems.Add(inputExchangeItem);
            }

            // --- Populate input exchange item for flow into the whole river ---
            EngineInputItem wholeRiverFlowInputItem = CreateInputInflowToRiver(flowQuantity, fullRiverElementSet);

            wholeRiverFlowInputItem.TimeSet.SetTimeHorizon(timeHorizon);
            EngineInputItems.Add(wholeRiverFlowInputItem);

            // --- Populate input exchange item for ground water level of the whole river ---
            EngineDInputItem gwLevelInputItem = CreateInputGwLevel(levelQuantity, fullRiverElementSet);

            gwLevelInputItem.TimeSet.SetTimeHorizon(timeHorizon);
            EngineInputItems.Add(gwLevelInputItem);

            // --- Populate output exchange items for flow in river branches, id based ---
            for (int i = 0; i < _numberOfNodes - 1; i++)
            {
                string     id         = "Branch:" + i;
                ElementSet elementSet = new ElementSet(id, id, ElementType.IdBased);
                elementSet.AddElement(new Element(id));

                EngineOutputItem outputExchangeItem = CreateOutputFlowInBranch(i, id, flowQuantity, elementSet);
                EngineOutputItems.Add(outputExchangeItem);
            }

            // --- populate output exchange items for leakage for individual branches --
            for (int i = 0; i < _numberOfNodes - 1; i++)
            {
                string     id         = "Branch:" + i;
                ElementSet elementSet = new ElementSet(id, id, ElementType.IdBased);
                elementSet.AddElement(new Element(id));

                EngineOutputItem outputExchangeItem = CreateOutputLeakageInBranch(i, id, leakageQuantity, elementSet);
                EngineOutputItems.Add(outputExchangeItem);
            }

            // --- Populate output exchange item for leakage from the whole georeferenced river ---
            EngineOutputItem wholeRiverOutputExchangeItem = CreateOuputLeakageInRiver(leakageQuantity, fullRiverElementSet);

            EngineOutputItems.Add(wholeRiverOutputExchangeItem);

            // --- Populate output exchange item for flow from the whole georeferenced river ---
            EngineOutputItem wholeRiverFlowOutputExchangeItem = CreateOutputFlowInRiver(flowQuantity, fullRiverElementSet);

            EngineOutputItems.Add(wholeRiverFlowOutputExchangeItem);

            // --- populate with initial state variables ---
            for (int i = 0; i < _numberOfNodes - 1; i++)
            {
                _flow[i] = 7;
            }

            foreach (EngineInputItem engineInputItem in EngineInputItems)
            {
                // TODO: Overwrites existing timeset, which has already had the time horizon set?
                engineInputItem.TimeSet = new TimeSet()
                {
                    HasDurations = _flowItemsAsSpan
                };
            }
            foreach (EngineOutputItem engineOutputItem in EngineOutputItems)
            {
                // TODO: Overwrites existing timeset, which has already had the time horizon set?
                engineOutputItem.TimeSet = new TimeSet()
                {
                    HasDurations = _flowItemsAsSpan
                };
            }

            Status = LinkableComponentStatus.Initialized;
        }