public void When_CircuitInstantiateOp_Expect_Reference() { var ckt = new Circuit( new VoltageSource("V1", "in", "0", 1.0)); var subckt = new ComponentInstanceData(new Circuit( new Resistor("Ra", "in", "out", 100), new Resistor("Rb", "out", "0", 100))); // Instantiate a subcircuit subckt.Name = "A"; subckt.NodeMap.Add("0", "0"); subckt.NodeMap["in"] = "in"; subckt.NodeMap["out"] = "out"; ckt.Instantiate(subckt); // Instantiate the subcircuit a second time subckt.Name = "B"; subckt.NodeMap.Remove("out"); subckt.NodeMap["in"] = "out"; ckt.Instantiate(subckt); // Do an operating point simulation var op = new OP("op"); op.ExportSimulationData += (sender, e) => { // vout = Ra / (Ra + Rb//(Ra+Rb)) Assert.AreEqual(0.4, e.GetVoltage("out"), 1e-12); }; op.Run(ckt); }
public void When_CircuitInstantiate_Expect_Entities() { var ckt = new Circuit( new VoltageSource("V1", "in", "0", 1.0)); var subckt = new ComponentInstanceData(new Circuit( new Resistor("Ra", "in", "out", 100), new Resistor("Rb", "out", "0", 100))); // Instantiate a subcircuit subckt.Name = "A"; subckt.NodeMap.Add("0", "0"); subckt.NodeMap["in"] = "in"; subckt.NodeMap["out"] = "out"; ckt.Instantiate(subckt); // Instantiate the subcircuit a second time subckt.Name = "B"; subckt.NodeMap.Remove("out"); subckt.NodeMap["in"] = "out"; ckt.Instantiate(subckt); // Test Assert.AreEqual(ckt.Contains("A/Ra"), true); Assert.AreEqual(ckt.Contains("A/Rb"), true); Assert.AreEqual(ckt.Contains("B/Ra"), true); Assert.AreEqual(ckt.Contains("B/Rb"), true); }
public void When_Subcircuit_Expect_Reference() { var subckt = new Circuit( new BehavioralCurrentSource("H1", "internal", "0", "V(in)+1"), new Resistor("R1", "internal", "out", 1e3)); var ckt = new Circuit( new VoltageSource("V1", "a", "0", 0.5), new Resistor("R1", "b", "0", 1e3)); // Instantiate the subcircuit var instance = new ComponentInstanceData(subckt, "x1"); instance.NodeMap.Add("0", "0"); instance.NodeMap.Add("in", "a"); instance.NodeMap.Add("out", "b"); ckt.Instantiate(instance); // Do simulation var op = new OP("op"); AnalyzeOp(ckt, op, new[] { new RealVoltageExport(op, "b") }, new[] { -1500.0 }); }