/// <summary> /// Initializes a new instance of the <see cref="SpiceInstance"/> class. /// </summary> /// <param name="parameters">The method description.</param> /// <param name="state">The biasing simulation state.</param> /// <param name="maxOrder">The maximum order.</param> protected SpiceInstance(SpiceMethod parameters, IBiasingSimulationState state, int maxOrder) { Parameters = parameters.ThrowIfNull(nameof(parameters)); State = state.ThrowIfNull(nameof(state)); MaxOrder = maxOrder; States = new NodeHistory <SpiceIntegrationState>(maxOrder + 2); }
/// <summary> /// Initializes a new instance of the <see cref="ModelTemperature"/> class. /// </summary> /// <param name="context">The context.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception> public ModelTemperature(IBindingContext context) : base(context) { context.ThrowIfNull(nameof(context)); _temperature = context.GetState <ITemperatureSimulationState>(); Parameters = context.GetParameterSet <ModelParameters>(); BiasingState = context.GetState <IBiasingSimulationState>(); }
/// <summary> /// Initializes a new instance of the <see cref="Temperature"/> class. /// </summary> /// <param name="context">The context.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception> public Temperature(IComponentBindingContext context) : base(context) { context.ThrowIfNull(nameof(context)); _temperature = context.GetState <ITemperatureSimulationState>(); ModelTemperature = context.ModelBehaviors.GetValue <ModelTemperature>(); Parameters = context.GetParameterSet <Parameters>(); ModelParameters = context.ModelBehaviors.GetParameterSet <ModelParameters>(); BiasingState = context.GetState <IBiasingSimulationState>(); }
/// <summary> /// Initializes a new instance of the <see cref="Time"/> class. /// </summary> /// <param name="context">The context.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception> public Time(IComponentBindingContext context) : base(context) { _time = context.GetState <ITimeSimulationState>(); _biasing = context.GetState <IBiasingSimulationState>(); _contPosNode = _biasing.Map[_biasing.GetSharedVariable(context.Nodes[2])]; _contNegNode = _biasing.Map[_biasing.GetSharedVariable(context.Nodes[3])]; _branchEq = _biasing.Map[Branch]; _elements = new ElementSet <double>(_biasing.Solver, null, new[] { _branchEq }); Signal = new DelayedSignal(1, Parameters.Delay); }
public DerivativeTesterBehavior(IBindingContext context, Func <double, double> reference, double initial, double relTol, double absTol) : base(context) { _biasing = context.GetState <IBiasingSimulationState>(); _method = context.GetState <IIntegrationMethod>(); _time = context.GetState <ITimeSimulationState>(); _derivative = _method.CreateDerivative(); _reference = reference; _initial = initial; _relTol = relTol; _absTol = absTol; }
/// <inheritdoc /> public void Update(IBiasingSimulationState state, CircuitContext context, IDiagnosticHandler diagnostics) { var map = context.Nodes.Shorts; double x, y; if (state.TryGetValue(map[X], out var value)) { x = value.Value; } else { diagnostics?.Post(new DiagnosticMessage(SeverityLevel.Error, "U001", $"Could not find variable '{X}'.")); x = 0.0; } if (state.TryGetValue(map[Y], out value)) { y = value.Value; } else { diagnostics?.Post(new DiagnosticMessage(SeverityLevel.Error, "U001", $"Could not find variable '{X}'.")); y = 0.0; } Location = new(x, y); if (state.TryGetValue(map[_pins.Right], out value)) { x = value.Value; } else { diagnostics?.Post(new DiagnosticMessage(SeverityLevel.Error, "U001", $"Could not find variable '{X}'.")); x = 0.0; } if (state.TryGetValue(map[_pins.Bottom], out value)) { y = value.Value; } else { diagnostics?.Post(new DiagnosticMessage(SeverityLevel.Error, "U001", $"Could not find variable '{X}'.")); y = 0.0; } EndLocation = new(x, y); // Update all pin locations as well // We ignore pin 0, because that is a dummy pin for (int i = 1; i < _pins.Count; i++) { _pins[i].Update(state, context, diagnostics); } }
/// <summary> /// Initializes a new instance of the <see cref="Time"/> class. /// </summary> /// <param name="context">The context.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception> public Time(IComponentBindingContext context) : base(context) { context.Nodes.CheckNodes(2); _biasing = context.GetState <IBiasingSimulationState>(); _time = context.GetState <ITimeSimulationState>(); _variables = new OnePort <double>(_biasing, context); _elements = new ElementSet <double>(_biasing.Solver, _variables.GetMatrixLocations(_biasing.Map), _variables.GetRhsIndices(_biasing.Map)); var method = context.GetState <IIntegrationMethod>(); _qcap = method.CreateDerivative(); }
/// <inheritdoc /> public void Update(IBiasingSimulationState state, CircuitContext context, IDiagnosticHandler diagnostics) { double x = 0, y = 0; if (state.TryGetValue(context.Nodes.Shorts[X], out var xValue)) { x = xValue.Value; } if (state.TryGetValue(context.Nodes.Shorts[Y], out var yValue)) { y = yValue.Value; } Location = new(x, y); }
/// <summary> /// Initializes a new instance of the <see cref="ConvergenceAid"/> class. /// </summary> /// <param name="variable">The variable.</param> /// <param name="state">The biasing simulation state.</param> /// <param name="value">The value.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="variable"/> or <paramref name="state"/> is <c>null</c>.</exception> /// <exception cref="SpiceSharpException">Thrown if the variable for the convergence aid was not found.</exception> public ConvergenceAid(IVariable variable, IBiasingSimulationState state, double value) { Variable = variable.ThrowIfNull(nameof(variable)); Value = value; _state = state.ThrowIfNull(nameof(state)); if (!state.Map.Contains(variable)) { throw new SpiceSharpException(Properties.Resources.Simulations_ConvergenceAidVariableNotFound.FormatString(variable.Name)); } _index = state.Map[variable]; _diagonal = _state.Solver.GetElement(new MatrixLocation(_index, _index)); _rhs = !Value.Equals(0.0) ? _state.Solver.GetElement(_index) : _state.Solver.FindElement(_index); _state.Solution[_index] = Value; }
/// <summary> /// Initializes a new instance of the <see cref="Biasing" /> class. /// </summary> /// <param name="context">The context for the behavior.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">Thrown if the simulation does not define an <see cref="IComplexSimulationState"/>.</exception> /// <exception cref="TypeNotFoundException">Thrown if the controlling entity does not have a behavior of type <see cref="IBranchedBehavior{T}"/>.</exception> public Biasing(ICurrentControlledBindingContext context) : base(context) { context.ThrowIfNull(nameof(context)); context.Nodes.CheckNodes(2); Parameters = context.GetParameterSet <Parameters>(); _biasing = context.GetState <IBiasingSimulationState>(); _variables = new OnePort <double>(_biasing, context); _control = context.ControlBehaviors.GetValue <IBranchedBehavior <double> >().Branch; var pos = _biasing.Map[_variables.Positive]; var neg = _biasing.Map[_variables.Negative]; var br = _biasing.Map[_control]; _elements = new ElementSet <double>(_biasing.Solver, new MatrixLocation(pos, br), new MatrixLocation(neg, br)); }
/// <summary> /// Initializes a new instance of the <see cref="BiasingBehavior"/> class. /// </summary> /// <param name="context">The context.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception> public BiasingBehavior(IComponentBindingContext context) : base(context) { context.ThrowIfNull(nameof(context)); Parameters = context.GetParameterSet <IndependentSourceParameters>(); _iteration = context.GetState <IIterationSimulationState>(); context.TryGetState(out _method); Waveform = Parameters.Waveform?.Create(_method); if (!Parameters.DcValue.Given) { // No DC value: either have a transient value or none if (Waveform != null) { SpiceSharpWarning.Warning(this, Properties.Resources.IndependentSources_NoDcUseWaveform.FormatString(Name)); Parameters.DcValue = new GivenParameter <double>(Waveform.Value, false); } else { SpiceSharpWarning.Warning(this, Properties.Resources.IndependentSources_NoDc.FormatString(Name)); } } // Connections _biasing = context.GetState <IBiasingSimulationState>(); context.TryGetState(out _method); _variables = new OnePort <double>(_biasing, context); Branch = _biasing.CreatePrivateVariable(Name.Combine("branch"), Units.Ampere); var pos = _biasing.Map[_variables.Positive]; var neg = _biasing.Map[_variables.Negative]; var br = _biasing.Map[Branch]; _elements = new ElementSet <double>(_biasing.Solver, new[] { new MatrixLocation(pos, br), new MatrixLocation(br, pos), new MatrixLocation(neg, br), new MatrixLocation(br, neg) }, new[] { br }); }
/// <summary> /// Initializes a new instance of the <see cref="BiasingBehavior"/> class. /// </summary> /// <param name="context">The context.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception> public BiasingBehavior(IComponentBindingContext context) : base(context) { context.ThrowIfNull(nameof(context)); context.Nodes.CheckNodes(4); _biasing = context.GetState <IBiasingSimulationState>(); Parameters = context.GetParameterSet <Parameters>(); _variables = new TwoPort <double>(_biasing, context); var pos = _biasing.Map[_variables.Right.Positive]; var neg = _biasing.Map[_variables.Right.Negative]; var contPos = _biasing.Map[_variables.Left.Positive]; var contNeg = _biasing.Map[_variables.Left.Negative]; _elements = new ElementSet <double>(_biasing.Solver, new[] { new MatrixLocation(pos, contPos), new MatrixLocation(pos, contNeg), new MatrixLocation(neg, contPos), new MatrixLocation(neg, contNeg) }); }
/// <summary> /// Initializes a new instance of the <see cref="Biasing"/> class. /// </summary> /// <param name="context">The context.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception> public Biasing(IComponentBindingContext context) : base(context) { context.ThrowIfNull(nameof(context)); Parameters = context.GetParameterSet <Parameters>(); _biasing = context.GetState <IBiasingSimulationState>(); _iteration = context.GetState <IIterationSimulationState>(); _variables = new OnePort <double>(_biasing, context); context.TryGetState <IIntegrationMethod>(out _method); Waveform = Parameters.Waveform?.Create(context); // Give some warnings if no value is given if (!Parameters.DcValue.Given) { // no DC value - either have a transient value or none SpiceSharpWarning.Warning(this, Waveform != null ? Properties.Resources.IndependentSources_NoDcUseWaveform.FormatString(Name) : Properties.Resources.IndependentSources_NoDc.FormatString(Name)); } _elements = new ElementSet <double>(_biasing.Solver, null, _variables.GetRhsIndices(_biasing.Map)); }
/// <summary> /// Initializes a new instance of the <see cref="Biasing"/> class. /// </summary> /// <param name="context">The context.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception> public Biasing(IComponentBindingContext context) : base(context) { context.ThrowIfNull(nameof(context)); context.Nodes.CheckNodes(4); Parameters = context.GetParameterSet <Parameters>(); _biasing = context.GetState <IBiasingSimulationState>(); _variables = new TwoPort <double>(_biasing, context); Branch = _biasing.CreatePrivateVariable(Name.Combine("branch"), Units.Ampere); var pos = _biasing.Map[_variables.Right.Positive]; var neg = _biasing.Map[_variables.Right.Negative]; var contPos = _biasing.Map[_variables.Left.Positive]; var contNeg = _biasing.Map[_variables.Left.Negative]; var br = _biasing.Map[Branch]; _elements = new ElementSet <double>(_biasing.Solver, new MatrixLocation(pos, br), new MatrixLocation(neg, br), new MatrixLocation(br, pos), new MatrixLocation(br, neg), new MatrixLocation(br, contPos), new MatrixLocation(br, contNeg)); }
/// <summary> /// Initializes a new instance of the <see cref="Instance" /> class. /// </summary> /// <param name="parameters">The parameters.</param> /// <param name="state">The biasing simulation state.</param> public Instance(Gear parameters, IBiasingSimulationState state) : base(parameters, state, _gearOrder) { }
/// <summary> /// Initializes a new instance of the <see cref="Instance"/> class. /// </summary> /// <param name="parameters">The parameters.</param> /// <param name="state">The biasing simulation state.</param> public Instance(Trapezoidal parameters, IBiasingSimulationState state) : base(parameters, state, _trapezoidalOrder) { _xmu = parameters.Xmu; }
/// <inheritdoc /> public void Update(IBiasingSimulationState state, CircuitContext context, IDiagnosticHandler diagnostics) { }
/// <summary> /// Creates an instance of the integration method. /// </summary> /// <param name="state">The biasing simulation state that will be used as a base.</param> /// <returns> /// The integration method. /// </returns> public override IIntegrationMethod Create(IBiasingSimulationState state) => new Instance(this, state);