/// <summary>Adds device to the circuit and connects it to the specified nodes.</summary> /// <param name="nodeConnections">Ids of the nodes to which the device terminals should connect.</param> /// <param name="device">The device to be added.</param> /// <returns></returns> public CircuitBuilder AddDevice(int[] nodeConnections, ICircuitDefinitionDevice device) { if (device.Tag != null && namedDevices.ContainsKey(device.Tag)) { throw new InvalidOperationException($"Circuit already contains device with name '{device.Tag}'"); } if (device.ConnectedNodes.Count != nodeConnections.Length) { throw new ArgumentException("Wrong number of connections."); } if (devices.Contains(device)) { throw new InvalidOperationException("Cannot insert same device twice more than once."); } // connect to nodes for (var i = 0; i < nodeConnections.Length; i++) { var id = nodeConnections[i]; EnsureHasNode(id); device.ConnectedNodes[i] = id; } devices.Add(device); if (device.Tag != null) { namedDevices[device.Tag] = device; } // invalidate cached validation result validatedCircuit = false; circuitException = null; return(this); }
/// <summary>Initializes a new instance of the <see cref="T:System.Object"></see> class.</summary> public CircuitBranchMetadata(int n1, int n2, BranchType branchType, ICircuitDefinitionDevice device) { N1 = n1; N2 = n2; BranchType = branchType; Device = device; }
/// <summary>Creates model instance for given definition device.</summary> /// <param name="device">Device to be instantiated.</param> /// <returns></returns> private IAnalysisDeviceModel <TAnalysisModel> CreateModel(ICircuitDefinitionDevice device) { if (modelCreators.TryGetValue(device.GetType(), out var factory)) { return(factory(device, this)); } throw new InvalidOperationException($"No model creator for type {device.GetType()}"); }
/// <summary>Gets model instance for a given device definition instance.</summary> /// <param name="device">The device definition.</param> /// <returns></returns> public IAnalysisDeviceModel <TAnalysisModel> GetModel(ICircuitDefinitionDevice device) { if (device == null) { throw new ArgumentNullException(nameof(device)); } if (resolutionCache.TryGetValue(device, out var model)) { return(model); } return(resolutionCache[device] = CreateModel(device)); }
/// <summary>Returns device implementation for corresponding circuit definition device.</summary> /// <param name="device">The tag of the queried device.</param> /// <returns></returns> public ILargeSignalDevice FindDevice(ICircuitDefinitionDevice device) { deviceLookup.TryGetValue(device, out var ret); return(ret); }
public ITestDeviceModel FindDevice(ICircuitDefinitionDevice device) { throw new NotImplementedException(); }