Ejemplo n.º 1
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));
        }
Ejemplo n.º 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>();

            _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());
        }
Ejemplo n.º 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)
        {
            _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)
            });
        }