/// <summary> /// Set up the simulation. /// </summary> /// <param name="circuit">The circuit that will be used.</param> /// <exception cref="ArgumentNullException">circuit</exception> /// <exception cref="SpiceSharp.CircuitException"> /// No frequency configuration found /// or /// No frequency sweep found /// </exception> protected override void Setup(Circuit circuit) { if (circuit == null) { throw new ArgumentNullException(nameof(circuit)); } base.Setup(circuit); // Get behaviors, configurations and states var config = Configurations.Get <FrequencyConfiguration>(); FrequencySweep = config.FrequencySweep ?? throw new CircuitException("No frequency sweep found"); // Create the state for complex numbers ComplexState = new ComplexSimulationState(); _loadStateEventArgs = new LoadStateEventArgs(ComplexState); var strategy = ComplexState.Solver.Strategy; strategy.RelativePivotThreshold = config.RelativePivotThreshold; strategy.AbsolutePivotThreshold = config.AbsolutePivotThreshold; // Setup behaviors _frequencyBehaviors = SetupBehaviors <BaseFrequencyBehavior>(circuit.Entities); var solver = ComplexState.Solver; for (var i = 0; i < _frequencyBehaviors.Count; i++) { _frequencyBehaviors[i].GetEquationPointers(solver); } ComplexState.Setup(Variables); }
/// <summary> /// Initializes a new instance of the <see cref="Noise"/> class. /// </summary> /// <param name="name">The identifier of the simulation.</param> /// <param name="output">The output node identifier.</param> /// <param name="reference">The reference output node identifier.</param> /// <param name="input">The input source identifier.</param> /// <param name="frequencySweep">The frequency sweep.</param> public Noise(string name, string output, string reference, string input, Sweep <double> frequencySweep) : base(name, frequencySweep) { Configurations.Add(new NoiseConfiguration(output, reference, input)); // Add behavior types in the order they are (usually) called BehaviorTypes.Add(typeof(INoiseBehavior)); }
/// <summary> /// Set up the simulation. /// </summary> /// <param name="entities">The circuit that will be used.</param> protected override void Setup(EntityCollection entities) { entities.ThrowIfNull(nameof(entities)); // Get behaviors, configurations and states var config = Configurations.Get <FrequencyConfiguration>(); FrequencySweep = config.FrequencySweep.ThrowIfNull("frequency sweep"); // Create the state for complex numbers ComplexState = new ComplexSimulationState(); var strategy = ComplexState.Solver.Strategy; strategy.RelativePivotThreshold = config.RelativePivotThreshold; strategy.AbsolutePivotThreshold = config.AbsolutePivotThreshold; // Setup the rest of the behaviors base.Setup(entities); // Cache local variables _frequencyBehaviors = EntityBehaviors.GetBehaviorList <IFrequencyBehavior>(); _loadStateEventArgs = new LoadStateEventArgs(ComplexState); ComplexState.Setup(Variables); }
/// <summary> /// Set up the simulation. /// </summary> /// <param name="entities">The circuit that will be used.</param> /// <exception cref="ArgumentNullException">circuit</exception> /// <exception cref="SpiceSharp.CircuitException"> /// No frequency configuration found /// or /// No frequency sweep found /// </exception> protected override void Setup(EntityCollection entities) { entities.ThrowIfNull(nameof(entities)); base.Setup(entities); // Get behaviors, configurations and states var config = Configurations.Get <FrequencyConfiguration>(); _frequencyBehaviors = EntityBehaviors.GetBehaviorList <IFrequencyBehavior>(); FrequencySweep = config.FrequencySweep.ThrowIfNull("frequency sweep"); // Create the state for complex numbers ComplexState = new ComplexSimulationState(); _loadStateEventArgs = new LoadStateEventArgs(ComplexState); var strategy = ComplexState.Solver.Strategy; strategy.RelativePivotThreshold = config.RelativePivotThreshold; strategy.AbsolutePivotThreshold = config.AbsolutePivotThreshold; // Setup behaviors var solver = ComplexState.Solver; for (var i = 0; i < _frequencyBehaviors.Count; i++) { _frequencyBehaviors[i].GetEquationPointers(solver); } ComplexState.Setup(Variables); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name</param> /// <param name="frequencySweep">Sweep for the frequency points</param> protected FrequencySimulation(Identifier name, Sweep <double> frequencySweep) : base(name) { ParameterSets.Add(new FrequencyConfiguration(frequencySweep)); // Create a complex state with shared matrix States.Add(new ComplexState()); }
/// <summary> /// Initializes a new instance of the <see cref="FrequencySimulation"/> class. /// </summary> /// <param name="name">The identifier of the simulation.</param> /// <param name="frequencySweep">The frequency sweep.</param> protected FrequencySimulation(string name, Sweep <double> frequencySweep) : base(name) { Configurations.Add(new FrequencyConfiguration(frequencySweep)); // Add behavior types in the order they are (usually) called BehaviorTypes.Add(typeof(IFrequencyBehavior)); }
/// <summary> /// Destroys the simulation. /// </summary> protected override void Unsetup() { // Remove references for (var i = 0; i < _frequencyBehaviors.Count; i++) { _frequencyBehaviors[i].Unbind(); } _frequencyBehaviors = null; // Remove the state ComplexState.Unsetup(); ComplexState = null; // Configuration FrequencySweep = null; base.Unsetup(); }
/// <summary> /// Unsetup the simulation /// </summary> protected override void Unsetup() { // Remove references for (int i = 0; i < FrequencyBehaviors.Count; i++) { FrequencyBehaviors[i].Unsetup(); } FrequencyBehaviors = null; // Remove the state ComplexState.Destroy(); ComplexState = null; // Configuration FrequencyConfiguration = null; FrequencySweep = null; base.Unsetup(); }
/// <summary> /// Setup the simulation /// </summary> /// <param name="circuit">Circuit</param> protected override void Setup(Circuit circuit) { if (circuit == null) { throw new ArgumentNullException(nameof(circuit)); } base.Setup(circuit); // Get behaviors, configurations and states ComplexState = States.Get <ComplexState>() ?? throw new CircuitException("No complex state found"); FrequencyConfiguration = ParameterSets.Get <FrequencyConfiguration>() ?? throw new CircuitException("No frequency configuration found"); FrequencySweep = FrequencyConfiguration.FrequencySweep ?? throw new CircuitException("No frequency sweep found"); FrequencyBehaviors = SetupBehaviors <BaseFrequencyBehavior>(circuit.Objects); var solver = ComplexState.Solver; for (int i = 0; i < FrequencyBehaviors.Count; i++) { FrequencyBehaviors[i].GetEquationPointers(solver); } }
/// <summary> /// Initializes a new instance of the <see cref="AC"/> class. /// </summary> /// <param name="name">The identifier of the simulation.</param> /// <param name="frequencySweep">The frequency sweep.</param> public AC(string name, Sweep <double> frequencySweep) : base(name, frequencySweep) { }
/// <summary> /// Initializes a new instance of the <see cref="FrequencySimulation"/> class. /// </summary> /// <param name="name">The identifier of the simulation.</param> /// <param name="frequencySweep">The frequency sweep.</param> protected FrequencySimulation(string name, Sweep <double> frequencySweep) : base(name) { Configurations.Add(new FrequencyConfiguration(frequencySweep)); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name</param> /// <param name="frequencySweep">Frequency sweep</param> public AC(Identifier name, Sweep <double> frequencySweep) : base(name, frequencySweep) { }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name</param> /// <param name="output">Output node</param> /// <param name="reference">Reference output node</param> /// <param name="input">Input</param> /// <param name="frequencySweep">Frequency sweep</param> public Noise(Identifier name, Identifier output, Identifier reference, Identifier input, Sweep <double> frequencySweep) : base(name, frequencySweep) { ParameterSets.Add(new NoiseConfiguration(output, reference, input)); States.Add(new NoiseState()); }
/// <summary> /// Constructor /// </summary> /// <param name="name">The name of the simulation</param> /// <param name="source">The name of the swept source</param> /// <param name="start">The starting value</param> /// <param name="stop">The stopping value</param> /// <param name="step">The step value</param> public DC(string name, CircuitIdentifier source, double start, double stop, double step) : base(name) { Sweep s = new Sweep(source, start, stop, step); Sweeps.Add(s); }
/// <summary> /// Initializes a new instance of the <see cref="Noise"/> class. /// </summary> /// <param name="name">The identifier of the simulation.</param> /// <param name="output">The output node identifier.</param> /// <param name="reference">The reference output node identifier.</param> /// <param name="input">The input source identifier.</param> /// <param name="frequencySweep">The frequency sweep.</param> public Noise(string name, string output, string reference, string input, Sweep <double> frequencySweep) : base(name, frequencySweep) { Configurations.Add(new NoiseConfiguration(output, reference, input)); }