Beispiel #1
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 });
        }
Beispiel #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 <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));
        }
Beispiel #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(ICurrentControlledBindingContext context)
            : base(context)
        {
            context.ThrowIfNull(nameof(context));
            context.Nodes.CheckNodes(2);

            Parameters = context.GetParameterSet <Parameters>();
            _biasing   = context.GetState <IBiasingSimulationState>();
            _variables = new OnePort <double>(_biasing, context);
            _control   = context.ControlBehaviors.GetValue <IBranchedBehavior <double> >().Branch;
            Branch     = _biasing.CreatePrivateVariable(Name.Combine("branch"), Units.Ampere);

            var pos = _biasing.Map[_variables.Positive];
            var neg = _biasing.Map[_variables.Negative];
            var cbr = _biasing.Map[_control];
            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, cbr));
        }