Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Frequency"/> class.
 /// </summary>
 /// <param name="context">The binding context.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
 public Frequency(IComponentBindingContext context)
     : base(context)
 {
     _complex   = context.GetState <IComplexSimulationState>();
     _variables = new OnePort <Complex>(_complex, context);
     _elements  = new ElementSet <Complex>(_complex.Solver, null, _variables.GetRhsIndices(_complex.Map));
 }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Frequency"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
 public Frequency(IComponentBindingContext context) : base(context)
 {
     _complex         = context.GetState <IComplexSimulationState>();
     ComplexVariables = new DiodeVariables <Complex>(Name, _complex, context);
     _elements        = new ElementSet <Complex>(_complex.Solver,
                                                 ComplexVariables.GetMatrixLocations(_complex.Map));
 }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Frequency"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
        public Frequency(IComponentBindingContext context)
            : base(context)
        {
            _complex = context.GetState <IComplexSimulationState>();

            CollectorPrime = _complex.GetSharedVariable(context.Nodes[0]);
            BasePrime      = _complex.GetSharedVariable(context.Nodes[1]);
            EmitterPrime   = _complex.GetSharedVariable(context.Nodes[2]);
            _collectorNode = _complex.Map[CollectorPrime];
            _baseNode      = _complex.Map[BasePrime];
            _emitterNode   = _complex.Map[EmitterPrime];
            _substrateNode = _complex.Map[_complex.GetSharedVariable(context.Nodes[3])];

            // Add a series collector node if necessary
            if (ModelParameters.CollectorResistance > 0)
            {
                CollectorPrime = _complex.CreatePrivateVariable(Name.Combine("col"), Units.Volt);
            }
            _collectorPrimeNode = _complex.Map[CollectorPrime];

            // Add a series base node if necessary
            if (ModelParameters.BaseResist > 0)
            {
                BasePrime = _complex.CreatePrivateVariable(Name.Combine("base"), Units.Volt);
            }
            _basePrimeNode = _complex.Map[BasePrime];

            // Add a series emitter node if necessary
            if (ModelParameters.EmitterResistance > 0)
            {
                EmitterPrime = _complex.CreatePrivateVariable(Name.Combine("emit"), Units.Volt);
            }
            _emitterPrimeNode = _complex.Map[EmitterPrime];

            _elements = new ElementSet <Complex>(_complex.Solver,
                                                 new MatrixLocation(_collectorNode, _collectorNode),
                                                 new MatrixLocation(_baseNode, _baseNode),
                                                 new MatrixLocation(_emitterNode, _emitterNode),
                                                 new MatrixLocation(_collectorPrimeNode, _collectorPrimeNode),
                                                 new MatrixLocation(_basePrimeNode, _basePrimeNode),
                                                 new MatrixLocation(_emitterPrimeNode, _emitterPrimeNode),
                                                 new MatrixLocation(_collectorNode, _collectorPrimeNode),
                                                 new MatrixLocation(_baseNode, _basePrimeNode),
                                                 new MatrixLocation(_emitterNode, _emitterPrimeNode),
                                                 new MatrixLocation(_collectorPrimeNode, _collectorNode),
                                                 new MatrixLocation(_collectorPrimeNode, _basePrimeNode),
                                                 new MatrixLocation(_collectorPrimeNode, _emitterPrimeNode),
                                                 new MatrixLocation(_basePrimeNode, _baseNode),
                                                 new MatrixLocation(_basePrimeNode, _collectorPrimeNode),
                                                 new MatrixLocation(_basePrimeNode, _emitterPrimeNode),
                                                 new MatrixLocation(_emitterPrimeNode, _emitterNode),
                                                 new MatrixLocation(_emitterPrimeNode, _collectorPrimeNode),
                                                 new MatrixLocation(_emitterPrimeNode, _basePrimeNode),
                                                 new MatrixLocation(_substrateNode, _substrateNode),
                                                 new MatrixLocation(_collectorPrimeNode, _substrateNode),
                                                 new MatrixLocation(_substrateNode, _collectorPrimeNode),
                                                 new MatrixLocation(_baseNode, _collectorPrimeNode),
                                                 new MatrixLocation(_collectorPrimeNode, _baseNode));
        }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Frequency"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
 public Frequency(IComponentBindingContext context)
     : base(context)
 {
     context.Nodes.CheckNodes(2);
     _complex   = context.GetState <IComplexSimulationState>();
     _variables = new OnePort <Complex>(_complex, context);
     _elements  = new ElementSet <Complex>(_complex.Solver, _variables.GetMatrixLocations(_complex.Map));
 }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Frequency"/> class.
 /// </summary>
 /// <param name="context">The binding context.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
 public Frequency(IComponentBindingContext context)
     : base(context)
 {
     ModelParameters = context.ModelBehaviors.GetParameterSet <ModelParameters>();
     Behavior        = context.Behaviors.GetValue <IMosfetBiasingBehavior>();
     _complex        = context.GetState <IComplexSimulationState>();
     Variables       = new MosfetVariables <Complex>(context, _complex);
     _elements       = new ElementSet <Complex>(_complex.Solver, Variables.GetMatrixLocations(_complex.Map));
 }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Frequency"/> class.
 /// </summary>
 /// <param name="context">The binding context.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
 public Frequency(IComponentBindingContext context)
     : base(context)
 {
     ModelParameters = context.ModelBehaviors.GetParameterSet <ModelParameters>();
     Behavior        = context.Behaviors.GetValue <IMosfetBiasingBehavior>();
     _complex        = context.GetState <IComplexSimulationState>();
     Variables       = new MosfetVariables <Complex>(Name, _complex, context.Nodes,
                                                     !ModelParameters.DrainResistance.Equals(0.0) || !ModelParameters.SheetResistance.Equals(0.0) && Behavior.Parameters.DrainSquares > 0,
                                                     !ModelParameters.SourceResistance.Equals(0.0) || !ModelParameters.SheetResistance.Equals(0.0) && Behavior.Parameters.SourceSquares > 0);
     _elements = new ElementSet <Complex>(_complex.Solver, Variables.GetMatrixLocations(_complex.Map));
 }
