Beispiel #1
0
        /// <summary>
        /// Unbind the behavior.
        /// </summary>
        public override void Unbind()
        {
            base.Unbind();

            // Get matrix pointers
            DrainDrainPtr             = null;
            GateGatePtr               = null;
            SourceSourcePtr           = null;
            BulkBulkPtr               = null;
            DrainPrimeDrainPrimePtr   = null;
            SourcePrimeSourcePrimePtr = null;
            DrainDrainPrimePtr        = null;
            GateBulkPtr               = null;
            GateDrainPrimePtr         = null;
            GateSourcePrimePtr        = null;
            SourceSourcePrimePtr      = null;
            BulkDrainPrimePtr         = null;
            BulkSourcePrimePtr        = null;
            DrainPrimeSourcePrimePtr  = null;
            DrainPrimeDrainPtr        = null;
            BulkGatePtr               = null;
            DrainPrimeGatePtr         = null;
            SourcePrimeGatePtr        = null;
            SourcePrimeSourcePtr      = null;
            DrainPrimeBulkPtr         = null;
            SourcePrimeBulkPtr        = null;
            SourcePrimeDrainPrimePtr  = null;

            // Get rhs pointers
            BulkPtr        = null;
            DrainPrimePtr  = null;
            SourcePrimePtr = null;
        }
Beispiel #2
0
        /// <summary>
        /// Bind behavior.
        /// </summary>
        /// <param name="simulation">The simulation.</param>
        /// <param name="context">Data provider</param>
        public override void Bind(Simulation simulation, BindingContext context)
        {
            base.Bind(simulation, context);

            // Get parameters
            BaseParameters = context.GetParameterSet <CommonBehaviors.IndependentSourceParameters>();

            // Setup the waveform
            BaseParameters.Waveform?.Setup();

            // Give some warnings if no value is given
            if (!BaseParameters.DcValue.Given)
            {
                // no DC value - either have a transient value or none
                CircuitWarning.Warning(this,
                                       BaseParameters.Waveform != null
                        ? "{0} has no DC value, transient time 0 value used".FormatString(Name)
                        : "{0} has no value, DC 0 assumed".FormatString(Name));
            }

            if (context is ComponentBindingContext cc)
            {
                PosNode = cc.Pins[0];
                NegNode = cc.Pins[1];
            }

            _state = ((BaseSimulation)simulation).RealState;
            var solver = _state.Solver;

            PosPtr = solver.GetRhsElement(PosNode);
            NegPtr = solver.GetRhsElement(NegNode);
        }
