Example #1
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;
            }
        }
        /// <summary>
        /// Remap a variable node to an <see cref="IVariable{T}"/>.
        /// </summary>
        /// <typeparam name="T">the variable type.</typeparam>
        /// <param name="factory">The variable factory.</param>
        /// <param name="node">The node.</param>
        /// <param name="ownBranch">The branch.</param>
        /// <returns>The variable.</returns>
        public IVariable <T> MapNode <T>(IVariableFactory <IVariable <T> > factory, VariableNode node, IVariable <T> ownBranch = null)
        {
            switch (node.NodeType)
            {
            case NodeTypes.Voltage:
                return(factory.GetSharedVariable(node.Name));

            case NodeTypes.Current:
                var container = Simulation.EntityBehaviors[node.Name];
                if (container == Behaviors)
                {
                    if (ownBranch == null)
                    {
                        throw new SpiceSharpException($"The behavior for {Entity.Name} does not define a branch current.");
                    }
                    return(ownBranch);
                }
                else if (container.TryGetValue <IBranchedBehavior <T> >(out var branched))
                {
                    return(branched.Branch);
                }
                else if (typeof(T) == typeof(double) && container.TryGetValue(out IBiasingBehavior tmpb) && tmpb is CurrentSources.Biasing biasing)
                {
                    var result = new FuncVariable <double>($"I({biasing.Name})", () => biasing.Current, Units.Ampere);
                    return(result as IVariable <T>);
                }
                else if (typeof(T) == typeof(Complex) && container.TryGetValue(out IFrequencyBehavior tmpf) && tmpf is CurrentSources.Frequency frequency)
                {
                    var result = new FuncVariable <Complex>($"I({frequency.Name})", () => frequency.ComplexCurrent, Units.Ampere);
                    return(result as IVariable <T>);
                }
Example #3
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]);
 }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Rules"/> class.
        /// </summary>
        /// <param name="factory">The variable factory.</param>
        /// <param name="comparer">The comparer for variable names.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="factory"/> is <c>null</c>.</exception>
        public Rules(IVariableFactory <IVariable> factory, IEqualityComparer <string> comparer)
        {
            var ground = factory.ThrowIfNull(nameof(factory)).GetSharedVariable(Constants.Ground);

            _floatingNode   = new FloatingNodeRule(ground);
            _groundPresence = new VariablePresenceRule(ground);
            Parameters      = new ComponentRuleParameters(factory, comparer ?? Constants.DefaultComparer);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MosfetVariables{T}"/> struct.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="factory">The factory.</param>
 /// <param name="nodes">The nodes.</param>
 /// <param name="internalDrain">If set to <c>true</c>, an internal drain is created, otherwise, the external drain is used.</param>
 /// <param name="internalSource">If set to <c>true</c>, an internal source is created, otherwise, the external source is used.</param>
 public MosfetVariables(string name, IVariableFactory <IVariable <T> > factory, IReadOnlyList <string> nodes, bool internalDrain, bool internalSource)
 {
     nodes.CheckNodes(4);
     Drain       = factory.GetSharedVariable(nodes[0]);
     Gate        = factory.GetSharedVariable(nodes[1]);
     Source      = factory.GetSharedVariable(nodes[2]);
     Bulk        = factory.GetSharedVariable(nodes[3]);
     DrainPrime  = internalDrain ? factory.CreatePrivateVariable(name.Combine("drain"), Units.Volt) : Drain;
     SourcePrime = internalSource ? factory.CreatePrivateVariable(name.Combine("source"), Units.Volt) : Source;
 }
Example #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TwoPort{T}"/> struct.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="context">The context.</param>
 public TwoPort(IVariableFactory <IVariable <T> > factory, IComponentBindingContext context)
 {
     context.Nodes.CheckNodes(4);
     Right = new OnePort <T>(
         factory.GetSharedVariable(context.Nodes[0]),
         factory.GetSharedVariable(context.Nodes[1]));
     Left = new OnePort <T>(
         factory.GetSharedVariable(context.Nodes[2]),
         factory.GetSharedVariable(context.Nodes[3]));
 }
Example #7
0
        public IVariableFactory CreateVariableFactory()
        {
            IVariableFactory factory = null;

            try
            {
                factory = new VariableFactory();
            }
            catch (Exception exception)
            {
                this.Log.Error("Exception message: " + exception.Message + " and stacktrace " + exception.StackTrace);
            }

            return(factory);
        }
        public VariableStore(IEnumerable <Variable> seedVariables, IVariableFactory variableFactory)
        {
            _allVariables = new Dictionary <string, Variable>();

            // Seed the dictionary
            if (seedVariables != null)
            {
                foreach (var item in seedVariables)
                {
                    _allVariables.Add(item.VariableName, item);
                }
            }

            VariableFactory = variableFactory ?? new DefaultVariableFactory();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="VariableFactory"/> class.
        /// </summary>
        /// <param name="name">The subcircuit instance name.</param>
        /// <param name="nodes">The nodes.</param>
        /// <param name="parent">The parent.</param>
        /// <param name="comparer">The equality comparer for nodes.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="name"/>, <paramref name="parent"/> or <paramref name="nodes"/> is <c>null</c>.</exception>
        public VariableFactory(string name, IVariableFactory <IVariable> parent, IEnumerable <Bridge <string> > nodes, IEqualityComparer <string> comparer)
        {
            _name   = name.ThrowIfNull(nameof(name));
            _parent = parent.ThrowIfNull(nameof(parent));
            nodes.ThrowIfNull(nameof(nodes));

            _nodeMap = new Dictionary <string, string>(comparer)
            {
                { Constants.Ground, Constants.Ground }
            };
            foreach (var bridge in nodes)
            {
                _nodeMap.Add(bridge.Local, bridge.Global);
            }
        }
Example #10
0
        public IVariableFactory CreateVariableFactory()
        {
            IVariableFactory factory = null;

            try
            {
                factory = new VariableFactory();
            }
            catch (Exception exception)
            {
                this.Log.Error(
                    exception.Message,
                    exception);
            }

            return(factory);
        }
Example #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DiodeVariables{T}"/> struct.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="factory">The factory.</param>
        /// <param name="context">The context.</param>
        public DiodeVariables(string name, IVariableFactory <IVariable <T> > factory, IComponentBindingContext context)
        {
            context.Nodes.CheckNodes(2);

            var mbp = context.ModelBehaviors.GetParameterSet <ModelParameters>();

            Positive = factory.GetSharedVariable(context.Nodes[0]);
            Negative = factory.GetSharedVariable(context.Nodes[1]);

            if (mbp.Resistance > 0)
            {
                PosPrime = factory.CreatePrivateVariable(name.Combine("pos"), Units.Volt);
            }
            else
            {
                PosPrime = Positive;
            }
        }
 public VariableSet(IEnumerable <Variable> allVariables, IVariableFactory variableFactory = null) : base(allVariables, variableFactory)
 {
     NotifyChanges = true;
 }
 public VariableSet(IVariableFactory variableFactory = null) : base(null, variableFactory)
 {
     NotifyChanges = true;
 }
        /// <summary>
        /// Remap a variable node to an <see cref="IVariable{T}"/>.
        /// </summary>
        /// <typeparam name="T">the variable type.</typeparam>
        /// <param name="factory">The variable factory.</param>
        /// <param name="node">The node.</param>
        /// <param name="ownBranch">The branch.</param>
        /// <returns>The variable.</returns>
        public IVariable <T> MapNode <T>(IVariableFactory <IVariable <T> > factory, VariableNode node, IVariable <T> ownBranch = null)
        {
            switch (node.NodeType)
            {
            case NodeTypes.Voltage:
                return(factory.GetSharedVariable(node.Name));

            case NodeTypes.Current:
                IBehaviorContainer container;
                IBiasingBehavior   tmpb;
                IFrequencyBehavior tmpf;

                // Get the relevant behaviors
                if (Simulation.EntityBehaviors.Comparer.Equals(node.Name, Behaviors.Name))
                {
                    container = Behaviors;
                }
                else
                {
                    container = Simulation.EntityBehaviors[node.Name];
                }

                if (container == Behaviors)
                {
                    if (ownBranch == null)
                    {
                        throw new SpiceSharpException($"The behavior for {Entity.Name} does not define a branch current.");
                    }
                    return(ownBranch);
                }
                else if (container.TryGetValue <IBranchedBehavior <T> >(out var branched))
                {
                    // Best-case scenario! Our behaviors define a branched behavior!
                    return(branched.Branch);
                }
                else if (typeof(T) == typeof(double) && container.TryGetValue(out tmpb) && tmpb is CurrentSources.Biasing biasing)
                {
                    // If whatever is being is asked is the current from a current source, then we also don't have a problem
                    var result = new FuncVariable <double>($"I({biasing.Name})", () => biasing.Current, Units.Ampere);
                    return(result as IVariable <T>);
                }
                else if (typeof(T) == typeof(Complex) && container.TryGetValue(out tmpf) && tmpf is CurrentSources.Frequency frequency)
                {
                    // Current source = no problem
                    var result = new FuncVariable <Complex>($"I({frequency.Name})", () => frequency.ComplexCurrent, Units.Ampere);
                    return(result as IVariable <T>);
                }
                else
                {
                    var result = container.CreatePropertyGetter <T>("i");
                    if (result == null)
                    {
                        goto default;
                    }
                    SpiceSharpWarning.Warning(this, SpiceSharpBehavioral.Properties.Resources.LooseLinkCurrent.FormatString(container.Name));
                    return(new FuncVariable <T>($"@{container.Name}[i]", result, Units.Ampere));
                }

            default:
                throw new SpiceSharpException($"Could not determine the variable {node.Name}");
            }
        }
Example #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ComponentRuleParameters"/> class.
 /// </summary>
 /// <param name="factory">The variable factory.</param>
 /// <param name="comparer">The comparer for comparing variable names.</param>
 public ComponentRuleParameters(IVariableFactory <IVariable> factory, IEqualityComparer <string> comparer)
 {
     Factory  = factory.ThrowIfNull(nameof(factory));
     Comparer = comparer.ThrowIfNull(nameof(comparer));
 }
 public GeometryFactory(MapinfoSession MISession)
 {
     this.misession       = MISession;
     this.variablefactory = new VariableFactory(MISession);
 }
 public GeometryFactory(IMapinfoWrapper mapinfoInstance, IVariableFactory variableFactory)
 {
     this.wrapper         = mapinfoInstance;
     this.variablefactory = variableFactory;
 }
 internal GeometryFactory(MapinfoSession MISession, IVariableFactory variableFactory)
 {
     this.misession       = MISession;
     this.variablefactory = variableFactory;
 }