/// <summary> /// Load the device in the circuit /// </summary> /// <param name="ckt">The circuit</param> public override void Load(Circuit ckt) { var state = ckt.State; var rstate = state.Real; double time = 0.0; double value = 0.0; rstate.Matrix[VSRCposNode, VSRCbranch] += 1.0; rstate.Matrix[VSRCbranch, VSRCposNode] += 1.0; rstate.Matrix[VSRCnegNode, VSRCbranch] -= 1.0; rstate.Matrix[VSRCbranch, VSRCnegNode] -= 1.0; if (state.Domain == CircuitState.DomainTypes.Time) { if (ckt.Method != null) { time = ckt.Method.Time; } // Use the waveform if possible if (VSRCwaveform != null) { value = VSRCwaveform.At(time); } else { value = VSRCdcValue * state.SrcFact; } } else { value = VSRCdcValue * state.SrcFact; } rstate.Rhs[VSRCbranch] += value; }
/// <summary> /// Accept the current timepoint as the solution /// </summary> /// <param name="ckt">The circuit</param> public override void Accept(Circuit ckt) { if (VSRCwaveform != null) { VSRCwaveform.Accept(ckt); } }
/// <summary> /// Setup the voltage source /// </summary> /// <param name="ckt">The circuit</param> public override void Setup(Circuit ckt) { // Bind the nodes var nodes = BindNodes(ckt); VSRCposNode = nodes[0].Index; VSRCnegNode = nodes[1].Index; VSRCbranch = CreateNode(ckt, Name.Grow("#branch"), CircuitNode.NodeType.Current).Index; // Setup the waveform if specified VSRCwaveform?.Setup(ckt); }
/// <summary> /// Constructor /// </summary> /// <param name="name">The name of the voltage source</param> /// <param name="pos">The positive node</param> /// <param name="neg">The negative node</param> /// <param name="w">The waveform</param> public Voltagesource(string name, string pos, string neg, Waveform w) : base(name, 2) { Connect(pos, neg); VSRCwaveform.Set(w); }