Beispiel #3
0
        /// <summary>
        /// Bind the behavior.
        /// </summary>
        public override void Bind(Simulation simulation, BindingContext context)
        {
            base.Bind(simulation, context);

            // Cache some objects that we will use often
            _bp         = context.GetParameterSet <BaseParameters>();
            _state      = ((BaseSimulation)simulation).RealState;
            _baseConfig = simulation.Configurations.Get <BaseConfiguration>();

            // Find the nodes that the resistor is connected to
            if (context is ComponentBindingContext cbc)
            {
                _nodeA = cbc.Pins[0];
                _nodeB = cbc.Pins[1];
            }

            // We need 4 matrix elements here
            var solver = _state.Solver;

            _aaPtr = solver.GetMatrixElement(_nodeA, _nodeA);
            _abPtr = solver.GetMatrixElement(_nodeA, _nodeB);
            _baPtr = solver.GetMatrixElement(_nodeB, _nodeA);
            _bbPtr = solver.GetMatrixElement(_nodeB, _nodeB);

            // We also need 2 RHS vector elements
            _aPtr = solver.GetRhsElement(_nodeA);
            _bPtr = solver.GetRhsElement(_nodeB);
        }
        /// <summary>
        /// Gets matrix pointers
        /// </summary>
        /// <param name="variables">Nodes</param>
        /// <param name="solver">Solver</param>
        public override void GetEquationPointers(VariableSet variables, Solver <double> solver)
        {
            if (variables == null)
            {
                throw new ArgumentNullException(nameof(variables));
            }
            if (solver == null)
            {
                throw new ArgumentNullException(nameof(solver));
            }

            // Add series drain node if necessary
            if (_mbp.DrainResistance > 0 || _mbp.SheetResistance > 0 && _bp.DrainSquares > 0)
            {
                DrainNodePrime = variables.Create(Name.Combine("drain")).Index;
            }
            else
            {
                DrainNodePrime = _drainNode;
            }

            // Add series source node if necessary
            if (_mbp.SourceResistance > 0 || _mbp.SheetResistance > 0 && _bp.SourceSquares > 0)
            {
                SourceNodePrime = variables.Create(Name.Combine("source")).Index;
            }
            else
            {
                SourceNodePrime = _sourceNode;
            }

            // Get matrix pointers
            DrainDrainPtr             = solver.GetMatrixElement(_drainNode, _drainNode);
            GateGatePtr               = solver.GetMatrixElement(_gateNode, _gateNode);
            SourceSourcePtr           = solver.GetMatrixElement(_sourceNode, _sourceNode);
            BulkBulkPtr               = solver.GetMatrixElement(_bulkNode, _bulkNode);
            DrainPrimeDrainPrimePtr   = solver.GetMatrixElement(DrainNodePrime, DrainNodePrime);
            SourcePrimeSourcePrimePtr = solver.GetMatrixElement(SourceNodePrime, SourceNodePrime);
            DrainDrainPrimePtr        = solver.GetMatrixElement(_drainNode, DrainNodePrime);
            GateBulkPtr               = solver.GetMatrixElement(_gateNode, _bulkNode);
            GateDrainPrimePtr         = solver.GetMatrixElement(_gateNode, DrainNodePrime);
            GateSourcePrimePtr        = solver.GetMatrixElement(_gateNode, SourceNodePrime);
            SourceSourcePrimePtr      = solver.GetMatrixElement(_sourceNode, SourceNodePrime);
            BulkDrainPrimePtr         = solver.GetMatrixElement(_bulkNode, DrainNodePrime);
            BulkSourcePrimePtr        = solver.GetMatrixElement(_bulkNode, SourceNodePrime);
            DrainPrimeSourcePrimePtr  = solver.GetMatrixElement(DrainNodePrime, SourceNodePrime);
            DrainPrimeDrainPtr        = solver.GetMatrixElement(DrainNodePrime, _drainNode);
            BulkGatePtr               = solver.GetMatrixElement(_bulkNode, _gateNode);
            DrainPrimeGatePtr         = solver.GetMatrixElement(DrainNodePrime, _gateNode);
            SourcePrimeGatePtr        = solver.GetMatrixElement(SourceNodePrime, _gateNode);
            SourcePrimeSourcePtr      = solver.GetMatrixElement(SourceNodePrime, _sourceNode);
            DrainPrimeBulkPtr         = solver.GetMatrixElement(DrainNodePrime, _bulkNode);
            SourcePrimeBulkPtr        = solver.GetMatrixElement(SourceNodePrime, _bulkNode);
            SourcePrimeDrainPrimePtr  = solver.GetMatrixElement(SourceNodePrime, DrainNodePrime);

            // Get rhs pointers
            BulkPtr        = solver.GetRhsElement(_bulkNode);
            DrainPrimePtr  = solver.GetRhsElement(DrainNodePrime);
            SourcePrimePtr = solver.GetRhsElement(SourceNodePrime);
        }
        public override PointStyle OnSelectDragPointStyle(VectorElement element, VectorElementDragPointStyle dragPointStyle)
        {
            if (styleNormal == null)
            {
                PointStyleBuilder builder = new PointStyleBuilder();
                builder.Color = new Color(0, 255, 255, 255);
                builder.Size  = 20;

                styleNormal = builder.BuildStyle();

                builder.Size = 15;

                styleVirtual = builder.BuildStyle();

                builder.Color = new Color(255, 255, 0, 255);
                builder.Size  = 30;

                styleSelected = builder.BuildStyle();
            }

            if (dragPointStyle == VectorElementDragPointStyle.VectorElementDragPointStyleSelected)
            {
                return(styleSelected);
            }

            if (dragPointStyle == VectorElementDragPointStyle.VectorElementDragPointStyleVirtual)
            {
                return(styleVirtual);
            }

            return(styleNormal);
        }
Beispiel #6
0
 /// <summary>
 /// Unbind the behavior.
 /// </summary>
 public override void Unbind()
 {
     base.Unbind();
     _state = null;
     PosPtr = null;
     NegPtr = null;
 }
Beispiel #7
0
 /// <summary>
 /// Get equation pointers
 /// </summary>
 /// <param name="solver">Solver</param>
 public void GetEquationPointers(Solver <Complex> solver)
 {
     if (solver == null)
     {
         throw new ArgumentNullException(nameof(solver));
     }
     CPosPtr = solver.GetRhsElement(PosNode);
     CNegPtr = solver.GetRhsElement(NegNode);
 }
Beispiel #8
0
        // Converts the value of the element to a hexadecimal representation.
        public static string ValueAsHex(this VectorElement element)
        {
            byte[] values = element.GetValues();

            string hex = BitConverter
                         .ToString(values)
                         .Replace("-", "");

            return($"0x{hex}");
        }