Пример #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Frequency"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
        public Frequency(BindingContext context)
            : base(context)
        {
            _complex = context.GetState <IComplexSimulationState>();
            _branch1 = context.Inductor1Behaviors.GetValue <IBranchedBehavior <Complex> >().Branch;
            _branch2 = context.Inductor2Behaviors.GetValue <IBranchedBehavior <Complex> >().Branch;

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

            _elements = new ElementSet <Complex>(_complex.Solver,
                                                 new MatrixLocation(br1, br2),
                                                 new MatrixLocation(br2, br1));
        }
Пример #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Frequency"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
        public Frequency(ICurrentControlledBindingContext context)
            : base(context)
        {
            _complex = context.GetState <IComplexSimulationState>();

            _variables = new OnePort <Complex>(_complex, context);
            _control   = context.ControlBehaviors.GetValue <IBranchedBehavior <Complex> >().Branch;

            var pos = _complex.Map[_variables.Positive];
            var neg = _complex.Map[_variables.Negative];
            var br  = _complex.Map[_control];

            _elements = new ElementSet <Complex>(_complex.Solver,
                                                 new MatrixLocation(pos, br),
                                                 new MatrixLocation(neg, br));
        }
Пример #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FrequencyBehavior"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
        public FrequencyBehavior(IComponentBindingContext context)
            : base(context)
        {
            _complex   = context.GetState <IComplexSimulationState>();
            _variables = new TwoPort <Complex>(_complex, context);

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

            _elements = new ElementSet <Complex>(_complex.Solver,
                                                 new MatrixLocation(pos, contPos),
                                                 new MatrixLocation(pos, contNeg),
                                                 new MatrixLocation(neg, contPos),
                                                 new MatrixLocation(neg, contNeg));
        }
Пример #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Frequency"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
        public Frequency(IComponentBindingContext context)
            : base(context)
        {
            _complex   = context.GetState <IComplexSimulationState>();
            _variables = new OnePort <Complex>(_complex, context);
            Branch     = _complex.CreatePrivateVariable(Name.Combine("branch"), Units.Ampere);

            var pos = _complex.Map[_variables.Positive];
            var neg = _complex.Map[_variables.Negative];
            var br  = _complex.Map[Branch];

            _elements = new ElementSet <Complex>(_complex.Solver,
                                                 new MatrixLocation(pos, br),
                                                 new MatrixLocation(neg, br),
                                                 new MatrixLocation(br, neg),
                                                 new MatrixLocation(br, pos),
                                                 new MatrixLocation(br, br));
        }
