Пример #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 <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)
            });
        }
Пример #2
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)
            });
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Biasing"/> class.
        /// </summary>
        /// <param name="context">The binding context.</param>
        public Time(IComponentBindingContext context)
            : base(context)
        {
            context.ThrowIfNull(nameof(context));
            context.Nodes.CheckNodes(4);

            var _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[] {
                new MatrixLocation(pos, br),
                new MatrixLocation(neg, br),
                new MatrixLocation(br, pos),
                new MatrixLocation(br, neg),
                new MatrixLocation(br, contPos),
                new MatrixLocation(br, contNeg)
            }, new[] { br });
        }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Frequency"/> class.
        /// </summary>
        /// <param name="context">The binding context.</param>
        public Frequency(IComponentBindingContext context)
            : base(context)
        {
            context.ThrowIfNull(nameof(context));
            context.Nodes.CheckNodes(LaplaceVoltageControlledVoltageSource.PinCount);

            var bstate = context.GetState <IBiasingSimulationState>();

            _dblVariables = new TwoPort <double>(bstate, context);
            var pos     = bstate.Map[_dblVariables.Right.Positive];
            var neg     = bstate.Map[_dblVariables.Right.Negative];
            var contPos = bstate.Map[_dblVariables.Left.Positive];
            var contNeg = bstate.Map[_dblVariables.Left.Negative];

            _dblElements = new ElementSet <double>(bstate.Solver, new[] {
                new MatrixLocation(pos, contPos),
                new MatrixLocation(pos, contNeg),
                new MatrixLocation(neg, contPos),
                new MatrixLocation(neg, contNeg)
            });

            var cstate = context.GetState <IComplexSimulationState>();

            _cplxVariables = new TwoPort <Complex>(cstate, context);
            pos            = cstate.Map[_cplxVariables.Right.Positive];
            neg            = cstate.Map[_cplxVariables.Right.Negative];
            contPos        = cstate.Map[_cplxVariables.Left.Positive];
            contNeg        = cstate.Map[_cplxVariables.Left.Negative];
            _cplxElements  = new ElementSet <Complex>(cstate.Solver, new[] {
                new MatrixLocation(pos, contPos),
                new MatrixLocation(pos, contNeg),
                new MatrixLocation(neg, contPos),
                new MatrixLocation(neg, contNeg)
            });
        }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OnePort{T}"/> struct.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="context">The context.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
 /// <exception cref="NodeMismatchException">Thrown if <paramref name="context"/> does not define exactly 2 nodes.</exception>
 public OnePort(IVariableFactory <IVariable <T> > factory, IComponentBindingContext context)
 {
     context
     .ThrowIfNull(nameof(context))
     .Nodes.CheckNodes(2);
     Positive = factory.GetSharedVariable(context.Nodes[0]);
     Negative = factory.GetSharedVariable(context.Nodes[1]);
 }
Пример #6
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>();
 }
Пример #7
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>();
        }
Пример #8
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));
        }
Пример #9
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 });
        }
Пример #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Biasing"/> class.
        /// </summary>
        /// <param name="context">The binding context.</param>
        public Frequency(IComponentBindingContext context)
            : base(context)
        {
            context.ThrowIfNull(nameof(context));
            context.Nodes.CheckNodes(4);

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

            _dblVariables = new TwoPort <double>(state, context);
            _dblBranch    = state.CreatePrivateVariable(Name.Combine("branch"), Units.Ampere);
            var pos     = state.Map[_dblVariables.Right.Positive];
            var neg     = state.Map[_dblVariables.Right.Negative];
            var contPos = state.Map[_dblVariables.Left.Positive];
            var contNeg = state.Map[_dblVariables.Left.Negative];
            var br      = state.Map[_dblBranch];

            _dblElements = new ElementSet <double>(state.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));

            var cstate = context.GetState <IComplexSimulationState>();

            _cplxVariables = new TwoPort <Complex>(cstate, context);
            _cplxBranch    = cstate.CreatePrivateVariable(Name.Combine("branch"), Units.Ampere);
            pos            = cstate.Map[_cplxVariables.Right.Positive];
            neg            = cstate.Map[_cplxVariables.Right.Negative];
            contPos        = cstate.Map[_cplxVariables.Left.Positive];
            contNeg        = cstate.Map[_cplxVariables.Left.Negative];
            br             = cstate.Map[_cplxBranch];
            _cplxElements  = new ElementSet <Complex>(cstate.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));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Time"/> class.
        /// </summary>
        /// <param name="context"></param>
        public Time(IComponentBindingContext context)
            : base(context)
        {
            context.ThrowIfNull(nameof(context));
            context.Nodes.CheckNodes(LaplaceVoltageControlledVoltageSource.PinCount);

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

            _variables = new TwoPort <double>(state, context);
            var pos     = state.Map[_variables.Right.Positive];
            var neg     = state.Map[_variables.Right.Negative];
            var contPos = state.Map[_variables.Left.Positive];
            var contNeg = state.Map[_variables.Left.Negative];

            _elements = new ElementSet <double>(state.Solver, new[] {
                new MatrixLocation(pos, contPos),
                new MatrixLocation(pos, contNeg),
                new MatrixLocation(neg, contPos),
                new MatrixLocation(neg, contNeg)
            }, new[] { pos, neg });
        }
Пример #12
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;
        }
Пример #13
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)
            });
        }
Пример #14
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));
        }
Пример #15
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>();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="BuilderCreatedEventArgs{T}"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="builder">The builder.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> or <paramref name="builder"/> is <c>null</c>.</exception>
 public BuilderCreatedEventArgs(IComponentBindingContext context, IFunctionBuilder <T> builder)
 {
     Context = context.ThrowIfNull(nameof(builder));
     Builder = builder.ThrowIfNull(nameof(builder));
 }
Пример #17
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>();
 }