Beispiel #9
0
        /// <summary>
        /// Get the matrix elements
        /// </summary>
        /// <param name="variables">Variables</param>
        /// <param name="solver">Solver</param>
        public override void GetEquationPointers(VariableSet variables, Solver <double> solver)
        {
            if (solver == null)
            {
                throw new ArgumentNullException(nameof(solver));
            }

            _posPtr = solver.GetRhsElement(_posNode);
            _negPtr = solver.GetRhsElement(_negNode);
        }
        /// <summary>
        /// Get equation pointers
        /// </summary>
        /// <param name="solver">Solver</param>
        public override void GetEquationPointers(Solver <Complex> solver)
        {
            if (solver == null)
            {
                throw new ArgumentNullException(nameof(solver));
            }

            PosPtr = solver.GetRhsElement(_posNode);
            NegPtr = solver.GetRhsElement(_negNode);
        }
 /// <summary>
 /// Unbind the behavior.
 /// </summary>
 public override void Unbind()
 {
     base.Unbind();
     _state        = null;
     CPosBranchPtr = null;
     CBranchPosPtr = null;
     CNegBranchPtr = null;
     CBranchNegPtr = null;
     CBranchPtr    = null;
 }
        /// <summary>
        /// Bind the behavior.
        /// </summary>
        /// <param name="simulation">The simulation.</param>
        /// <param name="context">The context.</param>
        public override void Bind(Simulation simulation, BindingContext context)
        {
            base.Bind(simulation, context);

            var solver = ((BaseSimulation)simulation).RealState.Solver;

            Ibr1Ptr = solver.GetRhsElement(BranchEq1);
            Ibr2Ptr = solver.GetRhsElement(BranchEq2);

            Signals = new DelayedSignal(2, BaseParameters.Delay);
        }
Beispiel #13
0
        /// <summary>
        /// Gets matrix pointers
        /// </summary>
        /// <param name="variables">Nodes</param>
        /// <param name="solver">Solver</param>
        public void GetEquationPointers(VariableSet variables, Solver <double> solver)
        {
            variables.ThrowIfNull(nameof(variables));
            solver.ThrowIfNull(nameof(solver));

            // Add series drain node if necessary
            if (ModelParameters.DrainResistance > 0 || ModelParameters.SheetResistance > 0 && BaseParameters.DrainSquares > 0)
            {
                DrainNodePrime = variables.Create(Name.Combine("drain")).Index;
            }
            else
            {
                DrainNodePrime = DrainNode;
            }

            // Add series source node if necessary
            if (ModelParameters.SourceResistance > 0 || ModelParameters.SheetResistance > 0 && BaseParameters.SourceSquares > 0)
            {
                SourceNodePrime = variables.Create(Name.Combine("source")).Index;
            }
            else
            {
                SourceNodePrime = SourceNode;
            }

            // Get matrix pointers
            DrainDrainPtr             = solver.GetMatrixElement(DrainNode, DrainNode);
            GateGatePtr               = solver.GetMatrixElement(GateNode, GateNode);
            SourceSourcePtr           = solver.GetMatrixElement(SourceNode, SourceNode);
            BulkBulkPtr               = solver.GetMatrixElement(BulkNode, BulkNode);
            DrainPrimeDrainPrimePtr   = solver.GetMatrixElement(DrainNodePrime, DrainNodePrime);
            SourcePrimeSourcePrimePtr = solver.GetMatrixElement(SourceNodePrime, SourceNodePrime);
            DrainDrainPrimePtr        = solver.GetMatrixElement(DrainNode, DrainNodePrime);
            GateBulkPtr               = solver.GetMatrixElement(GateNode, BulkNode);
            GateDrainPrimePtr         = solver.GetMatrixElement(GateNode, DrainNodePrime);
            GateSourcePrimePtr        = solver.GetMatrixElement(GateNode, SourceNodePrime);
            SourceSourcePrimePtr      = solver.GetMatrixElement(SourceNode, SourceNodePrime);
            BulkDrainPrimePtr         = solver.GetMatrixElement(BulkNode, DrainNodePrime);
            BulkSourcePrimePtr        = solver.GetMatrixElement(BulkNode, SourceNodePrime);
            DrainPrimeSourcePrimePtr  = solver.GetMatrixElement(DrainNodePrime, SourceNodePrime);
            DrainPrimeDrainPtr        = solver.GetMatrixElement(DrainNodePrime, DrainNode);
            BulkGatePtr               = solver.GetMatrixElement(BulkNode, GateNode);
            DrainPrimeGatePtr         = solver.GetMatrixElement(DrainNodePrime, GateNode);
            SourcePrimeGatePtr        = solver.GetMatrixElement(SourceNodePrime, GateNode);
            SourcePrimeSourcePtr      = solver.GetMatrixElement(SourceNodePrime, SourceNode);
            DrainPrimeBulkPtr         = solver.GetMatrixElement(DrainNodePrime, BulkNode);
            SourcePrimeBulkPtr        = solver.GetMatrixElement(SourceNodePrime, BulkNode);
            SourcePrimeDrainPrimePtr  = solver.GetMatrixElement(SourceNodePrime, DrainNodePrime);

            // Get rhs pointers
            BulkPtr        = solver.GetRhsElement(BulkNode);
            DrainPrimePtr  = solver.GetRhsElement(DrainNodePrime);
            SourcePrimePtr = solver.GetRhsElement(SourceNodePrime);
        }
        // Allocate Y-matrix and RHS-vector elements
        public override void GetEquationPointers(VariableSet variables, Solver <double> solver)
        {
            // We need 4 matrix elements here
            _aaPtr = solver.GetMatrixElement(_nodeA, _nodeA);
            _abPtr = solver.GetMatrixElement(_nodeA, _nodeB);
            _baPtr = solver.GetMatrixElement(_nodeB, _nodeA);
            _bbPtr = solver.GetMatrixElement(_nodeB, _nodeB);

            // We also need 2 RHS vector elements
            _aPtr = solver.GetRhsElement(_nodeA);
            _bPtr = solver.GetRhsElement(_nodeB);
        }
