Exemplo n.º 1
0
        /// <summary>
        /// Generate a mutual inductance
        /// </summary>
        /// <param name="name">Name</param>
        /// <param name="parameters">Parameters</param>
        /// <param name="netlist">Netlist</param>
        /// <returns></returns>
        protected ICircuitObject GenerateMut(CircuitIdentifier name, List <Token> parameters, Netlist netlist)
        {
            MutualInductance mut = new MutualInductance(name);

            switch (parameters.Count)
            {
            case 0: throw new ParseException($"Inductor name expected for mutual inductance \"{name}\"");

            case 1: throw new ParseException(parameters[0], "Inductor name expected", false);

            case 2: throw new ParseException(parameters[1], "Coupling factor expected", false);
            }

            // Read two inductors
            if (!ReaderExtension.IsName(parameters[0]))
            {
                throw new ParseException(parameters[0], "Component name expected");
            }
            mut.MUTind1 = new CircuitIdentifier(parameters[0].image);
            if (!ReaderExtension.IsName(parameters[1]))
            {
                throw new ParseException(parameters[1], "Component name expected");
            }
            mut.MUTind2 = new CircuitIdentifier(parameters[1].image);
            mut.MUTcoupling.Set(netlist.ParseDouble(parameters[2]));
            return(mut);
        }
        /// <summary>
        /// Generates a new mutual inductance.
        /// </summary>
        /// <param name="name">The name of generated mutual inductance.</param>
        /// <param name="parameters">Parameters and pins for mutual inductance.</param>
        /// <param name="context">Reading context.</param>
        /// <returns>
        /// A new instance of mutual inductance.
        /// </returns>
        protected SpiceSharp.Components.Component GenerateMut(string name, ParameterCollection parameters, ICircuitContext context)
        {
            var mut = new MutualInductance(name);

            switch (parameters.Count)
            {
            case 0:
                context.Result.Validation.Add(new ValidationEntry(ValidationEntrySource.Reader,
                                                                  ValidationEntryLevel.Warning,
                                                                  $"Inductor name expected for mutual inductance \"{name}\"", parameters.LineInfo));
                return(null);

            case 1:
                context.Result.Validation.Add(new ValidationEntry(ValidationEntrySource.Reader,
                                                                  ValidationEntryLevel.Warning,
                                                                  $"Inductor name expected", parameters.LineInfo));
                return(null);

            case 2:
                context.Result.Validation.Add(new ValidationEntry(ValidationEntrySource.Reader,
                                                                  ValidationEntryLevel.Warning,
                                                                  $"Coupling factor expected", parameters.LineInfo));
                return(null);
            }

            if (!(parameters[0] is SingleParameter))
            {
                context.Result.Validation.Add(new ValidationEntry(ValidationEntrySource.Reader,
                                                                  ValidationEntryLevel.Warning,
                                                                  $"Component name expected", parameters.LineInfo));
                return(null);
            }

            if (!(parameters[1] is SingleParameter))
            {
                context.Result.Validation.Add(new ValidationEntry(ValidationEntrySource.Reader,
                                                                  ValidationEntryLevel.Warning,
                                                                  $"Component name expected", parameters.LineInfo));
                return(null);
            }

            mut.InductorName1 = parameters.Get(0).Image;
            mut.InductorName2 = parameters.Get(1).Image;

            context.SetParameter(mut, "k", parameters.Get(2));

            return(mut);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BindingContext" /> class.
 /// </summary>
 /// <param name="component">The component that creates the behavior.</param>
 /// <param name="simulation">The simulation for which the behavior is created.</param>
 /// <param name="behaviors">The created behaviors.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="component"/>, <paramref name="simulation"/> or <paramref name="behaviors"/> is <c>null</c>.</exception>
 public BindingContext(MutualInductance component, ISimulation simulation, IBehaviorContainer behaviors)
     : base(component, simulation, behaviors)
 {
     Inductor1Behaviors = simulation.EntityBehaviors[component.InductorName1.ThrowIfNull(nameof(component.InductorName1))];
     Inductor2Behaviors = simulation.EntityBehaviors[component.InductorName2.ThrowIfNull(nameof(component.InductorName2))];
 }