Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Biasing"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
        public Biasing(IComponentBindingContext context)
            : base(context)
        {
            context.ThrowIfNull(nameof(context));
            context.Nodes.CheckNodes(4);

            Parameters = context.GetParameterSet <VoltageDelayParameters>();
            var state = context.GetState <IBiasingSimulationState>();

            _posNode     = state.Map[state.GetSharedVariable(context.Nodes[0])];
            _negNode     = state.Map[state.GetSharedVariable(context.Nodes[1])];
            _contPosNode = state.Map[state.GetSharedVariable(context.Nodes[2])];
            _contNegNode = state.Map[state.GetSharedVariable(context.Nodes[3])];
            Branch       = state.CreatePrivateVariable(Name.Combine("branch"), Units.Ampere);
            _branchEq    = state.Map[Branch];

            BiasingElements = new ElementSet <double>(state.Solver, new[] {
                new MatrixLocation(_posNode, _branchEq),
                new MatrixLocation(_negNode, _branchEq),
                new MatrixLocation(_branchEq, _posNode),
                new MatrixLocation(_branchEq, _negNode),
                new MatrixLocation(_branchEq, _contPosNode),
                new MatrixLocation(_branchEq, _contNegNode)
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MosfetVariables{T}"/> struct.
        /// </summary>
        /// <param name="context">The binding context.</param>
        /// <param name="factory">The variable factory.</param>
        public MosfetVariables(IComponentBindingContext context, IVariableFactory <IVariable <T> > factory)
        {
            var nodes = context.Nodes.CheckNodes(4);

            Drain  = factory.GetSharedVariable(nodes[0]);
            Gate   = factory.GetSharedVariable(nodes[1]);
            Source = factory.GetSharedVariable(nodes[2]);
            Bulk   = factory.GetSharedVariable(nodes[3]);
            var bp  = context.GetParameterSet <Parameters>();
            var mbp = context.ModelBehaviors.GetParameterSet <ModelParameters>();

            if (!mbp.DrainResistance.Equals(0.0) || !mbp.SheetResistance.Equals(0.0) && bp.DrainSquares > 0)
            {
                DrainPrime = factory.CreatePrivateVariable(context.Behaviors.Name.Combine("drain"), Units.Volt);
            }
            else
            {
                DrainPrime = Drain;
            }

            if (!mbp.SourceResistance.Equals(0.0) || !mbp.SheetResistance.Equals(0.0) && bp.SourceSquares > 0)
            {
                SourcePrime = factory.CreatePrivateVariable(context.Behaviors.Name.Combine("source"), Units.Volt);
            }
            else
            {
                SourcePrime = Source;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Biasing"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
        public Biasing(IComponentBindingContext context)
            : base(context)
        {
            context.ThrowIfNull(nameof(context));
            context.Nodes.CheckNodes(4);

            Parameters = context.GetParameterSet <Parameters>();
            var state = context.GetState <IBiasingSimulationState>();

            Variables = new TwoPort <double>(state, context);
            int posNode     = state.Map[Variables.Right.Positive];
            int negNode     = state.Map[Variables.Right.Negative];
            int contPosNode = state.Map[Variables.Left.Positive];
            int contNegNode = state.Map[Variables.Left.Negative];

            Branch = state.CreatePrivateVariable(Name.Combine("branch"), Units.Ampere);
            int branchEq = state.Map[Branch];

            BiasingElements = new ElementSet <double>(state.Solver, new[] {
                new MatrixLocation(posNode, branchEq),
                new MatrixLocation(negNode, branchEq),
                new MatrixLocation(branchEq, posNode),
                new MatrixLocation(branchEq, negNode),
                new MatrixLocation(branchEq, contPosNode),
                new MatrixLocation(branchEq, contNegNode)
            });
        }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Temperature"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
 public Temperature(IComponentBindingContext context)
     : base(context)
 {
     context.ThrowIfNull(nameof(context));
     _temperature     = context.GetState <ITemperatureSimulationState>();
     ModelParameters  = context.ModelBehaviors.GetParameterSet <ModelParameters>();
     ModelTemperature = context.ModelBehaviors.GetValue <ModelTemperature>();
     Parameters       = context.GetParameterSet <Parameters>();
 }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Temperature"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
        public Temperature(IComponentBindingContext context) : base(context)
        {
            context.ThrowIfNull(nameof(context));

            // Get parameters
            Parameters = context.GetParameterSet <Parameters>();
            if (context.ModelBehaviors != null)
            {
                _mbp = context.ModelBehaviors.GetParameterSet <ModelParameters>();
            }

            // Connections
            _temperature = context.GetState <ITemperatureSimulationState>();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Biasing"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
        public Biasing(IComponentBindingContext context)
            : base(context)
        {
            context.ThrowIfNull(nameof(context));
            context.Nodes.CheckNodes(4);

            // Get parameters
            Parameters = context.GetParameterSet <Parameters>();
            Parameters.CalculateDefaults();
            BiasingState = context.GetState <IBiasingSimulationState>();
            _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])];

            Internal1 = BiasingState.CreatePrivateVariable(Name.Combine("int1"), Units.Volt);
            _int1     = BiasingState.Map[Internal1];
            Internal2 = BiasingState.CreatePrivateVariable(Name.Combine("int2"), Units.Volt);
            _int2     = BiasingState.Map[Internal2];
            Branch1   = BiasingState.CreatePrivateVariable(Name.Combine("branch1"), Units.Ampere);
            _br1      = BiasingState.Map[Branch1];
            Branch2   = BiasingState.CreatePrivateVariable(Name.Combine("branch2"), Units.Ampere);
            _br2      = BiasingState.Map[Branch2];

            BiasingElements = new ElementSet <double>(BiasingState.Solver,
                                                      new MatrixLocation(_pos1, _pos1),
                                                      new MatrixLocation(_pos1, _int1),
                                                      new MatrixLocation(_int1, _pos1),
                                                      new MatrixLocation(_int1, _int1),
                                                      new MatrixLocation(_int1, _br1),
                                                      new MatrixLocation(_br1, _int1),
                                                      new MatrixLocation(_neg1, _br1),
                                                      new MatrixLocation(_br1, _neg1),
                                                      new MatrixLocation(_pos2, _pos2),
                                                      new MatrixLocation(_pos2, _int2),
                                                      new MatrixLocation(_int2, _pos2),
                                                      new MatrixLocation(_int2, _int2),
                                                      new MatrixLocation(_int2, _br2),
                                                      new MatrixLocation(_br2, _int2),
                                                      new MatrixLocation(_neg2, _br2),
                                                      new MatrixLocation(_br2, _neg2),

                                                      // These are only used to calculate the biasing point
                                                      new MatrixLocation(_br1, _pos1),
                                                      new MatrixLocation(_br1, _pos2),
                                                      new MatrixLocation(_br1, _neg2),
                                                      new MatrixLocation(_br2, _br1),
                                                      new MatrixLocation(_br2, _br2));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BiasingBehavior"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
        public BiasingBehavior(IComponentBindingContext context)
            : base(context)
        {
            context.ThrowIfNull(nameof(context));

            Parameters = context.GetParameterSet <IndependentSourceParameters>();
            _iteration = context.GetState <IIterationSimulationState>();
            context.TryGetState(out _method);
            Waveform = Parameters.Waveform?.Create(_method);
            if (!Parameters.DcValue.Given)
            {
                // No DC value: either have a transient value or none
                if (Waveform != null)
                {
                    SpiceSharpWarning.Warning(this,
                                              Properties.Resources.IndependentSources_NoDcUseWaveform.FormatString(Name));
                    Parameters.DcValue = new GivenParameter <double>(Waveform.Value, false);
                }
                else
                {
                    SpiceSharpWarning.Warning(this,
                                              Properties.Resources.IndependentSources_NoDc.FormatString(Name));
                }
            }

            // Connections
            _biasing = context.GetState <IBiasingSimulationState>();
            context.TryGetState(out _method);

            _variables = new OnePort <double>(_biasing, context);
            Branch     = _biasing.CreatePrivateVariable(Name.Combine("branch"), Units.Ampere);
            var pos = _biasing.Map[_variables.Positive];
            var neg = _biasing.Map[_variables.Negative];
            var br  = _biasing.Map[Branch];

            _elements = new ElementSet <double>(_biasing.Solver, new[] {
                new MatrixLocation(pos, br),
                new MatrixLocation(br, pos),
                new MatrixLocation(neg, br),
                new MatrixLocation(br, neg)
            }, new[] { br });
        }
Exemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BiasingBehavior"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
        public BiasingBehavior(IComponentBindingContext context)
            : base(context)
        {
            context.ThrowIfNull(nameof(context));
            context.Nodes.CheckNodes(4);

            _biasing   = context.GetState <IBiasingSimulationState>();
            Parameters = context.GetParameterSet <Parameters>();
            _variables = new TwoPort <double>(_biasing, context);

            var pos     = _biasing.Map[_variables.Right.Positive];
            var neg     = _biasing.Map[_variables.Right.Negative];
            var contPos = _biasing.Map[_variables.Left.Positive];
            var contNeg = _biasing.Map[_variables.Left.Negative];

            _elements = new ElementSet <double>(_biasing.Solver, new[] {
                new MatrixLocation(pos, contPos),
                new MatrixLocation(pos, contNeg),
                new MatrixLocation(neg, contPos),
                new MatrixLocation(neg, contNeg)
            });
        }
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(IComponentBindingContext context)
            : base(context)
        {
            context.ThrowIfNull(nameof(context));
            _time     = context.GetState <ITimeSimulationState>();
            _behavior = context.Behaviors.GetValue <IMosfetBiasingBehavior>();
            _mp       = context.ModelBehaviors.GetParameterSet <ModelParameters>();
            _bp       = context.GetParameterSet <Parameters>();
            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.º 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Biasing"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
        public Biasing(IComponentBindingContext context) : base(context)
        {
            context.ThrowIfNull(nameof(context));

            Parameters = context.GetParameterSet <Parameters>();
            _biasing   = context.GetState <IBiasingSimulationState>();
            _iteration = context.GetState <IIterationSimulationState>();
            _variables = new OnePort <double>(_biasing, context);
            context.TryGetState <IIntegrationMethod>(out _method);
            Waveform = Parameters.Waveform?.Create(context);

            // Give some warnings if no value is given
            if (!Parameters.DcValue.Given)
            {
                // no DC value - either have a transient value or none
                SpiceSharpWarning.Warning(this,
                                          Waveform != null
                        ? Properties.Resources.IndependentSources_NoDcUseWaveform.FormatString(Name)
                        : Properties.Resources.IndependentSources_NoDc.FormatString(Name));
            }

            _elements = new ElementSet <double>(_biasing.Solver, null, _variables.GetRhsIndices(_biasing.Map));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Biasing"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
        public Biasing(IComponentBindingContext context)
            : base(context)
        {
            context.ThrowIfNull(nameof(context));
            context.Nodes.CheckNodes(4);

            Parameters = context.GetParameterSet <Parameters>();
            _biasing   = context.GetState <IBiasingSimulationState>();
            _variables = new TwoPort <double>(_biasing, context);
            Branch     = _biasing.CreatePrivateVariable(Name.Combine("branch"), Units.Ampere);
            var pos     = _biasing.Map[_variables.Right.Positive];
            var neg     = _biasing.Map[_variables.Right.Negative];
            var contPos = _biasing.Map[_variables.Left.Positive];
            var contNeg = _biasing.Map[_variables.Left.Negative];
            var br      = _biasing.Map[Branch];

            _elements = new ElementSet <double>(_biasing.Solver,
                                                new MatrixLocation(pos, br),
                                                new MatrixLocation(neg, br),
                                                new MatrixLocation(br, pos),
                                                new MatrixLocation(br, neg),
                                                new MatrixLocation(br, contPos),
                                                new MatrixLocation(br, contNeg));
        }
Exemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Temperature"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
 public Temperature(IComponentBindingContext context)
     : base(context)
 {
     context.ThrowIfNull(nameof(context));
     Parameters = context.GetParameterSet <Parameters>();
 }