/// <summary> /// Set up the simulation. /// </summary> /// <param name="entities">The circuit that will be used.</param> /// <exception cref="ArgumentNullException">circuit</exception> protected override void Setup(EntityCollection entities) { entities.ThrowIfNull(nameof(entities)); base.Setup(entities); // Get behaviors _noiseBehaviors = EntityBehaviors.GetBehaviorList <INoiseBehavior>(); // Get behaviors, parameters and states NoiseConfiguration = Configurations.Get <NoiseConfiguration>(); NoiseState = new NoiseState(); NoiseState.Setup(Variables); }
/// <summary> /// Set up the simulation. /// </summary> /// <param name="circuit">The circuit that will be used.</param> /// <exception cref="ArgumentNullException">circuit</exception> protected override void Setup(Circuit circuit) { if (circuit == null) { throw new ArgumentNullException(nameof(circuit)); } base.Setup(circuit); // Get behaviors _noiseBehaviors = EntityBehaviors.GetBehaviorList <INoiseBehavior>(); // Get behaviors, parameters and states NoiseConfiguration = Configurations.Get <NoiseConfiguration>(); NoiseState = new NoiseState(); NoiseState.Setup(Variables); }
/// <summary> /// Collect behaviors of all circuit entities while also setting them up /// </summary> /// <typeparam name="T">Base behavior</typeparam> /// <returns></returns> protected BehaviorList <T> SetupBehaviors <T>(IEnumerable <Entity> entities) where T : Behavior { if (entities == null) { throw new ArgumentNullException(nameof(entities)); } // Register all behaviors foreach (var o in entities) { T behavior = o.CreateBehavior <T>(this); if (behavior != null) { EntityBehaviors.Add(o.Name, behavior); } } return(EntityBehaviors.GetBehaviorList <T>()); }
/// <summary> /// Set up the simulation. /// </summary> /// <param name="circuit">The circuit that will be used.</param> /// <exception cref="ArgumentNullException">circuit</exception> protected override void Setup(EntityCollection circuit) { circuit.ThrowIfNull(nameof(circuit)); base.Setup(circuit); // Get behaviors and configuration data var config = Configurations.Get <BaseConfiguration>().ThrowIfNull("base configuration"); DcMaxIterations = config.DcMaxIterations; AbsTol = config.AbsoluteTolerance; RelTol = config.RelativeTolerance; _temperatureBehaviors = EntityBehaviors.GetBehaviorList <ITemperatureBehavior>(); _loadBehaviors = EntityBehaviors.GetBehaviorList <IBiasingBehavior>(); _initialConditionBehaviors = EntityBehaviors.GetBehaviorList <IInitialConditionBehavior>(); // Create the state for this simulation RealState = new BaseSimulationState { Gmin = config.Gmin }; _isPreordered = false; _shouldReorder = true; var strategy = RealState.Solver.Strategy; strategy.RelativePivotThreshold = config.RelativePivotThreshold; strategy.AbsolutePivotThreshold = config.AbsolutePivotThreshold; // Setup the load behaviors _realStateLoadArgs = new LoadStateEventArgs(RealState); for (var i = 0; i < _loadBehaviors.Count; i++) { _loadBehaviors[i].GetEquationPointers(Variables, RealState.Solver); } RealState.Setup(Variables); // Set up nodesets foreach (var ns in config.Nodesets) { _nodesets.Add(new ConvergenceAid(ns.Key, ns.Value)); } }
/// <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"> /// {0}: No time configuration".FormatString(Name) /// or /// {0}: No integration method specified".FormatString(Name) /// </exception> protected override void Setup(Circuit circuit) { if (circuit == null) { throw new ArgumentNullException(nameof(circuit)); } base.Setup(circuit); // Get behaviors and configurations var config = Configurations.Get <TimeConfiguration>() ?? throw new CircuitException("{0}: No time configuration".FormatString(Name)); _useIc = config.UseIc; Method = config.Method ?? throw new CircuitException("{0}: No integration method specified".FormatString(Name)); _transientBehaviors = EntityBehaviors.GetBehaviorList <ITimeBehavior>(); _acceptBehaviors = EntityBehaviors.GetBehaviorList <IAcceptBehavior>(); // Allow all transient behaviors to allocate equation elements and create states for (var i = 0; i < _transientBehaviors.Count; i++) { _transientBehaviors[i].GetEquationPointers(RealState.Solver); _transientBehaviors[i].CreateStates(Method); } Method.Setup(this); // TODO: Compatibility - initial conditions from nodes instead of configuration should be removed eventually if (config.InitialConditions.Count == 0) { foreach (var ns in Variables.InitialConditions) { _initialConditions.Add(new ConvergenceAid(ns.Key, ns.Value)); } } // Set up initial conditions foreach (var ic in config.InitialConditions) { _initialConditions.Add(new ConvergenceAid(ic.Key, ic.Value)); } }
/// <inheritdoc/> protected override void CreateBehaviors(IEntityCollection entities) { base.CreateBehaviors(entities); _transientBehaviors = EntityBehaviors.GetBehaviorList <ITimeBehavior>(); _acceptBehaviors = EntityBehaviors.GetBehaviorList <IAcceptBehavior>(); _truncatingBehaviors = EntityBehaviors.GetBehaviorList <ITruncatingBehavior>(); _method.Initialize(); // Set up initial conditions var state = GetState <IBiasingSimulationState>(); _initialConditions.Clear(); foreach (var ic in TimeParameters.InitialConditions) { if (state.ContainsKey(ic.Key)) { _initialConditions.Add(new ConvergenceAid(state.GetSharedVariable(ic.Key), GetState <IBiasingSimulationState>(), ic.Value)); } else { SpiceSharpWarning.Warning(this, Properties.Resources.Simulations_ConvergenceAidVariableNotFound.FormatString(ic.Key)); } } }
/// <inheritdoc /> protected override void CreateBehaviors(IEntityCollection entities) { base.CreateBehaviors(entities); _noiseBehaviors = EntityBehaviors.GetBehaviorList <INoiseBehavior>(); }