Beispiel #15
0
 public static float GetElement(this Vector2 v, VectorElement element)
 {
     switch (element)
     {
         case VectorElement.X:
             return v.X;
         case VectorElement.Y:
             return v.Y;
         default:
             throw new Exception("Tried to get non-existent element from vector.");
     }
 }
Beispiel #16
0
		public static Vector2 SetElement(this Vector2 v, VectorElement element, float value)
		{
			switch (element)
			{
				case VectorElement.X:
					return new Vector2(value, v.Y);
				case VectorElement.Y:
					return new Vector2(v.X, value);
				default:
					throw new Exception("Tried to set non-existent element in vector.");
			}
		}
Beispiel #17
0
        /// <summary>
        /// Gets the original data values by expanding
        /// sequences and applying scale and offset.
        /// </summary>
        /// <returns>A list of the original data values.</returns>
        private IList <object> GetOriginalValues()
        {
            IList <object> values         = new List <object>();
            VectorElement  valuesVector   = SeriesValues;
            StorageMethods storageMethods = Definition.StorageMethodID;

            bool    incremented = (storageMethods & StorageMethods.Increment) != 0;
            dynamic start, count, increment;

            bool    scaled = (storageMethods & StorageMethods.Scaled) != 0;
            dynamic offset = ((object)SeriesOffset != null) ? SeriesOffset.Get() : 0;
            dynamic scale  = ((object)SeriesScale != null) ? SeriesScale.Get() : 1;
            dynamic value;

            if (!scaled)
            {
                offset = 0;
                scale  = 1;
            }

            if (incremented)
            {
                start     = valuesVector.Get(0);
                count     = valuesVector.Get(1);
                increment = valuesVector.Get(2);

                for (int i = 0; i < count; i++)
                {
                    values.Add((object)(start + (i * increment)));
                }
            }
            else
            {
                for (int i = 0; i < valuesVector.Size; i++)
                {
                    values.Add(valuesVector.Get(i));
                }
            }

            if (valuesVector.TypeOfValue != PhysicalType.Timestamp)
            {
                for (int i = 0; i < values.Count; i++)
                {
                    value     = values[i];
                    values[i] = offset + (value * scale);
                }

                ApplyTransducerRatio(values);
            }

            return(values);
        }
        /// <summary>
        /// Add element in vector from array.
        /// </summary>
        /// <param name="value">element`s value</param>
        private void AddElementInVector(int value)
        {
            if (head == null)
            {
                head = new VectorElement(value, null);
                tail = head;
                return;
            }
            var currentElement = new VectorElement(value, null);

            tail.next = currentElement;
            tail      = currentElement;
        }
Beispiel #19
0
        /// <summary>
        /// Gets matrix pointers
        /// </summary>
        /// <param name="solver">Solver</param>
        public void GetEquationPointers(Solver <Complex> solver)
        {
            solver.ThrowIfNull(nameof(solver));

            // Get matrix elements
            CPosBranchPtr = solver.GetMatrixElement(PosNode, BranchEq);
            CBranchPosPtr = solver.GetMatrixElement(BranchEq, PosNode);
            CNegBranchPtr = solver.GetMatrixElement(NegNode, BranchEq);
            CBranchNegPtr = solver.GetMatrixElement(BranchEq, NegNode);

            // Get rhs elements
            CBranchPtr = solver.GetRhsElement(BranchEq);
        }
