Exemplo n.º 1
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.º 2
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(IComponentBindingContext context)
            : base(context)
        {
            _time = context.GetState <ITimeSimulationState>();
            var method = context.GetState <IIntegrationMethod>();

            _capCharge = method.CreateDerivative();
        }
Exemplo n.º 3
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(IComponentBindingContext context)
     : base(context)
 {
     _time        = context.GetState <ITimeSimulationState>();
     _biasing     = context.GetState <IBiasingSimulationState>();
     _contPosNode = _biasing.Map[_biasing.GetSharedVariable(context.Nodes[2])];
     _contNegNode = _biasing.Map[_biasing.GetSharedVariable(context.Nodes[3])];
     _branchEq    = _biasing.Map[Branch];
     _elements    = new ElementSet <double>(_biasing.Solver, null, new[] { _branchEq });
     Signal       = new DelayedSignal(1, Parameters.Delay);
 }
Exemplo n.º 4
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.º 5
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(IComponentBindingContext context)
     : base(context)
 {
     _time     = context.GetState <ITimeSimulationState>();
     _pos1     = BiasingState.Map[BiasingState.GetSharedVariable(context.Nodes[0])];
     _neg1     = BiasingState.Map[BiasingState.GetSharedVariable(context.Nodes[1])];
     _pos2     = BiasingState.Map[BiasingState.GetSharedVariable(context.Nodes[2])];
     _neg2     = BiasingState.Map[BiasingState.GetSharedVariable(context.Nodes[3])];
     _br1      = BiasingState.Map[Branch1];
     _br2      = BiasingState.Map[Branch2];
     _elements = new ElementSet <double>(BiasingState.Solver, null, new[] { _br1, _br2 });
     Signals   = new DelayedSignal(2, Parameters.Delay);
 }
Exemplo n.º 6
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(IComponentBindingContext context) : base(context)
        {
            context.Nodes.CheckNodes(2);
            _biasing   = context.GetState <IBiasingSimulationState>();
            _time      = context.GetState <ITimeSimulationState>();
            _variables = new OnePort <double>(_biasing, context);
            _elements  = new ElementSet <double>(_biasing.Solver,
                                                 _variables.GetMatrixLocations(_biasing.Map),
                                                 _variables.GetRhsIndices(_biasing.Map));
            var method = context.GetState <IIntegrationMethod>();

            _qcap = method.CreateDerivative();
        }
Exemplo n.º 7
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(IComponentBindingContext context)
            : base(context)
        {
            var state = context.GetState <IBiasingSimulationState>();
            var br    = state.Map[Branch];

            _time     = context.GetState <ITimeSimulationState>();
            _elements = new ElementSet <double>(state.Solver, new[] {
                new MatrixLocation(br, br)
            }, new[] { br });

            var method = context.GetState <IIntegrationMethod>();

            _flux = method.CreateDerivative();
        }
Exemplo n.º 8
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.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Time"/> class.
        /// </summary>
        /// <param name="context">The binding context.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
        public Time(BindingContext context) : base(context)
        {
            _time = context.GetState <ITimeSimulationState>();
            var state = context.GetState <IBiasingSimulationState>();
            var load1 = context.Inductor1Behaviors.GetValue <Inductors.Time>();

            _branch1 = load1.Branch;
            var load2 = context.Inductor2Behaviors.GetValue <Inductors.Time>();

            _branch2 = load2.Branch;

            // Register events for modifying the flux through the inductors
            load1.UpdateFlux += UpdateFlux1;
            load2.UpdateFlux += UpdateFlux2;

            var br1 = state.Map[_branch1];
            var br2 = state.Map[_branch2];

            _elements = new ElementSet <double>(state.Solver,
                                                new MatrixLocation(br1, br2),
                                                new MatrixLocation(br2, br1));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Time"/> class.
        /// </summary>
        /// <param name="context">The binding context.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
        public Time(IComponentBindingContext context)
            : base(context)
        {
            context.ThrowIfNull(nameof(context));
            _time     = context.GetState <ITimeSimulationState>();
            _behavior = context.Behaviors.GetValue <IMosfetBiasingBehavior>();
            _mp       = context.ModelBehaviors.GetParameterSet <ModelParameters>();
            var method = context.GetState <IIntegrationMethod>();

            _vgs = new StateValue <double>(2); method.RegisterState(_vgs);
            _vds = new StateValue <double>(2); method.RegisterState(_vds);
            _vbs = new StateValue <double>(2); method.RegisterState(_vbs);
            _cgs = new StateValue <double>(2); method.RegisterState(_cgs);
            _cgd = new StateValue <double>(2); method.RegisterState(_cgd);
            _cgb = new StateValue <double>(2); method.RegisterState(_cgb);
            _qgs = method.CreateDerivative();
            _qgd = method.CreateDerivative();
            _qgb = method.CreateDerivative();
            _qbd = method.CreateDerivative();
            _qbs = method.CreateDerivative();
            _behavior.UpdateContributions += UpdateTime;
        }
Exemplo n.º 11
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(IComponentBindingContext context) : base(context)
        {
            _time = context.GetState <ITimeSimulationState>();
            var method = context.GetState <IIntegrationMethod>();

            _qgs = method.CreateDerivative();
            _qgd = method.CreateDerivative();

            _gateNode        = BiasingState.Map[BiasingState.GetSharedVariable(context.Nodes[1])];
            _drainPrimeNode  = BiasingState.Map[DrainPrime];
            _sourcePrimeNode = BiasingState.Map[SourcePrime];

            _elements = new ElementSet <double>(BiasingState.Solver, new[] {
                new MatrixLocation(_gateNode, _drainPrimeNode),
                new MatrixLocation(_gateNode, _sourcePrimeNode),
                new MatrixLocation(_drainPrimeNode, _gateNode),
                new MatrixLocation(_sourcePrimeNode, _gateNode),
                new MatrixLocation(_gateNode, _gateNode),
                new MatrixLocation(_drainPrimeNode, _drainPrimeNode),
                new MatrixLocation(_sourcePrimeNode, _sourcePrimeNode)
            }, new[] { _gateNode, _drainPrimeNode, _sourcePrimeNode });
        }