/// <summary> /// Bind the behavior. /// </summary> public override void Bind(Simulation simulation, BindingContext context) { base.Bind(simulation, context); // Cache some objects that we will use often _bp = context.GetParameterSet <BaseParameters>(); _state = ((BaseSimulation)simulation).RealState; _baseConfig = simulation.Configurations.Get <BaseConfiguration>(); // Find the nodes that the resistor is connected to if (context is ComponentBindingContext cbc) { _nodeA = cbc.Pins[0]; _nodeB = cbc.Pins[1]; } // We need 4 matrix elements here var solver = _state.Solver; _aaPtr = solver.GetMatrixElement(_nodeA, _nodeA); _abPtr = solver.GetMatrixElement(_nodeA, _nodeB); _baPtr = solver.GetMatrixElement(_nodeB, _nodeA); _bbPtr = solver.GetMatrixElement(_nodeB, _nodeB); // We also need 2 RHS vector elements _aPtr = solver.GetRhsElement(_nodeA); _bPtr = solver.GetRhsElement(_nodeB); }
/// <summary> /// Creates a new instance of the <see cref="BiasingBehavior"/> class. /// </summary> /// <param name="name">The name of the behavior.</param> public BiasingBehavior(string name, ComponentBindingContext context) : base(name) { if (context == null) { throw new ArgumentNullException(nameof(context)); } // Get our resistor parameters (we want our A and B parameter values) _bp = context.GetParameterSet <BaseParameters>(); // Get the simulation parameters (we want to use Gmin) _baseConfig = context.GetSimulationParameterSet <BiasingParameters>(); // Request the node variables var state = context.GetState <IBiasingSimulationState>(); _nodeA = state.GetSharedVariable(context.Nodes[0]); _nodeB = state.GetSharedVariable(context.Nodes[1]); // We need 4 matrix elements and 2 RHS vector elements var indexA = state.Map[_nodeA]; var indexB = state.Map[_nodeB]; _elements = new ElementSet <double>(state.Solver, new[] { new MatrixLocation(indexA, indexA), new MatrixLocation(indexA, indexB), new MatrixLocation(indexB, indexA), new MatrixLocation(indexB, indexB) }, new[] { indexA, indexB }); }
/// <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; }
// Remove all references cached during setup public override void Unsetup(Simulation simulation) { _bp = null; }
// Get the base parameters public override void Setup(Simulation simulation, SetupDataProvider provider) { _baseConfig = simulation.Configurations.Get <BaseConfiguration>(); _bp = provider.GetParameterSet <BaseParameters>(); }