Exemplo n.º 1
0
 /// <summary>Performs necessary initialization of the device, like mapping to the equation system.</summary>
 /// <param name="adapter">The equation system builder.</param>
 /// <param name="context">Context of current simulation.</param>
 public override void Initialize(IEquationSystemAdapter adapter, ISimulationContext context)
 {
     stamper.Register(adapter, Anode, Cathode);
     voltage.Register(adapter, Anode, Cathode);
     firstDcPoint      = true;
     IntegrationMethod = context.SimulationParameters.IntegrationMethodFactory.CreateInstance();
 }
Exemplo n.º 2
0
        /// <inheritdoc/>
        public IWaveform Create(IBindingContext context)
        {
            IIntegrationMethod method = null;

            context?.TryGetState <IIntegrationMethod>(out method);
            return(new Instance(Points, method));
        }
Exemplo n.º 3
0
        /// <inheritdoc/>
        public IWaveform Create(IBindingContext context)
        {
            IIntegrationMethod method = null;
            TimeParameters     tp     = null;

            context?.TryGetState(out method);
            context?.TryGetSimulationParameterSet(out tp);
            double step = 1.0;

            if (!RiseTime.Given || !FallTime.Given)
            {
                if (tp is SpiceMethod sm)
                {
                    step = sm.InitialStep;
                }
                else if (tp != null)
                {
                    step = tp.StopTime / 50.0;
                }
            }
            return(new Instance(method,
                                InitialValue,
                                PulsedValue,
                                Delay,
                                RiseTime.Given ? RiseTime.Value : step,
                                FallTime.Given ? FallTime.Value : step,
                                PulseWidth,
                                Period));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Time"/> class.
        /// </summary>
        /// <param name="context">The binding context.</param>
        public Time(IBindingContext context)
            : base(context)
        {
            _bp = context.GetParameterSet <Parameters>();

            // Create derivatives for the numerator and denominator
            _state  = context.GetState <ITimeSimulationState>();
            _method = context.GetState <IIntegrationMethod>();
            if (_bp.Numerator.Length > 1)
            {
                _dNumerator = new IDerivative[_bp.Numerator.Length - 1];
                for (int i = 0; i < _dNumerator.Length; i++)
                {
                    _dNumerator[i] = _method.CreateDerivative();
                }
            }
            else
            {
                _dNumerator = null;
            }
            if (_bp.Denominator.Length > 1)
            {
                _dDenominator = new IDerivative[_bp.Denominator.Length - 1];
                for (int i = 0; i < _dDenominator.Length; i++)
                {
                    _dDenominator[i] = _method.CreateDerivative();
                }
            }
            else
            {
                _dDenominator = null;
            }
        }
Exemplo n.º 5
0
        /// <summary>Performs necessary initialization of the device, like mapping to the equation system.</summary>
        /// <param name="adapter">The equation system builder.</param>
        /// <param name="context">Context of current simulation.</param>
        public override void Initialize(IEquationSystemAdapter adapter, ISimulationContext context)
        {
            stamper.Register(adapter, bprimeNode, cprimeNode, eprimeNode);

            voltageBc.Register(adapter, bprimeNode, cprimeNode);
            voltageBe.Register(adapter, bprimeNode, eprimeNode);
            voltageCs.Register(adapter, cprimeNode, Substrate);

            capacbe.Register(adapter, bprimeNode, eprimeNode);
            capacbc.Register(adapter, bprimeNode, cprimeNode);
            capaccs.Register(adapter, cprimeNode, Substrate);

            chargebe = context.SimulationParameters.IntegrationMethodFactory.CreateInstance();
            chargebc = context.SimulationParameters.IntegrationMethodFactory.CreateInstance();
            chargecs = context.SimulationParameters.IntegrationMethodFactory.CreateInstance();

            gb.Register(adapter, bprimeNode, Base);
            gc.Register(adapter, cprimeNode, Collector);
            ge.Register(adapter, eprimeNode, Emitter);

            vT = PhysicalConstants.Boltzmann *
                 PhysicalConstants.CelsiusToKelvin(Parameters.NominalTemperature) /
                 PhysicalConstants.DevicearyCharge;

            VoltageBaseEmitter = DeviceHelpers.PnCriticalVoltage(Parameters.SaturationCurrent, vT);
        }
Exemplo n.º 6
0
            /// <summary>
            /// Initializes a new instance of the <see cref="Instance"/> class.
            /// </summary>
            /// <param name="method">The integration method.</param>
            /// <param name="vo">The offset.</param>
            /// <param name="va">The amplitude.</param>
            /// <param name="frequency">The frequency.</param>
            /// <param name="td">The delay.</param>
            /// <param name="theta">The theta.</param>
            /// <param name="phase">The phase.</param>
            public Instance(IIntegrationMethod method, double vo, double va, double frequency, double td, double theta, double phase)
            {
                _method = method;
                _vo     = vo;
                _va     = va;
                _freq   = frequency.GreaterThanOrEquals(nameof(frequency), 0) * 2.0 * Math.PI;
                _td     = td;
                _theta  = theta;
                _phase  = phase * Math.PI / 180;

                Value = _vo;
            }
Exemplo n.º 7
0
 public DerivativeTesterBehavior(IBindingContext context, Func <double, double> reference, double initial, double relTol, double absTol)
     : base(context)
 {
     _biasing    = context.GetState <IBiasingSimulationState>();
     _method     = context.GetState <IIntegrationMethod>();
     _time       = context.GetState <ITimeSimulationState>();
     _derivative = _method.CreateDerivative();
     _reference  = reference;
     _initial    = initial;
     _relTol     = relTol;
     _absTol     = absTol;
 }
Exemplo n.º 8
0
        /// <inheritdoc/>
        public IWaveform Create(IBindingContext context)
        {
            IIntegrationMethod method = null;
            TimeParameters     tp     = null;

            context?.TryGetState <IIntegrationMethod>(out method);
            context?.TryGetSimulationParameterSet <TimeParameters>(out tp);
            return(new Instance(method,
                                Offset,
                                Amplitude,
                                Frequency.Given ? Frequency.Value : 1.0 / (tp?.StopTime ?? 1.0),
                                Delay,
                                Theta,
                                Phase));
        }
Exemplo n.º 9
0
        /// <inheritdoc/>
        public IWaveform Create(IBindingContext context)
        {
            IIntegrationMethod method = null;
            TimeParameters     tp     = null;

            context?.TryGetState(out method);
            context?.TryGetSimulationParameterSet(out tp);
            return(new Instance(method,
                                Amplitude,
                                Offset,
                                ModulationFrequency,
                                CarrierFrequency.Given ? CarrierFrequency.Value : 1.0 / (tp?.StopTime ?? 1.0),
                                SignalDelay,
                                CarrierPhase,
                                SignalPhase));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Truncating"/> class.
        /// </summary>
        /// <param name="context">The sampler binding context.</param>
        public Truncating(SamplerBindingContext context)
            : base(context)
        {
            _parameters = context.GetParameterSet <Parameters>();
            _method     = context.GetState <IIntegrationMethod>();
            _points     = _parameters.Points.GetEnumerator();
            _continue   = _points.MoveNext();

            // Register to the export event
            context.RegisterToExportEvent(OnExportSimulationData);

            // Find the first timepoint that is eligible for targeting
            while (_continue && _points.Current < -_parameters.MinDelta)
            {
                _continue = _points.MoveNext();
            }
        }
Exemplo n.º 11
0
            /// <summary>
            /// Initializes a new instance of the <see cref="Instance"/> class.
            /// </summary>
            /// <param name="method">The integration method.</param>
            /// <param name="v1">The initial/low value.</param>
            /// <param name="v2">The pulsed/high value.</param>
            /// <param name="td">The delay.</param>
            /// <param name="tr">The rise time.</param>
            /// <param name="tf">The fall time.</param>
            /// <param name="pw">The pulse width.</param>
            /// <param name="per">The period.</param>
            public Instance(IIntegrationMethod method,
                            double v1, double v2, double td, double tr, double tf, double pw, double per)
            {
                _method = method;

                // Cache parameter values
                _v1  = v1;
                _v2  = v2;
                _td  = td.GreaterThanOrEquals(nameof(td), 0);
                _tr  = tr.GreaterThanOrEquals(nameof(tr), 0);
                _tf  = tf.GreaterThanOrEquals(nameof(tf), 0);
                _pw  = pw.GreaterThanOrEquals(nameof(pw), 0);
                _per = per.GreaterThanOrEquals(nameof(per), _tr + _pw + _tf);

                // Initialize the value
                At(0.0);
            }
Exemplo n.º 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Time"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
        public Time(BehavioralBindingContext context)
            : base(context)
        {
            var bp    = context.GetParameterSet <Parameters>();
            var state = context.GetState <IBiasingSimulationState>();

            _method = context.GetState <IIntegrationMethod>();
            _time   = context.GetState <ITimeSimulationState>();

            var derivatives         = new List <Func <double> >(Derivatives.Count);
            var derivativeVariables = new List <IVariable <double> >(Derivatives.Count);
            var builder             = new RealFunctionBuilder();

            builder.VariableFound += (sender, args) =>
            {
                if (args.Variable == null && DerivativeVariables.TryGetValue(args.Node, out var variable))
                {
                    args.Variable = variable;
                }
            };
            bp.RegisterBuilder(context, builder);
            var matLocs = new List <MatrixLocation>(Derivatives.Count * 2);
            var rhsLocs = Variables.GetRhsIndices(state.Map);

            foreach (var pair in Derivatives)
            {
                var variable = DerivativeVariables[pair.Key];
                if (state.Map.Contains(variable))
                {
                    derivatives.Add(builder.Build(pair.Value));
                    derivativeVariables.Add(variable);
                    matLocs.Add(new MatrixLocation(rhsLocs[0], state.Map[variable]));
                    matLocs.Add(new MatrixLocation(rhsLocs[1], state.Map[variable]));
                }
            }
            _value               = builder.Build(Function);
            _derivatives         = derivatives.ToArray();
            _values              = new double[_derivatives.Length * 2 + 2];
            _derivativeVariables = derivativeVariables.ToArray();

            // Get the matrix elements
            _elements = new ElementSet <double>(state.Solver, matLocs.ToArray(), rhsLocs);

            // Create the derivative
            _qcap = _method.CreateDerivative();
        }
Exemplo n.º 13
0
            /// <summary>
            /// Initializes a new instance of the <see cref="Instance"/> class.
            /// </summary>
            /// <param name="method">The integration method.</param>
            /// <param name="offset">The offset.</param>
            /// <param name="amplitude">The amplitude.</param>
            /// <param name="carrierFrequency">The carrier frequency.</param>
            /// <param name="modulationIndex">The modulation index.</param>
            /// <param name="signalFrequency">The signal frequency.</param>
            /// <param name="carrierPhase">The carrier phase.</param>
            /// <param name="signalPhase">The signal phase.</param>
            public Instance(IIntegrationMethod method,
                            double offset, double amplitude,
                            double carrierFrequency, double modulationIndex, double signalFrequency,
                            double carrierPhase, double signalPhase)
            {
                _method = method;
                _vo     = offset;
                _va     = amplitude;
                _fc     = carrierFrequency * Math.PI * 2.0;
                _mdi    = modulationIndex;
                _fs     = signalFrequency * Math.PI * 2.0;
                _phasec = carrierPhase * Math.PI / 180.0;
                _phases = signalPhase * Math.PI / 180.0;

                // Initialize the value
                At(0.0);
            }
Exemplo n.º 14
0
            /// <summary>
            /// Initializes a new instance of the <see cref="Instance"/> class.
            /// </summary>
            /// <param name="points">The points.</param>
            /// <param name="method">The integration method.</param>
            /// <exception cref="ArgumentException">Thrown if no points are specified, or if the time values are not monotonically increasing.</exception>
            public Instance(IEnumerable <Point> points, IIntegrationMethod method)
            {
                _method = method;
                _points = points.ThrowIfNull(nameof(points)).ToArray();
                if (_points.Length == 0)
                {
                    throw new ArgumentException(Properties.Resources.Waveforms_Pwl_Empty);
                }

                // Check monotonically increasing timepoints
                for (var i = 1; i < _points.Length; i++)
                {
                    if (_points[i - 1].Time >= _points[i].Time)
                    {
                        throw new ArgumentException(Properties.Resources.Waveforms_Pwl_NoIncreasingTimeValues);
                    }
                }
                _index = 0;

                Probe();
            }
Exemplo n.º 15
0
        private void integrateButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var    function = ExpressionParser.GetFunction(integrationFunctionInput.Text);
                double a        = double.Parse(integrationInputA.Text);
                double b        = double.Parse(integrationInputB.Text);
                if (b <= a)
                {
                    throw new ArgumentException($"Incorrect interval: [{a}; {b}]\nb must be greater then a");
                }

                int n = (int)integrNodesSlider.Value;

                IIntegrationMethod integrationMethod = null;
                if (integrationMethodSelect.SelectedIndex == 0)
                {
                    integrationMethod = new RectangleMethod();
                }
                else if (integrationMethodSelect.SelectedIndex == 1)
                {
                    integrationMethod = new TrapezoidMethod();
                }
                else if (integrationMethodSelect.SelectedIndex == 2)
                {
                    integrationMethod = new SimpsonsMethod();
                }

                double result = integrationMethod.Calculate(function, a, b, n);
                integrationResultText.Text = $"{result:f15}";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
        }
Exemplo n.º 16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Accept"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
 public Accept(IComponentBindingContext context)
     : base(context)
 {
     _method = context.GetState <IIntegrationMethod>();
 }
Exemplo n.º 17
0
 /// <inheritdoc />
 protected override void CreateStates()
 {
     base.CreateStates();
     _method = TimeParameters.Create(GetState <IBiasingSimulationState>());
 }
Exemplo n.º 18
0
 /// <inheritdoc/>
 public IWaveform Create(IIntegrationMethod method)
 {
     return(new Instance(method,
                         InitialValue, PulsedValue, Delay, RiseTime, FallTime, PulseWidth, Period));
 }
Exemplo n.º 19
0
 /// <inheritdoc/>
 public IWaveform Create(IIntegrationMethod method)
 {
     return(new Instance(Points, method));
 }
Exemplo n.º 20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Accept"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
 public Accept(IComponentBindingContext context)
     : base(context)
 {
     context.ThrowIfNull(nameof(context));
     _method = context.GetState <IIntegrationMethod>();
 }