/// <summary> /// Validate a circuit. /// </summary> /// <param name="entities">The circuit to be validated.</param> public void Validate(EntityCollection entities) { if (entities == null) { throw new ArgumentNullException(nameof(entities)); } // Initialize _hasSource = false; _voltageDriven.Clear(); _connectedGroups.Clear(); _connectedGroups.Add(0, 0); _cgroup = 1; _nodes.Clear(); // Check all entities foreach (var c in entities) { CheckEntity(c); } // Check if a voltage source is available if (!_hasSource) { throw new CircuitException("No independent source found"); } // Check if a circuit has ground if (!_hasGround) { throw new CircuitException("No ground found"); } // Check if a voltage driver is closing a loop var icc = FindVoltageDriveLoop(); if (icc != null) { throw new CircuitException("{0} closes a loop of voltage sources".FormatString(icc.Name)); } // Check for floating nodes var unconnected = FindFloatingNodes(); if (unconnected.Count > 0) { var un = new List <string>(); foreach (var n in _nodes) { var index = n.Index; if (unconnected.Contains(index)) { un.Add(n.Name); } } throw new CircuitException("{0}: Floating nodes found".FormatString(string.Join(",", un))); } }
/// <summary> /// Validate a circuit /// </summary> /// <param name="circuit">The circuit</param> public void Validate(Circuit circuit) { if (circuit == null) { throw new ArgumentNullException(nameof(circuit)); } // Connect all objects in the circuit, we need this information to find connectivity issues circuit.Objects.BuildOrderedComponentList(); // Initialize _hasSource = false; _voltageDriven.Clear(); _connectedGroups.Clear(); _connectedGroups.Add(0, 0); _cgroup = 1; _nodes.Clear(); // Check all objects foreach (var c in circuit.Objects) { CheckEntity(c); } // Check if a voltage source is available if (!_hasSource) { throw new CircuitException("No independent source found"); } // Check if a circuit has ground if (!_hasGround) { throw new CircuitException("No ground found"); } // Check if a voltage driver is closing a loop var icc = FindVoltageDriveLoop(); if (icc != null) { throw new CircuitException("{0} closes a loop of voltage sources".FormatString(icc.Name)); } // Check for floating nodes var unconnected = FindFloatingNodes(); if (unconnected.Count > 0) { List <Identifier> un = new List <Identifier>(); for (int i = 0; i < _nodes.Count; i++) { int index = _nodes[i].Index; if (unconnected.Contains(index)) { un.Add(_nodes[i].Name); } } throw new CircuitException("{0}: Floating nodes found".FormatString(string.Join(",", un))); } }