Beispiel #20
0
 /// <summary>
 /// Unbind the behavior.
 /// </summary>
 public override void Unbind()
 {
     base.Unbind();
     _bp         = null;
     _state      = null;
     _baseConfig = null;
     _aaPtr      = null;
     _abPtr      = null;
     _baPtr      = null;
     _bbPtr      = null;
     _aPtr       = null;
     _bPtr       = null;
 }
        /// <summary>
        /// Bind behavior.
        /// </summary>
        /// <param name="simulation">The simulation.</param>
        /// <param name="context">Data provider</param>
        public override void Bind(Simulation simulation, BindingContext context)
        {
            base.Bind(simulation, context);

            // Get parameters
            FrequencyParameters = context.GetParameterSet <CommonBehaviors.IndependentSourceFrequencyParameters>();

            _state = ((FrequencySimulation)simulation).ComplexState;
            var solver = _state.Solver;

            CPosPtr = solver.GetRhsElement(PosNode);
            CNegPtr = solver.GetRhsElement(NegNode);
        }
        /// <summary>
        /// Gets matrix pointer
        /// </summary>
        /// <param name="solver">Matrix</param>
        public void GetEquationPointers(Solver <double> solver)
        {
            if (solver == null)
            {
                throw new ArgumentNullException(nameof(solver));
            }

            // Get vector elements
            BranchPtr = solver.GetRhsElement(BranchEq);

            // Get matrix elements
            BranchBranchPtr = solver.GetMatrixElement(BranchEq, BranchEq);
        }
Beispiel #23
0
        /// <summary>
        /// Gets matrix pointer
        /// </summary>
        /// <param name="solver">Matrix</param>
        public override void GetEquationPointers(Solver <double> solver)
        {
            if (solver == null)
            {
                throw new ArgumentNullException(nameof(solver));
            }

            // Get current equation
            _branchEq = _load.BranchEq;
            BranchPtr = solver.GetRhsElement(_branchEq);

            // Get matrix pointers
            BranchBranchPtr = solver.GetMatrixElement(_branchEq, _branchEq);
        }
Beispiel #24
0
        public static Vector2 SetElement(this Vector2 v, VectorElement element, float value)
        {
            switch (element)
            {
            case VectorElement.X:
                return(new Vector2(value, v.Y));

            case VectorElement.Y:
                return(new Vector2(v.X, value));

            default:
                throw new Exception("Tried to set non-existent element in vector.");
            }
        }
Beispiel #25
0
        public static float GetElement(this Vector2 v, VectorElement element)
        {
            switch (element)
            {
            case VectorElement.X:
                return(v.X);

            case VectorElement.Y:
                return(v.Y);

            default:
                throw new Exception("Tried to get non-existent element from vector.");
            }
        }
Beispiel #26
0
        private double CalculateValueTotalWeight(Vector <double> vector, double value)
        {
            double sum = 0;

            for (int i = 0; i < vector.Length; ++i)
            {
                VectorElement element = vector[i];
                if (element.Value == value)
                {
                    sum += (1 / (element.Value * element.Weight));
                }
            }
            return(sum);
        }
Beispiel #27
0
        // Converts the value of the element to a string representation.
        public static string ValueAsString(this VectorElement element)
        {
            // The physical types Char1 and Char2 indicate the value is a string
            if (element.TypeOfValue == PhysicalType.Char1)
            {
                return(Encoding.ASCII.GetString(element.GetValues()).Trim((char)0));
            }

            if (element.TypeOfValue == PhysicalType.Char2)
            {
                return(Encoding.Unicode.GetString(element.GetValues()).Trim((char)0));
            }

            // Get the tag definition of the element being displayed
            Tag?tag = Tag.GetTag(element.TagOfElement);

            // Determine the format in which to display the values
            // based on the tag definition and the type of the value
            Func <int, string> formatter = element.TypeOfValue switch
            {
                PhysicalType.Complex8 => index => ((Complex)element.Get(index)).ToComplexNotation(),
                PhysicalType.Complex16 => index => ((Complex)element.Get(index)).ToComplexNotation(),

                PhysicalType.Timestamp => index =>
                {
                    string format = tag?.FormatString ?? "{0:yyyy-MM-dd HH:mm:ss.fffffff}";
                    object value  = element.Get(index);
                    return(string.Format(format, value));
                },

                _ => index =>
                {
                    string format = tag?.FormatString ?? "{0}";
                    object value  = element.Get(index);
                    return(string.Format(format, value));
                }
            };

            // Convert the values to their string representations
            IEnumerable <string> values = Enumerable
                                          .Range(0, element.Size)
                                          .Select(formatter);

            // Join the values in the collection
            // to a single, comma-separated string
            string join = string.Join(", ", values);

            // Wrap the string in curly braces and return
            return($"{{ {join} }}");
        }
 public override void OnElementModify(VectorElement element, Geometry geometry)
 {
     if (element is Point && geometry is PointGeometry)
     {
         (element as Point).Geometry = (PointGeometry)geometry;
     }
     else if (element is Line && geometry is LineGeometry)
     {
         (element as Line).Geometry = (LineGeometry)geometry;
     }
     else if (element is Polygon && geometry is PolygonGeometry)
     {
         (element as Polygon).Geometry = (PolygonGeometry)geometry;
     }
 }