Пример #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Frequency" /> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
        public Frequency(IComponentBindingContext context)
            : base(context)
        {
            _complex = context.GetState <IComplexSimulationState>();

            _pos1 = _complex.Map[_complex.GetSharedVariable(context.Nodes[0])];
            _neg1 = _complex.Map[_complex.GetSharedVariable(context.Nodes[1])];
            _pos2 = _complex.Map[_complex.GetSharedVariable(context.Nodes[2])];
            _neg2 = _complex.Map[_complex.GetSharedVariable(context.Nodes[3])];

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

            _elements = new ElementSet <Complex>(_complex.Solver,
                                                 new MatrixLocation(_pos1, _pos1),
                                                 new MatrixLocation(_pos1, _int1),
                                                 new MatrixLocation(_neg1, _br1),
                                                 new MatrixLocation(_pos2, _pos2),
                                                 new MatrixLocation(_neg2, _br2),
                                                 new MatrixLocation(_int1, _pos1),
                                                 new MatrixLocation(_int1, _int1),
                                                 new MatrixLocation(_int1, _br1),
                                                 new MatrixLocation(_int2, _int2),
                                                 new MatrixLocation(_int2, _br2),
                                                 new MatrixLocation(_br1, _neg1),
                                                 new MatrixLocation(_br1, _pos2),
                                                 new MatrixLocation(_br1, _neg2),
                                                 new MatrixLocation(_br1, _int1),
                                                 new MatrixLocation(_br1, _br2),
                                                 new MatrixLocation(_br2, _pos1),
                                                 new MatrixLocation(_br2, _neg1),
                                                 new MatrixLocation(_br2, _neg2),
                                                 new MatrixLocation(_br2, _int2),
                                                 new MatrixLocation(_br2, _br1),
                                                 new MatrixLocation(_pos2, _int2),
                                                 new MatrixLocation(_int2, _pos2));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Frequency"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        public Frequency(BehavioralBindingContext context)
            : base(context)
        {
            var bp = context.GetParameterSet <Parameters>();

            _state     = context.GetState <IComplexSimulationState>();
            _variables = new OnePort <Complex>(
                _state.GetSharedVariable(context.Nodes[0]),
                _state.GetSharedVariable(context.Nodes[1]));

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

            builder.VariableFound += (sender, args) =>
            {
                if (args.Variable == null && DerivativeVariables.TryGetValue(args.Node, out var variable))
                {
                    args.Variable = new FuncVariable <Complex>(variable.Name, () => variable.Value, variable.Unit);
                }
            };
            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 = context.MapNode(_state, 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]));
                }
            }
            _derivatives         = derivatives.ToArray();
            _values              = new Complex[_derivatives.Length * 2];
            _derivativeVariables = derivativeVariables.ToArray();
            _elements            = new ElementSet <Complex>(_state.Solver, matLocs.ToArray());
        }
Пример #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Frequency"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
        public Frequency(IComponentBindingContext context)
            : base(context)
        {
            _complex = context.GetState <IComplexSimulationState>();

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

            _elements = new ElementSet <Complex>(_complex.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)
            });
        }
Пример #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Frequency"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
        public Frequency(IComponentBindingContext context)
            : base(context)
        {
            _complex = context.GetState <IComplexSimulationState>();

            _variables = new TwoPort <Complex>(_complex, context);
            int posNode     = _complex.Map[_variables.Right.Positive];
            int negNode     = _complex.Map[_variables.Right.Negative];
            int contPosNode = _complex.Map[_variables.Left.Positive];
            int contNegNode = _complex.Map[_variables.Left.Negative];

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

            _elements = new ElementSet <Complex>(_complex.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)
            });
        }
Пример #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Frequency"/> class.
 /// </summary>
 /// <param name="context">The binding context.</param>
 protected Frequency(IBindingContext context)
     : base(context)
 {
     _state = context.GetState <IComplexSimulationState>();
 }