/// <summary> /// Unbind the behavior. /// </summary> public override void Unbind() { base.Unbind(); State = null; PosBranchPtr = null; NegBranchPtr = null; BranchPosPtr = null; BranchNegPtr = null; BranchControlPosPtr = null; BranchControlNegPtr = null; }
public double GetPower(BaseSimulationState state) { if (state == null) { throw new ArgumentNullException(nameof(state)); } var v = state.Solution[_posNode] - state.Solution[_negNode]; return(v * v * _bp.Coefficient); }
/// <summary> /// Unsetup the behavior. /// </summary> public override void Unbind() { base.Unbind(); // Remove events Load1.UpdateFlux -= UpdateFlux1; Load2.UpdateFlux -= UpdateFlux2; _state = null; Branch1Branch2 = null; Branch2Branch1 = null; }
public Complex GetPower(BaseSimulationState state) { if (state == null) { throw new ArgumentNullException(nameof(state)); } Complex v = state.Solution[_posNode] - state.Solution[_negNode]; Complex i = state.Solution[_contBranch] * _bp.Coefficient.Value; return(-v *Complex.Conjugate(i)); }
public virtual double GetPower(BaseSimulationState state) { if (state == null) { throw new ArgumentNullException(nameof(state)); } var value = CollectorCurrent * state.Solution[CollectorNode]; value += BaseCurrent * state.Solution[BaseNode]; value -= (CollectorCurrent + BaseCurrent) * state.Solution[EmitterNode]; return(value); }
/// <summary> /// Constructor /// </summary> /// <param name="inductance">Inductor</param> /// <param name="current">Current</param> /// <param name="flux">Flux</param> /// <param name="state">State</param> public UpdateFluxEventArgs(double inductance, double current, StateDerivative flux, BaseSimulationState state) { if (flux == null) { throw new ArgumentNullException(nameof(flux)); } Inductance = inductance; Current = current; OriginalFlux = flux.Current; Flux = flux; State = state ?? throw new ArgumentNullException(nameof(state)); }
/// <summary> /// Bind the behavior. for the specified simulation. /// </summary> /// <param name="simulation">The simulation.</param> /// <param name="context">The context.</param> public override void Bind(Simulation simulation, BindingContext context) { base.Bind(simulation, context); // Get parameters BaseParameters = context.GetParameterSet <BaseParameters>(); ModelParameters = context.GetParameterSet <ModelBaseParameters>("model"); // Get behaviors ModelTemperature = context.GetBehavior <ModelTemperatureBehavior>("model"); State = ((BaseSimulation)simulation).RealState; }
/// <summary> /// Unbind the behavior. /// </summary> public override void Unbind() { base.Unbind(); _bp = null; _state = null; _baseConfig = null; _aaPtr = null; _abPtr = null; _baPtr = null; _bbPtr = null; _aPtr = null; _bPtr = null; }
/// <summary> /// Bind the behavior. /// </summary> /// <param name="simulation">The simulation.</param> /// <param name="context">The data provider.</param> public override void Bind(Simulation simulation, BindingContext context) { base.Bind(simulation, context); // Get parameters BaseParameters = context.GetParameterSet <BaseParameters>(); if (context is ComponentBindingContext cc) { Pos1 = cc.Pins[0]; Neg1 = cc.Pins[1]; Pos2 = cc.Pins[2]; Neg2 = cc.Pins[3]; } State = ((BaseSimulation)simulation).RealState; var solver = State.Solver; var variables = simulation.Variables; Internal1 = variables.Create(Name.Combine("int1")).Index; Internal2 = variables.Create(Name.Combine("int2")).Index; BranchEq1 = variables.Create(Name.Combine("branch1"), VariableType.Current).Index; BranchEq2 = variables.Create(Name.Combine("branch2"), VariableType.Current).Index; Pos1Pos1Ptr = solver.GetMatrixElement(Pos1, Pos1); Pos1Int1Ptr = solver.GetMatrixElement(Pos1, Internal1); Int1Pos1Ptr = solver.GetMatrixElement(Internal1, Pos1); Int1Int1Ptr = solver.GetMatrixElement(Internal1, Internal1); Int1Ibr1Ptr = solver.GetMatrixElement(Internal1, BranchEq1); Ibr1Int1Ptr = solver.GetMatrixElement(BranchEq1, Internal1); Neg1Ibr1Ptr = solver.GetMatrixElement(Neg1, BranchEq1); Ibr1Neg1Ptr = solver.GetMatrixElement(BranchEq1, Neg1); Pos2Pos2Ptr = solver.GetMatrixElement(Pos2, Pos2); Pos2Int2Ptr = solver.GetMatrixElement(Pos2, Internal2); Int2Pos2Ptr = solver.GetMatrixElement(Internal2, Pos2); Int2Int2Ptr = solver.GetMatrixElement(Internal2, Internal2); Int2Ibr2Ptr = solver.GetMatrixElement(Internal2, BranchEq2); Ibr2Int2Ptr = solver.GetMatrixElement(BranchEq2, Internal2); Neg2Ibr2Ptr = solver.GetMatrixElement(Neg2, BranchEq2); Ibr2Neg2Ptr = solver.GetMatrixElement(BranchEq2, Neg2); // These pointers are only used to calculate the DC operating point Ibr1Pos1Ptr = solver.GetMatrixElement(BranchEq1, Pos1); Ibr1Pos2Ptr = solver.GetMatrixElement(BranchEq1, Pos2); Ibr1Neg2Ptr = solver.GetMatrixElement(BranchEq1, Neg2); Ibr2Ibr1Ptr = solver.GetMatrixElement(BranchEq2, BranchEq1); Ibr2Ibr2Ptr = solver.GetMatrixElement(BranchEq2, BranchEq2); }
/// <summary> /// Bind the behavior. /// </summary> /// <param name="simulation">The simulation.</param> /// <param name="context">The context.</param> public override void Bind(Simulation simulation, BindingContext context) { base.Bind(simulation, context); // Get parameters BaseParameters = context.GetParameterSet <CommonBehaviors.IndependentSourceParameters>(); // Setup the waveform BaseParameters.Waveform?.Setup(); if (!BaseParameters.DcValue.Given) { // No DC value: either have a transient value or none if (BaseParameters.Waveform != null) { CircuitWarning.Warning(this, "{0}: No DC value, transient time 0 value used".FormatString(Name)); BaseParameters.DcValue.RawValue = BaseParameters.Waveform.Value; } else { CircuitWarning.Warning(this, "{0}: No value, DC 0 assumed".FormatString(Name)); } } if (context is ComponentBindingContext cc) { PosNode = cc.Pins[0]; NegNode = cc.Pins[1]; } _state = ((BaseSimulation)simulation).RealState; var solver = _state.Solver; var variables = simulation.Variables; BranchEq = variables.Create(Name.Combine("branch"), VariableType.Current).Index; // Get matrix elements PosBranchPtr = solver.GetMatrixElement(PosNode, BranchEq); BranchPosPtr = solver.GetMatrixElement(BranchEq, PosNode); NegBranchPtr = solver.GetMatrixElement(NegNode, BranchEq); BranchNegPtr = solver.GetMatrixElement(BranchEq, NegNode); // Get rhs elements BranchPtr = solver.GetRhsElement(BranchEq); }
/// <summary> /// Bind the behavior. /// </summary> /// <param name="simulation">The simulation.</param> /// <param name="context">The context.</param> public override void Bind(Simulation simulation, BindingContext context) { base.Bind(simulation, context); _state = ((BaseSimulation)simulation).RealState; var solver = _state.Solver; PosPosPtr = solver.GetMatrixElement(PosNode, PosNode); NegNegPtr = solver.GetMatrixElement(NegNode, NegNode); NegPosPtr = solver.GetMatrixElement(NegNode, PosNode); PosNegPtr = solver.GetMatrixElement(PosNode, NegNode); PosPtr = solver.GetRhsElement(PosNode); NegPtr = solver.GetRhsElement(NegNode); var method = ((TimeSimulation)simulation).Method; QCap = method.CreateDerivative(); }
/// <summary> /// Bind behavior. /// </summary> /// <param name="simulation">The simulation.</param> /// <param name="context">Data provider</param> public override void Bind(Simulation simulation, BindingContext context) { base.Bind(simulation, context); // Get behaviors Load1 = context.GetBehavior <InductorBehaviors.TransientBehavior>("inductor1"); Load2 = context.GetBehavior <InductorBehaviors.TransientBehavior>("inductor2"); // Register events for modifying the flux through the inductors Load1.UpdateFlux += UpdateFlux1; Load2.UpdateFlux += UpdateFlux2; _state = ((BaseSimulation)simulation).RealState; var solver = _state.Solver; Branch1Branch2 = solver.GetMatrixElement(Load1.BranchEq, Load2.BranchEq); Branch2Branch1 = solver.GetMatrixElement(Load2.BranchEq, Load1.BranchEq); }
/// <summary> /// Bind the behavior. /// </summary> /// <param name="simulation">The simulation.</param> /// <param name="context">Data provider</param> public override void Bind(Simulation simulation, BindingContext context) { // Get parameters BaseParameters = context.GetParameterSet <BaseParameters>(); ModelBaseParameters modelParameters; if (context.TryGetParameterSet("model", out modelParameters)) { ModelParameters = modelParameters; } if (context is ComponentBindingContext cc) { PosNode = cc.Pins[0]; NegNode = cc.Pins[1]; } State = ((BaseSimulation)simulation).RealState; }
/// <summary> /// Bind the behavior. /// </summary> /// <param name="simulation">The simulation.</param> /// <param name="context">The context.</param> public override void Bind(Simulation simulation, BindingContext context) { base.Bind(simulation, context); // Get parameters BaseParameters = context.GetParameterSet <BaseParameters>(); if (context is ComponentBindingContext cc) { PosNode = cc.Pins[0]; NegNode = cc.Pins[1]; ContPosNode = cc.Pins[2]; ContNegNode = cc.Pins[3]; } _state = ((BaseSimulation)simulation).RealState; var solver = _state.Solver; PosControlPosPtr = solver.GetMatrixElement(PosNode, ContPosNode); PosControlNegPtr = solver.GetMatrixElement(PosNode, ContNegNode); NegControlPosPtr = solver.GetMatrixElement(NegNode, ContPosNode); NegControlNegPtr = solver.GetMatrixElement(NegNode, ContNegNode); }
/// <summary> /// Bind the behavior. /// </summary> /// <param name="simulation">The simulation.</param> /// <param name="context">The provider.</param> public override void Bind(Simulation simulation, BindingContext context) { base.Bind(simulation, context); // Get parameters. BaseParameters = context.GetParameterSet <BaseParameters>(); if (context is ComponentBindingContext cc) { PosNode = cc.Pins[0]; NegNode = cc.Pins[1]; } State = ((BaseSimulation)simulation).RealState; var solver = State.Solver; var variables = simulation.Variables; BranchEq = variables.Create(Name.Combine("branch"), VariableType.Current).Index; PosBranchPtr = solver.GetMatrixElement(PosNode, BranchEq); NegBranchPtr = solver.GetMatrixElement(NegNode, BranchEq); BranchNegPtr = solver.GetMatrixElement(BranchEq, NegNode); BranchPosPtr = solver.GetMatrixElement(BranchEq, PosNode); }
public double GetPower(BaseSimulationState state) { state.ThrowIfNull(nameof(state)); return(QCap.Derivative * (state.Solution[PosNode] - state.Solution[NegNode])); }
public double GetPower(BaseSimulationState state) { state.ThrowIfNull(nameof(state)); return(state.Solution[BranchEq] * (state.Solution[PosNode] - state.Solution[NegNode])); }
public double GetVoltage(BaseSimulationState state) { state.ThrowIfNull(nameof(state)); return(state.Solution[PosNode] - state.Solution[NegNode]); }
public double GetCurrent(BaseSimulationState state) { state.ThrowIfNull(nameof(state)); return(state.Solution[BranchEq]); }
public double GetPower(BaseSimulationState state) { state.ThrowIfNull(nameof(state)); return((state.Solution[PosNode] - state.Solution[PosNode]) * -Current); }
/// <summary> /// Setup the behavior /// </summary> public override void Bind(Simulation simulation, BindingContext context) { base.Bind(simulation, context); // Get configurations BaseConfiguration = simulation.Configurations.Get <BaseConfiguration>(); if (context is ComponentBindingContext cc) { DrainNode = cc.Pins[0]; GateNode = cc.Pins[1]; SourceNode = cc.Pins[2]; BulkNode = cc.Pins[3]; } _state = ((BaseSimulation)simulation).RealState; var solver = _state.Solver; var variables = simulation.Variables; if (ModelParameters.SheetResistance > 0 && BaseParameters.DrainSquares > 0.0) { DrainNodePrime = variables.Create(Name.Combine("drain")).Index; } else { DrainNodePrime = DrainNode; } DrainNodePrimePtr = solver.GetRhsElement(DrainNodePrime); if (ModelParameters.SheetResistance > 0 && BaseParameters.SourceSquares > 0.0) { SourceNodePrime = variables.Create(Name.Combine("source")).Index; } else { SourceNodePrime = SourceNode; } SourceNodePrimePtr = solver.GetRhsElement(SourceNodePrime); DdPtr = solver.GetMatrixElement(DrainNode, DrainNode); GgPtr = solver.GetMatrixElement(GateNode, GateNode); SsPtr = solver.GetMatrixElement(SourceNode, SourceNode); BbPtr = solver.GetMatrixElement(BulkNode, BulkNode); DPdpPtr = solver.GetMatrixElement(DrainNodePrime, DrainNodePrime); SPspPtr = solver.GetMatrixElement(SourceNodePrime, SourceNodePrime); DdpPtr = solver.GetMatrixElement(DrainNode, DrainNodePrime); GbPtr = solver.GetMatrixElement(GateNode, BulkNode); GdpPtr = solver.GetMatrixElement(GateNode, DrainNodePrime); GspPtr = solver.GetMatrixElement(GateNode, SourceNodePrime); SspPtr = solver.GetMatrixElement(SourceNode, SourceNodePrime); BdpPtr = solver.GetMatrixElement(BulkNode, DrainNodePrime); BspPtr = solver.GetMatrixElement(BulkNode, SourceNodePrime); DPspPtr = solver.GetMatrixElement(DrainNodePrime, SourceNodePrime); DPdPtr = solver.GetMatrixElement(DrainNodePrime, DrainNode); BgPtr = solver.GetMatrixElement(BulkNode, GateNode); DPgPtr = solver.GetMatrixElement(DrainNodePrime, GateNode); SPgPtr = solver.GetMatrixElement(SourceNodePrime, GateNode); SPsPtr = solver.GetMatrixElement(SourceNodePrime, SourceNode); DPbPtr = solver.GetMatrixElement(DrainNodePrime, BulkNode); SPbPtr = solver.GetMatrixElement(SourceNodePrime, BulkNode); SPdpPtr = solver.GetMatrixElement(SourceNodePrime, DrainNodePrime); GateNodePtr = solver.GetRhsElement(GateNode); BulkNodePtr = solver.GetRhsElement(BulkNode); }
/// <summary> /// Unbind the behavior. /// </summary> public override void Unbind() { base.Unbind(); State = null; }
/// <summary> /// Gets the value that is controlling the switch. /// </summary> /// <param name="state">The state.</param> /// <returns></returns> public override double GetValue(BaseSimulationState state) => state.Solution[ContPosNode] - state.Solution[ContNegNode];
public double GetCurrent(BaseSimulationState state) { state.ThrowIfNull(nameof(state)); return((state.Solution[PosNode] - state.Solution[NegNode]) * Conductance); }
public double GetPower(BaseSimulationState state) { state.ThrowIfNull(nameof(state)); return((state.Solution[PosNode] - state.Solution[NegNode]) * state.Solution[ControlBranchEq] * BaseParameters.Coefficient); }
public double GetCurrent(BaseSimulationState state) { state.ThrowIfNull(nameof(state)); return(state.Solution[ControlBranchEq] * BaseParameters.Coefficient); }
/// <summary> /// Gets the value that is controlling the switch. /// </summary> /// <param name="state">The state.</param> /// <returns></returns> public override double GetValue(BaseSimulationState state) => state.Solution[_loadBehavior.BranchEq];
/// <summary> /// Gets the value that is controlling the switch. /// </summary> /// <param name="state">The state.</param> /// <returns></returns> public abstract double GetValue(BaseSimulationState state);
/// <summary> /// Bind the behavior to the simulation. /// </summary> /// <param name="simulation">The simulation.</param> /// <param name="context">The binding context.</param> public override void Bind(Simulation simulation, BindingContext context) { base.Bind(simulation, context); // Get parameters BaseParameters = context.GetParameterSet <BaseParameters>(); // We are now going to parse the expression var parser = BaseParameters.Parser.ThrowIfNull("Parser")(simulation); var variables = simulation.Variables; // We want to keep track of derivatives, and which column they map to var map = new Dictionary <int, int>(); int Derivative(int index) { if (index <= 0) { return(-1); } if (!map.TryGetValue(index, out var d)) { map.Add(index, d = map.Count + 1); } return(d); }; // Catch the derivatives for Y-matrix loading void SpicePropertyFound(object sender, SpicePropertyFoundEventArgs <double> e) { var property = e.Property; if (BaseParameters.SpicePropertyComparer.Equals(property.Identifier, "V")) { // Only recognize V(a) or V(a, b) if (property.ArgumentCount != 1 && property.ArgumentCount != 2) { return; } // Get the nodes int index, refindex; if (BaseParameters.Instance != null && BaseParameters.Instance is ComponentInstanceData cid) { index = variables.MapNode(cid.GenerateNodeName(property[0])).Index; refindex = property.ArgumentCount > 1 ? variables.MapNode(cid.GenerateNodeName(property[1])).Index : 0; } else { index = variables.MapNode(property[0]).Index; refindex = property.ArgumentCount > 1 ? variables.MapNode(property[1]).Index : 0; } if (index != refindex) { if (index > 0 && refindex > 0) { e.Apply(null, Derivative(index), 1.0); e.Apply(() => _currentSolution[index] - _currentSolution[refindex], Derivative(refindex), -1.0); } else if (index > 0) { e.Apply(() => _currentSolution[index], Derivative(index), 1.0); } else if (refindex > 0) { e.Apply(() => - _currentSolution[refindex], Derivative(refindex), -1.0); } } } else if (BaseParameters.SpicePropertyComparer.Equals(property.Identifier, "I")) { // Only recognized I(xxx) if (property.ArgumentCount != 1) { return; } var component = property[0]; if (BaseParameters.Instance != null && BaseParameters.Instance is ComponentInstanceData cid) { component = cid.GenerateIdentifier(component); } // Get the voltage behavior to find the branch equation if (simulation.EntityBehaviors.TryGetBehaviors(component, out var ebd)) { // Check for voltage source behaviors if (ebd.TryGet <SpiceSharp.Components.VoltageSourceBehaviors.BiasingBehavior>(out var vsrcb)) { int index = vsrcb.BranchEq; e.Apply(() => _currentSolution[index], Derivative(index), 1.0); } else if (ebd.TryGet <SpiceSharp.Components.CurrentSourceBehaviors.BiasingBehavior>(out var isrcb)) { e.Apply(() => isrcb.Current); } } } }; parser.SpicePropertyFound += SpicePropertyFound; var parsedResult = parser.Parse(BaseParameters.Expression); parser.SpicePropertyFound -= SpicePropertyFound; Function = new BehavioralFunction(map, parsedResult); // Build the total method State = ((BaseSimulation)simulation).RealState; var solver = State.Solver; BuildFunctionMethod(solver); }
public double GetPower(BaseSimulationState state) { state.ThrowIfNull(nameof(state)); return(Current * Voltage); }