Beispiel #29
0
        /// <summary>
        /// Sets the values to be written to the PQDIF
        /// file for the increment storage method.
        /// </summary>
        /// <param name="start">The start of the increment.</param>
        /// <param name="count">The number of values in the series.</param>
        /// <param name="increment">The amount by which to increment each value in the series.</param>
        public void SetValues(object start, object count, object increment)
        {
            VectorElement seriesValuesElement;

            seriesValuesElement = new VectorElement()
            {
                Size         = 3,
                TagOfElement = SeriesValuesTag,
                TypeOfValue  = PhysicalTypeExtensions.GetPhysicalType(start.GetType())
            };

            seriesValuesElement.Set(0, start);
            seriesValuesElement.Set(1, count);
            seriesValuesElement.Set(2, increment);
        }
Beispiel #30
0
        private static DateTime[] ParseTimeData(SeriesInstance seriesInstance, double systemFrequency)
        {
            DateTime[] timeData;

            SeriesDefinition timeSeriesDefinition = seriesInstance.Definition;

            if (timeSeriesDefinition.ValueTypeID != SeriesValueType.Time)
            {
                return(null);
            }

            VectorElement seriesValues = seriesInstance.SeriesValues;

            if (seriesValues.TypeOfValue == PhysicalType.Timestamp)
            {
                timeData = seriesInstance.OriginalValues
                           .Select(Convert.ToDateTime)
                           .ToArray();
            }
            else if (timeSeriesDefinition.QuantityUnits == QuantityUnits.Cycles)
            {
                ChannelInstance channelInstance  = seriesInstance.Channel;
                DateTime        startTime        = channelInstance.ObservationRecord.StartTime;
                double          nominalFrequency = channelInstance.ObservationRecord?.Settings.NominalFrequency ?? systemFrequency;

                timeData = seriesInstance.OriginalValues
                           .Select(Convert.ToDouble)
                           .Select(cycles => cycles / nominalFrequency)
                           .Select(seconds => (long)(seconds * TimeSpan.TicksPerSecond))
                           .Select(TimeSpan.FromTicks)
                           .Select(timeSpan => startTime + timeSpan)
                           .ToArray();
            }
            else
            {
                ChannelInstance channelInstance = seriesInstance.Channel;
                DateTime        startTime       = channelInstance.ObservationRecord.StartTime;

                timeData = seriesInstance.OriginalValues
                           .Select(Convert.ToDouble)
                           .Select(seconds => (long)(seconds * TimeSpan.TicksPerSecond))
                           .Select(TimeSpan.FromTicks)
                           .Select(timeSpan => startTime + timeSpan)
                           .ToArray();
            }

            return(timeData);
        }
Beispiel #31
0
        /// <summary>
        /// Gets matrix pointers
        /// </summary>
        /// <param name="variables">Variables</param>
        /// <param name="solver">Solver</param>
        public void GetEquationPointers(VariableSet variables, Solver <double> solver)
        {
            variables.ThrowIfNull(nameof(variables));
            solver.ThrowIfNull(nameof(solver));

            BranchEq = variables.Create(Name.Combine("branch"), VariableType.Current).Index;

            // Get matrix elements
            PosBranchPtr = solver.GetMatrixElement(PosNode, BranchEq);
            BranchPosPtr = solver.GetMatrixElement(BranchEq, PosNode);
            NegBranchPtr = solver.GetMatrixElement(NegNode, BranchEq);
            BranchNegPtr = solver.GetMatrixElement(BranchEq, NegNode);

            // Get rhs elements
            BranchPtr = solver.GetRhsElement(BranchEq);
        }
        /// <summary>
        /// Gets matrix pointers
        /// </summary>
        /// <param name="solver">Solver</param>
        public override void GetEquationPointers(Solver <Complex> solver)
        {
            if (solver == null)
            {
                throw new ArgumentNullException(nameof(solver));
            }

            // Get matrix elements
            PosBranchPtr = solver.GetMatrixElement(_posNode, _branchEq);
            BranchPosPtr = solver.GetMatrixElement(_branchEq, _posNode);
            NegBranchPtr = solver.GetMatrixElement(_negNode, _branchEq);
            BranchNegPtr = solver.GetMatrixElement(_branchEq, _negNode);

            // Get rhs elements
            BranchPtr = solver.GetRhsElement(_branchEq);
        }
