/// <summary> /// Execute behavior /// </summary> void IBiasingBehavior.Load() { var state = _state.ThrowIfNotBound(this); double value; PosBranchPtr.Value += 1; BranchPosPtr.Value += 1; NegBranchPtr.Value -= 1; BranchNegPtr.Value -= 1; if (Simulation is TimeSimulation) { // Use the waveform if possible if (BaseParameters.Waveform != null) { value = BaseParameters.Waveform.Value; } else { value = BaseParameters.DcValue * state.SourceFactor; } } else { value = BaseParameters.DcValue * state.SourceFactor; } Voltage = value; BranchPtr.Value += value; }
/// <summary> /// Loads the Y-matrix and Rhs-vector. /// </summary> void IBiasingBehavior.Load() { bool currentState; var state = _state.ThrowIfNotBound(this); // decide the state of the switch if (state.Init == InitializationModes.Fix || state.Init == InitializationModes.Junction) { if (BaseParameters.ZeroState) { // Switch specified "on" CurrentState = true; currentState = true; } else { // Switch specified "off" CurrentState = false; currentState = false; } } else { // Get the previous state var ctrl = Method.GetValue(state); if (UseOldState) { // Calculate the current state if (ctrl > ModelParameters.Threshold + ModelParameters.Hysteresis) { currentState = true; } else if (ctrl < ModelParameters.Threshold - ModelParameters.Hysteresis) { currentState = false; } else { currentState = PreviousState; } CurrentState = currentState; UseOldState = false; } else { PreviousState = CurrentState; // Calculate the current state if (ctrl > ModelParameters.Threshold + ModelParameters.Hysteresis) { CurrentState = true; currentState = true; } else if (ctrl < ModelParameters.Threshold - ModelParameters.Hysteresis) { CurrentState = false; currentState = false; } else { currentState = PreviousState; } // Ensure one more iteration if (currentState != PreviousState) { state.IsConvergent = false; } } // Store the current state CurrentState = currentState; // If the state changed, ensure one more iteration if (currentState != PreviousState) { state.IsConvergent = false; } } // Get the current conduction var gNow = currentState ? ModelParameters.OnConductance : ModelParameters.OffConductance; Conductance = gNow; // Load the Y-matrix PosPosPtr.Value += gNow; PosNegPtr.Value -= gNow; NegPosPtr.Value -= gNow; NegNegPtr.Value += gNow; }