Exemple #1
0
        public void IterationController()
        {
            IScalarSet resultQ = (IScalarSet)controller.GetValues(new TimeStamp(0.1), "link5");
            IScalarSet resultH = (IScalarSet)controller.GetValues(new TimeStamp(0.1), "link6");

            Assert.AreEqual(0.5, resultQ.GetScalar(0));
            Assert.AreEqual(0.5, resultH.GetScalar(0));
        }
Exemple #2
0
 protected override void DataArrived(DateTime simulationTime, string modelId, string quantity, string elementSet, IScalarSet scalarSet)
 {
     string simTime = simulationTime.ToShortDateString() + " " + simulationTime.ToLongTimeString();
     string scalar = "";
     for (int i = 0; i < scalarSet.Count; i++)
     {
         scalar += scalarSet.GetScalar(i);
         if (i < scalarSet.Count - 1) scalar += ",";
     }
     writeRow(new string[] { simTime, modelId, elementSet, quantity, scalar });
 }
        public IScalarSet Product(IScalarSet vector)
        {
            var outputValues = new double[RowCount];

            foreach (var entry in Values)
            {
                outputValues[entry.Key.Row] += entry.Value * vector.GetScalar(entry.Key.Column);
            }

            return(new ScalarSet(outputValues));
        }
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="source">The scalar set to copy</param>
 public ScalarSet(IScalarSet source)
 {
     if ( source == null )
     {
         throw new Exception("ScalarSet Constructor from \"Source\": source == null");
     }
     _values = new double[source.Count];
     for (int i = 0; i < source.Count; i++)
     {
         _values[i] = source.GetScalar(i);
     }
 }
Exemple #5
0
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="source">The scalar set to copy</param>
 public ScalarSet(IScalarSet source)
 {
     if (source == null)
     {
         throw new Exception("ScalarSet Constructor from \"Source\": source == null");
     }
     _values = new double[source.Count];
     for (int i = 0; i < source.Count; i++)
     {
         _values[i] = source.GetScalar(i);
     }
 }
        public override ITimeSpaceValueSet GetEngineValues(ExchangeItem exchangeItem)
        {
            IScalarSet    scalarSet = (IScalarSet)_engineApiAccess.GetValues(exchangeItem.ValueDefinition.Caption, exchangeItem.SpatialDefinition.Caption);
            List <double> values    = new List <double>(scalarSet.Count);

            for (int i = 0; i < scalarSet.Count; i++)
            {
                values.Add(scalarSet.GetScalar(i));
            }
            return(new ValueSet(new List <IList> {
                values
            }));
        }
Exemple #7
0
        public IScalarSet Product(IScalarSet vector)
        {
            var outputValues = new double[RowCount];

            for (var i = 0; i < RowCount; i++)
            {
                for (var j = 0; j < ColumnCount; j++)
                {
                    outputValues[i] += this[i, j] * vector.GetScalar(j);
                }
            }

            return(new ScalarSet(outputValues));
        }
        public void OnEvent(IEvent Event)
        {
            ILink[] links = GetAcceptingLinks();
            foreach (ILink link in links)
            {
                if (link.SourceComponent == Event.Sender)
                {
                    IValueSet values = Event.Sender.GetValues(Event.SimulationTime, link.ID);

                    if (values is IScalarSet)
                    {
                        IScalarSet scalarSet = (IScalarSet)values;
                        DataArrived(CalendarConverter.ModifiedJulian2Gregorian(Event.SimulationTime.ModifiedJulianDay),
                                    Event.Sender.ModelID, link.SourceQuantity.ID, link.SourceElementSet.ID, scalarSet);
                    }
                }
            }
        }
        /// <summary>
        /// Retrieves data from the providing LinkableComponent as defined
        /// in the Link and sets this data in the engine
        /// </summary>
        public virtual void UpdateInput()
        {
            ITime inputTime = this._engine.GetInputTime(link.TargetQuantity.ID, link.TargetElementSet.ID);

            if (inputTime != null)
            {
                SendEvent(EventType.TargetBeforeGetValuesCall, this.link.TargetComponent);
                IScalarSet sourceValueSet = (IScalarSet)link.SourceComponent.GetValues(inputTime, link.ID);

                //The input values set is copied in ordet to avoid the risk that it is changed be the provider.

                double    targetMissValDef = this._engine.GetMissingValueDefinition();
                ScalarSet targetValueSet   = new ScalarSet(sourceValueSet);

                for (int i = 0; i < sourceValueSet.Count; i++)
                {
                    if (!sourceValueSet.IsValid(i))
                    {
                        targetValueSet.data[i] = targetMissValDef;
                    }
                }

                targetValueSet.MissingValueDefinition = targetMissValDef;
                targetValueSet.CompareDoublesEpsilon  = targetMissValDef / 1.0e+10;
                if (link.TargetComponent is LinkableRunEngine && ((LinkableRunEngine)link.TargetComponent).SendExtendedEventInfo)
                {
                    string msg = " Quantity: " + link.TargetQuantity.ID + "  Recieved values:";
                    if (sourceValueSet is IScalarSet)
                    {
                        for (int i = 0; i < ((IScalarSet)sourceValueSet).Count; i++)
                        {
                            msg += (((IScalarSet)sourceValueSet).GetScalar(i).ToString() + ", ");
                        }
                    }
                    SendEvent(EventType.TargetAfterGetValuesReturn, this.link.TargetComponent, msg);
                }
                else
                {
                    SendEvent(EventType.TargetAfterGetValuesReturn, this.link.TargetComponent);
                }
                this.Engine.SetValues(link.TargetQuantity.ID, link.TargetElementSet.ID, targetValueSet);
            }
        }
        public void Add(IScalarSet valueSet)
        {
            // fast way
            if (valueSet is ScalarSet)
            {
                var scalarValueSet = valueSet as ScalarSet;
                for (var i = 0; i < _values.Length; i++)
                {
                    _values[i] += scalarValueSet._values[i];
                }

                return;
            }

            // slow way
            for (int i = 0; i < valueSet.Count; i++)
            {
                _values[i] += valueSet.GetScalar(i);
            }
        }
        /// <summary>
        /// Copy constructor
        /// </summary>
        /// <param name="source">The scalar set to copy</param>
        public ScalarSet(IScalarSet source)
        {
            if (source == null)
            {
                throw new Exception("ScalarSet Constructor from \"Source\": source == null");
            }

            if (source is ScalarSet)
            {
                var scalarSetSource = source as ScalarSet;
                _values = (double[])scalarSetSource._values.Clone();
                _compareDoublesEpsilon  = scalarSetSource._compareDoublesEpsilon;
                _missingValueDefinition = scalarSetSource._missingValueDefinition;
                return;
            }

            _values = new double[source.Count];
            for (int i = 0; i < source.Count; i++)
            {
                _values[i] = source.GetScalar(i);
            }
        }
 protected abstract void DataArrived(DateTime simulationTime, string modelId, string quantity, string elementSet, IScalarSet scalarSet);
Exemple #13
0
 public void Add(IScalarSet set)
 {
     throw new NotImplementedException();
 }
        protected override void DataArrived(DateTime simulationTime, string modelId, string quantity, string elementSet, IScalarSet scalarSet)
        {
            string simTime = simulationTime.ToShortDateString() + " " + simulationTime.ToLongTimeString();
            string scalar  = "";

            for (int i = 0; i < scalarSet.Count; i++)
            {
                scalar += scalarSet.GetScalar(i);
                if (i < scalarSet.Count - 1)
                {
                    scalar += ",";
                }
            }
            writeRow(new string[] { simTime, modelId, elementSet, quantity, scalar });
        }