public void CanAddClonedDevice() { var device = new Resistor(5); builder.AddDevice(new[] { 1, 2 }, device); builder.AddDevice(new[] { 1, 2 }, device.Clone()); }
/// <summary>Processes given set of statements.</summary> protected override void DoProcess() { var name = DeviceName; var nodes = GetNodeIds(1, 2); if (RawStatement.Length < 4) { return; // nothing more to do here } ICircuitDefinitionDevice device; if (char.IsDigit(RawStatement[3].Value[0]) || RawStatement[3].Value[0] == '-' || RawStatement[3].Value[0] == '+' ) // constant source { var val = GetValue(3); device = GetDevice(new ConstantBehavior { Value = val }, name); } else // tran function { var paramTokens = Utils.Parser.Retokenize(RawStatement, 3).ToList(); device = GetDevice(GetBehaviorParam(paramTokens), name); } if (Errors == 0) { CircuitBuilder.AddDevice(nodes, device); } }
/// <summary>Adds a resistor between specified nodes.</summary> /// <param name="builder">The builder.</param> /// <param name="nodes">Array of connections of the subcircuit.</param> /// <param name="subcircuit">Resistance of the resistor in ohms.</param> /// <param name="tag">Tag to identify the device.</param> /// <returns></returns> public static CircuitBuilder AddSubcircuit(this CircuitBuilder builder, int[] nodes, ISubcircuitDefinition subcircuit, object tag = null) { builder.AddDevice(nodes, new Subcircuit(subcircuit, tag)); return(builder); }
/// <summary>Adds a diode between specified nodes.</summary> /// <param name="builder">The builder.</param> /// <param name="n1">Positive node of the device.</param> /// <param name="n2">Negative node of the device.</param> /// <param name="config">Function for configuring device model parameters.</param> /// <param name="tag">Tag to identify the device.</param> /// <returns></returns> public static CircuitBuilder AddDiode(this CircuitBuilder builder, int n1, int n2, Action <DiodeParams> config, object tag = null) { var param = DiodeParams.Default; config(param); builder.AddDevice(new[] { n1, n2 }, new Diode(param, tag)); return(builder); }
/// <summary>Adds a diode between specified nodes.</summary> /// <param name="builder">The builder.</param> /// <param name="nCollector">Collector node of the device.</param> /// <param name="nBase">Base node of the device.</param> /// <param name="nEmitter">Emitter node of the device.</param> /// <param name="config">Function for configuring device model parameters.</param> /// <param name="tag">Tag to identify the device.</param> /// <returns></returns> public static CircuitBuilder AddBjt(this CircuitBuilder builder, int nCollector, int nBase, int nEmitter, Action <BjtParams> config, object tag = null) { var param = BjtParams.Default; config(param); builder.AddDevice(new[] { nCollector, nBase, nEmitter, 0 }, new Bjt(param, tag)); return(builder); }
/// <summary>Processes given set of statements.</summary> protected override void DoProcess() { var name = DeviceName; var nodes = GetNodeIds(1, 2); var rvalue = GetValue(3); if (Errors == 0) { CircuitBuilder.AddDevice(nodes, new Resistor(rvalue, name)); } }
/// <summary>Processes given set of statements.</summary> protected override void DoProcess() { var name = DeviceName; var nodes = GetNodeIds(1, 4); var gain = GetValue(5); if (Errors == 0) { CircuitBuilder.AddDevice(nodes, new Vccs(gain, name)); } }
/// <summary>Processes given set of statements.</summary> protected override void DoProcess() { var name = DeviceName; var nodes = GetNodeIds(1, 2); var cvalue = GetValue(3); var ic = GetInitialCondition(); if (Errors == 0) { CircuitBuilder.AddDevice(nodes, new Capacitor(cvalue, ic, name)); } }
public static void SimpleSubcircuit() { var builder = new CircuitBuilder(); var batteryDefinition = builder .AddVoltageSource(1, 2, 9) .AddResistor(2, 3, 1.5) .BuildSubcircuit(new[] { 1, 3 }); builder.Clear(); builder .AddDevice(new[] { 0, 1 }, new Subcircuit(batteryDefinition)) .AddSubcircuit(new[] { 0, 1 }, batteryDefinition); }
public static void Simple() { // requires NextGenSpice.Core.Circuit and // NextGenSpice.Core.Devices namespace var builder = new CircuitBuilder(); builder .AddDevice(new[] { 1, 0 }, new VoltageSource(12, "VS")) .AddDevice(new[] { 0, 2 }, new Resistor(10)) .AddDevice(new[] { 1, 2 }, new Resistor(10)) .AddDevice(new[] { 2, 3 }, new Resistor(5)) .AddDevice(new[] { 1, 3 }, new Resistor(5)); var circuit = builder.BuildCircuit(); // var builder = new CircuitBuilder(); // builder // .AddVoltageSource(1, 0, 12) // .AddResistor(0, 2, 10) // .AddResistor(1, 2, 10) // .AddResistor(2, 3, 5) // .AddResistor(1, 3, 5); // var circuit = builder.BuildCircuit(); var model = circuit.GetLargeSignalModel(); // equivalent to var m = AnalysisModelCreator .Instance.Create <LargeSignalCircuitModel>(circuit); // builder // .AddVoltageSource(1, 0, 12, "VS") //// .AddDevice(new[] { 1, 0 }, new VoltageSourceDevice(12, "VS")) //// ... model.EstablishDcBias(); Console.WriteLine(model.NodeVoltages[1]); // 12 V Console.WriteLine(model.NodeVoltages[2]); // 8 V Console.WriteLine(model.NodeVoltages[3]); // 10 V // equivalent to // var vsource = (ITwoTerminalLargeSignalDevice) model.Devices.Single( // dev => dev.DefinitionDevice.Tag.Equals("VS")); var vsouce = (ITwoTerminalLargeSignalDevice)model.FindDevice("VS"); Console.WriteLine(vsouce.Current); // -0.8 V }
/// <summary>Adds an inductor between specified nodes.</summary> /// <param name="builder">The builder.</param> /// <param name="n1">Positive node of the device.</param> /// <param name="n2">Negative node of the device.</param> /// <param name="inductance">Inductance of the inductor in henry.</param> /// <param name="initialCurrent">Initial current across the inductor.</param> /// <param name="tag">Tag to identify the device.</param> /// <returns></returns> public static CircuitBuilder AddInductor(this CircuitBuilder builder, int n1, int n2, double inductance, double?initialCurrent = null, object tag = null) { builder.AddDevice(new[] { n1, n2 }, new Inductor(inductance, initialCurrent, tag)); return(builder); }
/// <summary>Adds a constant voltage source between specified nodes.</summary> /// <param name="builder">The builder.</param> /// <param name="n1">Positive node of the device.</param> /// <param name="n2">Negative node of the device.</param> /// <param name="voltage">Voltage of the source in volts.</param> /// <param name="tag">Tag to identify the device.</param> /// <returns></returns> public static CircuitBuilder AddVoltageSource(this CircuitBuilder builder, int n1, int n2, double voltage, object tag = null) { builder.AddDevice(new[] { n1, n2 }, new VoltageSource(voltage, tag)); return(builder); }
/// <summary>Adds a diode between specified nodes.</summary> /// <param name="builder">The builder.</param> /// <param name="n1">Positive node of the device.</param> /// <param name="n2">Negative node of the device.</param> /// <param name="param">Model parameters of the device.</param> /// <param name="tag">Tag to identify the device.</param> /// <returns></returns> public static CircuitBuilder AddDiode(this CircuitBuilder builder, int n1, int n2, DiodeParams param, object tag = null) { builder.AddDevice(new[] { n1, n2 }, new Diode(param, tag)); return(builder); }
/// <summary>Adds a behaviored current source between specified nodes.</summary> /// <param name="builder">The builder.</param> /// <param name="n1">Positive node of the device.</param> /// <param name="n2">Negative node of the device.</param> /// <param name="param">Parameters of the desired behavior.</param> /// <param name="tag">Tag to identify the device.</param> /// <returns></returns> public static CircuitBuilder AddCurrentSource(this CircuitBuilder builder, int n1, int n2, InputSourceBehavior param, object tag = null) { builder.AddDevice(new[] { n1, n2 }, new CurrentSource(param, tag)); return(builder); }
/// <summary>Adds a constant current source between specified nodes.</summary> /// <param name="builder">The builder.</param> /// <param name="n1">Positive node of the device.</param> /// <param name="n2">Negative node of the device.</param> /// <param name="current">Current of the source in ampers.</param> /// <param name="tag">Tag to identify the device.</param> /// <returns></returns> public static CircuitBuilder AddCurrentSource(this CircuitBuilder builder, int n1, int n2, double current, object tag = null) { builder.AddDevice(new[] { n1, n2 }, new CurrentSource(current, tag)); return(builder); }
/// <summary>Adds a capacitor between specified nodes.</summary> /// <param name="builder">The builder.</param> /// <param name="n1">Positive node of the device.</param> /// <param name="n2">Negative node of the device.</param> /// <param name="capacitance">Capacitance of the capacitor in farads.</param> /// <param name="initialVoltage">Initial voltage across the capacitor.</param> /// <param name="tag">Tag to identify the device.</param> /// <returns></returns> public static CircuitBuilder AddCapacitor(this CircuitBuilder builder, int n1, int n2, double capacitance, double?initialVoltage = null, object tag = null) { builder.AddDevice(new[] { n1, n2 }, new Capacitor(capacitance, initialVoltage, tag)); return(builder); }
/// <summary>Adds a diode between specified nodes.</summary> /// <param name="builder">The builder.</param> /// <param name="nCollector">Collector node of the device.</param> /// <param name="nBase">Base node of the device.</param> /// <param name="nEmitter">Emitter node of the device.</param> /// <param name="param">Model parameters of the device.</param> /// <param name="tag">Tag to identify the device.</param> /// <returns></returns> public static CircuitBuilder AddBjt(this CircuitBuilder builder, int nCollector, int nBase, int nEmitter, BjtParams param, object tag = null) { builder.AddDevice(new[] { nCollector, nBase, nEmitter, 0 }, new Bjt(param, tag)); return(builder); }
/// <summary>Adds a resistor between specified nodes.</summary> /// <param name="builder">The builder.</param> /// <param name="n1">Positive node of the device.</param> /// <param name="n2">Negative node of the device.</param> /// <param name="resistance">Resistance of the resistor in ohms.</param> /// <param name="tag">Tag to identify the device.</param> /// <returns></returns> public static CircuitBuilder AddResistor(this CircuitBuilder builder, int n1, int n2, double resistance, object tag = null) { builder.AddDevice(new[] { n1, n2 }, new Resistor(resistance, tag)); return(builder); }