Beispiel #33
0
        private UIComponent buildValueMemberField(Type type, IProperty property, VectorElement element)
        {
            Container field = new Container();
            field.Tint.Value = Color.Black;

            field.Add(new Binding<float, bool>(field.Opacity, x => x ? 1.0f : 0.5f, field.Highlighted));

            TextElement textField = new TextElement();
            textField.FontFile.Value = "Font";
            field.Children.Add(textField);

            field.Add(new CommandBinding<Point>(field.MouseLeftDown, delegate(Point mouse)
            {
                field.SwallowMouseEvents.Value = true;
                field.MouseLocked.Value = true;
            }));
            field.Add(new CommandBinding<Point>(field.MouseLeftUp, delegate(Point mouse)
            {
                field.SwallowMouseEvents.Value = false;
                field.MouseLocked.Value = false;
            }));

            if (type.Equals(typeof(Vector2)))
            {
                Property<Vector2> socket = (Property<Vector2>)property;
                field.Add(new CommandBinding<Point, int>(field.MouseScrolled, () => this.selectedStringProperty == null && field.MouseLocked, delegate(Point mouse, int scroll)
                {
                    this.NeedsSave.Value = true;
                    float delta = scroll * (this.EnablePrecision ? EditorUI.precisionDelta : EditorUI.normalDelta);
                    socket.Value = socket.Value.SetElement(element, socket.Value.GetElement(element) + delta);
                }));
                textField.Add(new Binding<string, Vector2>(textField.Text, x => x.GetElement(element).ToString("F"), socket));
            }
            else if (type.Equals(typeof(Vector3)))
            {
                Property<Vector3> socket = (Property<Vector3>)property;
                field.Add(new CommandBinding<Point, int>(field.MouseScrolled, () => this.selectedStringProperty == null && field.MouseLocked, delegate(Point mouse, int scroll)
                {
                    this.NeedsSave.Value = true;
                    float delta = scroll * (this.EnablePrecision ? EditorUI.precisionDelta : EditorUI.normalDelta);
                    socket.Value = socket.Value.SetElement(element, socket.Value.GetElement(element) + delta);
                }));
                textField.Add(new Binding<string, Vector3>(textField.Text, x => x.GetElement(element).ToString("F"), socket));
            }
            else if (type.Equals(typeof(Vector4)))
            {
                Property<Vector4> socket = (Property<Vector4>)property;
                field.Add(new CommandBinding<Point, int>(field.MouseScrolled, () => this.selectedStringProperty == null && field.MouseLocked, delegate(Point mouse, int scroll)
                {
                    this.NeedsSave.Value = true;
                    float delta = scroll * (this.EnablePrecision ? EditorUI.precisionDelta : EditorUI.normalDelta);
                    socket.Value = socket.Value.SetElement(element, socket.Value.GetElement(element) + delta);
                }));
                textField.Add(new Binding<string, Vector4>(textField.Text, x => x.GetElement(element).ToString("F"), socket));
            }
            else if (type.Equals(typeof(Quaternion)))
            {
                Property<Quaternion> socket = (Property<Quaternion>)property;
                field.Add(new CommandBinding<Point, int>(field.MouseScrolled, () => this.selectedStringProperty == null && field.MouseLocked, delegate(Point mouse, int scroll)
                {
                    this.NeedsSave.Value = true;
                    float delta = scroll * (this.EnablePrecision ? EditorUI.precisionDelta : EditorUI.normalDelta);
                    socket.Value = socket.Value.SetElement(element, socket.Value.GetElement(element) + delta);
                }));
                textField.Add(new Binding<string, Quaternion>(textField.Text, x => x.GetElement(element).ToString("F"), socket));
            }
            else if (type.Equals(typeof(Color)))
            {
                Property<Color> socket = (Property<Color>)property;
                field.Add(new CommandBinding<Point, int>(field.MouseScrolled, () => this.selectedStringProperty == null && field.MouseLocked, delegate(Point mouse, int scroll)
                {
                    this.NeedsSave.Value = true;
                    socket.Value = socket.Value.SetElement(element, (byte)Math.Max(0, Math.Min(255, socket.Value.GetElement(element) + scroll)));
                }));
                textField.Add(new Binding<string, Color>(textField.Text, x => x.GetElement(element).ToString(), socket));
            }

            return field;
        }
Beispiel #34
0
 public static byte GetElement(this Color v, VectorElement element)
 {
     switch (element)
     {
         case VectorElement.X:
             return v.R;
         case VectorElement.Y:
             return v.G;
         case VectorElement.Z:
             return v.B;
         case VectorElement.W:
             return v.A;
         default:
             throw new Exception("Tried to get non-existent element from color.");
     }
 }
Beispiel #35
0
 public override void OnVectorElementClicked(VectorElement element, double x, double y,  bool longClick)
 {
     Log.Debug ("NT", "OnVectorElementClicked "  + x + " " + y + " " + element+ " " + longClick);
 }
Beispiel #36
0
 public static Color SetElement(this Color v, VectorElement element, byte value)
 {
     switch (element)
     {
         case VectorElement.X:
             return new Color(value, v.G, v.B, v.A);
         case VectorElement.Y:
             return new Color(v.R, value, v.B, v.A);
         case VectorElement.Z:
             return new Color(v.R, v.G, value, v.A);
         case VectorElement.W:
             return new Color(v.R, v.G, v.B, value);
         default:
             throw new Exception("Tried to set non-existent element in color.");
     }
 }
Beispiel #37
0
 public override void OnLabelClicked(VectorElement element, bool longClick)
 {
     Log.Debug ("NT", "OnLabelClicked " + element+ " " + longClick);
 }
Beispiel #38
0
 public abstract void VisitVectorSingleElement(VectorElement element);
Beispiel #39
0
 public override void VisitVectorSingleElement(VectorElement element)
 {
     //throw new NotImplementedException();
 }
Beispiel #40
0
 public override void VisitVectorSingleElement(VectorElement element)
 {
     try
     {
         VectorElement temp = element;
         if (inParallelFor == 1)
         {
             if (parallelVars.Contains(element.getVar().getText()))
             {
             }
             else
             {
                 vectorData(element.getVar().getText());
             }
             parallelString.Append(temp.getVar().getText());
             parallelString.Append("[");
             if (temp.getRange() is VariableElement)
                 parallelString.Append(((VariableElement)temp.getRange()).getText());
             else if (temp.getRange() is IntegerElement)
                 parallelString.Append(((IntegerElement)temp.getRange()).getText());
             parallelString.Append("]");
             
         }
         else
         {
             PerformVectorSingleElementOperation(element);
         }
     }
     catch (Exception e) { sendres(112, "Error in vector element\n"); e.GetType(); }
 
 }
Beispiel #41
0
 public static Quaternion SetElement(this Quaternion v, VectorElement element, float value)
 {
     switch (element)
     {
         case VectorElement.X:
             return new Quaternion(value, v.Y, v.Z, v.W);
         case VectorElement.Y:
             return new Quaternion(v.X, value, v.Z, v.W);
         case VectorElement.Z:
             return new Quaternion(v.X, v.Y, value, v.W);
         case VectorElement.W:
             return new Quaternion(v.X, v.Y, v.Z, value);
         default:
             throw new Exception("Tried to set non-existent element in vector.");
     }
 }
Beispiel #42
0
 public void PerformVectorSingleElementOperation(VectorElement temp)
 {
     if (map_contains_matrix(temp.getVar().getText()))
     {
         VectorVariableDeclaration matTemp = null;
         if (temp != null)
         {
             matTemp = (VectorVariableDeclaration)mVariableMap[temp.getVar().getText()];
             int loc = getIndex(temp);
             
             if (matTemp != null)
             {
                 if (loc < int.Parse(matTemp.getRange().getText()))
                 {
                     if (matTemp.getType() == "int")
                     {
                         int val = matTemp.getintValueat(loc);
                         IntegerElement elem = new IntegerElement();
                         elem.setText(val.ToString());
                         mat_stack.Push(elem);
                     }
                     else if (matTemp.getType() == "double")
                     {
                         double val = matTemp.getdoubleValueat(loc);
                         DoubleElement elem = new DoubleElement();
                         elem.setText(val.ToString());
                         mat_stack.Push(elem);
                     }
                 }
                 else
                 {
                     Console.Write("Range out of bound\n");
                     sendres(112, "Range out of bound\n");
                 }
             }
         }
     }
 }
Beispiel #43
0
 private int getIndex(VectorElement temp)
 {
     try
     {
         if (temp.getRange() is IntegerElement)
         {
             string r = ((IntegerElement)temp.getRange()).getText();
             return int.Parse(r);
         }
         else
         {
             string r = ((IntegerElement)(mVariableMap[((VariableElement)temp.getRange()).getText()])).getText();
             return int.Parse(r);
         }
     }
     catch (Exception e) { sendres(112, "Invalid index\n"); e.GetType(); return 0; }
 }